[Xquartz-dev] Xquartz-dev Digest, Vol 78, Issue 9

Ken Thomases ken at codeweavers.com
Sun Mar 22 14:24:36 PDT 2015

On Mar 22, 2015, at 3:15 PM, René J.V. Bertin <rjvbertin at gmail.com> wrote:

> On Sunday March 22 2015 12:00:02 xquartz-dev-request at lists.macosforge.org wrote:
>> I presume since it is just XQuartz that is seeing this issue that there must
>> be *something* I could do put XQuartz in a mode that would prevent this
>> focus loss, but I'm at a loss to know what that is because I have no idea
>> why the focus is being allowed to be stolen in the first place.
> Let's see how wide open the door is I'm about to kick in :)
> I think that what happens is that some application starts in a way that it becomes the front application (is it (still) possible to launch an app through LaunchServices without that happening?). It, or the OS returns focus to the application that had it (which is something that could be done so quickly that there's very little chance anything gets lost). Normally, someone would know what window was the key window in that application, but X11 must be different. Either no window gets focus, or the wrong window.

Well, there is something wrong in the way XQuartz is handling focus.  It's actually possible to demonstrate it entirely within XQuartz.  With an xterm window open and focused, simply open the Help menu in XQuartz's menu bar.  Since the Search item in that menu has a text field that receives focus, it steals it from the xterm window.  When you dismiss the menu, the xterm window does not get focus back.  I suspect that the problem with external apps stealing focus is similar.

Something similar happens if you bring up the About XQuartz window and then close it.  Or the Preferences window.  Etc.

Basically, when a Cocoa window is focused, X11 is deactivated.  When the Cocoa window is closed, X11 is not reactivated.

For the custom X server in CrossOver (based on a very old X.org code base), I created an invisible Cocoa window to act as a proxy for X11's focus.  Basically, X11's focus has an entry in the Cocoa window list.  When X11 has focus, that naturally takes focus away from other Cocoa windows.  When Cocoa would return focus to its last key window (e.g. Help menu is dismissed; About panel is closed) and the proxy is that window, X11 gets focus.


More information about the Xquartz-dev mailing list