5

I have a very annoying issue with the X11 app on OS X when using it to run things remotely over SSH. Every now and then (it's pretty regular, I'd say about each 1-2 minutes), the app I'm in loses focus, and the keyboard doesn't get sent to it anymore. However, X11 is still the foreground app.

Any ideas on what could be causing this and/or how to debug this?

houbysoft
  • 9,182
  • What X11 app are you running? If you're using a window manager or desktop manager (ie. GNOME or KDE), do you have 'focus follows mouse' enabled? – EmmEff Mar 01 '13 at 23:58
  • @EmmEff: I am just running a bunch of gnome-terminal windows without any desktop managers. – houbysoft Mar 02 '13 at 00:27
  • @emmeff. This user is on OS X. There is no focus follows mouse feature. I use Terminal and have seen no such issues. Do these things you're doing require the X11 framework on OS X or can you get away with another terminal client? – bispymusic Mar 02 '13 at 02:48
  • @bispymusic: it's much more convenient doing it this way, because I can just ssh in once and then launch multiple terminals on the machine. To use Terminal.app for this I'd have to open multiple ssh connections – houbysoft Mar 02 '13 at 03:07
  • @bispymusic If you need focus follows mouse feature you can configure in XQuartz preferences. There's no default X11 in OS X 10.8 – Eir Nym Mar 09 '13 at 23:22
  • @houbysoft have you tried to use screen or tmux applications on mac/or server (I can't figure where do you need to multiplex your terminal) – Eir Nym Mar 09 '13 at 23:26
  • @EirNym: I am aware of those, but the thing is sometimes I need to run other (graphical) programs over SSH as well, so it'd be more convenient if I could just get this fixed for all X11 apps. – houbysoft Mar 09 '13 at 23:32
  • ssh -XY and terminal multiplexing? also you can share single SSH connection (using ControlMaster auto) – Eir Nym Mar 09 '13 at 23:48
  • @EirNym, no, the point is I want to run say firefox on the remote server – houbysoft Mar 10 '13 at 02:19
  • @houbysoft hehe, it can be done much easer than you do! Just make your ssh socks proxy with -D. Something like ssh -D1234 user@server. Now you add to your browser setting to use socks proxy 127.0.0.1:1234… and you browse via your server! There's less traffic, and much more comfortable – Eir Nym Mar 10 '13 at 07:20
  • @EirNym: yes, I know, but still, sometimes I just need the X interface / it is more convenient... I get that there are alternatives but I'd like this to work since it requires the least set up (it's not only about firefox). – houbysoft Mar 10 '13 at 09:29
  • which keys do you provide to ssh when you run it? – Eir Nym Mar 10 '13 at 09:30
  • @EirNym: I use password-based authentication (can't change that unfortunately, I'm not administering the server) – houbysoft Mar 10 '13 at 09:48
  • No-no-no! I mean other flags and options you use like -X, -Y and others – Eir Nym Mar 10 '13 at 10:21
  • @EirNym: oh, you mean arguments? -XC usually – houbysoft Mar 10 '13 at 18:38
  • Please, try -Y. It fixes several "bugs". – Eir Nym Mar 10 '13 at 22:27
  • Check out the python script from https://xquartz.macosforge.org/trac/ticket/58, it monitors which process grabs the focus. I have the same issue and it turns out com.apple.WebKit.WebContent is the culprit – Jamgold Apr 29 '14 at 18:56
  • I detected the same problem on Mountain Lion (10.8.5) and XQuartz (2.7.6). I'm only using Xterm and within them I'm either working locally or on remote servers through ssh. → houbysoft: have you already diagnosed that this focus loss is related to the use of ssh? – dan Jul 22 '14 at 09:37
  • 2

2 Answers2

2

ssh: wrong culprit

I have this loss of focus on a variable frequency on XQuartz without any ssh command.

On the other hand I found a heavy relationship between this XQuartz loss of focus and the launch of:

Google Software Update (com.google.Keystone.Agent)

Analysis of this bug

2 tools help during this investigation:

  1. watch activations Python script

    [...]
    2014-07-22 17:06:04.622 Python[95279:1307] activated Google Software Update (com.google.Keystone.Agent)
    2014-07-22 17:06:08.410 Python[95279:1307] activated loginwindow (com.apple.loginwindow)
    [...]
    
  2. lastcomm | head -10 immediatly after the event →

    [...]
    diskmanage -S      root     __         0.00 secs Tue Jul 22 17:06 (0:00:18.03)
    GoogleSoft -S      root     __         0.11 secs Tue Jul 22 17:06 (0:00:30.03)
    [...]
    
dan
  • 12,177
  • 8
  • 58
  • 136
  • 1
    Excellent answer for helping debug the situation. In my case it was GPG Suite Updater, with possible (closed) thread here: https://gpgtools.tenderapp.com/discussions/feedback/4109-gpgsuite-updater-steals-focus-from-x11-apps – esmit Apr 06 '20 at 12:33
1

I found this link: http://xquartz.macosforge.org/trac/ticket/133, which suggests that ARDAgent is the offending app, and that unchecking System Preferences -> Sharing -> Remote Management solves the problem.

I didn't have Remote Management switched on, but I did have File Sharing and Remote Login ticked. Switching off both (finally!) solved the problem of losing focus.

I haven't tested which of the two was causing the trouble.