don't strip the xkey event states, and make the menus work with non-US stuff. github/xkb origin/xkb xkb
authorDana Jansens <danakj@orodu.net>
Thu, 11 Feb 2010 14:46:16 +0000 (09:46 -0500)
committerDana Jansens <danakj@orodu.net>
Thu, 11 Feb 2010 14:46:16 +0000 (09:46 -0500)
xkb needs to read the state in the event to translate it into a character properly.
menus have to respond to keypress events to work with non-US keyboard stuff,
  so make that happen but still exec stuff on keyrelease

openbox/actions/cyclewindows.c
openbox/actions/desktop.c
openbox/actions/directionalwindows.c
openbox/actions/execute.c
openbox/event.c
openbox/keyboard.c
openbox/menuframe.c
openbox/moveresize.c
openbox/prompt.c

index d1112242d6f1f7c74c495551e3623361507b97a3..cad08700557f548dc1ce1eeb08e315f9a3ca7a96 100644 (file)
@@ -5,6 +5,7 @@
 #include "openbox/focus_cycle.h"
 #include "openbox/openbox.h"
 #include "gettext.h"
+#include "obt/keyboard.h"
 
 typedef struct {
     gboolean linear;
@@ -172,6 +173,14 @@ static gboolean i_input_func(guint initial_state,
                              gboolean *used)
 {
     Options *o = options;
+    guint mods;
+
+    mods = obt_keyboard_only_modmasks(e->xkey.state);
+    if (e->type == KeyRelease) {
+        /* remove from the state the mask of the modifier key being
+           released, if it is a modifier key being released that is */
+        mods &= ~obt_keyboard_keycode_to_modmask(e->xkey.keycode);
+    }
 
     if (e->type == KeyPress) {
         /* Escape cancels no matter what */
@@ -192,7 +201,7 @@ static gboolean i_input_func(guint initial_state,
     }
     /* They released the modifiers */
     else if (e->type == KeyRelease && initial_state &&
-             (e->xkey.state & initial_state) == 0)
+             (mods & initial_state) == 0)
     {
         o->cancel = FALSE;
         o->state = e->xkey.state;
index 5b0282cc69f1edb87460aaba3ee61a9e0511c977..e794bf8be3be9269cac9cd26a3a422ddb024ff3a 100644 (file)
@@ -2,7 +2,7 @@
 #include "openbox/screen.h"
 #include "openbox/client.h"
 #include "openbox/openbox.h"
-#include <glib.h>
+#include "obt/keyboard.h"
 
 typedef enum {
     LAST,
@@ -300,6 +300,15 @@ static gboolean i_input_func(guint initial_state,
                              gpointer options,
                              gboolean *used)
 {
+    guint mods;
+
+    mods = obt_keyboard_only_modmasks(e->xkey.state);
+    if (e->type == KeyRelease) {
+        /* remove from the state the mask of the modifier key being
+           released, if it is a modifier key being released that is */
+        mods &= ~obt_keyboard_keycode_to_modmask(e->xkey.keycode);
+    }
+
     if (e->type == KeyPress) {
         /* Escape cancels no matter what */
         if (ob_keycode_match(e->xkey.keycode, OB_KEY_ESCAPE)) {
@@ -315,7 +324,7 @@ static gboolean i_input_func(guint initial_state,
     }
     /* They released the modifiers */
     else if (e->type == KeyRelease && initial_state &&
-             (e->xkey.state & initial_state) == 0)
+             (mods & initial_state) == 0)
     {
         return FALSE;
     }
index 2cca450c6d919981784a1b26f237d78afd5f6df6..bf735209d68e9567fa76ee3f74ca63bce69cd4fb 100644 (file)
@@ -256,6 +256,15 @@ static gboolean i_input_func(guint initial_state,
                              gpointer options,
                              gboolean *used)
 {
+    guint mods;
+
+    mods = obt_keyboard_only_modmasks(e->xkey.state);
+    if (e->type == KeyRelease) {
+        /* remove from the state the mask of the modifier key being
+           released, if it is a modifier key being released that is */
+        mods &= ~obt_keyboard_keycode_to_modmask(e->xkey.keycode);
+    }
+
     if (e->type == KeyPress) {
         /* Escape cancels no matter what */
         if (ob_keycode_match(e->xkey.keycode, OB_KEY_ESCAPE)) {
@@ -273,7 +282,7 @@ static gboolean i_input_func(guint initial_state,
     }
     /* They released the modifiers */
     else if (e->type == KeyRelease && initial_state &&
-             (e->xkey.state & initial_state) == 0)
+             (mods & initial_state) == 0)
     {
         end_cycle(FALSE, e->xkey.state, options);
         return FALSE;
index 0e9e7387e518cc19f55382c8ac937ac79367ad2f..618153b0a343100322659473e1f9a555a09ce9eb 100644 (file)
@@ -23,13 +23,6 @@ typedef struct {
 static gpointer setup_func(xmlNodePtr node);
 static void     free_func(gpointer options);
 static gboolean run_func(ObActionsData *data, gpointer options);
-/*
-static gboolean i_input_func(guint initial_state,
-                             XEvent *e,
-                             gpointer options,
-                             gboolean *used);
-static void     i_cancel_func(gpointer options);
-*/
 
 void action_execute_startup(void)
 {
index 5ed8956e936b6f626e79fbc7950e4b9b5344e754..04d682a29e3806bdca84036307a422c8fb4adde6 100644 (file)
@@ -270,13 +270,8 @@ static void event_hack_mods(XEvent *e)
         e->xbutton.state = obt_keyboard_only_modmasks(e->xbutton.state);
         break;
     case KeyPress:
-        //e->xkey.state = obt_keyboard_only_modmasks(e->xkey.state);
         break;
     case KeyRelease:
-        //e->xkey.state = obt_keyboard_only_modmasks(e->xkey.state);
-        /* remove from the state the mask of the modifier key being
-           released, if it is a modifier key being released that is */
-        //e->xkey.state &= ~obt_keyboard_keycode_to_modmask(e->xkey.keycode);
         break;
     case MotionNotify:
         e->xmotion.state = obt_keyboard_only_modmasks(e->xmotion.state);
@@ -1812,153 +1807,152 @@ static gboolean event_handle_menu_input(XEvent *ev)
                 f->child == e->frame)
                 menu_frame_select(e->frame, e, FALSE);
     }
-    /* Allow control while going thru the menu */
-    else if (ev->type == KeyPress && (state & ~ControlMask) == 0) {
-        guint keycode, state;
-        static gunichar unikey;
+    else {
+        static guint keycode;
+        static gboolean doexec;
         ObMenuFrame *frame;
+        guint mods;
+        gunichar unikey;
 
-        keycode = ev->xkey.keycode;
-        state = obt_keyboard_only_modmasks(ev->xkey.state);
+        g_assert(ev->type == KeyPress || ev->type == KeyRelease);
+
+        /* get the modifiers */
+        mods = obt_keyboard_only_modmasks(ev->xkey.state);
 
         frame = find_active_or_last_menu();
         if (frame == NULL)
             g_assert_not_reached(); /* there is no active menu */
 
-        frame->got_press = TRUE;
+        /* Allow control while going thru the menu */
+        else if (ev->type == KeyPress && (mods & ~ControlMask) == 0) {
+            /* remember the last pressed key */
+            keycode = ev->xkey.keycode;
+            doexec = FALSE;
 
-        if (ob_keycode_match(keycode, OB_KEY_ESCAPE)) {
-            menu_frame_hide_all();
-            ret = TRUE;
-        }
+            frame->got_press = TRUE;
 
-        else if (ob_keycode_match(keycode, OB_KEY_LEFT)) {
-            /* Left goes to the parent menu */
-            if (frame->parent) {
-                /* remove focus from the child */
-                menu_frame_select(frame, NULL, TRUE);
-                /* and put it in the parent */
-                menu_frame_select(frame->parent, frame->parent->selected,
-                                  TRUE);
+            if (ob_keycode_match(ev->xkey.keycode, OB_KEY_ESCAPE)) {
+                menu_frame_hide_all();
+                ret = TRUE;
             }
-            ret = TRUE;
-        }
 
-        else if (ob_keycode_match(keycode, OB_KEY_RIGHT)) {
-            /* Right goes to the selected submenu */
-            if (frame->selected->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU)
-            {
-                /* make sure it is visible */
-                menu_frame_select(frame, frame->selected, TRUE);
-                menu_frame_select_next(frame->child);
+            else if (ob_keycode_match(ev->xkey.keycode, OB_KEY_LEFT)) {
+                /* Left goes to the parent menu */
+                if (frame->parent) {
+                    /* remove focus from the child */
+                    menu_frame_select(frame, NULL, TRUE);
+                    /* and put it in the parent */
+                    menu_frame_select(frame->parent, frame->parent->selected,
+                                      TRUE);
+                }
+                ret = TRUE;
             }
-            ret = TRUE;
-        }
 
-        else if (ob_keycode_match(keycode, OB_KEY_UP)) {
-            menu_frame_select_previous(frame);
-            ret = TRUE;
-        }
-
-        else if (ob_keycode_match(keycode, OB_KEY_DOWN)) {
-            menu_frame_select_next(frame);
-            ret = TRUE;
-        }
+            else if (ob_keycode_match(ev->xkey.keycode, OB_KEY_RIGHT)) {
+                /* Right goes to the selected submenu */
+                if (frame->selected->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU)
+                {
+                    /* make sure it is visible */
+                    menu_frame_select(frame, frame->selected, TRUE);
+                    menu_frame_select_next(frame->child);
+                }
+                ret = TRUE;
+            }
 
-        else if (ob_keycode_match(keycode, OB_KEY_HOME)) {
-            menu_frame_select_first(frame);
-            ret = TRUE;
-        }
+            else if (ob_keycode_match(ev->xkey.keycode, OB_KEY_UP)) {
+                menu_frame_select_previous(frame);
+                ret = TRUE;
+            }
 
-        else if (ob_keycode_match(keycode, OB_KEY_END)) {
-            menu_frame_select_last(frame);
-            ret = TRUE;
-        }
+            else if (ob_keycode_match(ev->xkey.keycode, OB_KEY_DOWN)) {
+                menu_frame_select_next(frame);
+                ret = TRUE;
+            }
 
-        /* Remember the last keypress */
-        else {
-            unikey = obt_keyboard_keypress_to_unichar(&ev->xkey);
-            ret = !!unikey;
-        }
-    }
+            else if (ob_keycode_match(ev->xkey.keycode, OB_KEY_HOME)) {
+                menu_frame_select_first(frame);
+                ret = TRUE;
+            }
 
-    /* Use KeyRelease events for running things so that the key release
-       doesn't get sent to the focused application.
+            else if (ob_keycode_match(ev->xkey.keycode, OB_KEY_END)) {
+                menu_frame_select_last(frame);
+                ret = TRUE;
+            }
 
-       Allow ControlMask only, and don't bother if the menu is empty */
-    else if (ev->type == KeyRelease && (state & ~ControlMask) == 0 &&
-             frame->entries && frame->got_press)
-    {
-        g_print("release unikey %lu\n", unikey);
+            /* keyboard accelerator shortcuts. (if it was a valid key) */
+            else if ((unikey = obt_keyboard_keypress_to_unichar(&ev->xkey))) {
+                GList *start;
+                GList *it;
+                ObMenuEntryFrame *found = NULL;
+                guint num_found = 0;
+
+                /* start after the selected one */
+                start = frame->entries;
+                if (frame->selected) {
+                    for (it = start; frame->selected != it->data;
+                         it = g_list_next(it))
+                        g_assert(it != NULL); /* nothing was selected? */
+                    /* next with wraparound */
+                    start = g_list_next(it);
+                    if (start == NULL) start = frame->entries;
+                }
 
-        if (ob_keycode_match(keycode, OB_KEY_RETURN)) {
-            /* Enter runs the active item or goes into the submenu.
-               Control-Enter runs it without closing the menu. */
-            if (frame->child)
-                menu_frame_select_next(frame->child);
-            else if (frame->selected)
-                menu_entry_frame_execute(frame->selected, state);
+                it = start;
+                do {
+                    ObMenuEntryFrame *e = it->data;
+                    gunichar entrykey = 0;
 
-            ret = TRUE;
-        }
+                    if (e->entry->type == OB_MENU_ENTRY_TYPE_NORMAL)
+                        entrykey = e->entry->data.normal.shortcut;
+                    else if (e->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU)
+                        entrykey = e->entry->data.submenu.submenu->shortcut;
 
-        /* keyboard accelerator shortcuts. (if it was a valid key) */
-        else if (unikey != 0) {
-            GList *start;
-            GList *it;
-            ObMenuEntryFrame *found = NULL;
-            guint num_found = 0;
-
-            /* start after the selected one */
-            start = frame->entries;
-            if (frame->selected) {
-                for (it = start; frame->selected != it->data;
-                     it = g_list_next(it))
-                    g_assert(it != NULL); /* nothing was selected? */
-                /* next with wraparound */
-                start = g_list_next(it);
-                if (start == NULL) start = frame->entries;
-            }
+                    if (unikey == entrykey) {
+                        if (found == NULL) found = e;
+                        ++num_found;
+                    }
 
-            it = start;
-            do {
-                ObMenuEntryFrame *e = it->data;
-                gunichar entrykey = 0;
+                    /* next with wraparound */
+                    it = g_list_next(it);
+                    if (it == NULL) it = frame->entries;
+                } while (it != start);
 
-                if (e->entry->type == OB_MENU_ENTRY_TYPE_NORMAL)
-                    entrykey = e->entry->data.normal.shortcut;
-                else if (e->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU)
-                    entrykey = e->entry->data.submenu.submenu->shortcut;
+                if (found) {
+                    menu_frame_select(frame, found, TRUE);
+                    /* execute this when the key is released */
+                    doexec = num_found == 1;
 
-                if (unikey == entrykey) {
-                    if (found == NULL) found = e;
-                    ++num_found;
+                    ret = TRUE;
                 }
+            }
+        }
 
-                /* next with wraparound */
-                it = g_list_next(it);
-                if (it == NULL) it = frame->entries;
-            } while (it != start);
+        /* Use KeyRelease events for running things so that the key release
+           doesn't get sent to the focused application.
 
-            if (found) {
-                if (found->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
-                    num_found == 1)
-                {
-                    menu_frame_select(frame, found, TRUE);
-                    usleep(50000); /* highlight the item for a short bit so
-                                      the user can see what happened */
-                    menu_entry_frame_execute(found, state);
-                } else {
-                    menu_frame_select(frame, found, TRUE);
-                    if (num_found == 1)
-                        menu_frame_select_next(frame->child);
-                }
+           Allow ControlMask only, and don't bother if the menu is empty */
+        else if (ev->type == KeyRelease && (mods & ~ControlMask) == 0 &&
+                 frame->entries && frame->got_press)
+        {
+            if (ob_keycode_match(ev->xkey.keycode, OB_KEY_RETURN)) {
+                /* Enter runs the active item or goes into the submenu.
+                   Control-Enter runs it without closing the menu. */
+                if (frame->child)
+                    menu_frame_select_next(frame->child);
+                else if (frame->selected)
+                    menu_entry_frame_execute(frame->selected, ev->xkey.state);
 
                 ret = TRUE;
             }
+
+            if (doexec && keycode == ev->xkey.keycode) {
+                if (frame->selected->entry->type == OB_MENU_ENTRY_TYPE_NORMAL)
+                    menu_entry_frame_execute(frame->selected, ev->xkey.state);
+                else
+                    menu_frame_select_next(frame->child);
+            }
         }
     }
-}
 
     return ret;
 }
index 5f7531e39d7f35acb7019cbd8e4fb80359519467..e2b72b36f0a94364a63a51de55fdf274cc11be25 100644 (file)
@@ -33,6 +33,7 @@
 #include "moveresize.h"
 #include "popup.h"
 #include "gettext.h"
+#include "obt/keyboard.h"
 
 #include <glib.h>
 
@@ -175,9 +176,17 @@ gboolean keyboard_process_interactive_grab(const XEvent *e, ObClient **client)
     gboolean handled = FALSE;
     gboolean done = FALSE;
     gboolean cancel = FALSE;
+    guint state;
+
+    state = obt_keyboard_only_modmasks(ev->xkey.state);
+    if (e->type == KeyRelease) {
+        /* remove from the state the mask of the modifier key being
+           released, if it is a modifier key being released that is */
+        state &= ~obt_keyboard_keycode_to_modmask(e->xkey.keycode);
+    }
 
     if (istate.active) {
-        if ((e->type == KeyRelease && !(istate.state & e->xkey.state))) {
+        if ((e->type == KeyRelease && !(istate.state & state))) {
             done = TRUE;
             handled = TRUE;
         } else if (e->type == KeyPress) {
@@ -194,7 +203,7 @@ gboolean keyboard_process_interactive_grab(const XEvent *e, ObClient **client)
         }
 
         if (done)
-            keyboard_interactive_end(e->xkey.state, cancel, e->xkey.time,TRUE);
+            keyboard_interactive_end(state, cancel, e->xkey.time,TRUE);
 
         if (handled)
             *client = istate.client;
@@ -208,6 +217,7 @@ gboolean keyboard_event(ObClient *client, const XEvent *e)
 {
     KeyBindingTree *p;
     gboolean used;
+    guint state;
 
     if (e->type == KeyRelease) {
         grab_key_passive_count(-1);
@@ -217,8 +227,10 @@ gboolean keyboard_event(ObClient *client, const XEvent *e)
     g_assert(e->type == KeyPress);
     grab_key_passive_count(1);
 
+    state = obt_keyboard_only_modmasks(e->xkey.state);
+
     if (e->xkey.keycode == config_keyboard_reset_keycode &&
-        e->xkey.state == config_keyboard_reset_state)
+        state == config_keyboard_reset_state)
     {
         obt_main_loop_timeout_remove(ob_main_loop, chain_timeout);
         keyboard_reset_chains(-1);
@@ -232,7 +244,7 @@ gboolean keyboard_event(ObClient *client, const XEvent *e)
         p = curpos->first_child;
     while (p) {
         if (p->key == e->xkey.keycode &&
-            p->state == e->xkey.state)
+            p->state == state)
         {
             /* if we hit a key binding, then close any open menus and run it */
             if (menu_frame_visible)
index e850f2d8f7a121f2fcc5f7a35865b2c14d081681..f8978b179f3e4b8f52bb5153a51e6e923ef8fb0d 100644 (file)
@@ -1264,9 +1264,10 @@ void menu_entry_frame_execute(ObMenuEntryFrame *self, guint state)
         GSList *acts = self->entry->data.normal.actions;
         ObClient *client = self->frame->client;
         ObMenuFrame *frame = self->frame;
+        guint mods = obt_keyboard_only_modmasks(state);
 
         /* release grabs before executing the shit */
-        if (!(state & ControlMask)) {
+        if (!(mods & ControlMask)) {
             event_cancel_all_key_grabs();
             frame = NULL;
         }
index ec9cb1037cd8c98dc2e33ca043be2c7ef0750624..e125bbcdde1bfa0e806ffc0c3f879cc981a814a5 100644 (file)
@@ -923,13 +923,15 @@ gboolean moveresize_event(XEvent *e)
                    ob_keycode_match(e->xkey.keycode, OB_KEY_DOWN) ||
                    ob_keycode_match(e->xkey.keycode, OB_KEY_UP))
         {
+            guint state = obt_keyboard_only_modmasks(e->xkey.state);
+
             if (corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_KEYBOARD)) {
-                resize_with_keys(e->xkey.keycode, e->xkey.state);
+                resize_with_keys(e->xkey.keycode, state);
                 used = TRUE;
             } else if (corner ==
                        OBT_PROP_ATOM(NET_WM_MOVERESIZE_MOVE_KEYBOARD))
             {
-                move_with_keys(e->xkey.keycode, e->xkey.state);
+                move_with_keys(e->xkey.keycode, state);
                 used = TRUE;
             }
         }
index 4f8930d7872d4261de50fce567ad8b9c0b128c80..1bf84c80035a00e79349b0651f530a98e7f1a7db 100644 (file)
@@ -520,15 +520,16 @@ void prompt_hide(ObPrompt *self)
 gboolean prompt_key_event(ObPrompt *self, XEvent *e)
 {
     gboolean shift;
-    guint shift_mask;
+    guint shift_mask, state;
 
     if (e->type != KeyPress) return FALSE;
 
     shift_mask = obt_keyboard_modkey_to_modmask(OBT_KEYBOARD_MODKEY_SHIFT);
-    shift = !!(e->xkey.state & shift_mask);
+    state = obt_keyboard_only_modmasks(e->xkey.state);
+    shift = !!(state & shift_mask);
 
     /* only accept shift */
-    if (e->xkey.state != 0 && e->xkey.state != shift_mask)
+    if (state != 0 && state != shift_mask)
         return FALSE;
 
     if (ob_keycode_match(e->xkey.keycode, OB_KEY_ESCAPE))