diff options
| author | Dana Jansens <danakj@orodu.net> | 2007-04-18 19:22:59 +0000 |
|---|---|---|
| committer | Dana Jansens <danakj@orodu.net> | 2007-04-18 19:22:59 +0000 |
| commit | 90cd9c62192194d1b3ab868a77fe56a9b1e215c2 (patch) | |
| tree | 9110d9f62f519cbc12c3a881f8f6ad8cbaed8897 /openbox/client.c | |
| parent | f18d9a95399f9588151bf142b0f03b0781527171 (diff) | |
get rid of global client_last_user_time variable.
add ObClientTimeHeap. This is a max-heap of the clients based on their user times. this only includes the clients whose user time is not CurrentTime. the maximum from this heap replaces the client_last_user_time variable, so that you always have the latest time, not the last time that was changed.
hoefully it works, so far it seems to.
Diffstat (limited to 'openbox/client.c')
| -rw-r--r-- | openbox/client.c | 60 |
1 files changed, 41 insertions, 19 deletions
diff --git a/openbox/client.c b/openbox/client.c index 7f4cba21..9d679738 100644 --- a/openbox/client.c +++ b/openbox/client.c @@ -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,7 +275,7 @@ 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); /* per-app settings override stuff, and return the settings for other @@ -405,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 @@ -414,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; } @@ -436,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); @@ -538,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); @@ -949,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) @@ -1852,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)); */ } } @@ -3067,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 { |
