1

I want to change some tmux styling when the terminal loses focus/becomes inactive (i.e. when I've clicked on an open Google Chrome window). I know I could check with the window manager to see which application window is focused, but this doesn't work across window managers.

Do terminal emulators themselves expose this information at all?

I tried running showkey -a to see if any escape sequence was sent when focus was lost, and it doesn't look like it.

Christopher Shroba
  • 7,006
  • 8
  • 40
  • 68
  • https://unix.stackexchange.com/questions/480052/how-do-i-detect-whether-my-terminal-has-focus-in-the-gui-from-a-shell-script/606323#606323 – HappyFace Aug 25 '20 at 21:57

1 Answers1

1

I think some terminals implement this, but not all, based on this comment on the issue tracker for the vim-tmux-focus-events plugin:

About the question "I was expecting the event to fire when changing focus between different windows in my window manager": yea, I see how that would be very useful. I think this might be dependent on the terminal application you're using. I just tested this on OSX and here's some quick results:

  • it's working for iTerm when tmux is running inside the window
  • not working for iTerm running plain bash + vim inside (no tmux)
  • not working for Terminal.app (with or without tmux)

[...]

So, if I'm not wrong, it's up to terminal applications to implement "focus gained", "focus lost" functionality.

I have a vague memory (though I don't remember for sure) that focus gain/loss might have worked for me when using that plugin and gnome-terminal, so it might be worth a try.

ash
  • 5,139
  • 2
  • 27
  • 39