all repos — openbox @ c5c34cca1c9b57424fa7ca686995126f627903ab

openbox fork - make it a bit more like ryudo

if no launch time is provided for an application, make one up.

if the window is related to other existing windows
  and one of those windows was the last used
    then we will give it a launch time equal to the last user time,
    which will end up giving the window focus probably.
  else
    the window is related to other windows, but you are not working in them?
    seems suspicious, so we will give it a launch time of NOW - STEAL_INTERVAL,
    so it will be given focus only if we didn't use something else during the
    steal interval.
else
  the window is all on its own, so we can't judge it.  give it a launch time
  equal to the last user time, so it will probably take focus.

this way running things from a terminal will give them focus, but popups
without a launch time shouldn't steal focus so easily.
Dana Jansens danakj@orodu.net
commit

c5c34cca1c9b57424fa7ca686995126f627903ab

parent

5e38690d65459262e028cdbcddf8a1417287f156

5 files changed, 88 insertions(+), 9 deletions(-)

jump to
M openbox/client.copenbox/client.c

@@ -712,13 +712,59 @@ "launched at %u (last user interaction time %u)",

self->window, steal_time, launch_time, event_last_user_time); - /* if it's on another desktop... */ + /* + if no launch time is provided for an application, make one up. + + if the window is related to other existing windows + and one of those windows was the last used + then we will give it a launch time equal to the last user time, + which will end up giving the window focus probably. + else + the window is related to other windows, but you are not working in + them? + seems suspicious, so we will give it a launch time of + NOW - STEAL_INTERVAL, + so it will be given focus only if we didn't use something else + during the steal interval. + else + the window is all on its own, so we can't judge it. give it a launch + time equal to the last user time, so it will probably take focus. + + this way running things from a terminal will give them focus, but popups + without a launch time shouldn't steal focus so easily. + */ + + if (!launch_time) { + if (client_has_relative(self)) { + if (event_last_user_time && client_search_focus_group_full(self)) { + /* our relative is focused */ + launch_time = event_last_user_time; + ob_debug("Unknown launch time, using %u window in active " + "group", launch_time); + } + else { + /* has relatives which are not being used. suspicious */ + launch_time = event_time() - OB_EVENT_USER_TIME_DELAY; + ob_debug("Unknown launch time, using %u window in inactive " + "group", launch_time); + } + } + else { + /* the window is on its own, probably the user knows it is going + to appear */ + launch_time = event_last_user_time; + ob_debug("Unknown launch time, using %u for solo window", + launch_time); + } + } + + /* if it's on another desktop + then if allow_other_desktop is false, we don't want to let it steal + focus, unless it was launched after we changed desktops + */ if (!(self->desktop == screen_desktop || self->desktop == DESKTOP_ALL) && - /* and (we dont know when it launched, and we don't want to allow - focus stealing from other desktops */ - ((!launch_time && !allow_other_desktop) || - /* or the timestamp is from before you changed desktops) */ + (!allow_other_desktop || (screen_desktop_user_time && !event_time_after(launch_time, screen_desktop_user_time)))) {

@@ -731,9 +777,9 @@ /* If the user is working in another window right now, then don't

steal focus */ if (!relative_focused && event_last_user_time && - (!launch_time || - (event_time_after(event_last_user_time, launch_time) && - event_last_user_time != launch_time)) && + /* last user time must be strictly > launch_time to block focus */ + (event_time_after(event_last_user_time, launch_time) && + event_last_user_time != launch_time) && event_time_after(event_last_user_time, steal_time - OB_EVENT_USER_TIME_DELAY)) {

@@ -2435,6 +2481,11 @@

gboolean client_has_parent(ObClient *self) { return self->parents != NULL; +} + +gboolean client_has_children(ObClient *self) +{ + return self->transients != NULL; } gboolean client_is_oldfullscreen(const ObClient *self,

@@ -4459,6 +4510,13 @@

gboolean client_has_group_siblings(ObClient *self) { return self->group && self->group->members->next; +} + +gboolean client_has_relative(ObClient *self) +{ + return client_has_parent(self) || + client_has_group_siblings(self) || + client_has_children(self); } /*! Returns TRUE if the client is running on the same machine as Openbox */
M openbox/client.hopenbox/client.h

@@ -657,6 +657,10 @@ FALSE if it's not transient or there is no window for it to be

transient for */ gboolean client_has_parent(ObClient *self); +/*! Return TRUE if the client has some transient children, and FALSE otherwise. +*/ +gboolean client_has_children(ObClient *self); + /*! Searches a client's immediate parents for a focused window. The function does not check for the passed client, only for *ONE LEVEL* of its parents. If no focused parent is found, NULL is returned.

@@ -740,6 +744,11 @@

ObClient* client_under_pointer(void); gboolean client_has_group_siblings(ObClient *self); + +/*! Returns TRUE if the client has a transient child, a parent, or a + group member. Returns FALSE otherwise. +*/ +gboolean client_has_relative(ObClient *self); /*! Returns TRUE if the client is running on the same machine as Openbox */ gboolean client_on_localhost(ObClient *self);
M openbox/event.copenbox/event.c

@@ -273,7 +273,7 @@ /* watch that if we get an event earlier than the last specified user_time,

which can happen if the clock goes backwards, we erase the last specified user_time */ if (t && event_last_user_time && event_time_after(event_last_user_time, t)) - event_last_user_time = CurrentTime; + event_reset_user_time(); event_sourcetime = CurrentTime; event_curtime = t;

@@ -2251,3 +2251,8 @@ void event_update_user_time(void)

{ event_last_user_time = event_time(); } + +void event_reset_user_time(void) +{ + event_last_user_time = CurrentTime; +}
M openbox/event.hopenbox/event.h

@@ -85,4 +85,7 @@ event_time().

*/ void event_update_user_time(void); +/*! Reset the timestamp for when the user has last used the focused window. */ +void event_reset_user_time(void); + #endif
M openbox/focus.copenbox/focus.c

@@ -100,6 +100,10 @@ if (ob_state() != OB_STATE_EXITING) {

active = client ? client->window : None; OBT_PROP_SET32(obt_root(ob_screen), NET_ACTIVE_WINDOW, WINDOW, active); } + + /* when focus is moved to a new window, the last_user_time timestamp would + no longer be valid, as it applies for the focused window */ + event_reset_user_time(); } static ObClient* focus_fallback_target(gboolean allow_refocus,