gtk+ r21545 - in trunk: . docs/reference docs/reference/gdk gdk gdk/x11
- From: matthiasc svn gnome org
- To: svn-commits-list gnome org
- Subject: gtk+ r21545 - in trunk: . docs/reference docs/reference/gdk gdk gdk/x11
- Date: Mon, 29 Sep 2008 20:40:46 +0000 (UTC)
Author: matthiasc
Date: Mon Sep 29 20:40:45 2008
New Revision: 21545
URL: http://svn.gnome.org/viewvc/gtk+?rev=21545&view=rev
Log:
2008-09-29 Matthias Clasen <mclasen redhat com>
Bug 107000 â Add signals to GdkKeymap for monitoring caps_lock, etc.
* gdk/gdk.symbols:
* gdk/gdkkeys.[ch]: Add a new GdkKeymap::state-changed signal, and
a gdk_keymap_get_caps_lock_state function.
* gdk/x11/gdkkeys-x11.c: Implement it here. For now, only emit
state-changed when caps lock lockedness changes.
* gdk/x11/gdkdisplay-x11.c: Also select for modifier lock status
changes in the XkbSelectEventDetails call.
Modified:
trunk/ChangeLog
trunk/docs/reference/ChangeLog
trunk/docs/reference/gdk/gdk-sections.txt
trunk/gdk/gdk.symbols
trunk/gdk/gdkkeys.c
trunk/gdk/gdkkeys.h
trunk/gdk/x11/gdkdisplay-x11.c
trunk/gdk/x11/gdkkeys-x11.c
Modified: trunk/docs/reference/gdk/gdk-sections.txt
==============================================================================
--- trunk/docs/reference/gdk/gdk-sections.txt (original)
+++ trunk/docs/reference/gdk/gdk-sections.txt Mon Sep 29 20:40:45 2008
@@ -992,6 +992,7 @@
gdk_keymap_get_entries_for_keycode
gdk_keymap_get_direction
gdk_keymap_have_bidi_layouts
+gdk_keymap_get_caps_lock_state
<SUBSECTION>
gdk_keyval_name
Modified: trunk/gdk/gdk.symbols
==============================================================================
--- trunk/gdk/gdk.symbols (original)
+++ trunk/gdk/gdk.symbols Mon Sep 29 20:40:45 2008
@@ -829,6 +829,7 @@
gdk_keymap_get_entries_for_keyval
gdk_keymap_get_for_display
gdk_keymap_have_bidi_layouts
+gdk_keymap_get_caps_lock_state
gdk_keymap_lookup_key
gdk_keymap_translate_keyboard_state
gdk_keyval_convert_case
Modified: trunk/gdk/gdkkeys.c
==============================================================================
--- trunk/gdk/gdkkeys.c (original)
+++ trunk/gdk/gdkkeys.c Mon Sep 29 20:40:45 2008
@@ -33,6 +33,7 @@
enum {
DIRECTION_CHANGED,
KEYS_CHANGED,
+ STATE_CHANGED,
LAST_SIGNAL
};
@@ -81,6 +82,26 @@
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE,
0);
+
+ /**
+ * GdkKeymap::state-changed:
+ * @keymap: the object on which the signal is emitted
+ *
+ * The ::state-changed signal is emitted when the state of the
+ * keyboard changes, e.g when the Caps Lock is turned on or off.
+ * See gdk_keyboard_get_caps_lock_state().
+ *
+ * Since: 2.16
+ */
+ signals[STATE_CHANGED] =
+ g_signal_new ("state_changed",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GdkKeymapClass, state_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0);
}
static void
Modified: trunk/gdk/gdkkeys.h
==============================================================================
--- trunk/gdk/gdkkeys.h (original)
+++ trunk/gdk/gdkkeys.h Mon Sep 29 20:40:45 2008
@@ -75,6 +75,7 @@
void (*direction_changed) (GdkKeymap *keymap);
void (*keys_changed) (GdkKeymap *keymap);
+ void (*state_changed) (GdkKeymap *keymap);
};
GType gdk_keymap_get_type (void) G_GNUC_CONST;
@@ -106,6 +107,7 @@
gint *n_entries);
PangoDirection gdk_keymap_get_direction (GdkKeymap *keymap);
gboolean gdk_keymap_have_bidi_layouts (GdkKeymap *keymap);
+gboolean gdk_keymap_get_caps_lock_state (GdkKeymap *keymap);
/* Key values
*/
Modified: trunk/gdk/x11/gdkdisplay-x11.c
==============================================================================
--- trunk/gdk/x11/gdkdisplay-x11.c (original)
+++ trunk/gdk/x11/gdkdisplay-x11.c Mon Sep 29 20:40:45 2008
@@ -356,7 +356,7 @@
XkbSelectEventDetails (display_x11->xdisplay,
XkbUseCoreKbd, XkbStateNotify,
XkbAllStateComponentsMask,
- XkbGroupLockMask);
+ XkbGroupLockMask|XkbModifierLockMask);
XkbSetDetectableAutoRepeat (display_x11->xdisplay,
True,
Modified: trunk/gdk/x11/gdkkeys-x11.c
==============================================================================
--- trunk/gdk/x11/gdkkeys-x11.c (original)
+++ trunk/gdk/x11/gdkkeys-x11.c Mon Sep 29 20:40:45 2008
@@ -82,9 +82,10 @@
GdkModifierType group_switch_mask;
GdkModifierType num_lock_mask;
GdkModifierType modmap[8];
- gboolean sun_keypad;
PangoDirection current_direction;
- gboolean have_direction;
+ guint sun_keypad : 1;
+ guint have_direction : 1;
+ guint caps_lock_state : 1;
guint current_serial;
#ifdef HAVE_XKB
@@ -656,12 +657,17 @@
return xkb->ctrls->num_groups;
}
-static void
+static gboolean
update_direction (GdkKeymapX11 *keymap_x11,
gint group)
{
XkbDescPtr xkb = get_xkb (keymap_x11);
Atom group_atom;
+ gboolean had_direction;
+ PangoDirection old_direction;
+
+ had_direction = keymap_x11->have_direction;
+ old_direction = keymap_x11->current_direction;
group_atom = xkb->names->groups[group];
@@ -672,6 +678,21 @@
keymap_x11->current_group_atom = group_atom;
keymap_x11->have_direction = TRUE;
}
+
+ return !had_direction || old_direction != keymap_x11->current_direction;
+}
+
+static gboolean
+update_lock_state (GdkKeymapX11 *keymap_x11,
+ gint locked_mods)
+{
+ gboolean caps_lock_state;
+
+ caps_lock_state = keymap_x11->caps_lock_state;
+
+ keymap_x11->caps_lock_state = (locked_mods & GDK_LOCK_MASK) != 0;
+
+ return caps_lock_state != keymap_x11->caps_lock_state;
}
/* keep this in sync with the XkbSelectEventDetails() call
@@ -684,19 +705,16 @@
GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
XkbEvent *xkb_event = (XkbEvent *)xevent;
+ g_print ("keymap state changed\n");
if (display_x11->keymap)
{
GdkKeymapX11 *keymap_x11 = GDK_KEYMAP_X11 (display_x11->keymap);
- gboolean had_direction;
- PangoDirection direction;
-
- had_direction = keymap_x11->have_direction;
- direction = keymap_x11->current_direction;
-
- update_direction (keymap_x11, XkbStateGroup (&xkb_event->state));
- if (!had_direction || direction != keymap_x11->current_direction)
- g_signal_emit_by_name (keymap_x11, "direction_changed");
+ if (update_direction (keymap_x11, XkbStateGroup (&xkb_event->state)))
+ g_signal_emit_by_name (keymap_x11, "direction-changed");
+
+ if (update_lock_state (keymap_x11, xkb_event->state.locked_mods))
+ g_signal_emit_by_name (keymap_x11, "state-changed");
}
}
@@ -793,6 +811,29 @@
}
/**
+ * gdk_keymap_get_caps_lock_state:
+ * @keymap: a #GdkKeymap
+ *
+ * Returns wether the Caps Lock modifer is locked.
+ *
+ * Returns: %TRUE if Caps Lock is on
+ *
+ * Since: 2.16
+ */
+gboolean
+gdk_keymap_get_caps_lock_state (GdkKeymap *keymap)
+{
+ GdkKeymapX11 *keymap_x11;
+
+ keymap = GET_EFFECTIVE_KEYMAP (keymap);
+
+ keymap_x11 = GDK_KEYMAP_X11 (keymap);
+
+ return keymap_x11->caps_lock_state;
+}
+
+
+/**
* gdk_keymap_get_entries_for_keyval:
* @keymap: a #GdkKeymap, or %NULL to use the default keymap
* @keyval: a keyval, such as %GDK_a, %GDK_Up, %GDK_Return, etc.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]