* doc/HELPER-PROTOCOL - Add im_switcher_start and im_switcher_quit to fix bug #2112. * helper/im-switcher-gtk.c - (parse_helper_str): Call parse_helper_str_im_switcher() to parse "im_switcher_{start,quit}". - (parse_helper_str_im_switcher): New function. - (main): Check if another uim-im-switcher exists by trying to contact one. If one exists, this process exits. * qt4/switcher/qt4.cpp - (UimImSwitcher::UimImSwitcher): Check if another uim-im-switcher exists by trying to contact one. If one exists, this process exits. - (UimImSwitcher::slotStdinActivated): Call parseHelperStrImSwitcher() to parse "im_switcher_{start,quit}". - (UimImSwitcher::parseHelperStrImSwitcher): New function. * qt4/switcher/qt4.h - (UimImSwitcher): Add parseHelperStrImSwitcher(). --- doc/HELPER-PROTOCOL | 23 ++++++++++++++++++++++- helper/im-switcher-gtk.c | 16 ++++++++++++++++ qt4/switcher/qt4.cpp | 13 +++++++++++++ qt4/switcher/qt4.h | 2 +- 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/doc/HELPER-PROTOCOL b/doc/HELPER-PROTOCOL index 2787ce6..1d6ee8f 100644 --- a/doc/HELPER-PROTOCOL +++ b/doc/HELPER-PROTOCOL @@ -91,7 +91,9 @@ protocol within uim. im_change_this_application_only | prop_update_custom | custom_reload_notify | - commit_string) "\n" + commit_string | + im_switcher_start | + im_switcher_quit) "\n" charset_specifier = "charset=" charset "\n" charset = "UTF-8" | "EUC-JP" | "GB18030" | @@ -324,6 +326,25 @@ protocol within uim. commit_string = "commit_string\n" charset_specifier str_to_commit "\n" str_to_commit = /^[^\n]+$/ + - im_switcher_start + + This message notifies that a new uim-im-switcher is started. + When an existing old uim-im-switcher receives im_switcher_start, + the existing uim-im-switcher must send im_switcher_quit + to quit newly started uim-im-switcher. + + See also im_switcher_quit. + + im_switcher_start = "im_switcher_start\n" + + - im_switcher_quit + + This message requests newly started uim-im-switcher to quit. + All uim-im-switcher must quit immediately after received this message. + + See also im_switcher_start. + + im_switcher_quit = "im_switcher_quit\n" Local Variables: mode: indented-text diff --git a/helper/im-switcher-gtk.c b/helper/im-switcher-gtk.c index af09ae2..9bcd853 100644 --- a/helper/im-switcher-gtk.c +++ b/helper/im-switcher-gtk.c @@ -56,6 +56,8 @@ reload_im_list(GtkWindow *window, gpointer user_data); static void parse_helper_str(const char *sent_str); static void +parse_helper_str_im_switcher(const char *im_switcher_str_new); +static void parse_helper_str_im_list(const char *im_list_str_new); static void check_helper_connection(void); @@ -430,6 +432,8 @@ parse_helper_str(const char *sent_str) { if (g_str_has_prefix(sent_str, "im_list") == TRUE) { parse_helper_str_im_list(sent_str); + } else if (g_str_has_prefix(sent_str, "im_switcher_") == TRUE) { + parse_helper_str_im_switcher(sent_str); } } @@ -443,6 +447,15 @@ get_text(const char *str) } static void +parse_helper_str_im_switcher(const char *im_switcher_str_new) +{ + if (g_str_has_prefix(im_switcher_str_new, "im_switcher_start\n") == TRUE) + uim_helper_send_message(uim_fd, "im_switcher_quit\n"); + else if (g_str_has_prefix(im_switcher_str_new, "im_switcher_quit\n") == TRUE) + gtk_main_quit(); +} + +static void parse_helper_str_im_list(const char *im_list_str_new) { gchar **lines; @@ -556,6 +569,9 @@ main(int argc, char *argv[]) uim_fd = -1; check_helper_connection(); + /* to check if another uim-im-switcher exists */ + uim_helper_send_message( uim_fd, "im_switcher_start\n" ); + /* To load input method list */ uim_helper_send_message(uim_fd, "im_list_get\n"); diff --git a/qt4/switcher/qt4.cpp b/qt4/switcher/qt4.cpp index f29b42a..3057ed7 100644 --- a/qt4/switcher/qt4.cpp +++ b/qt4/switcher/qt4.cpp @@ -85,6 +85,9 @@ UimImSwitcher::UimImSwitcher( QWidget *parent ) uim_fd = -1; checkHelperConnection(); + /* to check if another uim-im-switcher exists */ + uim_helper_send_message( uim_fd, "im_switcher_start\n" ); + /* to load input method list */ uim_helper_send_message( uim_fd, "im_list_get\n" ); @@ -244,6 +247,8 @@ void UimImSwitcher::slotStdinActivated() reloadImList(); else if ( msg.startsWith( QLatin1String( "im_list" ) ) ) parseHelperStrImList( msg ); + else if ( msg.startsWith( QLatin1String( "im_switcher_" ) ) ) + parseHelperStrImSwitcher( msg ); } } @@ -306,3 +311,11 @@ void UimImSwitcher::reloadImList() /* send request to get im list */ uim_helper_send_message( uim_fd, "im_list_get\n" ); } + +void UimImSwitcher::parseHelperStrImSwitcher( const QString &message ) +{ + if ( message.startsWith( QLatin1String( "im_switcher_start\n" ) ) ) + uim_helper_send_message( uim_fd, "im_switcher_quit\n" ); + else if ( message.startsWith( QLatin1String( "im_switcher_quit\n" ) ) ) + QApplication::instance()->quit(); +} diff --git a/qt4/switcher/qt4.h b/qt4/switcher/qt4.h index 0a40703..8fd6bd6 100644 --- a/qt4/switcher/qt4.h +++ b/qt4/switcher/qt4.h @@ -62,8 +62,8 @@ protected: static void helper_disconnect_cb(); void parseHelperStrImList( const QString &message ); - void reloadImList(); + void parseHelperStrImSwitcher( const QString &message ); protected slots: void slotStdinActivated(); -- 1.6.4.2