SF.net SVN: geany:[4441] trunk

eht16 at users.sourceforge.net eht16 at xxxxx
Mon Nov 23 22:25:11 UTC 2009


Revision: 4441
          http://geany.svn.sourceforge.net/geany/?rev=4441&view=rev
Author:   eht16
Date:     2009-11-23 22:25:11 +0000 (Mon, 23 Nov 2009)

Log Message:
-----------
Add keybindings_check_event() to manually check GdkKeyEvents against Geany's keybindings.

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/src/keybindings.c
    trunk/src/keybindings.h

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2009-11-23 21:03:24 UTC (rev 4440)
+++ trunk/ChangeLog	2009-11-23 22:25:11 UTC (rev 4441)
@@ -8,6 +8,9 @@
    Add new command line option "--socket-file" to be able to specify
    separate socket filenames for instances 
    (closes #2896027, patch by Jörn Reder, thanks).
+ * src/keybindings.c, src/keybindings.h:
+   Add keybindings_check_event() to manually check GdkKeyEvents against
+   Geany's keybindings.
 
 
 2009-11-22  Enrico Tröger  <enrico(dot)troeger(at)uvena(dot)de>

Modified: trunk/src/keybindings.c
===================================================================
--- trunk/src/keybindings.c	2009-11-23 21:03:24 UTC (rev 4440)
+++ trunk/src/keybindings.c	2009-11-23 22:25:11 UTC (rev 4441)
@@ -1138,6 +1138,52 @@
 }
 
 
+/* Stripped down version of the main keypress event handler which can be used
+ * to process foreign events. Instead of executing the keybinding, a pointer to the
+ * keybinding structure is returned.
+ * Additionally, the group_id and binding_id are filled with the appropriate indexes
+ * if non-NULL. */
+const GeanyKeyBinding *keybindings_check_event(GdkEventKey *ev, gint *group_id, gint *binding_id)
+{
+	guint state, keyval;
+	gsize g, i;
+	GeanyKeyGroup *group;
+	GeanyKeyBinding *kb;
+
+	if (ev->keyval == 0)
+		return FALSE;
+
+	keyval = ev->keyval;
+	state = ev->state & gtk_accelerator_get_default_mod_mask();
+	/* hack to get around that CTRL+Shift+r results in GDK_R not GDK_r */
+	if ((ev->state & GDK_SHIFT_MASK) || (ev->state & GDK_LOCK_MASK))
+		if (keyval >= GDK_A && keyval <= GDK_Z)
+			keyval += GDK_a - GDK_A;
+
+	if (keyval >= GDK_KP_Space && keyval < GDK_KP_Equal)
+		keyval = key_kp_translate(keyval);
+
+	for (g = 0; g < keybinding_groups->len; g++)
+	{
+		group = g_ptr_array_index(keybinding_groups, g);
+
+		for (i = 0; i < group->count; i++)
+		{
+			kb = &group->keys[i];
+			if (keyval == kb->key && state == kb->mods)
+			{
+				if (group_id != NULL)
+					*group_id = g;
+				if (binding_id != NULL)
+					*binding_id = i;
+				return kb;
+			}
+		}
+	}
+	return NULL;
+}
+
+
 /* central keypress event handler, almost all keypress events go to this function */
 static gboolean on_key_press_event(GtkWidget *widget, GdkEventKey *ev, gpointer user_data)
 {
@@ -1155,7 +1201,7 @@
 		document_check_disk_status(doc, FALSE);
 
 	keyval = ev->keyval;
-    state = ev->state & gtk_accelerator_get_default_mod_mask();
+	state = ev->state & gtk_accelerator_get_default_mod_mask();
 	/* hack to get around that CTRL+Shift+r results in GDK_R not GDK_r */
 	if ((ev->state & GDK_SHIFT_MASK) || (ev->state & GDK_LOCK_MASK))
 		if (keyval >= GDK_A && keyval <= GDK_Z)

Modified: trunk/src/keybindings.h
===================================================================
--- trunk/src/keybindings.h	2009-11-23 21:03:24 UTC (rev 4440)
+++ trunk/src/keybindings.h	2009-11-23 22:25:11 UTC (rev 4441)
@@ -366,5 +366,7 @@
 
 void keybindings_show_shortcuts(void);
 
+const GeanyKeyBinding *keybindings_check_event(GdkEventKey *ev, gint *group_id, gint *binding_id);
+
 #endif
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list