- ob_debug_type(OB_DEBUG_FOCUS,
- "Want to focus window 0x%x at time %u "
- "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 (!(self->desktop == screen_desktop ||
- self->desktop == DESKTOP_ALL) &&
- /* the timestamp is from before you changed desktops */
- launch_time && screen_desktop_user_time &&
- !event_time_after(launch_time, screen_desktop_user_time))
- {
- steal = FALSE;
- ob_debug_type(OB_DEBUG_FOCUS,
- "Not focusing the window because its on another "
- "desktop\n");
+ ob_debug("Want to focus window 0x%x at time %u "
+ "launched at %u (last user interaction time %u) "
+ "request from %s, allow other desktop: %s, "
+ "desktop switch time %u",
+ self->window, steal_time, launch_time,
+ event_last_user_time,
+ (request_from_user ? "user" : "other"),
+ (allow_other_desktop ? "yes" : "no"),
+ screen_desktop_user_time);
+
+ /*
+ 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 if (!request_from_user) {
+ /* 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 {
+ /* has relatives which are not being used, but the user seems
+ to want to go there! */
+ launch_time = event_last_user_time;
+ ob_debug("Unknown launch time, using %u - user request",
+ 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 - independent window",
+ launch_time);
+ }
+ }
+
+ /* if it's on another desktop
+ and if allow_other_desktop is true, we generally let it steal focus.
+ but if it didn't come from the user, don't let it steal unless it was
+ launched before the user switched desktops.
+ focus, unless it was launched after we changed desktops and the request
+ came from the user
+ */
+ if (!screen_compare_desktops(screen_desktop, self->desktop)) {
+ /* must be allowed */
+ if (!allow_other_desktop) {
+ steal = FALSE;
+ ob_debug("Not focusing the window because its on another desktop");
+ }
+ /* if we don't know when the desktop changed, but request is from an
+ application, don't let it change desktop on you */
+ else if (!request_from_user) {
+ steal = FALSE;
+ ob_debug("Not focusing the window because non-user request");
+ }