File: Xkb.patch

package info (click to toggle)
keybinder 0.3.1-2.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 1,880 kB
  • sloc: sh: 11,397; ansic: 602; makefile: 151; python: 10
file content (158 lines) | stat: -rw-r--r-- 4,920 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
Description: Fix crash with Xkb extension
Author: Roland Stigge <stigge@antcom.de>

Index: keybinder/libkeybinder/bind.c
===================================================================
--- keybinder.orig/libkeybinder/bind.c	2015-11-07 16:05:53.007356713 -0500
+++ keybinder/libkeybinder/bind.c	2015-11-07 16:07:10.944805805 -0500
@@ -72,6 +72,8 @@
 static GSList *bindings = NULL;
 static guint32 last_event_time = 0;
 static gboolean processing_event = FALSE;
+static gboolean detected_xkb_extension = FALSE;
+static gboolean use_xkb_extension = FALSE;
 
 /* Return the modifier mask that needs to be pressed to produce key in the
  * given group (keyboard layout) and level ("shift level").
@@ -193,13 +195,15 @@
 	GdkKeymap *map;
 	GdkKeymapKey *keys;
 	gint n_keys;
-	GdkModifierType add_modifiers;
-	XkbDescPtr xmap;
+	GdkModifierType add_modifiers = 0;
+	XkbDescPtr xmap = NULL;
 	gboolean success = FALSE;
 
-	xmap = XkbGetMap(GDK_WINDOW_XDISPLAY(rootwin),
-	                 XkbAllClientInfoMask,
-	                 XkbUseCoreKbd);
+	if (use_xkb_extension) {
+		xmap = XkbGetMap(GDK_WINDOW_XDISPLAY(rootwin),
+		                 XkbAllClientInfoMask,
+		                 XkbUseCoreKbd);
+	}
 
 	map = gdk_keymap_get_default();
 	gdk_keymap_get_entries_for_keyval(map, keyval, &keys, &n_keys);
@@ -216,16 +220,24 @@
 			continue;
 		}
 
-		add_modifiers = FinallyGetModifiersForKeycode(xmap,
+
+		TRACE (g_print("grab/ungrab keycode: %d, lev: %d, grp: %d, ",
+			keys[k].keycode, keys[k].level, keys[k].group));
+		if (use_xkb_extension) {
+			add_modifiers = FinallyGetModifiersForKeycode(xmap,
 		                                              keys[k].keycode,
 		                                              keys[k].group,
 		                                              keys[k].level);
+		} else if (keys[k].level > 0) {
+			/* skip shifted/modified keys in non-xkb mode
+			 * this might mean the key can't be bound at all
+			 */
+			continue;
+		}
 
 		if (add_modifiers == MODIFIERS_ERROR) {
 			continue;
 		}
-		TRACE (g_print("grab/ungrab keycode: %d, lev: %d, grp: %d, ",
-			keys[k].keycode, keys[k].level, keys[k].group));
 		TRACE (g_print("modifiers: 0x%x (consumed: 0x%x)\n",
 		               add_modifiers | modifiers, add_modifiers));
 		if (grab_ungrab_with_ignorable_modifiers(rootwin,
@@ -243,7 +255,9 @@
 
 	}
 	g_free(keys);
-	XkbFreeKeyboard(xmap, 0, TRUE);
+	if (xmap) {
+		XkbFreeKeyboard(xmap, 0, TRUE);
+	}
 
 	return success;
 }
@@ -360,7 +374,8 @@
 				xevent->xkey.keycode, 
 				xevent->xkey.state));
 
-		gdk_keymap_translate_keyboard_state(
+		if (use_xkb_extension) {
+			gdk_keymap_translate_keyboard_state(
 				keymap,
 				xevent->xkey.keycode,
 				modifiers,
@@ -369,6 +384,10 @@
 				 */
 				WE_ONLY_USE_ONE_GROUP,
 				&keyval, NULL, NULL, &consumed);
+		} else {
+			consumed = 0;
+			keyval = XLookupKeysym(&xevent->xkey, 0);
+		}
 
 		/* Map non-virtual to virtual modifiers */
 		modifiers &= ~consumed;
@@ -447,6 +466,26 @@
 {
 	GdkKeymap *keymap = gdk_keymap_get_default ();
 	GdkWindow *rootwin = gdk_get_default_root_window ();
+	Display *disp;
+	int xkb_opcode;
+	int xkb_event_base;
+	int xkb_error_base;
+	int majver = XkbMajorVersion;
+	int minver = XkbMinorVersion;
+
+	if (!(disp = XOpenDisplay(NULL))) {
+		g_warning("keybinder_init: Unable to open display");
+		return;
+	}
+
+	detected_xkb_extension = XkbQueryExtension(disp,
+	                                           &xkb_opcode,
+	                                           &xkb_event_base,
+	                                           &xkb_error_base,
+	                                           &majver, &minver);
+
+	use_xkb_extension = detected_xkb_extension;
+	TRACE(g_print("XKB: %d, version: %d, %d\n", use_xkb_extension, majver, minver));
 
 	gdk_window_add_filter (rootwin, filter_func, NULL);
 
@@ -465,6 +504,20 @@
 }
 
 /**
+ * keybinder_set_use_cooked_accelerators: (skip)
+ * @keystring: an accelerator description (gtk_accelerator_parse() format)
+ * @handler:   callback function
+ * @user_data: data to pass to @handler
+ *
+ * Set cooked accelerators.
+ */
+void
+keybinder_set_use_cooked_accelerators (gboolean use_cooked)
+{
+       use_xkb_extension = use_cooked && detected_xkb_extension;
+}
+
+/**
  * keybinder_bind: (skip)
  * @keystring: an accelerator description (gtk_accelerator_parse() format)
  * @handler:   callback function
Index: keybinder/libkeybinder/keybinder.h
===================================================================
--- keybinder.orig/libkeybinder/keybinder.h	2015-11-07 16:05:53.007356713 -0500
+++ keybinder/libkeybinder/keybinder.h	2015-11-07 16:05:52.951355672 -0500
@@ -32,6 +32,8 @@
 
 void keybinder_init (void);
 
+void keybinder_set_use_cooked_accelerators (gboolean use_cooked);
+
 gboolean keybinder_bind (const char *keystring,
                          KeybinderHandler  handler,
                          void *user_data);