summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorJens Granseuer <jensgr@gmx.net>2008-04-13 10:40:01 +0000
committerJens Granseuer <jensg@src.gnome.org>2008-04-13 10:40:01 +0000
commit3117d2312aaea6e608f501887e0a12da3227739f (patch)
tree99d4a491adfad85bb2a221b68bc52dc0c9b09359 /plugins
parent4d592fa9afa8df38dfabec87a1771b0c5416b3c7 (diff)
downloadgnome-settings-daemon-3117d2312aaea6e608f501887e0a12da3227739f.tar.gz
Extract some functionality used by several plugins into a separate shared
2008-04-13 Jens Granseuer <jensgr@gmx.net> Extract some functionality used by several plugins into a separate shared helper library (bug #525426). * configure.ac: * plugins/Makefile.am: * plugins/common/Makefile.am: * plugins/common/gsd-keygrab.c: * plugins/common/gsd-keygrab.h: * plugins/common/eggaccelerators.c: * plugins/common/eggaccelerators.h: new shared components * plugins/keybindings/Makefile.am: * plugins/keybindings/eggaccelerators.c: * plugins/keybindings/eggaccelerators.h: * plugins/keybindings/gsd-keybindings-manager.c: (binding_register_keys), (keybindings_filter): * plugins/media-keys/Makefile.am: * plugins/media-keys/actions/Makefile.am: * plugins/media-keys/actions/acme.h: * plugins/media-keys/eggaccelerators.c: * plugins/media-keys/eggaccelerators.h: * plugins/media-keys/gsd-media-keys-manager.c: (update_kbd_cb), (init_kbd), (acme_filter_events): make keybindings and media-keys plugins use the shared components svn path=/trunk/; revision=306
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Makefile.am1
-rw-r--r--plugins/common/Makefile.am21
-rw-r--r--plugins/common/eggaccelerators.c (renamed from plugins/keybindings/eggaccelerators.c)0
-rw-r--r--plugins/common/eggaccelerators.h (renamed from plugins/keybindings/eggaccelerators.h)0
-rw-r--r--plugins/common/gsd-keygrab.c128
-rw-r--r--plugins/common/gsd-keygrab.h44
-rw-r--r--plugins/keybindings/Makefile.am6
-rw-r--r--plugins/keybindings/gsd-keybindings-manager.c115
-rw-r--r--plugins/media-keys/Makefile.am8
-rw-r--r--plugins/media-keys/actions/Makefile.am1
-rw-r--r--plugins/media-keys/actions/acme.h8
-rw-r--r--plugins/media-keys/eggaccelerators.c632
-rw-r--r--plugins/media-keys/eggaccelerators.h95
-rw-r--r--plugins/media-keys/gsd-media-keys-manager.c122
14 files changed, 219 insertions, 962 deletions
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 7cf05687..2d33061d 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -1,6 +1,7 @@
NULL =
SUBDIRS = \
+ common \
a11y-keyboard \
background \
clipboard \
diff --git a/plugins/common/Makefile.am b/plugins/common/Makefile.am
new file mode 100644
index 00000000..4c90114c
--- /dev/null
+++ b/plugins/common/Makefile.am
@@ -0,0 +1,21 @@
+
+noinst_LTLIBRARIES = libcommon.la
+
+libcommon_la_SOURCES = \
+ eggaccelerators.c \
+ eggaccelerators.h \
+ gsd-keygrab.c \
+ gsd-keygrab.h
+
+libcommon_la_CPPFLAGS = \
+ $(AM_CPPFLAGS)
+
+libcommon_la_CFLAGS = \
+ $(SETTINGS_PLUGIN_CFLAGS) \
+ $(AM_CFLAGS)
+
+libcommon_la_LDFLAGS = \
+ $(GSD_PLUGIN_LDFLAGS)
+
+libcommon_la_LIBADD = \
+ $(SETTINGS_PLUGIN_LIBS)
diff --git a/plugins/keybindings/eggaccelerators.c b/plugins/common/eggaccelerators.c
index f112821d..f112821d 100644
--- a/plugins/keybindings/eggaccelerators.c
+++ b/plugins/common/eggaccelerators.c
diff --git a/plugins/keybindings/eggaccelerators.h b/plugins/common/eggaccelerators.h
index b5302f88..b5302f88 100644
--- a/plugins/keybindings/eggaccelerators.h
+++ b/plugins/common/eggaccelerators.h
diff --git a/plugins/common/gsd-keygrab.c b/plugins/common/gsd-keygrab.c
new file mode 100644
index 00000000..165f7038
--- /dev/null
+++ b/plugins/common/gsd-keygrab.c
@@ -0,0 +1,128 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2001-2003 Bastien Nocera <hadess@hadess.net>
+ * Copyright (C) 2006-2007 William Jon McCann <mccann@jhu.edu>
+ * Copyright (C) 2008 Jens Granseuer <jensgr@gmx.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#include "config.h"
+
+#include <gdk/gdk.h>
+#include <gdk/gdkx.h>
+
+#include "gsd-keygrab.h"
+
+/* we exclude shift, GDK_CONTROL_MASK and GDK_MOD1_MASK since we know what
+ these modifiers mean
+ these are the mods whose combinations are bound by the keygrabbing code */
+#define GSD_IGNORED_MODS (0x2000 /*Xkb modifier*/ | GDK_LOCK_MASK | \
+ GDK_MOD2_MASK | GDK_MOD3_MASK | GDK_MOD4_MASK | GDK_MOD5_MASK)
+/* these are the ones we actually use for global keys, we always only check
+ * for these set */
+#define GSD_USED_MODS (GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK)
+
+
+static gboolean
+grab_key_real (guint keycode,
+ GdkWindow *root,
+ gboolean grab,
+ int mask)
+{
+ gdk_error_trap_push ();
+ if (grab) {
+ XGrabKey (GDK_DISPLAY (),
+ keycode,
+ mask,
+ GDK_WINDOW_XID (root),
+ True,
+ GrabModeAsync,
+ GrabModeAsync);
+ } else {
+ XUngrabKey (GDK_DISPLAY (),
+ keycode,
+ mask,
+ GDK_WINDOW_XID (root));
+ }
+
+ gdk_flush ();
+ return gdk_error_trap_pop () == 0;
+}
+
+/* Grab the key. In order to ignore GSD_IGNORED_MODS we need to grab
+ * all combinations of the ignored modifiers and those actually used
+ * for the binding (if any).
+ *
+ * inspired by all_combinations from gnome-panel/gnome-panel/global-keys.c */
+#define N_BITS 32
+void
+grab_key (Key *key,
+ gboolean grab,
+ GSList *screens)
+{
+ int indexes[N_BITS]; /* indexes of bits we need to flip */
+ int i;
+ int bit;
+ int bits_set_cnt;
+ int uppervalue;
+ guint mask = GSD_IGNORED_MODS & ~key->state & GDK_MODIFIER_MASK;
+
+ bit = 0;
+ /* store the indexes of all set bits in mask in the array */
+ for (i = 0; mask; ++i, mask >>= 1) {
+ if (mask & 0x1) {
+ indexes[bit++] = i;
+ }
+ }
+
+ bits_set_cnt = bit;
+
+ uppervalue = 1 << bits_set_cnt;
+ /* grab all possible modifier combinations for our mask */
+ for (i = 0; i < uppervalue; ++i) {
+ GSList *l;
+ int j;
+ int result = 0;
+
+ /* map bits in the counter to those in the mask */
+ for (j = 0; j < bits_set_cnt; ++j) {
+ if (i & (1 << j)) {
+ result |= (1 << indexes[j]);
+ }
+ }
+
+ for (l = screens; l; l = l->next) {
+ GdkScreen *screen = l->data;
+ if (!grab_key_real (key->keycode,
+ gdk_screen_get_root_window (screen),
+ grab,
+ result | key->state)) {
+ g_warning ("Grab failed, another application may already have access to key '%u'",
+ key->keycode);
+ return;
+ }
+ }
+ }
+}
+
+gboolean
+match_key (Key *key, XEvent *event)
+{
+ return (key != NULL
+ && key->keycode == event->xkey.keycode
+ && key->state == (event->xkey.state & GSD_USED_MODS));
+}
diff --git a/plugins/common/gsd-keygrab.h b/plugins/common/gsd-keygrab.h
new file mode 100644
index 00000000..6dde2a02
--- /dev/null
+++ b/plugins/common/gsd-keygrab.h
@@ -0,0 +1,44 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2008 Jens Granseuer <jensgr@gmx.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GSD_COMMON_KEYGRAB_H
+#define __GSD_COMMON_KEYGRAB_H
+
+G_BEGIN_DECLS
+
+#include <glib.h>
+#include <X11/keysym.h>
+
+typedef struct {
+ guint keysym;
+ guint state;
+ guint keycode;
+} Key;
+
+
+void grab_key (Key *key,
+ gboolean grab,
+ GSList *screens);
+
+gboolean match_key (Key *key,
+ XEvent *event);
+
+G_END_DECLS
+
+#endif /* __GSD_COMMON_KEYGRAB_H */
diff --git a/plugins/keybindings/Makefile.am b/plugins/keybindings/Makefile.am
index c7b940d5..b89ad086 100644
--- a/plugins/keybindings/Makefile.am
+++ b/plugins/keybindings/Makefile.am
@@ -9,12 +9,11 @@ libkeybindings_la_SOURCES = \
gsd-keybindings-plugin.c \
gsd-keybindings-manager.h \
gsd-keybindings-manager.c \
- eggaccelerators.h \
- eggaccelerators.c \
$(NULL)
libkeybindings_la_CPPFLAGS = \
-I$(top_srcdir)/gnome-settings-daemon \
+ -I$(top_srcdir)/plugins/common \
-DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \
$(AM_CPPFLAGS)
@@ -27,7 +26,8 @@ libkeybindings_la_LDFLAGS = \
$(NULL)
libkeybindings_la_LIBADD = \
- $(SETTINGS_PLUGIN_LIBS) \
+ $(top_builddir)/plugins/common/libcommon.la \
+ $(SETTINGS_PLUGIN_LIBS) \
$(NULL)
plugin_in_files = \
diff --git a/plugins/keybindings/gsd-keybindings-manager.c b/plugins/keybindings/gsd-keybindings-manager.c
index d81b7cff..d1bbd797 100644
--- a/plugins/keybindings/gsd-keybindings-manager.c
+++ b/plugins/keybindings/gsd-keybindings-manager.c
@@ -41,28 +41,14 @@
#include "gnome-settings-profile.h"
#include "gsd-keybindings-manager.h"
+#include "gsd-keygrab.h"
#include "eggaccelerators.h"
-/* we exclude shift, GDK_CONTROL_MASK and GDK_MOD1_MASK since we know what
- these modifiers mean
- these are the mods whose combinations are bound by the keygrabbing code */
-#define IGNORED_MODS (0x2000 /*Xkb modifier*/ | GDK_LOCK_MASK | \
- GDK_MOD2_MASK | GDK_MOD3_MASK | GDK_MOD4_MASK | GDK_MOD5_MASK)
-/* these are the ones we actually use for global keys, we always only check
- * for these set */
-#define USED_MODS (GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK)
-
#define GCONF_BINDING_DIR "/desktop/gnome/keybindings"
#define GSD_KEYBINDINGS_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_KEYBINDINGS_MANAGER, GsdKeybindingsManagerPrivate))
typedef struct {
- guint keysym;
- guint state;
- guint keycode;
-} Key;
-
-typedef struct {
char *binding_str;
char *action;
char *gconf_key;
@@ -257,7 +243,6 @@ bindings_get_entry (GsdKeybindingsManager *manager,
return TRUE;
}
-
static gboolean
key_already_used (GsdKeybindingsManager *manager,
Binding *binding)
@@ -277,86 +262,6 @@ key_already_used (GsdKeybindingsManager *manager,
}
static void
-grab_key (GdkWindow *root,
- Key *key,
- int result,
- gboolean grab)
-{
- gdk_error_trap_push ();
-
- if (grab) {
- XGrabKey (GDK_DISPLAY (),
- key->keycode,
- (result | key->state),
- GDK_WINDOW_XID (root),
- True,
- GrabModeAsync,
- GrabModeAsync);
- } else {
- XUngrabKey (GDK_DISPLAY (),
- key->keycode,
- (result | key->state),
- GDK_WINDOW_XID (root));
- }
- gdk_flush ();
- if (gdk_error_trap_pop ()) {
- g_warning (_("It seems that another application already has access to key '%u'."),
- key->keycode);
- }
-}
-
-/* Grab the key. In order to ignore IGNORED_MODS we need to grab
- * all combinations of the ignored modifiers and those actually used
- * for the binding (if any).
- *
- * inspired by all_combinations from gnome-panel/gnome-panel/global-keys.c */
-#define N_BITS 32
-static void
-do_grab (GsdKeybindingsManager *manager,
- gboolean grab,
- Key *key)
-{
- int indexes[N_BITS]; /* indexes of bits we need to flip */
- int i;
- int bit;
- int bits_set_cnt;
- int uppervalue;
- guint mask = IGNORED_MODS & ~key->state & GDK_MODIFIER_MASK;
-
- bit = 0;
- /* store the indices of all set bits in mask in the array */
- for (i = 0; mask; ++i, mask >>= 1) {
- if (mask & 0x1) {
- indexes[bit++] = i;
- }
- }
-
- bits_set_cnt = bit;
-
- uppervalue = 1 << bits_set_cnt;
- /* grab all possible modifier combinations for our mask */
- for (i = 0; i < uppervalue; ++i) {
- GSList *l;
- int j, result = 0;
-
- /* map bits in the counter to those in the mask */
- for (j = 0; j < bits_set_cnt; ++j) {
- if (i & (1<<j)) {
- result |= (1<<indexes[j]);
- }
- }
-
- for (l = manager->priv->screens; l ; l = l->next) {
- GdkScreen *screen = l->data;
- grab_key (gdk_screen_get_root_window (screen),
- key,
- result,
- grab);
- }
- }
-}
-
-static void
binding_register_keys (GsdKeybindingsManager *manager)
{
GSList *li;
@@ -372,15 +277,15 @@ binding_register_keys (GsdKeybindingsManager *manager)
/* Ungrab key if it changed and not clashing with previously set binding */
if (! key_already_used (manager, binding)) {
if (binding->previous_key.keycode) {
- do_grab (manager, FALSE, &binding->previous_key);
+ grab_key (&binding->previous_key, FALSE, manager->priv->screens);
}
- do_grab (manager, TRUE, &binding->key);
+ grab_key (&binding->key, TRUE, manager->priv->screens);
binding->previous_key.keysym = binding->key.keysym;
binding->previous_key.state = binding->key.state;
binding->previous_key.keycode = binding->key.keycode;
} else
- g_warning (_("Key Binding (%s) is already in use"), binding->binding_str);
+ g_warning ("Key binding (%s) is already in use", binding->binding_str);
}
}
gdk_flush ();
@@ -471,23 +376,17 @@ keybindings_filter (GdkXEvent *gdk_xevent,
GdkEvent *event,
GsdKeybindingsManager *manager)
{
- XEvent *xevent = (XEvent *)gdk_xevent;
- guint keycode;
- guint state;
+ XEvent *xevent = (XEvent *) gdk_xevent;
GSList *li;
if (xevent->type != KeyPress) {
return GDK_FILTER_CONTINUE;
}
- keycode = xevent->xkey.keycode;
- state = xevent->xkey.state;
-
for (li = manager->priv->binding_list; li != NULL; li = li->next) {
- Binding *binding = (Binding*) li->data;
+ Binding *binding = (Binding *) li->data;
- if (keycode == binding->key.keycode &&
- (state & USED_MODS) == binding->key.state) {
+ if (match_key (&binding->key, xevent)) {
GError *error = NULL;
gboolean retval;
gchar **argv = NULL;
diff --git a/plugins/media-keys/Makefile.am b/plugins/media-keys/Makefile.am
index 2e253ec3..b8dcf8b6 100644
--- a/plugins/media-keys/Makefile.am
+++ b/plugins/media-keys/Makefile.am
@@ -29,13 +29,12 @@ libmedia_keys_la_SOURCES = \
gsd-media-keys-manager.c \
gsd-media-keys-window.h \
gsd-media-keys-window.c \
- eggaccelerators.h \
- eggaccelerators.c \
$(BUILT_SOURCES) \
$(NULL)
libmedia_keys_la_CPPFLAGS = \
-I$(top_srcdir)/gnome-settings-daemon \
+ -I$(top_srcdir)/plugins/common \
-I$(top_builddir)/plugins/media-keys/actions \
-DPIXMAPDIR=\""$(pkgdatadir)"\" \
-DGLADEDIR=\""$(pkgdatadir)"\" \
@@ -50,6 +49,7 @@ libmedia_keys_la_LDFLAGS = \
$(GSD_PLUGIN_LDFLAGS)
libmedia_keys_la_LIBADD = \
+ $(top_builddir)/plugins/common/libcommon.la \
$(top_builddir)/plugins/media-keys/actions/libacme.la \
$(SETTINGS_PLUGIN_LIBS) \
$(XF86MISC_LIBS) \
@@ -94,14 +94,13 @@ test_media_keys_SOURCES = \
gsd-media-keys-manager.h \
gsd-media-keys-window.h \
gsd-media-keys-window.c \
- eggaccelerators.h \
- eggaccelerators.c \
test-media-keys.c \
$(BUILT_SOURCES) \
$(NULL)
test_media_keys_CPPFLAGS = \
-I$(top_srcdir)/gnome-settings-daemon \
+ -I$(top_srcdir)/plugins/common \
-I$(top_builddir)/plugins/media-keys/actions \
-DPIXMAPDIR=\""$(pkgdatadir)"\" \
-DGLADEDIR=\""$(pkgdatadir)"\" \
@@ -114,6 +113,7 @@ test_media_keys_CFLAGS = \
test_media_keys_LDADD = \
$(top_builddir)/gnome-settings-daemon/libgsd-profile.la \
+ $(top_builddir)/plugins/common/libcommon.la \
$(top_builddir)/plugins/media-keys/actions/libacme.la \
$(SETTINGS_DAEMON_LIBS) \
$(SETTINGS_PLUGIN_LIBS) \
diff --git a/plugins/media-keys/actions/Makefile.am b/plugins/media-keys/actions/Makefile.am
index 706e0a24..aba5b0ea 100644
--- a/plugins/media-keys/actions/Makefile.am
+++ b/plugins/media-keys/actions/Makefile.am
@@ -12,6 +12,7 @@ libacme_la_SOURCES = \
libacme_la_CPPFLAGS = \
-I$(top_srcdir)/gnome-settings-daemon \
+ -I$(top_srcdir)/plugins/common \
-DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \
$(AM_CPPFLAGS)
diff --git a/plugins/media-keys/actions/acme.h b/plugins/media-keys/actions/acme.h
index ff4d7ce5..60f9beb3 100644
--- a/plugins/media-keys/actions/acme.h
+++ b/plugins/media-keys/actions/acme.h
@@ -21,6 +21,8 @@
#ifndef __ACME_H__
#define __ACME_H__
+#include "gsd-keygrab.h"
+
#define GCONF_BINDING_DIR "/apps/gnome_settings_daemon/keybindings"
#define GCONF_MISC_DIR "/apps/gnome_settings_daemon"
@@ -47,12 +49,6 @@ enum {
HANDLED_KEYS
};
-typedef struct {
- guint keysym;
- guint state;
- guint keycode;
-} Key;
-
static struct {
int key_type;
const char *gconf_key;
diff --git a/plugins/media-keys/eggaccelerators.c b/plugins/media-keys/eggaccelerators.c
deleted file mode 100644
index f112821d..00000000
--- a/plugins/media-keys/eggaccelerators.c
+++ /dev/null
@@ -1,632 +0,0 @@
-/* eggaccelerators.c
- * Copyright (C) 2002 Red Hat, Inc.; Copyright 1998, 2001 Tim Janik
- * Developed by Havoc Pennington, Tim Janik
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#include "eggaccelerators.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include <gdk/gdkx.h>
-#include <gdk/gdkkeysyms.h>
-#include <gtk/gtkaccelgroup.h>
-
-enum
-{
- EGG_MODMAP_ENTRY_SHIFT = 0,
- EGG_MODMAP_ENTRY_LOCK = 1,
- EGG_MODMAP_ENTRY_CONTROL = 2,
- EGG_MODMAP_ENTRY_MOD1 = 3,
- EGG_MODMAP_ENTRY_MOD2 = 4,
- EGG_MODMAP_ENTRY_MOD3 = 5,
- EGG_MODMAP_ENTRY_MOD4 = 6,
- EGG_MODMAP_ENTRY_MOD5 = 7,
- EGG_MODMAP_ENTRY_LAST = 8
-};
-
-#define MODMAP_ENTRY_TO_MODIFIER(x) (1 << (x))
-
-typedef struct
-{
- EggVirtualModifierType mapping[EGG_MODMAP_ENTRY_LAST];
-
-} EggModmap;
-
-const EggModmap* egg_keymap_get_modmap (GdkKeymap *keymap);
-
-static inline gboolean
-is_alt (const gchar *string)
-{
- return ((string[0] == '<') &&
- (string[1] == 'a' || string[1] == 'A') &&
- (string[2] == 'l' || string[2] == 'L') &&
- (string[3] == 't' || string[3] == 'T') &&
- (string[4] == '>'));
-}
-
-static inline gboolean
-is_ctl (const gchar *string)
-{
- return ((string[0] == '<') &&
- (string[1] == 'c' || string[1] == 'C') &&
- (string[2] == 't' || string[2] == 'T') &&
- (string[3] == 'l' || string[3] == 'L') &&
- (string[4] == '>'));
-}
-
-static inline gboolean
-is_modx (const gchar *string)
-{
- return ((string[0] == '<') &&
- (string[1] == 'm' || string[1] == 'M') &&
- (string[2] == 'o' || string[2] == 'O') &&
- (string[3] == 'd' || string[3] == 'D') &&
- (string[4] >= '1' && string[4] <= '5') &&
- (string[5] == '>'));
-}
-
-static inline gboolean
-is_ctrl (const gchar *string)
-{
- return ((string[0] == '<') &&
- (string[1] == 'c' || string[1] == 'C') &&
- (string[2] == 't' || string[2] == 'T') &&
- (string[3] == 'r' || string[3] == 'R') &&
- (string[4] == 'l' || string[4] == 'L') &&
- (string[5] == '>'));
-}
-
-static inline gboolean
-is_shft (const gchar *string)
-{
- return ((string[0] == '<') &&
- (string[1] == 's' || string[1] == 'S') &&
- (string[2] == 'h' || string[2] == 'H') &&
- (string[3] == 'f' || string[3] == 'F') &&
- (string[4] == 't' || string[4] == 'T') &&
- (string[5] == '>'));
-}
-
-static inline gboolean
-is_shift (const gchar *string)
-{
- return ((string[0] == '<') &&
- (string[1] == 's' || string[1] == 'S') &&
- (string[2] == 'h' || string[2] == 'H') &&
- (string[3] == 'i' || string[3] == 'I') &&
- (string[4] == 'f' || string[4] == 'F') &&
- (string[5] == 't' || string[5] == 'T') &&
- (string[6] == '>'));
-}
-
-static inline gboolean
-is_control (const gchar *string)
-{
- return ((string[0] == '<') &&
- (string[1] == 'c' || string[1] == 'C') &&
- (string[2] == 'o' || string[2] == 'O') &&
- (string[3] == 'n' || string[3] == 'N') &&
- (string[4] == 't' || string[4] == 'T') &&
- (string[5] == 'r' || string[5] == 'R') &&
- (string[6] == 'o' || string[6] == 'O') &&
- (string[7] == 'l' || string[7] == 'L') &&
- (string[8] == '>'));
-}
-
-static inline gboolean
-is_release (const gchar *string)
-{
- return ((string[0] == '<') &&
- (string[1] == 'r' || string[1] == 'R') &&
- (string[2] == 'e' || string[2] == 'E') &&
- (string[3] == 'l' || string[3] == 'L') &&
- (string[4] == 'e' || string[4] == 'E') &&
- (string[5] == 'a' || string[5] == 'A') &&
- (string[6] == 's' || string[6] == 'S') &&
- (string[7] == 'e' || string[7] == 'E') &&
- (string[8] == '>'));
-}
-
-static inline gboolean
-is_meta (const gchar *string)
-{
- return ((string[0] == '<') &&
- (string[1] == 'm' || string[1] == 'M') &&
- (string[2] == 'e' || string[2] == 'E') &&
- (string[3] == 't' || string[3] == 'T') &&
- (string[4] == 'a' || string[4] == 'A') &&
- (string[5] == '>'));
-}
-
-static inline gboolean
-is_super (const gchar *string)
-{
- return ((string[0] == '<') &&
- (string[1] == 's' || string[1] == 'S') &&
- (string[2] == 'u' || string[2] == 'U') &&
- (string[3] == 'p' || string[3] == 'P') &&
- (string[4] == 'e' || string[4] == 'E') &&
- (string[5] == 'r' || string[5] == 'R') &&
- (string[6] == '>'));
-}
-
-static inline gboolean
-is_hyper (const gchar *string)
-{
- return ((string[0] == '<') &&
- (string[1] == 'h' || string[1] == 'H') &&
- (string[2] == 'y' || string[2] == 'Y') &&
- (string[3] == 'p' || string[3] == 'P') &&
- (string[4] == 'e' || string[4] == 'E') &&
- (string[5] == 'r' || string[5] == 'R') &&
- (string[6] == '>'));
-}
-
-static inline gboolean
-is_keycode (const gchar *string)
-{
- return ((string[0] == '0') &&
- (string[1] == 'x'));
-}
-
-/**
- * egg_accelerator_parse_virtual:
- * @accelerator: string representing an accelerator
- * @accelerator_key: return location for accelerator keyval
- * @accelerator_mods: return location for accelerator modifier mask
- *
- * Parses a string representing a virtual accelerator. The format
- * looks like "&lt;Control&gt;a" or "&lt;Shift&gt;&lt;Alt&gt;F1" or
- * "&lt;Release&gt;z" (the last one is for key release). The parser
- * is fairly liberal and allows lower or upper case, and also
- * abbreviations such as "&lt;Ctl&gt;" and "&lt;Ctrl&gt;".
- *
- * If the parse fails, @accelerator_key and @accelerator_mods will
- * be set to 0 (zero) and %FALSE will be returned. If the string contains
- * only modifiers, @accelerator_key will be set to 0 but %TRUE will be
- * returned.
- *
- * The virtual vs. concrete accelerator distinction is a relic of
- * how the X Window System works; there are modifiers Mod2-Mod5 that
- * can represent various keyboard keys (numlock, meta, hyper, etc.),
- * the virtual modifier represents the keyboard key, the concrete
- * modifier the actual Mod2-Mod5 bits in the key press event.
- *
- * Returns: %TRUE on success.
- */
-gboolean
-egg_accelerator_parse_virtual (const gchar *accelerator,
- guint *accelerator_key,
- guint *keycode,
- EggVirtualModifierType *accelerator_mods)
-{
- guint keyval;
- GdkModifierType mods;
- gint len;
- gboolean bad_keyval;
-
- if (accelerator_key)
- *accelerator_key = 0;
- if (accelerator_mods)
- *accelerator_mods = 0;
- if (keycode)
- *keycode = 0;
-
- g_return_val_if_fail (accelerator != NULL, FALSE);
-
- bad_keyval = FALSE;
-
- keyval = 0;
- mods = 0;
- len = strlen (accelerator);
- while (len)
- {
- if (*accelerator == '<')
- {
- if (len >= 9 && is_release (accelerator))
- {
- accelerator += 9;
- len -= 9;
- mods |= EGG_VIRTUAL_RELEASE_MASK;
- }
- else if (len >= 9 && is_control (accelerator))
- {
- accelerator += 9;
- len -= 9;
- mods |= EGG_VIRTUAL_CONTROL_MASK;
- }
- else if (len >= 7 && is_shift (accelerator))
- {
- accelerator += 7;
- len -= 7;
- mods |= EGG_VIRTUAL_SHIFT_MASK;
- }
- else if (len >= 6 && is_shft (accelerator))
- {
- accelerator += 6;
- len -= 6;
- mods |= EGG_VIRTUAL_SHIFT_MASK;
- }
- else if (len >= 6 && is_ctrl (accelerator))
- {
- accelerator += 6;
- len -= 6;
- mods |= EGG_VIRTUAL_CONTROL_MASK;
- }
- else if (len >= 6 && is_modx (accelerator))
- {
- static const guint mod_vals[] = {
- EGG_VIRTUAL_ALT_MASK, EGG_VIRTUAL_MOD2_MASK, EGG_VIRTUAL_MOD3_MASK,
- EGG_VIRTUAL_MOD4_MASK, EGG_VIRTUAL_MOD5_MASK
- };
-
- len -= 6;
- accelerator += 4;
- mods |= mod_vals[*accelerator - '1'];
- accelerator += 2;
- }
- else if (len >= 5 && is_ctl (accelerator))
- {
- accelerator += 5;
- len -= 5;
- mods |= EGG_VIRTUAL_CONTROL_MASK;
- }
- else if (len >= 5 && is_alt (accelerator))
- {
- accelerator += 5;
- len -= 5;
- mods |= EGG_VIRTUAL_ALT_MASK;
- }
- else if (len >= 6 && is_meta (accelerator))
- {
- accelerator += 6;
- len -= 6;
- mods |= EGG_VIRTUAL_META_MASK;
- }
- else if (len >= 7 && is_hyper (accelerator))
- {
- accelerator += 7;
- len -= 7;
- mods |= EGG_VIRTUAL_HYPER_MASK;
- }
- else if (len >= 7 && is_super (accelerator))
- {
- accelerator += 7;
- len -= 7;
- mods |= EGG_VIRTUAL_SUPER_MASK;
- }
- else
- {
- gchar last_ch;
-
- last_ch = *accelerator;
- while (last_ch && last_ch != '>')
- {
- last_ch = *accelerator;
- accelerator += 1;
- len -= 1;
- }
- }
- }
- else
- {
- keyval = gdk_keyval_from_name (accelerator);
-
- if (keyval == 0)
- {
- /* If keyval is 0, then maybe it's a keycode. Check for 0x## */
- if (len >= 4 && is_keycode (accelerator))
- {
- char keystring[5];
- gchar *endptr;
- gint tmp_keycode;
-
- memcpy (keystring, accelerator, 4);
- keystring [4] = '\000';
-
- tmp_keycode = strtol (keystring, &endptr, 16);
-
- if (endptr == NULL || *endptr != '\000')
- {
- bad_keyval = TRUE;
- }
- else if (keycode != NULL)
- {
- *keycode = tmp_keycode;
- /* 0x00 is an invalid keycode too. */
- if (*keycode == 0)
- bad_keyval = TRUE;
- }
- }
- }
- else if (keycode != NULL)
- {
- *keycode = XKeysymToKeycode (GDK_DISPLAY(), keyval);
- if (*keycode == 0)
- bad_keyval = TRUE;
- }
-
- accelerator += len;
- len -= len;
- }
- }
-
- if (accelerator_key)
- *accelerator_key = gdk_keyval_to_lower (keyval);
- if (accelerator_mods)
- *accelerator_mods = mods;
-
- return !bad_keyval;
-}
-
-/**
- * egg_virtual_accelerator_name:
- * @accelerator_key: accelerator keyval
- * @accelerator_mods: accelerator modifier mask
- * @returns: a newly-allocated accelerator name
- *
- * Converts an accelerator keyval and modifier mask
- * into a string parseable by egg_accelerator_parse_virtual().
- * For example, if you pass in #GDK_q and #EGG_VIRTUAL_CONTROL_MASK,
- * this function returns "&lt;Control&gt;q".
- *
- * The caller of this function must free the returned string.
- */
-gchar*
-egg_virtual_accelerator_name (guint accelerator_key,
- guint keycode,
- EggVirtualModifierType accelerator_mods)
-{
- gchar *gtk_name;
- GdkModifierType gdkmods = 0;
-
- egg_keymap_resolve_virtual_modifiers (NULL, accelerator_mods, &gdkmods);
- gtk_name = gtk_accelerator_name (accelerator_key, gdkmods);
-
- if (!accelerator_key)
- {
- gchar *name;
- name = g_strdup_printf ("%s0x%02x", gtk_name, keycode);
- g_free (gtk_name);
- return name;
- }
-
- return gtk_name;
-}
-
-/**
- * egg_virtual_accelerator_label:
- * @accelerator_key: accelerator keyval
- * @accelerator_mods: accelerator modifier mask
- * @returns: a newly-allocated accelerator label
- *
- * Converts an accelerator keyval and modifier mask
- * into a (possibly translated) string that can be displayed to
- * a user.
- * For example, if you pass in #GDK_q and #EGG_VIRTUAL_CONTROL_MASK,
- * and you use a German locale, this function returns "Strg+Q".
- *
- * The caller of this function must free the returned string.
- */
-gchar*
-egg_virtual_accelerator_label (guint accelerator_key,
- guint keycode,
- EggVirtualModifierType accelerator_mods)
-{
- gchar *gtk_label;
- GdkModifierType gdkmods = 0;
-
- egg_keymap_resolve_virtual_modifiers (NULL, accelerator_mods, &gdkmods);
- gtk_label = gtk_accelerator_get_label (accelerator_key, gdkmods);
-
- if (!accelerator_key)
- {
- gchar *label;
- label = g_strdup_printf ("%s0x%02x", gtk_label, keycode);
- g_free (gtk_label);
- return label;
- }
-
- return gtk_label;
-}
-
-void
-egg_keymap_resolve_virtual_modifiers (GdkKeymap *keymap,
- EggVirtualModifierType virtual_mods,
- GdkModifierType *concrete_mods)
-{
- GdkModifierType concrete;
- int i;
- const EggModmap *modmap;
-
- g_return_if_fail (concrete_mods != NULL);
- g_return_if_fail (keymap == NULL || GDK_IS_KEYMAP (keymap));
-
- modmap = egg_keymap_get_modmap (keymap);
-
- /* Not so sure about this algorithm. */
-
- concrete = 0;
- for (i = 0; i < EGG_MODMAP_ENTRY_LAST; ++i)
- {
- if (modmap->mapping[i] & virtual_mods)
- concrete |= MODMAP_ENTRY_TO_MODIFIER (i);
- }
-
- *concrete_mods = concrete;
-}
-
-void
-egg_keymap_virtualize_modifiers (GdkKeymap *keymap,
- GdkModifierType concrete_mods,
- EggVirtualModifierType *virtual_mods)
-{
- GdkModifierType virtual;
- int i;
- const EggModmap *modmap;
-
- g_return_if_fail (virtual_mods != NULL);
- g_return_if_fail (keymap == NULL || GDK_IS_KEYMAP (keymap));
-
- modmap = egg_keymap_get_modmap (keymap);
-
- /* Not so sure about this algorithm. */
-
- virtual = 0;
- for (i = 0; i < EGG_MODMAP_ENTRY_LAST; ++i)
- {
- if (MODMAP_ENTRY_TO_MODIFIER (i) & concrete_mods)
- {
- EggVirtualModifierType cleaned;
-
- cleaned = modmap->mapping[i] & ~(EGG_VIRTUAL_MOD2_MASK |
- EGG_VIRTUAL_MOD3_MASK |
- EGG_VIRTUAL_MOD4_MASK |
- EGG_VIRTUAL_MOD5_MASK);
-
- if (cleaned != 0)
- {
- virtual |= cleaned;
- }
- else
- {
- /* Rather than dropping mod2->mod5 if not bound,
- * go ahead and use the concrete names
- */
- virtual |= modmap->mapping[i];
- }
- }
- }
-
- *virtual_mods = virtual;
-}
-
-static void
-reload_modmap (GdkKeymap *keymap,
- EggModmap *modmap)
-{
- XModifierKeymap *xmodmap;
- int map_size;
- int i;
-
- /* FIXME multihead */
- xmodmap = XGetModifierMapping (gdk_x11_get_default_xdisplay ());
-
- memset (modmap->mapping, 0, sizeof (modmap->mapping));
-
- /* there are 8 modifiers in the order shift, shift lock,
- * control, mod1-5 with up to max_keypermod bindings each
- */
- map_size = 8 * xmodmap->max_keypermod;
- for (i = 3 * xmodmap->max_keypermod; i < map_size; ++i)
- {
- /* get the key code at this point in the map,
- * see if its keysym is one we're interested in
- */
- int keycode = xmodmap->modifiermap[i];
- GdkKeymapKey *keys;
- guint *keyvals;
- int n_entries;
- int j;
- EggVirtualModifierType mask;
-
- keys = NULL;
- keyvals = NULL;
- n_entries = 0;
-
- gdk_keymap_get_entries_for_keycode (keymap,
- keycode,
- &keys, &keyvals, &n_entries);
-
- mask = 0;
- for (j = 0; j < n_entries; ++j)
- {
- if (keyvals[j] == GDK_Num_Lock)
- mask |= EGG_VIRTUAL_NUM_LOCK_MASK;
- else if (keyvals[j] == GDK_Scroll_Lock)
- mask |= EGG_VIRTUAL_SCROLL_LOCK_MASK;
- else if (keyvals[j] == GDK_Meta_L ||
- keyvals[j] == GDK_Meta_R)
- mask |= EGG_VIRTUAL_META_MASK;
- else if (keyvals[j] == GDK_Hyper_L ||
- keyvals[j] == GDK_Hyper_R)
- mask |= EGG_VIRTUAL_HYPER_MASK;
- else if (keyvals[j] == GDK_Super_L ||
- keyvals[j] == GDK_Super_R)
- mask |= EGG_VIRTUAL_SUPER_MASK;
- else if (keyvals[j] == GDK_Mode_switch)
- mask |= EGG_VIRTUAL_MODE_SWITCH_MASK;
- }
-
- /* Mod1Mask is 1 << 3 for example, i.e. the
- * fourth modifier, i / keyspermod is the modifier
- * index
- */
- modmap->mapping[i/xmodmap->max_keypermod] |= mask;
-
- g_free (keyvals);
- g_free (keys);
- }
-
- /* Add in the not-really-virtual fixed entries */
- modmap->mapping[EGG_MODMAP_ENTRY_SHIFT] |= EGG_VIRTUAL_SHIFT_MASK;
- modmap->mapping[EGG_MODMAP_ENTRY_CONTROL] |= EGG_VIRTUAL_CONTROL_MASK;
- modmap->mapping[EGG_MODMAP_ENTRY_LOCK] |= EGG_VIRTUAL_LOCK_MASK;
- modmap->mapping[EGG_MODMAP_ENTRY_MOD1] |= EGG_VIRTUAL_ALT_MASK;
- modmap->mapping[EGG_MODMAP_ENTRY_MOD2] |= EGG_VIRTUAL_MOD2_MASK;
- modmap->mapping[EGG_MODMAP_ENTRY_MOD3] |= EGG_VIRTUAL_MOD3_MASK;
- modmap->mapping[EGG_MODMAP_ENTRY_MOD4] |= EGG_VIRTUAL_MOD4_MASK;
- modmap->mapping[EGG_MODMAP_ENTRY_MOD5] |= EGG_VIRTUAL_MOD5_MASK;
-
- XFreeModifiermap (xmodmap);
-}
-
-const EggModmap*
-egg_keymap_get_modmap (GdkKeymap *keymap)
-{
- EggModmap *modmap;
-
- if (keymap == NULL)
- keymap = gdk_keymap_get_default ();
-
- /* This is all a hack, much simpler when we can just
- * modify GDK directly.
- */
-
- modmap = g_object_get_data (G_OBJECT (keymap), "egg-modmap");
-
- if (modmap == NULL)
- {
- modmap = g_new0 (EggModmap, 1);
-
- /* FIXME modify keymap change events with an event filter
- * and force a reload if we get one
- */
-
- reload_modmap (keymap, modmap);
-
- g_object_set_data_full (G_OBJECT (keymap),
- "egg-modmap",
- modmap,
- g_free);
- }
-
- g_assert (modmap != NULL);
-
- return modmap;
-}
diff --git a/plugins/media-keys/eggaccelerators.h b/plugins/media-keys/eggaccelerators.h
deleted file mode 100644
index b5302f88..00000000
--- a/plugins/media-keys/eggaccelerators.h
+++ /dev/null
@@ -1,95 +0,0 @@
-/* eggaccelerators.h
- * Copyright (C) 2002 Red Hat, Inc.
- * Developed by Havoc Pennington
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#ifndef __EGG_ACCELERATORS_H__
-#define __EGG_ACCELERATORS_H__
-
-#include <gtk/gtkaccelgroup.h>
-#include <gdk/gdk.h>
-
-G_BEGIN_DECLS
-
-/* Where a value is also in GdkModifierType we coincide,
- * otherwise we don't overlap.
- */
-typedef enum
-{
- EGG_VIRTUAL_SHIFT_MASK = 1 << 0,
- EGG_VIRTUAL_LOCK_MASK = 1 << 1,
- EGG_VIRTUAL_CONTROL_MASK = 1 << 2,
-
- EGG_VIRTUAL_ALT_MASK = 1 << 3, /* fixed as Mod1 */
-
- EGG_VIRTUAL_MOD2_MASK = 1 << 4,
- EGG_VIRTUAL_MOD3_MASK = 1 << 5,
- EGG_VIRTUAL_MOD4_MASK = 1 << 6,
- EGG_VIRTUAL_MOD5_MASK = 1 << 7,
-
-#if 0
- GDK_BUTTON1_MASK = 1 << 8,
- GDK_BUTTON2_MASK = 1 << 9,
- GDK_BUTTON3_MASK = 1 << 10,
- GDK_BUTTON4_MASK = 1 << 11,
- GDK_BUTTON5_MASK = 1 << 12,
- /* 13, 14 are used by Xkb for the keyboard group */
-#endif
-
- EGG_VIRTUAL_MODE_SWITCH_MASK = 1 << 23,
- EGG_VIRTUAL_NUM_LOCK_MASK = 1 << 24,
- EGG_VIRTUAL_SCROLL_LOCK_MASK = 1 << 25,
-
- /* Also in GdkModifierType */
- EGG_VIRTUAL_SUPER_MASK = 1 << 26,
- EGG_VIRTUAL_HYPER_MASK = 1 << 27,
- EGG_VIRTUAL_META_MASK = 1 << 28,
-
- /* Also in GdkModifierType */
- EGG_VIRTUAL_RELEASE_MASK = 1 << 30,
-
- /* 28-31 24-27 20-23 16-19 12-15 8-11 4-7 0-3
- * 5 f 8 0 0 0 f f
- */
- EGG_VIRTUAL_MODIFIER_MASK = 0x5f8000ff
-
-} EggVirtualModifierType;
-
-gboolean egg_accelerator_parse_virtual (const gchar *accelerator,
- guint *accelerator_key,
- guint *keycode,
- EggVirtualModifierType *accelerator_mods);
-void egg_keymap_resolve_virtual_modifiers (GdkKeymap *keymap,
- EggVirtualModifierType virtual_mods,
- GdkModifierType *concrete_mods);
-void egg_keymap_virtualize_modifiers (GdkKeymap *keymap,
- GdkModifierType concrete_mods,
- EggVirtualModifierType *virtual_mods);
-
-gchar* egg_virtual_accelerator_name (guint accelerator_key,
- guint keycode,
- EggVirtualModifierType accelerator_mods);
-
-gchar* egg_virtual_accelerator_label (guint accelerator_key,
- guint keycode,
- EggVirtualModifierType accelerator_mods);
-
-G_END_DECLS
-
-
-#endif /* __EGG_ACCELERATORS_H__ */
diff --git a/plugins/media-keys/gsd-media-keys-manager.c b/plugins/media-keys/gsd-media-keys-manager.c
index bfeb0674..a700baf1 100644
--- a/plugins/media-keys/gsd-media-keys-manager.c
+++ b/plugins/media-keys/gsd-media-keys-manager.c
@@ -58,15 +58,6 @@
#define VOLUME_STEP 6 /* percents for one volume button press */
-/* we exclude shift, GDK_CONTROL_MASK and GDK_MOD1_MASK since we know what
- these modifiers mean
- these are the mods whose combinations are bound by the keygrabbing code */
-#define IGNORED_MODS (0x2000 /*Xkb modifier*/ | GDK_LOCK_MASK | \
- GDK_MOD2_MASK | GDK_MOD3_MASK | GDK_MOD4_MASK | GDK_MOD5_MASK)
-/* these are the ones we actually use for global keys, we always only check
- * for these set */
-#define USED_MODS (GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK)
-
#define GSD_MEDIA_KEYS_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_MEDIA_KEYS_MANAGER, GsdMediaKeysManagerPrivate))
typedef struct {
@@ -266,85 +257,6 @@ dialog_init (GsdMediaKeysManager *manager)
}
static gboolean
-grab_key_real (Key *key,
- GdkWindow *root,
- gboolean grab,
- int result)
-{
- gdk_error_trap_push ();
- if (grab) {
- XGrabKey (GDK_DISPLAY (),
- key->keycode,
- (result | key->state),
- GDK_WINDOW_XID (root),
- True,
- GrabModeAsync,
- GrabModeAsync);
- } else {
- XUngrabKey (GDK_DISPLAY (),
- key->keycode,
- (result | key->state),
- GDK_WINDOW_XID (root));
- }
-
- gdk_flush ();
-
- gdk_error_trap_pop ();
-
- return TRUE;
-}
-
-/* Grab the key. In order to ignore IGNORED_MODS we need to grab
- * all combinations of the ignored modifiers and those actually used
- * for the binding (if any).
- *
- * inspired by all_combinations from gnome-panel/gnome-panel/global-keys.c */
-#define N_BITS 32
-static void
-grab_key (GsdMediaKeysManager *manager,
- Key *key,
- gboolean grab)
-{
- int indexes[N_BITS]; /* indexes of bits we need to flip */
- int i;
- int bit;
- int bits_set_cnt;
- int uppervalue;
- guint mask = IGNORED_MODS & ~key->state & GDK_MODIFIER_MASK;
-
- bit = 0;
- /* store the indices of all set bits in mask in the array */
- for (i = 0; mask; ++i, mask >>= 1) {
- if (mask & 0x1) {
- indexes[bit++] = i;
- }
- }
-
- bits_set_cnt = bit;
-
- uppervalue = 1 << bits_set_cnt;
- /* grab all possible modifier combinations for our mask */
- for (i = 0; i < uppervalue; ++i) {
- GSList *l;
- int j;
- int result = 0;
-
- /* map bits in the counter to those in the mask */
- for (j = 0; j < bits_set_cnt; ++j) {
- if (i & (1 << j)) {
- result |= (1 << indexes[j]);
- }
- }
-
- for (l = manager->priv->screens; l ; l = l->next) {
- GdkScreen *screen = l->data;
- if (grab_key_real (key, gdk_screen_get_root_window (screen), grab, result) == FALSE)
- return;
- }
- }
-}
-
-static gboolean
is_valid_shortcut (const char *string)
{
if (string == NULL || string[0] == '\0') {
@@ -364,7 +276,6 @@ update_kbd_cb (GConfClient *client,
GsdMediaKeysManager *manager)
{
int i;
- gboolean found = FALSE;
g_return_if_fail (entry->key != NULL);
@@ -374,10 +285,8 @@ update_kbd_cb (GConfClient *client,
char *tmp;
Key *key;
- found = TRUE;
-
if (keys[i].key != NULL) {
- grab_key (manager, keys[i].key, FALSE);
+ grab_key (keys[i].key, FALSE, manager->priv->screens);
}
g_free (keys[i].key);
@@ -399,7 +308,7 @@ update_kbd_cb (GConfClient *client,
break;
}
- grab_key (manager, key, TRUE);
+ grab_key (key, TRUE, manager->priv->screens);
keys[i].key = key;
g_free (tmp);
@@ -407,10 +316,6 @@ update_kbd_cb (GConfClient *client,
break;
}
}
-
- if (found != FALSE) {
- return;
- }
}
static void
@@ -450,7 +355,7 @@ init_kbd (GsdMediaKeysManager *manager)
g_free (key);
continue;
}
- /*avoid grabbing all the keyboard when KeyCode cannot be retrieved */
+ /* avoid grabbing all the keyboard when KeyCode cannot be retrieved */
if (key->keycode == AnyKey) {
g_warning ("The shortcut key \"%s\" cannot be found on the current system, ignoring the binding", tmp);
g_free (tmp);
@@ -462,7 +367,7 @@ init_kbd (GsdMediaKeysManager *manager)
keys[i].key = key;
- grab_key (manager, key, TRUE);
+ grab_key (key, TRUE, manager->priv->screens);
}
gnome_settings_profile_end (NULL);
@@ -952,27 +857,16 @@ acme_filter_events (GdkXEvent *xevent,
GsdMediaKeysManager *manager)
{
XEvent *xev = (XEvent *) xevent;
- XAnyEvent *xanyev = (XAnyEvent *) xevent;
- guint keycode;
- guint state;
+ XAnyEvent *xany = (XAnyEvent *) xevent;
int i;
/* verify we have a key event */
- if (xev->xany.type != KeyPress
- && xev->xany.type != KeyRelease) {
+ if (xev->type != KeyPress && xev->type != KeyRelease) {
return GDK_FILTER_CONTINUE;
}
- keycode = xev->xkey.keycode;
- state = xev->xkey.state;
-
for (i = 0; i < HANDLED_KEYS; i++) {
- if (keys[i].key == NULL) {
- continue;
- }
-
- if (keys[i].key->keycode == keycode
- && (state & USED_MODS) == keys[i].key->state) {
+ if (match_key (keys[i].key, xev)) {
switch (keys[i].key_type) {
case VOLUME_DOWN_KEY:
case VOLUME_UP_KEY:
@@ -987,7 +881,7 @@ acme_filter_events (GdkXEvent *xevent,
}
}
- manager->priv->current_screen = acme_get_screen_from_event (manager, xanyev);
+ manager->priv->current_screen = acme_get_screen_from_event (manager, xany);
if (do_action (manager, keys[i].key_type) == FALSE) {
return GDK_FILTER_REMOVE;