From b1737bf29d2542852ed35f4806dd673447b42fa9 Mon Sep 17 00:00:00 2001 From: Yevgen Muntyan <17531749+muntyan@users.noreply.github.com> Date: Fri, 1 Jul 2005 10:26:55 +0000 Subject: [PATCH] MooTermBuffer::set_window_title, MooTermBuffer::set_icon_name signals --- moo/mooterm/mootermbuffer-private.h | 18 +++++---------- moo/mooterm/mootermbuffer.c | 35 +++++++++++++++++++++++++++++ moo/mooterm/mootermbuffer.h | 4 ++++ moo/mooterm/mootermparser.c | 8 +++---- moo/mooterm/mootermvt-unix.c | 13 ----------- tests/mterm.c | 3 +++ 6 files changed, 52 insertions(+), 29 deletions(-) diff --git a/moo/mooterm/mootermbuffer-private.h b/moo/mooterm/mootermbuffer-private.h index 8a4a6da6..8eec88e6 100644 --- a/moo/mooterm/mootermbuffer-private.h +++ b/moo/mooterm/mootermbuffer-private.h @@ -225,6 +225,12 @@ inline static void buf_thaw_cursor_notify (MooTermBuffer *buf) } +void moo_term_buffer_set_window_title (MooTermBuffer *buf, + const char *title); +void moo_term_buffer_set_icon_name (MooTermBuffer *buf, + const char *icon); + + /***************************************************************************/ typedef enum { @@ -826,18 +832,6 @@ inline static void buf_esc_m (G_GNUC_UNUSED MooTermBuffer *b g_warning ("%s: implement me", G_STRLOC); } -inline static void buf_set_window_title (G_GNUC_UNUSED MooTermBuffer *buf, - G_GNUC_UNUSED const char *title) -{ - g_warning ("%s: implement me", G_STRLOC); -} - -inline static void buf_set_icon_name (G_GNUC_UNUSED MooTermBuffer *buf, - G_GNUC_UNUSED const char *name) -{ - g_warning ("%s: implement me", G_STRLOC); -} - G_END_DECLS diff --git a/moo/mooterm/mootermbuffer.c b/moo/mooterm/mootermbuffer.c index fb0f9c76..5167cea5 100644 --- a/moo/mooterm/mootermbuffer.c +++ b/moo/mooterm/mootermbuffer.c @@ -43,6 +43,8 @@ enum { BELL, FLASH_SCREEN, SCREEN_SIZE_CHANGED, + SET_WINDOW_TITLE, + SET_ICON_NAME, LAST_SIGNAL }; @@ -122,6 +124,26 @@ static void moo_term_buffer_class_init (MooTermBufferClass *klass) G_TYPE_NONE, 2, G_TYPE_ULONG, G_TYPE_ULONG); + signals[SET_WINDOW_TITLE] = + g_signal_new ("set-window-title", + G_OBJECT_CLASS_TYPE (gobject_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (MooTermBufferClass, set_window_title), + NULL, NULL, + _moo_marshal_VOID__STRING, + G_TYPE_NONE, 1, + G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE); + + signals[SET_ICON_NAME] = + g_signal_new ("set-icon-name", + G_OBJECT_CLASS_TYPE (gobject_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (MooTermBufferClass, set_icon_name), + NULL, NULL, + _moo_marshal_VOID__STRING, + G_TYPE_NONE, 1, + G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE); + g_object_class_install_property (gobject_class, PROP_SCREEN_WIDTH, g_param_spec_ulong ("screen-width", @@ -609,3 +631,16 @@ MooTermBuffer *moo_term_buffer_new (gulong width, "screen-height", height, NULL)); } + + +void moo_term_buffer_set_window_title (MooTermBuffer *buf, + const char *title) +{ + g_signal_emit (buf, signals[SET_WINDOW_TITLE], 0, title); +} + +void moo_term_buffer_set_icon_name (MooTermBuffer *buf, + const char *icon) +{ + g_signal_emit (buf, signals[SET_ICON_NAME], 0, icon); +} diff --git a/moo/mooterm/mootermbuffer.h b/moo/mooterm/mootermbuffer.h index 36651e12..6598fa1e 100644 --- a/moo/mooterm/mootermbuffer.h +++ b/moo/mooterm/mootermbuffer.h @@ -83,6 +83,10 @@ struct _MooTermBufferClass { void (*bell) (MooTermBuffer *buf); void (*flash_screen) (MooTermBuffer *buf); + void (*set_window_title) (MooTermBuffer *buf, + const char *title); + void (*set_icon_name) (MooTermBuffer *buf, + const char *icon); }; diff --git a/moo/mooterm/mootermparser.c b/moo/mooterm/mootermparser.c index 1e15d709..49788bf5 100644 --- a/moo/mooterm/mootermparser.c +++ b/moo/mooterm/mootermparser.c @@ -462,10 +462,10 @@ static ParseCharResult parse_char (MooTermParser *p, const char *c) { case BEL: p->state = CLEAN; - p->title_len = p->buffer_len - 3; + p->title_len = p->buffer_len > 3 ? p->buffer_len - 4 : 0; if (p->title_len) - memcpy (p->title, p->buffer + 3, p->title_len); + memcpy (p->title, p->buffer + 4, p->title_len); else DEBUG_PRINT ("got \E]^G", NULL, 0); @@ -1526,9 +1526,9 @@ static void exec_command (MooTermParser *parser) title = g_strndup (parser->title, parser->title_len); if (set_title) - buf_set_window_title (parser->parent, title); + moo_term_buffer_set_window_title (parser->parent, title); if (set_icon) - buf_set_icon_name (parser->parent, title); + moo_term_buffer_set_icon_name (parser->parent, title); g_free (title); } diff --git a/moo/mooterm/mootermvt-unix.c b/moo/mooterm/mootermvt-unix.c index 28903651..a56143ae 100644 --- a/moo/mooterm/mootermvt-unix.c +++ b/moo/mooterm/mootermvt-unix.c @@ -34,7 +34,6 @@ #include #endif - #define TERM_EMULATION "xterm" #define READ_BUFSIZE 4096 #define POLL_TIME 5 @@ -341,18 +340,6 @@ static gboolean read_child_out (G_GNUC_UNUSED GIOChannel *source, break; default: - { - int i; - g_print ("got >>>"); - for (i = 0; i < r; ++i) - { - if (32 <= buf[i] && buf[i] <= 126) - g_print ("%c", buf[i]); - else - g_print ("<%d>", buf[i]); - } - g_print ("<<<\n"); - } feed_buffer (vt, buf, r); break; } diff --git a/tests/mterm.c b/tests/mterm.c index cd07bb0e..57cf9f19 100644 --- a/tests/mterm.c +++ b/tests/mterm.c @@ -57,6 +57,9 @@ int main (int argc, char *argv[]) "cursor-visible", TRUE, NULL); + g_signal_connect_swapped (buf, "set-window-title", + G_CALLBACK (gtk_window_set_title), win); + moo_term_fork_command (MOO_TERM (term), cmd, NULL, NULL); g_signal_connect (G_OBJECT (win), "destroy", gtk_main_quit, NULL);