Bug 723 - Windows get focus upon receiving an enter-notify x event even though the pointer didn't move with sloppy-focus.
Status: CLOSED FIXED
Alias: None
Product: Openbox
Classification: Unclassified
Component: general
Version: 3.0-alpha6
Hardware: PC Linux
: P5 enhancement
Assignee: Dana Jansens
QA Contact:
URL:
Depends on:
Blocks:
 
Reported: 2003-08-04 18:30 EDT by Tore Anderson
Modified: 2007-05-16 15:51:46 EDT
0 users

See Also:



Description Tore Anderson 2003-08-04 18:30:34 EDT
This is fairly easy to reproduce, and is extremely annoying when you're mostly
using the keyboard to move, resize, and switch between windows.

If you're using sloppy focus (focus follows pointer), and are in some way
using key bindings so a EnterNotify event is triggered, the client which
received that event is activated.  I've got two specific cases where this
bugs me:

1)
Place a Mozilla (M) window and another window (X) (doesn't really matter what
kind) next to each other (don't stack).  Then, place the pointer over the X
window.  Change focus to the Mozilla window without using the mouse (use
focus-cycle or directional-focus actions with the keybard).  Hit Ctrl-L and
start typing in an URL you've visited before, so the drop-down list of recently
visited urls appears and show you a list of suggested completions.  Type some
bullshit so none of them match and the list disappears.  Then BOOM!  The instant
the list is gone, the X window gets a EnterNotify X event, and subsequently the
focus.  Extremely annoying. 

2)
Stack two windows on top of each other.  Place the pointer over the stack,
and use a movetoedge* action to move one of them to some other place on the
desktop.  Whoops -- focus "fell through" to the window below, instead of
following the window I just moved.  Again, extremely annoying.

I tried to add a call to activate_client() after the client_configure() call
when writing the movetoedge* actions, hoping to steal back focus from the
window that got it after I moved the current window, but it seems the
EnterNotify handler is fired after the whole action is finished, so it didn't
work, and I don't know any other way to deal with it.  :-(

Kind regards,
-- 
Tore Anderson
Comment 1 Dana Jansens 2003-08-05 01:45:33 EDT
I honestly don't know how to make this better. I can't ignore the EnterNotify
events because I get other identical events for other situations where you do
want the focus to change. There's no way to tell the difference between 2
identical EnterNotify events, not that I know of anyhow. If anyone can come up
with something smart for this I'd be pleased to work on it, but I have attempted
to solve this before and just ran into a brick wall.
Comment 2 Tore Anderson 2003-08-05 08:27:49 EDT
Well, other window managers get it right, so there must be a way of solving it.

I'm at work right now, so I don't have time to go source-diving, I'll see if
I can do so later in the week.

Anyway, you'd want to ingore the EnterNotify events only if the pointer
position hasn't changed.  I don't know how difficult it would be to add
this check.  I'll take a look.

I don't agree the bug should be tagged as resolved though, as it is a bug,
and a very annoying one too.
Comment 3 Dana Jansens 2003-08-05 13:32:53 EDT
That's not all. The case that making this work breaks is:

You middle-click the titlebar - lowers the window, and it hides behind another
window. In every attempt I've made, fixing the case you have described breaks
that one. Making it ignore enter notifies when the mouse hasn't move is another
solution that breaks this case.

Are these other window managers that get it right also broken in this situation?
Comment 4 Tore Anderson 2003-08-05 15:56:16 EDT
I dare say that's a broken way of implementing the lower action.  You're then
basing it on the premise that the mouse will hover above the stack when it's
triggered, which is certainly not true in all situations.  For instance,
you might have three windows, two xterms stacked on top of each other, and a XMMS
in a corner corner.  The mouse is hovering over the XMMS window, while the
xterm on top of the stack has keyboard focus.  I call my preset keybinding to
lower the top xterm -- but the xterm that's now on top of the stack do -not- get
focus.

Another case it will break is if you've got two windows like this, and the
lower action bound to some mouse click with the title bar:

 +====+
 |    |=+
 |    | |
 |    | |
 +----+ |     
  +-----+

The newly raised window won't get focus.

On top of my head, I would have solved this not on the basis on where the
pointer reside (it's not unlikely that this position is totally irrelevant
anyway, as the lower function can be bound to keyboard hotkeys), but rather
on seeing if there was any client that got a VisibilityNotify event with
state VisibilityUnobscured as a result of the lowering, and then go on to
activating that client.  Perhaps, if no client got VisibilityUnobscured,
instead do some maths on the Expose events some clients might have got, and 
focus the one that got the largest addition of visible area as a result of
the lowering.

Do you agree with my reasoning?  I'm not familiar with the event handling code
of ob3 but I will look into it if you're agreeing that this would be a better
way.  The current way is a serious hindrance to using ob3 and using the keyboard
as much as possible (I detest the mouse, I believe was really close to getting
RSI before I switched to fvwm which allowed me to use the keyboard for all the
window manipulation).

