]> Dogcows Code - chaz/openbox/blobdiff - openbox/client.c
get rid of global client_last_user_time variable.
[chaz/openbox] / openbox / client.c
index 9c6c74bdb23feaeec645b2c5d0fbef29ad7f6677..9d679738fee34f1523f72d488e9e6b6060e6acf1 100644 (file)
@@ -18,6 +18,7 @@
 */
 
 #include "client.h"
+#include "client_time_heap.h"
 #include "debug.h"
 #include "startupnotify.h"
 #include "dock.h"
@@ -56,10 +57,10 @@ typedef struct
     gpointer data;
 } Destructor;
 
-GList         *client_list           = NULL;
+GList            *client_list        = NULL;
+ObClientTimeHeap *client_user_times  = NULL;
 
 static GSList *client_destructors    = NULL;
-static Time    client_last_user_time = CurrentTime;
 
 static void client_get_all(ObClient *self);
 static void client_toggle_border(ObClient *self, gboolean show);
@@ -84,11 +85,13 @@ void client_startup(gboolean reconfig)
 {
     if (reconfig) return;
 
+    client_user_times = client_time_heap_new();
     client_set_list();
 }
 
 void client_shutdown(gboolean reconfig)
 {
+    client_time_heap_free(client_user_times);
 }
 
 void client_add_destructor(ObClientDestructor func, gpointer data)
@@ -272,13 +275,14 @@ void client_manage(Window window)
     self->wmstate = WithdrawnState; /* make sure it gets updated first time */
     self->layer = -1;
     self->desktop = screen_num_desktops; /* always an invalid value */
-    self->user_time = client_last_user_time;
+    self->user_time = CurrentTime;
 
     client_get_all(self);
-    client_restore_session_state(self);
     /* per-app settings override stuff, and return the settings for other
        uses too */
     settings = client_get_settings_state(self);
+    /* the session should get the last say */
+    client_restore_session_state(self);
 
     client_calc_layer(self);
 
@@ -404,7 +408,8 @@ void client_manage(Window window)
     if (activate) {
         /* This is focus stealing prevention */
         ob_debug("Want to focus new window 0x%x with time %u (last time %u)\n",
-                 self->window, self->user_time, client_last_user_time);
+                 self->window, self->user_time,
+                 client_time_heap_maximum(client_user_times));
 
         /* If a nothing at all, or a parent was focused, then focus this
            always
@@ -413,9 +418,10 @@ void client_manage(Window window)
             activate = TRUE;
         else
         {
+            guint32 last_time = client_time_heap_maximum(client_user_times);
             /* If time stamp is old, don't steal focus */
-            if (self->user_time &&
-                !event_time_after(self->user_time, client_last_user_time))
+            if (self->user_time && last_time &&
+                !event_time_after(self->user_time, last_time))
             {
                 activate = FALSE;
             }
@@ -435,7 +441,8 @@ void client_manage(Window window)
         } else {
             ob_debug("Focus stealing prevention activated for %s with time %u "
                      "(last time %u)\n",
-                     self->title, self->user_time, client_last_user_time);
+                     self->title, self->user_time,
+                     client_time_heap_maximum(client_user_times));
             /* if the client isn't focused, then hilite it so the user
                knows it is there */
             client_hilite(self, TRUE);
@@ -537,6 +544,9 @@ void client_unmanage(ObClient *self)
     /* we dont want events no more */
     XSelectInput(ob_display, self->window, NoEventMask);
 
+    /* remove from the time heap */
+    client_time_heap_remove(client_user_times, self);
+
     client_list = g_list_remove(client_list, self);
     stacking_remove(self);
     g_hash_table_remove(window_map, &self->window);
@@ -948,7 +958,7 @@ static void client_get_all(ObClient *self)
     client_update_sm_client_id(self);
     client_update_strut(self);
     client_update_icons(self);
-    client_update_user_time(self, FALSE);
+    client_update_user_time(self);
 }
 
 static void client_get_startup_id(ObClient *self)
@@ -1851,27 +1861,35 @@ void client_update_icons(ObClient *self)
         frame_adjust_icon(self->frame);
 }
 
-void client_update_user_time(ObClient *self, gboolean new_event)
+void client_update_user_time(ObClient *self)
 {
     guint32 time;
 
     if (PROP_GET32(self->window, net_wm_user_time, cardinal, &time)) {
-        self->user_time = time;
+        guint32 otime = self->user_time;
         /* we set this every time, not just when it grows, because in practice
            sometimes time goes backwards! (ntpdate.. yay....) so.. if it goes
            backward we don't want all windows to stop focusing. we'll just
            assume noone is setting times older than the last one, cuz that
            would be pretty stupid anyways
-           However! This is called when a window is mapped to get its user time
-           but it's an old number, it's not changing it from new user
-           interaction, so in that case, don't change the last user time.
         */
-        if (new_event)
-            client_last_user_time = time;
+        self->user_time = time;
+        /* adjust the time heap - windows with CurrentTime for their user_time
+           are not in the heap */
+        if (time == CurrentTime && otime != CurrentTime)
+            client_time_heap_remove(client_user_times, self);
+        else if (time != CurrentTime && otime == CurrentTime)
+            client_time_heap_add(client_user_times, self);
+        else if (time != CurrentTime && otime != CurrentTime) {
+            if (event_time_after(time, otime))
+                client_time_heap_increase_key(client_user_times, self);
+            else
+                client_time_heap_decrease_key(client_user_times, self);
+        }
 
         /*
         ob_debug("window %s user time %u\n", self->title, time);
-        ob_debug("last user time %u\n", client_last_user_time);
+        ob_debug("last user time %u\n", client_time_heap_maximum(client_user_times));
         */
     }
 }
@@ -3066,16 +3084,21 @@ static void client_unfocus(ObClient *self)
 
 void client_activate(ObClient *self, gboolean here, gboolean user)
 {
+    guint32 last_time;
+
     /* XXX do some stuff here if user is false to determine if we really want
        to activate it or not (a parent or group member is currently
        active)?
     */
     ob_debug("Want to activate window 0x%x with time %u (last time %u), "
              "source=%s\n",
-             self->window, event_curtime, client_last_user_time,
+             self->window, event_curtime,
+             client_time_heap_maximum(client_user_times),
              (user ? "user" : "application"));
-    if (!user && event_curtime &&
-        !event_time_after(event_curtime, client_last_user_time))
+
+    last_time = client_time_heap_maximum(client_user_times);
+    if (!user && event_curtime && last_time &&
+        !event_time_after(event_curtime, last_time))
     {
         client_hilite(self, TRUE);
     } else {
This page took 0.028351 seconds and 4 git commands to generate.