summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Kareh <[email protected]>2018-03-07 06:41:17 -0500
committerraveit65 <[email protected]>2018-03-10 20:44:58 +0100
commitd0368790c6deda728eb46337247bd0a9a844ac4b (patch)
treef1bdb8aac708a991a28fbab9f24fd148fc6ea718
parent705b5d1f887e3e280faa60368bb8e999a88715b6 (diff)
downloadmate-settings-daemon-d0368790c6deda728eb46337247bd0a9a844ac4b.tar.bz2
mate-settings-daemon-d0368790c6deda728eb46337247bd0a9a844ac4b.tar.xz
Prevent media-keys bindings from swallowing modifier keys
This changes how the media-keys manager determines successful key-bindings from KeyRelease to KeyPress so that it does not conflict with third-party applications that want to use modifier keys as global key-bindings. We've already done this change for general keybindings and marco. It also cleans up a bunch of deprectation warnings.
-rw-r--r--plugins/keybindings/msd-keybindings-manager.c20
-rw-r--r--plugins/media-keys/msd-media-keys-manager.c52
2 files changed, 49 insertions, 23 deletions
diff --git a/plugins/keybindings/msd-keybindings-manager.c b/plugins/keybindings/msd-keybindings-manager.c
index f04ac54..76905db 100644
--- a/plugins/keybindings/msd-keybindings-manager.c
+++ b/plugins/keybindings/msd-keybindings-manager.c
@@ -297,10 +297,12 @@ key_already_used (MsdKeybindingsManager *manager,
static void
binding_unregister_keys (MsdKeybindingsManager *manager)
{
+ GdkDisplay *dpy;
GSList *li;
gboolean need_flush = FALSE;
- gdk_error_trap_push ();
+ dpy = gdk_display_get_default ();
+ gdk_x11_display_error_trap_push (dpy);
for (li = manager->priv->binding_list; li != NULL; li = li->next) {
Binding *binding = (Binding *) li->data;
@@ -312,18 +314,20 @@ binding_unregister_keys (MsdKeybindingsManager *manager)
}
if (need_flush)
- gdk_flush ();
+ gdk_display_flush (dpy);
- gdk_error_trap_pop_ignored ();
+ gdk_x11_display_error_trap_pop_ignored (dpy);
}
static void
binding_register_keys (MsdKeybindingsManager *manager)
{
GSList *li;
+ GdkDisplay *dpy;
gboolean need_flush = FALSE;
- gdk_error_trap_push ();
+ dpy = gdk_display_get_default ();
+ gdk_x11_display_error_trap_push (dpy);
/* Now check for changes and grab new key if not already used */
for (li = manager->priv->binding_list; li != NULL; li = li->next) {
@@ -353,8 +357,8 @@ binding_register_keys (MsdKeybindingsManager *manager)
}
if (need_flush)
- gdk_flush ();
- if (gdk_error_trap_pop ())
+ gdk_display_flush (dpy);
+ if (gdk_x11_display_error_trap_pop (dpy))
g_warning ("Grab failed for some keys, another application may already have access the them.");
}
@@ -540,11 +544,11 @@ msd_keybindings_manager_start (MsdKeybindingsManager *manager,
(GdkFilterFunc) keybindings_filter,
manager);
- gdk_error_trap_push ();
+ gdk_x11_display_error_trap_push (dpy);
/* Add KeyPressMask to the currently reportable event masks */
XGetWindowAttributes (xdpy, xwindow, &atts);
XSelectInput (xdpy, xwindow, atts.your_event_mask | KeyPressMask);
- gdk_error_trap_pop_ignored ();
+ gdk_x11_display_error_trap_pop_ignored (dpy);
manager->priv->screens = get_screens_list ();
diff --git a/plugins/media-keys/msd-media-keys-manager.c b/plugins/media-keys/msd-media-keys-manager.c
index 5fab74e..34e4c01 100644
--- a/plugins/media-keys/msd-media-keys-manager.c
+++ b/plugins/media-keys/msd-media-keys-manager.c
@@ -264,11 +264,13 @@ update_kbd_cb (GSettings *settings,
MsdMediaKeysManager *manager)
{
int i;
+ GdkDisplay *dpy;
gboolean need_flush = TRUE;
g_return_if_fail (settings_key != NULL);
- gdk_error_trap_push ();
+ dpy = gdk_display_get_default ();
+ gdk_x11_display_error_trap_push (dpy);
/* Find the key that was modified */
for (i = 0; i < HANDLED_KEYS; i++) {
@@ -313,19 +315,21 @@ update_kbd_cb (GSettings *settings,
}
if (need_flush)
- gdk_flush ();
- if (gdk_error_trap_pop ())
+ gdk_display_flush (dpy);
+ if (gdk_x11_display_error_trap_pop (dpy))
g_warning ("Grab failed for some keys, another application may already have access the them.");
}
static void init_kbd(MsdMediaKeysManager* manager)
{
int i;
+ GdkDisplay *dpy;
gboolean need_flush = FALSE;
mate_settings_profile_start(NULL);
- gdk_error_trap_push();
+ dpy = gdk_display_get_default ();
+ gdk_x11_display_error_trap_push (dpy);
for (i = 0; i < HANDLED_KEYS; i++)
{
@@ -373,10 +377,10 @@ static void init_kbd(MsdMediaKeysManager* manager)
if (need_flush)
{
- gdk_flush();
+ gdk_display_flush (dpy);
}
- if (gdk_error_trap_pop ())
+ if (gdk_x11_display_error_trap_pop (dpy))
{
g_warning("Grab failed for some keys, another application may already have access the them.");
}
@@ -1057,7 +1061,7 @@ acme_filter_events (GdkXEvent *xevent,
int i;
/* verify we have a key event */
- if (xev->type != KeyPress && xev->type != KeyRelease) {
+ if (xev->type != KeyPress) {
return GDK_FILTER_CONTINUE;
}
@@ -1071,10 +1075,6 @@ acme_filter_events (GdkXEvent *xevent,
return GDK_FILTER_CONTINUE;
}
break;
- default:
- if (xev->type != KeyRelease) {
- return GDK_FILTER_CONTINUE;
- }
}
manager->priv->current_screen = acme_get_screen_from_event (manager, xany);
@@ -1094,9 +1094,15 @@ static gboolean
start_media_keys_idle_cb (MsdMediaKeysManager *manager)
{
GSList *l;
+ GdkDisplay *dpy;
+ Display *xdpy;
g_debug ("Starting media_keys manager");
mate_settings_profile_start (NULL);
+
+ dpy = gdk_display_get_default ();
+ xdpy = GDK_DISPLAY_XDISPLAY (dpy);
+
manager->priv->volume_monitor = g_volume_monitor_get ();
manager->priv->settings = g_settings_new (BINDING_SCHEMA);
@@ -1105,14 +1111,28 @@ start_media_keys_idle_cb (MsdMediaKeysManager *manager)
/* Start filtering the events */
for (l = manager->priv->screens; l != NULL; l = l->next) {
+ GdkWindow *window;
+ Window xwindow;
+ XWindowAttributes atts;
+
mate_settings_profile_start ("gdk_window_add_filter");
+ window = gdk_screen_get_root_window (l->data);
+ xwindow = GDK_WINDOW_XID (window);
+
g_debug ("adding key filter for screen: %d",
gdk_x11_screen_get_screen_number (l->data));
- gdk_window_add_filter (gdk_screen_get_root_window (l->data),
+ gdk_window_add_filter (window,
(GdkFilterFunc)acme_filter_events,
manager);
+
+ gdk_x11_display_error_trap_push (dpy);
+ /* Add KeyPressMask to the currently reportable event masks */
+ XGetWindowAttributes (xdpy, xwindow, &atts);
+ XSelectInput (xdpy, xwindow, atts.your_event_mask | KeyPressMask);
+ gdk_x11_display_error_trap_pop_ignored (dpy);
+
mate_settings_profile_end ("gdk_window_add_filter");
}
@@ -1161,6 +1181,7 @@ void
msd_media_keys_manager_stop (MsdMediaKeysManager *manager)
{
MsdMediaKeysManagerPrivate *priv = manager->priv;
+ GdkDisplay *dpy;
GSList *ls;
GList *l;
int i;
@@ -1190,7 +1211,8 @@ msd_media_keys_manager_stop (MsdMediaKeysManager *manager)
}
need_flush = FALSE;
- gdk_error_trap_push ();
+ dpy = gdk_display_get_default ();
+ gdk_x11_display_error_trap_push (dpy);
for (i = 0; i < HANDLED_KEYS; ++i) {
if (keys[i].key) {
@@ -1204,9 +1226,9 @@ msd_media_keys_manager_stop (MsdMediaKeysManager *manager)
}
if (need_flush)
- gdk_flush ();
+ gdk_display_flush (dpy);
- gdk_error_trap_pop_ignored ();
+ gdk_x11_display_error_trap_pop_ignored (dpy);
g_slist_free (priv->screens);
priv->screens = NULL;