[gnome-settings-daemon] keygrab: Allow unmodified and synchronous grabs if requested
- From: Rui Matos <rtcm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon] keygrab: Allow unmodified and synchronous grabs if requested
- Date: Sun, 23 Sep 2012 15:42:33 +0000 (UTC)
commit 45d0ca402ed8783fa4028e0a4fc27df74bbfbe75
Author: Rui Matos <tiagomatos gmail com>
Date: Fri Sep 21 02:29:46 2012 +0200
keygrab: Allow unmodified and synchronous grabs if requested
Unmodified grabs are useful not only for a certain range of keysyms
but calling code has to deal with them specifically so make it
available on explicit request.
Likewise, synchronous grabs are useful as they allow us to replay
events that might be interesting to other applications but also need
special care on the calling side.
This patch changes the API so that both of the above options can be
requested and makes ungrabbing separate from the calling code
perspective.
https://bugzilla.gnome.org/show_bug.cgi?id=681685
plugins/common/gsd-keygrab.c | 31 +++++++++++++++++++++-----
plugins/common/gsd-keygrab.h | 10 +++++++-
plugins/media-keys/gsd-media-keys-manager.c | 16 ++++++-------
3 files changed, 41 insertions(+), 16 deletions(-)
---
diff --git a/plugins/common/gsd-keygrab.c b/plugins/common/gsd-keygrab.c
index 7d90c38..91713a7 100644
--- a/plugins/common/gsd-keygrab.c
+++ b/plugins/common/gsd-keygrab.c
@@ -76,6 +76,7 @@ static void
grab_key_real (guint keycode,
GdkWindow *root,
gboolean grab,
+ gboolean synchronous,
XIGrabModifiers *mods,
int num_mods)
{
@@ -96,7 +97,7 @@ grab_key_real (guint keycode,
keycode,
GDK_WINDOW_XID (root),
GrabModeAsync,
- GrabModeAsync,
+ synchronous ? GrabModeSync : GrabModeAsync,
False,
&evmask,
num_mods,
@@ -132,10 +133,11 @@ grab_key_real (guint keycode,
* operations with one flush only.
*/
#define N_BITS 32
-void
-grab_key_unsafe (Key *key,
- gboolean grab,
- GSList *screens)
+static void
+grab_key_internal (Key *key,
+ gboolean grab,
+ GsdKeygrabFlags flags,
+ GSList *screens)
{
int indexes[N_BITS]; /* indexes of bits we need to flip */
int i;
@@ -161,7 +163,8 @@ grab_key_unsafe (Key *key,
* The exception is the XFree86 keys and the Function keys
* (which are useful to grab without a modifier).
*/
- if ((modifiers & gsd_used_mods) == 0 &&
+ if (!(flags & GSD_KEYGRAB_ALLOW_UNMODIFIED) &&
+ (modifiers & gsd_used_mods) == 0 &&
!IN_RANGE(key->keysym, XF86KEYS_RANGE_MIN, XF86KEYS_RANGE_MAX) &&
!IN_RANGE(key->keysym, FKEYS_RANGE_MIN, FKEYS_RANGE_MAX) &&
key->keysym != GDK_KEY_Pause &&
@@ -224,6 +227,7 @@ grab_key_unsafe (Key *key,
grab_key_real (*code,
gdk_screen_get_root_window (screen),
grab,
+ flags & GSD_KEYGRAB_SYNCHRONOUS,
(XIGrabModifiers *) all_mods->data,
all_mods->len);
}
@@ -231,6 +235,21 @@ grab_key_unsafe (Key *key,
g_array_free (all_mods, TRUE);
}
+void
+grab_key_unsafe (Key *key,
+ GsdKeygrabFlags flags,
+ GSList *screens)
+{
+ grab_key_internal (key, TRUE, flags, screens);
+}
+
+void
+ungrab_key_unsafe (Key *key,
+ GSList *screens)
+{
+ grab_key_internal (key, FALSE, 0, screens);
+}
+
static gboolean
have_xkb (Display *dpy)
{
diff --git a/plugins/common/gsd-keygrab.h b/plugins/common/gsd-keygrab.h
index e450072..6ec8847 100644
--- a/plugins/common/gsd-keygrab.h
+++ b/plugins/common/gsd-keygrab.h
@@ -32,11 +32,19 @@ typedef struct {
guint *keycodes;
} Key;
+typedef enum {
+ GSD_KEYGRAB_NORMAL = 0,
+ GSD_KEYGRAB_ALLOW_UNMODIFIED = 1 << 0,
+ GSD_KEYGRAB_SYNCHRONOUS = 1 << 1
+} GsdKeygrabFlags;
void grab_key_unsafe (Key *key,
- gboolean grab,
+ GsdKeygrabFlags flags,
GSList *screens);
+void ungrab_key_unsafe (Key *key,
+ GSList *screens);
+
gboolean match_xi2_key (Key *key,
XIDeviceEvent *event);
diff --git a/plugins/media-keys/gsd-media-keys-manager.c b/plugins/media-keys/gsd-media-keys-manager.c
index 2228519..9c84d7f 100644
--- a/plugins/media-keys/gsd-media-keys-manager.c
+++ b/plugins/media-keys/gsd-media-keys-manager.c
@@ -392,7 +392,7 @@ grab_media_key (MediaKey *key,
if (key->key != NULL) {
need_flush = TRUE;
- grab_key_unsafe (key->key, FALSE, manager->priv->screens);
+ ungrab_key_unsafe (key->key, manager->priv->screens);
}
free_key (key->key);
@@ -407,7 +407,7 @@ grab_media_key (MediaKey *key,
return need_flush;
}
- grab_key_unsafe (key->key, TRUE, manager->priv->screens);
+ grab_key_unsafe (key->key, GSD_KEYGRAB_NORMAL, manager->priv->screens);
g_free (tmp);
@@ -507,9 +507,8 @@ update_custom_binding (GsdMediaKeysManager *manager,
if (key->key) {
gdk_error_trap_push ();
- grab_key_unsafe (key->key,
- FALSE,
- manager->priv->screens);
+ ungrab_key_unsafe (key->key,
+ manager->priv->screens);
gdk_flush ();
if (gdk_error_trap_pop ())
@@ -587,9 +586,8 @@ gsettings_custom_changed_cb (GSettings *settings,
if (key->key) {
gdk_error_trap_push ();
- grab_key_unsafe (key->key,
- FALSE,
- manager->priv->screens);
+ ungrab_key_unsafe (key->key,
+ manager->priv->screens);
gdk_flush ();
if (gdk_error_trap_pop ())
@@ -2299,7 +2297,7 @@ gsd_media_keys_manager_stop (GsdMediaKeysManager *manager)
key = g_ptr_array_index (manager->priv->keys, i);
if (key->key)
- grab_key_unsafe (key->key, FALSE, priv->screens);
+ ungrab_key_unsafe (key->key, priv->screens);
}
g_ptr_array_free (priv->keys, TRUE);
priv->keys = NULL;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]