[mutter/wayland: 8/15] Move meta_ui_parse_accelerator into core/
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/wayland: 8/15] Move meta_ui_parse_accelerator into core/
- Date: Mon, 7 Apr 2014 15:23:04 +0000 (UTC)
commit 0466fe9301c8d33564809a547de91977904edef7
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Mon Apr 7 10:48:16 2014 -0400
Move meta_ui_parse_accelerator into core/
We're currently using GTK+ for this, but we'll stop doing that fairly
quickly and instead just copy the GTK+ code in-tree.
src/Makefile.am | 2 +
src/core/keybindings.c | 3 +-
src/core/meta-accel-parse.c | 184 +++++++++++++++++++++++++++++++++++++++++++
src/core/meta-accel-parse.h | 43 ++++++++++
src/core/prefs.c | 11 ++-
src/ui/ui.c | 158 -------------------------------------
src/ui/ui.h | 12 ---
7 files changed, 237 insertions(+), 176 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 61a14fe..2d6a7df 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -78,6 +78,8 @@ libmutter_wayland_la_SOURCES = \
backends/x11/meta-monitor-manager-xrandr.c \
backends/x11/meta-monitor-manager-xrandr.h \
backends/x11/meta-xrandr-shared.h \
+ core/meta-accel-parse.c \
+ core/meta-accel-parse.h \
core/above-tab-keycode.c \
core/barrier.c \
meta/barrier.h \
diff --git a/src/core/keybindings.c b/src/core/keybindings.c
index 88ff425..cefcf23 100644
--- a/src/core/keybindings.c
+++ b/src/core/keybindings.c
@@ -41,6 +41,7 @@
#include "screen-private.h"
#include <meta/prefs.h>
#include "util-private.h"
+#include "meta-accel-parse.h"
#include <X11/keysym.h>
#include <string.h>
@@ -1284,7 +1285,7 @@ meta_display_grab_accelerator (MetaDisplay *display,
guint mask = 0;
MetaVirtualModifier modifiers = 0;
- if (!meta_ui_parse_accelerator (accelerator, &keysym, &keycode, &modifiers))
+ if (!meta_parse_accelerator (accelerator, &keysym, &keycode, &modifiers))
{
meta_topic (META_DEBUG_KEYBINDINGS,
"Failed to parse accelerator\n");
diff --git a/src/core/meta-accel-parse.c b/src/core/meta-accel-parse.c
new file mode 100644
index 0000000..2a165ef
--- /dev/null
+++ b/src/core/meta-accel-parse.c
@@ -0,0 +1,184 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+
+/*
+ * Copyright (C) 2014 Red Hat
+ *
+ * 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.
+ *
+ * Written by:
+ * Jasper St. Pierre <jstpierre mecheye net>
+ */
+
+#include "config.h"
+
+#include "meta-accel-parse.h"
+
+#include <gtk/gtk.h>
+#include <string.h>
+#include <stdlib.h>
+
+static void
+accelerator_parse (const char *accel,
+ guint *keysym,
+ guint *keycode,
+ GdkModifierType *keymask)
+{
+ const char *above_tab;
+
+ if (accel[0] == '0' && accel[1] == 'x')
+ {
+ *keysym = 0;
+ *keycode = (guint) strtoul (accel, NULL, 16);
+ *keymask = 0;
+
+ return;
+ }
+
+ /* The key name 'Above_Tab' is special - it's not an actual keysym name,
+ * but rather refers to the key above the tab key. In order to use
+ * the GDK parsing for modifiers in combination with it, we substitute
+ * it with 'Tab' temporarily before calling gtk_accelerator_parse().
+ */
+#define is_word_character(c) (g_ascii_isalnum(c) || ((c) == '_'))
+#define ABOVE_TAB "Above_Tab"
+#define ABOVE_TAB_LEN 9
+
+ above_tab = strstr (accel, ABOVE_TAB);
+ if (above_tab &&
+ (above_tab == accel || !is_word_character (above_tab[-1])) &&
+ !is_word_character (above_tab[ABOVE_TAB_LEN]))
+ {
+ char *before = g_strndup (accel, above_tab - accel);
+ char *after = g_strdup (above_tab + ABOVE_TAB_LEN);
+ char *replaced = g_strconcat (before, "Tab", after, NULL);
+
+ gtk_accelerator_parse (replaced, NULL, keymask);
+
+ g_free (before);
+ g_free (after);
+ g_free (replaced);
+
+ *keysym = META_KEY_ABOVE_TAB;
+ return;
+ }
+
+#undef is_word_character
+#undef ABOVE_TAB
+#undef ABOVE_TAB_LEN
+
+ gtk_accelerator_parse (accel, keysym, keymask);
+}
+
+gboolean
+meta_parse_accelerator (const char *accel,
+ unsigned int *keysym,
+ unsigned int *keycode,
+ MetaVirtualModifier *mask)
+{
+ GdkModifierType gdk_mask = 0;
+ guint gdk_sym = 0;
+ guint gdk_code = 0;
+
+ *keysym = 0;
+ *keycode = 0;
+ *mask = 0;
+
+ if (!accel[0] || strcmp (accel, "disabled") == 0)
+ return TRUE;
+
+ accelerator_parse (accel, &gdk_sym, &gdk_code, &gdk_mask);
+ if (gdk_mask == 0 && gdk_sym == 0 && gdk_code == 0)
+ return FALSE;
+
+ if (gdk_sym == None && gdk_code == 0)
+ return FALSE;
+
+ if (gdk_mask & GDK_RELEASE_MASK) /* we don't allow this */
+ return FALSE;
+
+ *keysym = gdk_sym;
+ *keycode = gdk_code;
+
+ if (gdk_mask & GDK_SHIFT_MASK)
+ *mask |= META_VIRTUAL_SHIFT_MASK;
+ if (gdk_mask & GDK_CONTROL_MASK)
+ *mask |= META_VIRTUAL_CONTROL_MASK;
+ if (gdk_mask & GDK_MOD1_MASK)
+ *mask |= META_VIRTUAL_ALT_MASK;
+ if (gdk_mask & GDK_MOD2_MASK)
+ *mask |= META_VIRTUAL_MOD2_MASK;
+ if (gdk_mask & GDK_MOD3_MASK)
+ *mask |= META_VIRTUAL_MOD3_MASK;
+ if (gdk_mask & GDK_MOD4_MASK)
+ *mask |= META_VIRTUAL_MOD4_MASK;
+ if (gdk_mask & GDK_MOD5_MASK)
+ *mask |= META_VIRTUAL_MOD5_MASK;
+ if (gdk_mask & GDK_SUPER_MASK)
+ *mask |= META_VIRTUAL_SUPER_MASK;
+ if (gdk_mask & GDK_HYPER_MASK)
+ *mask |= META_VIRTUAL_HYPER_MASK;
+ if (gdk_mask & GDK_META_MASK)
+ *mask |= META_VIRTUAL_META_MASK;
+
+ return TRUE;
+}
+
+gboolean
+meta_parse_modifier (const char *accel,
+ MetaVirtualModifier *mask)
+{
+ GdkModifierType gdk_mask = 0;
+ guint gdk_sym = 0;
+ guint gdk_code = 0;
+
+ *mask = 0;
+
+ if (accel == NULL || !accel[0] || strcmp (accel, "disabled") == 0)
+ return TRUE;
+
+ accelerator_parse (accel, &gdk_sym, &gdk_code, &gdk_mask);
+ if (gdk_mask == 0 && gdk_sym == 0 && gdk_code == 0)
+ return FALSE;
+
+ if (gdk_sym != None || gdk_code != 0)
+ return FALSE;
+
+ if (gdk_mask & GDK_RELEASE_MASK) /* we don't allow this */
+ return FALSE;
+
+ if (gdk_mask & GDK_SHIFT_MASK)
+ *mask |= META_VIRTUAL_SHIFT_MASK;
+ if (gdk_mask & GDK_CONTROL_MASK)
+ *mask |= META_VIRTUAL_CONTROL_MASK;
+ if (gdk_mask & GDK_MOD1_MASK)
+ *mask |= META_VIRTUAL_ALT_MASK;
+ if (gdk_mask & GDK_MOD2_MASK)
+ *mask |= META_VIRTUAL_MOD2_MASK;
+ if (gdk_mask & GDK_MOD3_MASK)
+ *mask |= META_VIRTUAL_MOD3_MASK;
+ if (gdk_mask & GDK_MOD4_MASK)
+ *mask |= META_VIRTUAL_MOD4_MASK;
+ if (gdk_mask & GDK_MOD5_MASK)
+ *mask |= META_VIRTUAL_MOD5_MASK;
+ if (gdk_mask & GDK_SUPER_MASK)
+ *mask |= META_VIRTUAL_SUPER_MASK;
+ if (gdk_mask & GDK_HYPER_MASK)
+ *mask |= META_VIRTUAL_HYPER_MASK;
+ if (gdk_mask & GDK_META_MASK)
+ *mask |= META_VIRTUAL_META_MASK;
+
+ return TRUE;
+}
diff --git a/src/core/meta-accel-parse.h b/src/core/meta-accel-parse.h
new file mode 100644
index 0000000..1d58375
--- /dev/null
+++ b/src/core/meta-accel-parse.h
@@ -0,0 +1,43 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright (C) 2014 Red Hat
+ *
+ * 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.
+ *
+ * Written by:
+ * Jasper St. Pierre <jstpierre mecheye net>
+ */
+
+#ifndef META_ACCEL_PARSE_H
+#define META_ACCEL_PARSE_H
+
+#include <glib.h>
+#include <meta/common.h>
+
+/* Not a real key symbol but means "key above the tab key"; this is
+ * used as the default keybinding for cycle_group.
+ * 0x2xxxxxxx is a range not used by GDK or X. the remaining digits are
+ * randomly chosen */
+#define META_KEY_ABOVE_TAB 0x2f7259c9
+
+gboolean meta_parse_accelerator (const char *accel,
+ unsigned int *keysym,
+ unsigned int *keycode,
+ MetaVirtualModifier *mask);
+gboolean meta_parse_modifier (const char *accel,
+ MetaVirtualModifier *mask);
+
+#endif /* META_ACCEL_PARSE_H */
diff --git a/src/core/prefs.c b/src/core/prefs.c
index a2d01de..98d62ee 100644
--- a/src/core/prefs.c
+++ b/src/core/prefs.c
@@ -36,6 +36,7 @@
#include <string.h>
#include <stdlib.h>
#include "keybindings-private.h"
+#include "meta-accel-parse.h"
/* If you add a key, it needs updating in init() and in the gsettings
* notify listener and of course in the .schemas file.
@@ -1323,7 +1324,7 @@ mouse_button_mods_handler (GVariant *value,
*result = NULL; /* ignored */
string_value = g_variant_get_string (value, NULL);
- if (!string_value || !meta_ui_parse_modifier (string_value, &mods))
+ if (!string_value || !meta_parse_modifier (string_value, &mods))
{
meta_topic (META_DEBUG_KEYBINDINGS,
"Failed to parse new GSettings value\n");
@@ -1627,9 +1628,9 @@ overlay_key_handler (GVariant *value,
*result = NULL; /* ignored */
string_value = g_variant_get_string (value, NULL);
- if (string_value && meta_ui_parse_accelerator (string_value, &combo.keysym,
- &combo.keycode,
- &combo.modifiers))
+ if (string_value && meta_parse_accelerator (string_value, &combo.keysym,
+ &combo.keycode,
+ &combo.modifiers))
;
else
{
@@ -1887,7 +1888,7 @@ update_binding (MetaKeyPref *binding,
keycode = 0;
mods = 0;
- if (!meta_ui_parse_accelerator (strokes[i], &keysym, &keycode, &mods))
+ if (!meta_parse_accelerator (strokes[i], &keysym, &keycode, &mods))
{
meta_topic (META_DEBUG_KEYBINDINGS,
"Failed to parse new GSettings value\n");
diff --git a/src/ui/ui.c b/src/ui/ui.c
index 6fe435e..9dbb6a6 100644
--- a/src/ui/ui.c
+++ b/src/ui/ui.c
@@ -32,11 +32,6 @@
#include <stdlib.h>
#include <cairo-xlib.h>
-static void meta_ui_accelerator_parse (const char *accel,
- guint *keysym,
- guint *keycode,
- GdkModifierType *keymask);
-
struct _MetaUI
{
Display *xdisplay;
@@ -715,159 +710,6 @@ meta_ui_have_a_theme (void)
return meta_theme_get_current () != NULL;
}
-static void
-meta_ui_accelerator_parse (const char *accel,
- guint *keysym,
- guint *keycode,
- GdkModifierType *keymask)
-{
- const char *above_tab;
-
- if (accel[0] == '0' && accel[1] == 'x')
- {
- *keysym = 0;
- *keycode = (guint) strtoul (accel, NULL, 16);
- *keymask = 0;
-
- return;
- }
-
- /* The key name 'Above_Tab' is special - it's not an actual keysym name,
- * but rather refers to the key above the tab key. In order to use
- * the GDK parsing for modifiers in combination with it, we substitute
- * it with 'Tab' temporarily before calling gtk_accelerator_parse().
- */
-#define is_word_character(c) (g_ascii_isalnum(c) || ((c) == '_'))
-#define ABOVE_TAB "Above_Tab"
-#define ABOVE_TAB_LEN 9
-
- above_tab = strstr (accel, ABOVE_TAB);
- if (above_tab &&
- (above_tab == accel || !is_word_character (above_tab[-1])) &&
- !is_word_character (above_tab[ABOVE_TAB_LEN]))
- {
- char *before = g_strndup (accel, above_tab - accel);
- char *after = g_strdup (above_tab + ABOVE_TAB_LEN);
- char *replaced = g_strconcat (before, "Tab", after, NULL);
-
- gtk_accelerator_parse (replaced, NULL, keymask);
-
- g_free (before);
- g_free (after);
- g_free (replaced);
-
- *keysym = META_KEY_ABOVE_TAB;
- return;
- }
-
-#undef is_word_character
-#undef ABOVE_TAB
-#undef ABOVE_TAB_LEN
-
- gtk_accelerator_parse (accel, keysym, keymask);
-}
-
-gboolean
-meta_ui_parse_accelerator (const char *accel,
- unsigned int *keysym,
- unsigned int *keycode,
- MetaVirtualModifier *mask)
-{
- GdkModifierType gdk_mask = 0;
- guint gdk_sym = 0;
- guint gdk_code = 0;
-
- *keysym = 0;
- *keycode = 0;
- *mask = 0;
-
- if (!accel[0] || strcmp (accel, "disabled") == 0)
- return TRUE;
-
- meta_ui_accelerator_parse (accel, &gdk_sym, &gdk_code, &gdk_mask);
- if (gdk_mask == 0 && gdk_sym == 0 && gdk_code == 0)
- return FALSE;
-
- if (gdk_sym == None && gdk_code == 0)
- return FALSE;
-
- if (gdk_mask & GDK_RELEASE_MASK) /* we don't allow this */
- return FALSE;
-
- *keysym = gdk_sym;
- *keycode = gdk_code;
-
- if (gdk_mask & GDK_SHIFT_MASK)
- *mask |= META_VIRTUAL_SHIFT_MASK;
- if (gdk_mask & GDK_CONTROL_MASK)
- *mask |= META_VIRTUAL_CONTROL_MASK;
- if (gdk_mask & GDK_MOD1_MASK)
- *mask |= META_VIRTUAL_ALT_MASK;
- if (gdk_mask & GDK_MOD2_MASK)
- *mask |= META_VIRTUAL_MOD2_MASK;
- if (gdk_mask & GDK_MOD3_MASK)
- *mask |= META_VIRTUAL_MOD3_MASK;
- if (gdk_mask & GDK_MOD4_MASK)
- *mask |= META_VIRTUAL_MOD4_MASK;
- if (gdk_mask & GDK_MOD5_MASK)
- *mask |= META_VIRTUAL_MOD5_MASK;
- if (gdk_mask & GDK_SUPER_MASK)
- *mask |= META_VIRTUAL_SUPER_MASK;
- if (gdk_mask & GDK_HYPER_MASK)
- *mask |= META_VIRTUAL_HYPER_MASK;
- if (gdk_mask & GDK_META_MASK)
- *mask |= META_VIRTUAL_META_MASK;
-
- return TRUE;
-}
-
-gboolean
-meta_ui_parse_modifier (const char *accel,
- MetaVirtualModifier *mask)
-{
- GdkModifierType gdk_mask = 0;
- guint gdk_sym = 0;
- guint gdk_code = 0;
-
- *mask = 0;
-
- if (accel == NULL || !accel[0] || strcmp (accel, "disabled") == 0)
- return TRUE;
-
- meta_ui_accelerator_parse (accel, &gdk_sym, &gdk_code, &gdk_mask);
- if (gdk_mask == 0 && gdk_sym == 0 && gdk_code == 0)
- return FALSE;
-
- if (gdk_sym != None || gdk_code != 0)
- return FALSE;
-
- if (gdk_mask & GDK_RELEASE_MASK) /* we don't allow this */
- return FALSE;
-
- if (gdk_mask & GDK_SHIFT_MASK)
- *mask |= META_VIRTUAL_SHIFT_MASK;
- if (gdk_mask & GDK_CONTROL_MASK)
- *mask |= META_VIRTUAL_CONTROL_MASK;
- if (gdk_mask & GDK_MOD1_MASK)
- *mask |= META_VIRTUAL_ALT_MASK;
- if (gdk_mask & GDK_MOD2_MASK)
- *mask |= META_VIRTUAL_MOD2_MASK;
- if (gdk_mask & GDK_MOD3_MASK)
- *mask |= META_VIRTUAL_MOD3_MASK;
- if (gdk_mask & GDK_MOD4_MASK)
- *mask |= META_VIRTUAL_MOD4_MASK;
- if (gdk_mask & GDK_MOD5_MASK)
- *mask |= META_VIRTUAL_MOD5_MASK;
- if (gdk_mask & GDK_SUPER_MASK)
- *mask |= META_VIRTUAL_SUPER_MASK;
- if (gdk_mask & GDK_HYPER_MASK)
- *mask |= META_VIRTUAL_HYPER_MASK;
- if (gdk_mask & GDK_META_MASK)
- *mask |= META_VIRTUAL_META_MASK;
-
- return TRUE;
-}
-
gboolean
meta_ui_window_is_widget (MetaUI *ui,
Window xwindow)
diff --git a/src/ui/ui.h b/src/ui/ui.h
index 9633b2c..56e19fc 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -145,18 +145,6 @@ gboolean meta_ui_window_should_not_cause_focus (Display *xdisplay,
void meta_ui_set_current_theme (const char *name);
gboolean meta_ui_have_a_theme (void);
-/* Not a real key symbol but means "key above the tab key"; this is
- * used as the default keybinding for cycle_group.
- * 0x2xxxxxxx is a range not used by GDK or X. the remaining digits are
- * randomly chosen */
-#define META_KEY_ABOVE_TAB 0x2f7259c9
-
-gboolean meta_ui_parse_accelerator (const char *accel,
- unsigned int *keysym,
- unsigned int *keycode,
- MetaVirtualModifier *mask);
-gboolean meta_ui_parse_modifier (const char *accel,
- MetaVirtualModifier *mask);
gboolean meta_ui_window_is_widget (MetaUI *ui,
Window xwindow);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]