merge r5701 and r5702 from trunk (i also meant trunk earlier when i said HEAD)
authorMikael Magnusson <mikachu@comhem.se>
Wed, 28 Mar 2007 01:57:36 +0000 (01:57 +0000)
committerMikael Magnusson <mikachu@comhem.se>
Wed, 28 Mar 2007 01:57:36 +0000 (01:57 +0000)
openbox/client.c
openbox/event.c
openbox/event.h
openbox/grab.c

index a51ecfd7c7ed54ce2ba0e094d394b9969cb6f885..6866e8d8da8749cabbd7a5801c65b556b736cd1c 100644 (file)
@@ -414,8 +414,11 @@ void client_manage(Window window)
         else
         {
             /* If time stamp is old, don't steal focus */
-            if (self->user_time && self->user_time < client_last_user_time)
+            if (self->user_time &&
+                !event_time_after(self->user_time, client_last_user_time))
+            {
                 activate = FALSE;
+            }
             /* Don't steal focus from globally active clients.
                I stole this idea from KWin. It seems nice.
              */
@@ -3031,9 +3034,11 @@ void client_activate(ObClient *self, gboolean here, gboolean user)
              "source=%s\n",
              self->window, event_curtime, client_last_user_time,
              (user ? "user" : "application"));
-    if (!user && event_curtime && event_curtime < client_last_user_time)
+    if (!user && event_curtime &&
+        !event_time_after(event_curtime, client_last_user_time))
+    {
         client_hilite(self, TRUE);
-    else {
+    else {
         if (client_normal(self) && screen_showing_desktop)
             screen_show_desktop(FALSE);
         if (self->iconic)
index 75cf5d2e6f3471f4ea0e2b59051719285e083568..15724968844289e85c554903cd48e276c0998ebe 100644 (file)
@@ -1376,3 +1376,15 @@ void event_ignore_queued_enters()
     }
     g_slist_free(saved);
 }
+
+gboolean event_time_after(Time t1, Time t2)
+{
+    /*
+      Timestamp values wrap around (after about 49.7 days). The server, given
+      its current time is represented by timestamp T, always interprets
+      timestamps from clients by treating half of the timestamp space as being
+      later in time than T.
+      - http://tronche.com/gui/x/xlib/input/pointer-grabbing.html
+    */
+    return t1 >= t2 && t1 <= t2 + (1 << (sizeof(Time)*8-1));
+}
index 44bf54a0bad8bbe1ba7f33656f20175381e525cc..4221e54d9e9685d340108183f550fca4e779ef16 100644 (file)
@@ -47,4 +47,8 @@ void event_ignore_queued_enters();
    window for focus */
 void event_halt_focus_delay();
 
+/*! Compare t1 and t2, taking into account wraparound. True if t1
+  comes at the same time or later than t2. */
+gboolean event_time_after(Time t1, Time t2);
+
 #endif
index f63da5e94f3829b72b68a8f3c9f13c353538ec2a..991956da622b291e9ab4a05f5a02a10f086a9de5 100644 (file)
@@ -38,6 +38,14 @@ static guint pgrabs = 0;
 /*! The time at which the last grab was made */
 static Time  grab_time = CurrentTime;
 
+static Time ungrab_time()
+{
+    Time t = event_curtime;
+    if (!(t == 0 || event_time_after(t, grab_time)))
+        t = grab_time;
+    return t;
+}
+
 gboolean grab_on_keyboard()
 {
     return kgrabs > 0;
@@ -65,10 +73,7 @@ gboolean grab_keyboard(gboolean grab)
             ret = TRUE;
     } else if (kgrabs > 0) {
         if (--kgrabs == 0) {
-            Time t = event_curtime;
-            if (t != 0 && t < grab_time)
-                t = grab_time;
-            XUngrabKeyboard(ob_display, t);
+            XUngrabKeyboard(ob_display, ungrab_time());
         }
         ret = TRUE;
     }
@@ -94,10 +99,7 @@ gboolean grab_pointer(gboolean grab, ObCursor cur)
             ret = TRUE;
     } else if (pgrabs > 0) {
         if (--pgrabs == 0) {
-            Time t = event_curtime;
-            if (t != 0 && t < grab_time)
-                t = grab_time;
-            XUngrabPointer(ob_display, event_curtime);
+            XUngrabPointer(ob_display, ungrab_time());
         }
         ret = TRUE;
     }
@@ -122,10 +124,7 @@ gboolean grab_pointer_window(gboolean grab, ObCursor cur, Window win)
             ret = TRUE;
     } else if (pgrabs > 0) {
         if (--pgrabs == 0) {
-            Time t = event_curtime;
-            if (t != 0 && t < grab_time)
-                t = grab_time;
-            XUngrabPointer(ob_display, event_curtime);
+            XUngrabPointer(ob_display, ungrab_time());
         }
         ret = TRUE;
     }