]> Dogcows Code - chaz/openbox/blobdiff - openbox/event.c
scary commit..but here goes.
[chaz/openbox] / openbox / event.c
index a5d983c3b64ddda26ceb0b70a10a7a01a2ca64a9..6314c9f79640029f614f4f8c2e0991550e7c1ec7 100644 (file)
@@ -1,19 +1,20 @@
 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
 
-event.c for the Openbox window manager
-Copyright (c) 2003        Ben Jansens
+   event.c for the Openbox window manager
+   Copyright (c) 2006        Mikael Magnusson
+   Copyright (c) 2003        Ben Jansens
 
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
 
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
-See the COPYING file for a copy of the GNU General Public License.
+   See the COPYING file for a copy of the GNU General Public License.
 */
 
 #include "event.h"
@@ -50,6 +51,9 @@ See the COPYING file for a copy of the GNU General Public License.
 #ifdef HAVE_SIGNAL_H
 #  include <signal.h>
 #endif
+#ifdef XKB
+#  include <X11/XKBlib.h>
+#endif
 
 #ifdef USE_SM
 #include <X11/ICE/ICElib.h>
@@ -82,7 +86,12 @@ static gboolean menu_hide_delay_func(gpointer data);
                              (e)->xfocus.detail == NotifyAncestor || \
                              (e)->xfocus.detail > NotifyNonlinearVirtual)
 
-Time event_lasttime = 0;
+/* The most recent time at which an event with a timestamp occured. */
+static Time event_lasttime = 0;
+/* The time for the current event being processed
+   (it's the event_lasttime for events without times, if this is a bug then
+   use CurrentTime instead, but it seems ok) */
+Time event_curtime = CurrentTime;
 
 /*! The value of the mask for the NumLock modifier */
 guint NumLockMask;
@@ -141,10 +150,10 @@ void event_startup(gboolean reconfig)
         const KeyCode num_lock = XKeysymToKeycode(ob_display, XK_Num_Lock);
         const KeyCode scroll_lock = XKeysymToKeycode(ob_display,
                                                      XK_Scroll_Lock);
-         
+
         for (cnt = 0; cnt < size; ++cnt) {
             if (! modmap->modifiermap[cnt]) continue;
-              
+
             if (num_lock == modmap->modifiermap[cnt])
                 NumLockMask = mask_table[cnt / modmap->max_keypermod];
             if (scroll_lock == modmap->modifiermap[cnt])
@@ -171,6 +180,7 @@ void event_shutdown(gboolean reconfig)
 #endif
 
     client_remove_destructor(focus_delay_client_dest);
+    client_remove_destructor(event_client_dest);
     XFreeModifiermap(modmap);
 }
 
@@ -246,18 +256,27 @@ static void event_set_lasttime(XEvent *e)
         break;
     }
 
-    if (t > event_lasttime)
+    if (t > event_lasttime) {
         event_lasttime = t;
+        event_curtime = event_lasttime;
+    } else if (t == 0) {
+        event_curtime = event_lasttime;
+    } else {
+        event_curtime = t;
+    }
 }
 
 #define STRIP_MODS(s) \
