+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.
+
2008-09-29 Kristian Rietveld <kris@imendio.com>
Bug 487624 - Tooltips doesn't get updated if ther's no mouse motion
enum {
DIRECTION_CHANGED,
KEYS_CHANGED,
+ STATE_CHANGED,
LAST_SIGNAL
};
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
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
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];
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
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");
}
}
return FALSE;
}
+/**
+ * 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