Bug 5419 - Executing a browser via key bindings when it is already open causes the new window to open in background and with no focus
Status: REOPENED
Alias: None
Product: Openbox
Classification: Unclassified
Component: general
Version: 3.5.0
Hardware: PC Linux
: P3 normal
Assignee: Dana Jansens
QA Contact:
URL:
Depends on:
Blocks:
 
Reported: 2012-01-21 18:06 EST by Douglas A. Augusto
Modified: 2016-10-14 08:26:48 EDT
4 users (show)

See Also:


Attachments
Allows windows to steal focus briefly after executing via a keybinding (2.64 KB, patch)
2012-09-14 02:33 EDT, rephorm
git bisect log (6.37 KB, text/plain)
2014-11-08 16:11 EST, Douglas A. Augusto

Description Douglas A. Augusto 2012-01-21 18:06:59 EST
After upgrading to Openbox 3.5.0, I noticed a very annoying issue with respect
to executing a browser (via key bindings) in order to open a new browser window.
I'm using the default rc.xml with the following additional key binding:

    <keybind key="W-f">
      <action name="Execute">
        <startupnotify>
          <enabled>yes</enabled>
        </startupnotify>
        <command>iceweasel</command>
      </action>
    </keybind>


When Iceweasel is already open somewhere else (in any desktop window), if I
press W-f and there is any other window on the current desktop, the newly
opened browser window goes behind the currently focused window, i.e. doesn't
raise, and also doesn't get focus. Thus, whenever I press W-f to open a new
browser window I need also to press Alt-tab in order to raise and transfer
the focus to that window.

When no previous Iceweasel window exists, then the new window is correctly
raised and focused. Also, removing the startupnotify option doesn't help.

I've confirmed this issue with Chromium too.


My system:

Debian GNU/Linux testing/unstable (x86_64), Openbox 3.5.0-2, Iceweasel 9.0.1-1,
and Chromium 15.0.874

Openbox's focus and placement policies (rc.xml):

   <focus>
     <focusNew>yes</focusNew>
     <followMouse>no</followMouse>
     <focusLast>yes</focusLast>
     <underMouse>no</underMouse>
     <focusDelay>200</focusDelay>
     <raiseOnFocus>no</raiseOnFocus>
   </focus>

   <placement>
     <policy>Smart</policy>
     <center>yes</center>
     <monitor>Primary</monitor>
     <primaryMonitor>1</primaryMonitor>
   </placement>
Comment 1 rephorm 2012-09-14 02:33:13 EDT
Created attachment 3264 [details]
Allows windows to steal focus briefly after executing via a keybinding
Comment 2 Douglas A. Augusto 2012-09-14 04:58:50 EDT
Hi Brian Mattern,

Thank you very much for your patch. It fixes the annoying issue reported in
this bug.

By the way, is it possible to extend your patch to also handle cases where the
browser is executed, for instance, directly from a terminal (that is, not via a
key binding)? Currently, even with the patch applied, if I execute the browser
within some terminals, such as roxterm (by typing "firefox" or clicking on a
link), the window still opens in background and with no focus.

Again, thank you.
Comment 3 Dana Jansens 2012-09-30 22:47:35 EDT
Fixed in http://git.io/wrUj4A by not making the execute action cause us to think you're using the current window.
Comment 4 Douglas A. Augusto 2013-10-22 01:30:15 EDT
Hi Dana Jansens,

