Bob Marley Algorithm

The Bob Marley Algorithm (BMA) is a method used in awesome to fix a certain number of problem regarding the sloppy focus.

= Description of the problem = The problems are well described on this page.

Basically, when the mouse cursor move we want the window it is entering to have focus. When the mouse pointer enters a window, the window manager receives a EnterNotify event. When the mouse pointer leave a window, the window manager receives a LeaveNotify event. Based on this event, we can now on which window the mouse is and then give the focus to it (or do any other thing).

When you give focus with such a method, that's called sloppy focus.

But in a certain number of case, it can be the window that move, appear or disappear. An in such cases, X will also send you a EnterNotify or LeaveNotify event. We qualify this event as spurious, because the mouse pointer did not move at all: that means that basically the user did not do anything, it just a window that has moved or re-sized itself under the cursor.

= Solution in ahwm = Alex Hioreanu who described the problem very well in the page linked above, came up with a light solution, based on events serial number. Unfortunately, this method is not very reliable and can fail in some case.

= Solution in awesome: BMA = I came up with a solution one day while listening to the great Bob, hence the name of this method. The problems addressed and resolved by this idea are problem 2, 3, and a part of problem 5.

Problem 4 and the other part of problem 5 is addressed by awful.autofocus.

Actually, the solution is quite simple: we know, as a window manager, when a window will be moved or resized, because we either send this event, or listen for them.

So before doing any action like moving, resizing, mapping or unmapping a window, we just readjust the event list we are listening on all clients to be the same as usual but without the EnterNotify and LeaveNotify event.

This has to be readjusted on all clients: when you are unmapping a window, you don't know exactly which window is under the cursor. Even if you know, you can't be sure something will happen between your unmap and the event notification (unless you grab the server, which is a bit ugly and more complicated).

This method has the advantage to work very well, but also the disadvantage of sending 2*N X messages to the server to readjust the client event mask.