Revert "i learnt what xkb does with the state."
[mikachu/openbox.git] / openbox / event.c
index d5791a0..f7fe030 100644 (file)
@@ -652,6 +652,7 @@ static void event_process(const XEvent *ec, gpointer data)
         /* keyboard layout changes for modifier mapping changes. reload the
            modifier map, and rebind all the key bindings as appropriate */
         ob_debug("Keyboard map changed. Reloading keyboard bindings.\n");
+        XRefreshKeyboardMapping(&e->xmapping);
         ob_set_state(OB_STATE_RECONFIGURING);
         modkeys_shutdown(TRUE);
         modkeys_startup(TRUE);
@@ -1323,11 +1324,23 @@ static void event_handle_client(ObClient *client, XEvent *e)
                        (e->xclient.data.l[0] == 2 ? "user" : "INVALID"))));
             /* XXX make use of data.l[2] !? */
             if (e->xclient.data.l[0] == 1 || e->xclient.data.l[0] == 2) {
-                event_curtime = e->xclient.data.l[1];
+                /* we can not trust the timestamp from applications.
+                   e.g. chromium passes a very old timestamp.  openbox thinks
+                   the window will get focus and calls XSetInputFocus with the
+                   (old) timestamp, which doesn't end up moving focus at all.
+                   but the window is raised, not hilited, etc, as if it was
+                   really going to get focus.
+
+                   so do not use this timestamp in event_curtime, as this would
+                   be used in XSetInputFocus.
+                */
+                /*event_curtime = e->xclient.data.l[1];*/
                 if (e->xclient.data.l[1] == 0)
                     ob_debug_type(OB_DEBUG_APP_BUGS,
                                   "_NET_ACTIVE_WINDOW message for window %s is"
                                   " missing a timestamp\n", client->title);
+
+                event_curtime = event_get_server_time();
             } else
                 ob_debug_type(OB_DEBUG_APP_BUGS,
                               "_NET_ACTIVE_WINDOW message for window %s is "
@@ -1700,14 +1713,23 @@ static gboolean event_handle_menu_keyboard(XEvent *ev)
 
         else if (ob_keycode_match(keycode, OB_KEY_LEFT)) {
             /* Left goes to the parent menu */
-            if (frame->parent)
+            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;
         }
 
         else if (ob_keycode_match(keycode, OB_KEY_RIGHT)) {
             /* Right goes to the selected submenu */
-            if (frame->child) menu_frame_select_next(frame->child);
+            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;
         }
 
@@ -1720,6 +1742,16 @@ static gboolean event_handle_menu_keyboard(XEvent *ev)
             menu_frame_select_next(frame);
             ret = TRUE;
         }
+
+        else if (ob_keycode_match(keycode, OB_KEY_HOME)) {
+            menu_frame_select_first(frame);
+            ret = TRUE;
+        }
+
+        else if (ob_keycode_match(keycode, OB_KEY_END)) {
+            menu_frame_select_last(frame);
+            ret = TRUE;
+        }
     }
 
     /* Use KeyRelease events for running things so that the key release doesn't
@@ -1800,6 +1832,15 @@ static gboolean event_handle_menu_keyboard(XEvent *ev)
     return ret;
 }
 
+static Bool event_look_for_menu_enter(Display *d, XEvent *ev, XPointer arg)
+{
+    ObMenuFrame *f = (ObMenuFrame*)arg;
+    ObMenuEntryFrame *e;
+    return ev->type == EnterNotify &&
+        (e = g_hash_table_lookup(menu_frame_map, &ev->xcrossing.window)) &&
+        !e->ignore_enters && e->frame == f;
+}
+
 static gboolean event_handle_menu(XEvent *ev)
 {
     ObMenuFrame *f;
@@ -1837,15 +1878,16 @@ static gboolean event_handle_menu(XEvent *ev)
         if (ev->xcrossing.detail == NotifyInferior)
             break;
 
-        if ((e = g_hash_table_lookup(menu_frame_map, &ev->xcrossing.window)) &&
-            (f = find_active_menu()) && f->selected == e &&
-            e->entry->type != OB_MENU_ENTRY_TYPE_SUBMENU)
+        if ((e = g_hash_table_lookup(menu_frame_map, &ev->xcrossing.window)))
         {
-            ObMenuEntryFrame *u = menu_entry_frame_under(ev->xcrossing.x_root,
-                                                         ev->xcrossing.y_root);
-            /* if we're just going from one entry in the menu to the next,
-               don't unselect stuff first */
-            if (!u || e->frame != u->frame)
+            XEvent ce;
+
+            /* check if an EnterNotify event is coming, and if not, then select
+               nothing in the menu */
+            if (XCheckIfEvent(ob_display, &ce, event_look_for_menu_enter,
+                              (XPointer)e->frame))
+                XPutBackEvent(ob_display, &ce);
+            else
                 menu_frame_select(e->frame, NULL, FALSE);
         }
         break;
@@ -1918,9 +1960,6 @@ static gboolean focus_delay_func(gpointer data)
     ObFocusDelayData *d = data;
     Time old = event_curtime;
 
-    /* don't move focus and kill the menu or the move/resize */
-    if (menu_frame_visible || moveresize_in_progress) return FALSE;
-
     event_curtime = d->time;
     event_curserial = d->serial;
     if (client_focus(d->client) && config_focus_raise)