[Xquartz-dev] Intermittent loss of input focus?
Kyle J. McKay
mackyle at gmail.com
Sun Mar 22 14:51:17 PDT 2015
On March 22, 2015 01:28:33 PDT, Jeremy Huddleston Sequoia wrote:
> This has come up before.
> The issue is http://xquartz.macosforge.org/trac/ticket/58, and
> there's a radar filed for the issue that is pretty much just as old.
> Note that XQuartz has no say in giving up focus. Something else is
> stealing focus from us. 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.
> In any event, you can run the attached script (which Ken Thomases
> provided to the list a couple years ago) to find out what is
> stealing the focus and possibly stop it from periodically doing so
> (by disabling it, deleting it, etc):
> Hope that helps.
Just to satisfy my curiosity, I took a look at this.
I was able to duplicate it after building and running the "Mail Status
I think I understand what's happening. Let me include some logging
004 17:35:56.744: 'appl'/7 (kEventClassApplication/
-psn_0_2757281 (X11.bin) pid 30108
004 17:36:55.880: 'appl'/7 (kEventClassApplication/
-psn_0_2937549 (System Events) pid 32342
What's happening in this case is that 'Mail Status Control.app' is a
LSUIElement=1 app and it periodically runs an AppleScript using this
appleScript = [[NSAppleScript alloc] initWithContentsOfURL: scriptURL
*ae = [appleScript executeAndReturnError:&errorDict];
Now the script in question includes a bunch of stuff in a 'tell
application "Mail"' block (but it only runs that if Mail.app is
already running, so if you try to duplicate this using "Mail Status
Control.app" you will need to make sure Mail.app is already running).
For whatever reason, that causes the front switch to "System
Here's the thing though. Other applications that are frontmost when
the mail check triggers do not get a switch to System Events.
And, just like the bug report says, if I click on X11.app in the Dock
to bring it back to the front it doesn't get them either. However, if
after clicking on X11.app in the Dock to bring it forward, I then
click on a different X11.app window (other than the one that became
active after clicking on X11.app in the Dock), X11.app will start
getting the switch to System Events at the next mail check again.
So clearly, the code that activates a different X11.app window even
when X11.app is already frontmost is enough to trigger the bug.
As a hack, X11.app could always examine the processMode
modeOnlyBackground bit of the application that's becoming frontmost
and attempt to compensate (looks like it's set for both LSUIElement=1
and LSBackgroundOnly=1 apps).
 Downloaded source from archive.org and built it.
More information about the Xquartz-dev