IM Toggle Patch



Greetings,

Below is a patch for gtk-2.09 that borrows emacs' ctrl+\ sequence
to toggle between an IM and unfiltered input.  "unfiltered" meaning
whatever the system default would be for your keyboard.  In "Keyman"
the toggle key is configurable, but usually ctrl+alt+G I believe.  The
GTK IM support opens up wonderful new worlds but the absense of a
toggle sequence in gnome 2 has meant so much hand-mouse travel for me
(unix and vi commands, etc) that I find myself returning to older tools
to avoid the hassle.  If not this, I hope some approach for key based
IM toggles will be considered for GTK.

I've tested only with the supplied tests/testtext so far and it seems
to work sanely.  Someone will definitely need to review this (I've
left debugging code in) for leaks, proper struct value settings, etc.

thanks,

/Daniel


*** gtk+-2.0.9/gtk/gtkimmulticontext.c	2002-10-22 15:16:51.000000000 -0400
--- gtk+-2.0.9/gtk/gtkimmulticontext-with-toggle.c	2002-12-03 16:57:12.000000000 -0500
***************
*** 21,26 ****
--- 21,27 ----
  
  #include <string.h>
  #include <locale.h>
+ #include <stdio.h>
  
  #include "gtksignal.h"
  #include "gtkimmulticontext.h"
***************
*** 73,80 ****
--- 74,87 ----
  							     gint               offset,
  							     gint               n_chars,
  							     GtkIMMulticontext *multicontext);
+ 
  static GtkIMContextClass *parent_class;
  
+ static gboolean gtk_im_multicontext_filter_keypress_im_toggle (GtkIMMulticontext *multicontext,
+                                                                GdkEventKey  *event);
+ 
+ #define SIMPLE_ID "gtk-im-context-simple"
+ 
  static const gchar *global_context_id = NULL;
  
  GtkType
***************
*** 282,297 ****
--- 289,338 ----
  }
  
  static gboolean
+ gtk_im_multicontext_filter_keypress_im_toggle (GtkIMMulticontext *multicontext,
+ 				               GdkEventKey  *event)
+ {
+   fprintf (stderr, "In gtk_im_multicontext_filter_keypress_im_toggle, %s\n", multicontext->context_id );
+ 
+   if (event->type == GDK_KEY_RELEASE && event->state & (GDK_CONTROL_MASK)) {
+       fprintf (stderr, "  GOT Control Mask\n" );
+       if ( event->keyval == '\\' ) {
+         fprintf (stderr, "    GOT Control+\\\n" );
+ 	if (strcmp (global_context_id, SIMPLE_ID) != 0) {
+           	fprintf (stderr, "      Setting Default\n" );
+ 		global_context_id = SIMPLE_ID;
+                 gtk_im_multicontext_set_slave (multicontext, NULL, FALSE);
+ 		// gtk_im_multicontext_finalize (multicontext);  required?
+   		return TRUE;
+ 	}
+ 	else {
+           multicontext->context_id = global_context_id = NULL;
+           multicontext->slave = NULL;  /* leak? */
+           fprintf (stderr, "      Setting Locale-Default\n" );
+ 	}
+       }
+   }
+ 
+   return FALSE;
+ }
+ 
+ static gboolean
  gtk_im_multicontext_filter_keypress (GtkIMContext *context,
  				     GdkEventKey  *event)
  {
    GtkIMMulticontext *multicontext = GTK_IM_MULTICONTEXT (context);
+ 
+   if ( gtk_im_multicontext_filter_keypress_im_toggle (multicontext, event) )
+     return FALSE;
+ 
+   {
    GtkIMContext *slave = gtk_im_multicontext_get_slave (multicontext);
  
    if (slave)
      return gtk_im_context_filter_keypress (slave, event);
    else
      return FALSE;
+   }
  }
  
  static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]