-       s &= ~(LockMask | NumLockMask | ScrollLockMask), \
-       /* kill off the Button1Mask etc, only want the modifiers */ \
-       s &= (ControlMask | ShiftMask | Mod1Mask | \
+        s &= ~(LockMask | NumLockMask | ScrollLockMask), \
+        /* kill off the Button1Mask etc, only want the modifiers */ \
+        s &= (ControlMask | ShiftMask | Mod1Mask | \
               Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask) \
 
 static void event_hack_mods(XEvent *e)
 {
+#ifdef XKB
+    XkbStateRec xkb_state;
+#endif
     KeyCode *kp;
     gint i, k;
 
@@ -273,6 +292,12 @@ static void event_hack_mods(XEvent *e)
         STRIP_MODS(e->xkey.state);
         /* remove from the state the mask of the modifier being released, if
            it is a modifier key being released (this is a little ugly..) */
+#ifdef XKB
+        if (XkbGetState(ob_display, XkbUseCoreKbd, &xkb_state) == Success) {
+            e->xkey.state = xkb_state.compat_state;
+            break;
+        }
+#endif
         kp = modmap->modifiermap;
         for (i = 0; i < mask_table_size; ++i) {
             for (k = 0; k < modmap->max_keypermod; ++k) {
@@ -317,7 +342,7 @@ static gboolean event_ignore(XEvent *e, ObClient *client)
            want will be of type NotifyAncestor. This situation does not occur
            for FocusOut, so it is safely ignored there.
         */
-       if (INVALID_FOCUSIN(e) ||
+        if (INVALID_FOCUSIN(e) ||
             client == NULL) {
 #ifdef DEBUG_FOCUS
             ob_debug("FocusIn on %lx mode %d detail %d IGNORED\n",
@@ -336,7 +361,7 @@ static gboolean event_ignore(XEvent *e, ObClient *client)
 #endif
         break;
     case FocusOut:
-       if (INVALID_FOCUSOUT(e)) {
+        if (INVALID_FOCUSOUT(e)) {
 #ifdef DEBUG_FOCUS
         ob_debug("FocusOut on %lx mode %d detail %d IGNORED\n",
                  e->xfocus.window, e->xfocus.mode, e->xfocus.detail);
@@ -495,7 +520,7 @@ static void event_process(const XEvent *ec, gpointer data)
         /* unhandled configure requests must be used to configure the
            window directly */
         XWindowChanges xwc;
-              
+
         xwc.x = e->xconfigurerequest.x;
         xwc.y = e->xconfigurerequest.y;
         xwc.width = e->xconfigurerequest.width;
@@ -531,7 +556,7 @@ static void event_process(const XEvent *ec, gpointer data)
 
                 menu_can_hide = FALSE;
                 ob_main_loop_timeout_add(ob_main_loop,
-                                         G_USEC_PER_SEC / 4,
+                                         config_menu_hide_delay * 1000,
                                          menu_hide_delay_func,
                                          NULL, NULL);
 
@@ -554,7 +579,7 @@ static void event_handle_root(XEvent *e)
     switch(e->type) {
     case SelectionClear:
         ob_debug("Another WM has requested to replace us. Exiting.\n");
-        ob_exit(0);
+        ob_exit_replace();
         break;
 
     case ClientMessage:
@@ -571,6 +596,11 @@ static void event_handle_root(XEvent *e)
                 screen_set_num_desktops(d);
         } else if (msgtype == prop_atoms.net_showing_desktop) {
             screen_show_desktop(e->xclient.data.l[0] != 0);
+        } else if (msgtype == prop_atoms.ob_control) {
+            if (e->xclient.data.l[0] == 1)
+                ob_reconfigure();
+            else if (e->xclient.data.l[0] == 2)
+                ob_restart();
         }
         break;
     case PropertyNotify:
@@ -587,11 +617,6 @@ static void event_handle_root(XEvent *e)
         break;
     default:
         ;
-#ifdef VIDMODE
-        if (extensions_vidmode && e->type == extensions_vidmode_event_basep) {
-            ob_debug("VIDMODE EVENT\n");
-        }
-#endif
     }
 }
 
@@ -715,7 +740,7 @@ static void event_handle_client(ObClient *client, XEvent *e)
             if (config_focus_follow && config_focus_delay)
                 ob_main_loop_timeout_remove_data(ob_main_loop,
                                                  focus_delay_func,
-                                                 client);
+                                                 client, TRUE);
             break;
         default:
             break;
@@ -834,13 +859,13 @@ static void event_handle_client(ObClient *client, XEvent *e)
                 gint fh = h +
                      client->frame->size.top + client->frame->size.bottom;
                 client_find_onscreen(client, &newx, &newy, fw, fh,
-                                     client_normal(client));
+                                     FALSE);
                 if (e->xconfigurerequest.value_mask & CWX)
                     x = newx;
                 if (e->xconfigurerequest.value_mask & CWY)
                     y = newy;
             }
-              
+
             switch (client->gravity) {
             case NorthEastGravity:
             case EastGravity:
@@ -910,7 +935,7 @@ static void event_handle_client(ObClient *client, XEvent *e)
                                        it can happen now when the window is on
                                        another desktop, but we still don't
                                        want it! */
-        client_activate(client, FALSE);
+        client_activate(client, FALSE, TRUE);
         break;
     case ClientMessage:
         /* validate cuz we query stuff off the client here */
@@ -964,8 +989,15 @@ static void event_handle_client(ObClient *client, XEvent *e)
             ob_debug("net_close_window for 0x%lx\n", client->window);
             client_close(client);
         } else if (msgtype == prop_atoms.net_active_window) {
-            ob_debug("net_active_window for 0x%lx\n", client->window);
-            client_activate(client, FALSE);
+            ob_debug("net_active_window for 0x%lx source=%s\n",
+                     client->window,
+                     (e->xclient.data.l[0] == 0 ? "unknown" :
+                      (e->xclient.data.l[0] == 1 ? "application" :
+                       (e->xclient.data.l[0] == 2 ? "user" : "INVALID"))));
+            /* XXX make use of data.l[1] and [2] ! */
+            client_activate(client, FALSE,
+                            (e->xclient.data.l[0] == 0 ||
+                             e->xclient.data.l[0] == 2));
         } else if (msgtype == prop_atoms.net_wm_moveresize) {
             ob_debug("net_wm_moveresize for 0x%lx\n", client->window);
             if ((Atom)e->xclient.data.l[2] ==
@@ -1038,7 +1070,7 @@ static void event_handle_client(ObClient *client, XEvent *e)
                 if (e->xclient.data.l[0] & 1 << 9)
                     y = newy;
             }
-              
+
             client_configure(client, OB_CORNER_TOPLEFT,
                              x, y, w, h, FALSE, TRUE);
 
@@ -1133,7 +1165,10 @@ static void event_handle_dock(ObDock *s, XEvent *e)
 {
     switch (e->type) {
     case ButtonPress:
-        stacking_raise(DOCK_AS_WINDOW(s));
+        if (e->xbutton.button == 1)
+            stacking_raise(DOCK_AS_WINDOW(s), FALSE);
+        else if (e->xbutton.button == 2)
+            stacking_lower(DOCK_AS_WINDOW(s), FALSE);
         break;
     case EnterNotify:
         dock_hide(FALSE);
@@ -1275,7 +1310,8 @@ static gboolean focus_delay_func(gpointer data)
 
 static void focus_delay_client_dest(ObClient *client, gpointer data)
 {
-    ob_main_loop_timeout_remove_data(ob_main_loop, focus_delay_func, client);
+    ob_main_loop_timeout_remove_data(ob_main_loop, focus_delay_func,
+                                     client, TRUE);
 }
 
 static void event_client_dest(ObClient *client, gpointer data)
This page took 0.028137 seconds and 4 git commands to generate.