[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 22 of 22] Fixed inability to focus windows via mouse



# HG changeset patch
# User John H. Robinson, IV <jhriv@ucsd.edu>
# Date 1225266843 25200
# Branch wm_0_92
# Node ID 8640d186c4f424a9c7977cb3672ab96e855c36fa
# Parent  ce1b81cb49375becb2268da560cb586f9aaf7bb6
Fixed inability to focus windows via mouse


http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=102314
Pedro Gimeno <parigalo@formauri.es>

I found this statement in actions.c (function wSetFocusTo) suspicious:

    if (scr->flags.ignore_focus_events || LastFocusChange > timestamp)
        return;

timestamp is defined like this:

    int timestamp=LastTimestamp;

where LastTimestamp is of type Time (which is an unsigned 32-bit integer
according to my /usr/include/X11/X.h) and so is LastFocusChange.

This way of comparing timestamps is broken and not only because of the
signedness. If this is the cause of this bug, then it should be
reproducable exactly every 24 days, 20 hours, 31 mins, 23.648 seconds
(which is 2^31 milliseconds) or maybe the double.

I've attached a patch that compares the timestamps properly. It is done
against version 0.92.0-6.1 which is current in etch as of this writing.

I have just checked that it does not seem to break anything and that
reverting the condition (the direction of the comparison) causes the
expected symptoms. I have not verified that the bug is periodic, so I
can't be sure that this will fix it. If necessary I can wait for another
24 days (or maybe 48) if no downtime happens here, to verify the
periodicity of the bug and another 24 (or 48) more to check if the fix
works.

diff -r ce1b81cb4937 -r 8640d186c4f4 src/actions.c
--- a/src/actions.c	Sun Oct 26 21:42:52 2008 -0700
+++ b/src/actions.c	Wed Oct 29 00:54:03 2008 -0700
@@ -78,6 +78,15 @@
 #define SHADE_STEPS	shadePars[(int)wPreferences.shade_speed].steps
 #define SHADE_DELAY	shadePars[(int)wPreferences.shade_speed].delay
 
+static int
+compareTimes(Time t1, Time t2)
+{
+    Time diff;
+    if (t1 == t2)
+      return 0;
+    diff = t1 - t2;
+    return (diff < 60000) ? 1 : -1;
+}
 
 /*
  *----------------------------------------------------------------------
@@ -99,11 +108,11 @@
 
     WWindow *old_focused;
     WWindow *focused=scr->focused_window;
-    int timestamp=LastTimestamp;
+    Time timestamp=LastTimestamp;
     WApplication *oapp=NULL, *napp=NULL;
     int wasfocused;
 
-    if (scr->flags.ignore_focus_events || LastFocusChange > timestamp)
+    if (scr->flags.ignore_focus_events || compareTimes(LastFocusChange, timestamp) > 0)
         return;
 
     if (!old_scr)


-- 
To unsubscribe, send mail to wmaker-dev-unsubscribe@lists.windowmaker.info.