I am using Openbox 3.5.2-3 (from Debian) and still experiencing this bug. The only difference is that now it happens about half the time.
Comment 5 Dana Jansens 2013-11-11 15:43:17 EST
Does it happen when you have another browser window focused? Or only when you have some other application focused?
Comment 6 Douglas A. Augusto 2013-11-14 09:26:10 EST
(In reply to comment #5)
> Does it happen when you have another browser window focused? Or only when
> you have some other application focused?

Dear Jansens,

It seems that the necessary conditions are (1) there is at least one browser's
window open elsewhere and (2) no window of that browser is currently focused
(some other application has the focus).

In other words, if either an existing browser's window has the focus or I am
opening the first window of the browser (starting the browser), then the window
is focused correctly (instead of going to background and not receiving the focus).
Comment 7 Douglas A. Augusto 2014-05-03 14:23:35 EDT
Dear All,

Any news on this?

Is there anything I can do? I wouldn't probably be able to fix the issue by myself, but maybe I could help.
Comment 8 David Breese 2014-11-07 17:36:54 EST
I too seem to be experiencing this in openbox 3.5.2-8 from debian testing/sid.  

1. Just like you said, if I have an iceweasel window open, and I type "iceweasel" in an xfce4-terminal window, the new browser window consistently fails to steal focus from the terminal window.  For me this only happens with browser, nothing else yet.  

2. I also still experience the version of the bug you originally reported, opening windows via keybindings.  And for me this happens equally to xfce4-terminal itself, as it does to iceweasel.  Reports elsewhere suggest that it also happens with many other programs.  

In both cases, the two necessary conditions Douglas described, apply also for me: the bug only occurs if there is a window of the program I'm trying to open already open somewhere else, AND if no window of the program I'm trying to open is already currently focused.  

For reference:
-Bug 5776: https://bugzilla.icculus.org/show_bug.cgi?id=5776
-Launchpad bug 957808: https://bugs.launchpad.net/ubuntu/+source/openbox/+bug/957808

Let me know if I can help in any way.
Comment 9 Douglas A. Augusto 2014-11-08 16:09:30 EST
I used git bisect to track down the commit that introduced the bug (somewhat painful due to many compilation failures across revisions). The bad commit is d614beb:

commit d614bebf6a0c4b79d62cf4f703ee6a511fd0b904
Author: Dana Jansens <danakj@orodu.net>
Date:   Wed Sep 29 15:45:37 2010 -0400

    don't steal focus from a window if it was used very recently, when someone uses _NET_ACTIVE request.

diff --git a/openbox/client.c b/openbox/client.c
index ccc64c6..8eeb052 100644
--- a/openbox/client.c
+++ b/openbox/client.c
@@ -730,9 +730,10 @@ static gboolean client_can_steal_focus(ObClient *self,
         /* If the user is working in another window right now, then don't
            steal focus */
         if (!parent_focused &&
-            event_last_user_time && launch_time &&
-            event_time_after(event_last_user_time, launch_time) &&
-            event_last_user_time != launch_time &&
+            event_last_user_time &&
+            (!launch_time ||
+             (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))
         {
Comment 10 Douglas A. Augusto 2014-11-08 16:11:40 EST
Created attachment 3500 [details]
git bisect log
Comment 11 Douglas A. Augusto 2016-01-21 12:04:31 EST
Hi,

FYI, unfortunately I can still reproduce this four-year-old bug in Openbox 3.6.1.
Comment 12 Mikachu 2016-01-22 05:25:19 EST
This may happen if the focused window is a program that thinks you're "using" it because you pressed the windows key. It would probably be best to fix that program to not do that.
Comment 13 Douglas A. Augusto 2016-01-25 09:10:18 EST
Hi Mikachu,

The bug also happens without pressing any keybindings, just typing
"iceweasel<enter>" inside a terminal emulator is enough. But you may have a point
there. This bug seems to be only reproducible on VTE-based terminals (roxterm,
terminator, lxterminal, xfce4-terminal, gnome-terminal); I couldn't reproduce
it in xterm or mrxvt, for instance. Would it be a VTE-related issue, then?
Comment 14 bruno 2016-10-11 05:04:59 EDT
I was experiencing this in a reasonably updated Lubuntu 16.04. I've worked around this following the advice at
https://wiki.archlinux.org/index.php/openbox#Windows_load_behind_the_active_window

I added
<application class="*">
  <focus>yes</focus>
</application>

inside the already existing <applications></applications> section of ~/.config/openbox/lubuntu-rc.xml
Comment 15 Douglas A. Augusto 2016-10-14 08:26:48 EDT
(In reply to bruno from comment #14)
> I was experiencing this in a reasonably updated Lubuntu 16.04. I've worked
> around this following the advice at
> https://wiki.archlinux.org/index.php/
> openbox#Windows_load_behind_the_active_window
> 
> I added
> <application class="*">
>   <focus>yes</focus>
> </application>


Hi Bruno,

I had been struggling with this annoying behavior for almost five years, but now thanks to your advice the issue seems to be vanished. Thank you very much!