By the way:  I do not know how the fvwm handles lowering, as I never used that
function -- I prefer keeping windows un-stacked.

Tore
Comment 5 Dana Jansens 2003-08-25 03:53:35 EDT
I recently got an email from someone else interested in this. His proposal was
to not handle EnterNotify events, but instead focus a window when a motion event
ocurred over an unfocused window.

I'm not sure if this is an appropriate solution or not... as the case of the
lowering window would instead leave the focus on the lowered window until the
cursor moved.
Comment 6 Dana Jansens 2003-08-25 12:53:38 EDT
The motion events option turns out to not be a good one. Many apps, like mozilla
foor example, catch the motion events and don't propogate them, so Openbox
doesn't receive them for much of the mozilla window.
Comment 7 Tore Anderson 2003-08-27 18:00:09 EDT
Yes, and I don't think it would've been a very good idea anyway.  A conventional
mouse easily moves a few pixels simply because your your desktop moves a bit
when you shift your arm position, which could cause focus to jump around a
bit erratically.

However, you've yet to comment on my proposal (ignore EnterNotify if pointer
position hasn't changed, and use Visibility*/Expose events in the lower action
instead).  Would that be a feasible way of doing it, or is it too difficult to
implement the transition thing that we'd need?

(I'm sorry I've been more or less oblivious to ob developement lately, I've
been almost drowning in work and have used all the rest of my time for resting.)

Tore
Comment 8 Ava Jarvis 2003-09-02 11:51:01 EDT
Metacity also exhibits this behaviour with Mozilla.

Oroborus does not exhibit this behaviour with Mozilla, but only because it
centers the mouse pointer on the window whenever you use keys to focus.  (It
also has a somewhat annoying delay for which you have to hold the modifier key
down for in order for focus to stay on the newly focused window, but this is
probably a configuration thingy somewhere I forgot to set.)

As for moving the focused window out from under the mouse with keystrokes, and
focus falling through: in spite of recentering the cursor, Oroborus exhibits the
same bug.  Metacity does not because it recenters the cursor before the move,
and keeps the cursor centered throughout the move.

I think that keeping the pointer centered on the window when certain actions are
taken via keystrokes, in the case of focus follows mouse, is the best solution
(obviously ironing out any bugs that Metacity or Oroborus have).  Such a thing
would make sense, and when I was using FVWM, I think I actually implemented this
solution when I was in my sloppy focus phase.
Comment 9 Dana Jansens 2003-09-02 13:24:18 EDT
I just had 2 brilliant thoughts.

1) Remove the move/resize actions that are causing these problems, since there
are already KeyboardMove and KeyboardResize that let you move in all directions
and use the mouse if you want, and won't have this problem.

2) Grab the mouse pointer, move the window, ungrab the mouse pointer. Problem
goes away.

I think 1) is better, as the actions are kind of redundant.
Comment 10 Dana Jansens 2003-09-02 13:55:05 EDT
I have implemented 2) in CVS. So moves will no longer cause problems. I think
this resolves all the issues raised here. Please contradict me if I missed
something else.
Comment 11 Tore Anderson 2003-09-02 14:02:51 EDT
I'm not sure how your first suggestion would solve the problem I first
described in this bug log (the Mozilla window placed next to the xterm),
as it does not involve any moving or resizing of any windows.  But then
again, I don't see how it would be solved by #2 either.  It is mayhap
a bug in Mozilla?  No, the same thing appear to happen in Konqueror as
well.  :-(

Also, I can't see how the actions are redundant, either -- KeyboardMove
and KeyboardResize seems to me to be interactive, while the MoveToEdge
and GrowToEdge actions just snaps to the nearest edge.  Unless you can
give the KeyboardMove and the KeyboardResize information that you should
go to the nearest edge in a given direction instead of interactively
moving them with the arrow keys, they offer quite different features.

About #2 -- it sounds very very simple.  Would that basically suppress
all pointer-related events while the pointer is grabbed?

Tore
Comment 12 Tore Anderson 2003-09-02 14:19:28 EDT
Yes, it works like a charm now, for moving and resizing!  Thanks!  :-)

However the problem with focus warping to the window the mouse hovers over
when a drop-down list in another (previously focused) window closes, still
persists.  Hmm, I've got no idea on how to deal with that at the moment
though.  :-(

Tore
Comment 13 Dana Jansens 2003-09-02 14:38:25 EDT
Ah yes, the menus. Reopening the bug. I haven't a good idea on this one either yet.
Comment 14 Dana Jansens 2003-09-15 02:12:34 EDT
So I think this is fixed in CVS now. Let me know.
Comment 15 Tore Anderson 2003-09-15 03:12:06 EDT
Indeed, it is working flawlessly now!  Thanks!  :-)

Tore