summaryrefslogtreecommitdiff
path: root/libcaribou/xadapter.vala
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2011-06-02 12:56:01 -0400
committerEitan Isaacson <eitan@monotonous.org>2011-06-08 11:15:53 -0700
commitea323335ac66a5633f00fd62c9284e6bff7bdeb5 (patch)
tree3ae8c91ae105cea40edf6e85ee3a8e751da0deab /libcaribou/xadapter.vala
parent04cd580db692079335b8331e1dd3f3c05142007b (diff)
downloadcaribou-ea323335ac66a5633f00fd62c9284e6bff7bdeb5.tar.gz
xadapter: get all group information from libxklavier
The XkbStateNotifyEvent "group" field does not seem to correspond reliably to libxklavier group numbers, resulting in warnings and crashes when we try to look up the libxklavier group name corresponding to an apparently-bogus group number. Fix this by using Xkl.State's group rather than the Xkb event's. https://bugzilla.gnome.org/show_bug.cgi?id=651724
Diffstat (limited to 'libcaribou/xadapter.vala')
-rw-r--r--libcaribou/xadapter.vala38
1 files changed, 24 insertions, 14 deletions
diff --git a/libcaribou/xadapter.vala b/libcaribou/xadapter.vala
index cad827b..8b6b196 100644
--- a/libcaribou/xadapter.vala
+++ b/libcaribou/xadapter.vala
@@ -35,7 +35,8 @@ namespace Caribou {
HashTable<uint, KeyButtonHandler> key_funcs;
construct {
- Xkb.State state;
+ Xkb.State xkb_state;
+ unowned Xkl.State xkl_state;
Gdk.Window rootwin = Gdk.get_default_root_window();
this.xdisplay = Gdk.X11Display.get_xdisplay (rootwin.get_display ());
@@ -44,11 +45,15 @@ namespace Caribou {
Xkb.GBN_AllComponentsMask,
Xkb.UseCoreKbd);
this.xkl_engine = Xkl.Engine.get_instance (this.xdisplay);
+ xkl_engine.start_listen (Xkl.EngineListenModes.TRACK_KEYBOARD_STATE);
+ xkl_state = this.xkl_engine.get_current_state ();
+ this.group = (uchar) xkl_state.group;
+ Signal.connect_object (xkl_engine, "X-state-changed",
+ (Callback) xkl_state_changed,
+ this, ConnectFlags.AFTER);
- Xkb.get_state (this.xdisplay, Xkb.UseCoreKbd, out state);
-
- this.group = state.group;
- this.modifiers = state.mods;
+ Xkb.get_state (this.xdisplay, Xkb.UseCoreKbd, out xkb_state);
+ this.modifiers = xkb_state.mods;
this.reserved_keycode = 0;
@@ -78,8 +83,10 @@ namespace Caribou {
private Gdk.FilterReturn x_event_filter (Gdk.XEvent xevent, Gdk.Event event) {
void* pointer = &xevent;
- Xkb.Event *xkbev = (Xkb.Event *) pointer;
- X.Event *xev = (X.Event *) pointer;
+ Xkb.Event* xkbev = (Xkb.Event *) pointer;
+ X.Event* xev = (X.Event *) pointer;
+
+ this.xkl_engine.filter_events(xev);
if (xev.type == X.EventType.ButtonPress ||
xev.type == X.EventType.ButtonRelease) {
@@ -98,13 +105,7 @@ namespace Caribou {
xev.type == X.EventType.KeyPress);
} else if (xkbev.any.xkb_type == Xkb.StateNotify) {
Xkb.StateNotifyEvent *sevent = &xkbev.state;
- if ((sevent.changed & Xkb.GroupStateMask) != 0) {
- string group_name;
- string variant_name;
- this.group = (uchar) sevent.group;
- get_current_group (out group_name, out variant_name);
- group_changed (this.group, group_name, variant_name);
- } else if ((sevent.changed & Xkb.ModifierStateMask) != 0) {
+ if ((sevent.changed & Xkb.ModifierStateMask) != 0) {
this.modifiers = (uchar) sevent.mods;
}
}
@@ -112,6 +113,15 @@ namespace Caribou {
return Gdk.FilterReturn.CONTINUE;
}
+ private static void xkl_state_changed (Xkl.Engine xklengine, int type, int group, bool restore, XAdapter self) {
+ string group_name;
+ string variant_name;
+
+ self.group = (uchar) group;
+ self.get_current_group (out group_name, out variant_name);
+ self.group_changed (self.group, group_name, variant_name);
+ }
+
private uchar get_reserved_keycode () {
uchar i;
unowned Xkb.Desc xkbdesc = this.xkbdesc;