I'm using i3 as my WM with a Dual-Head setup. I have already mapped some keys to switch between workspaces on one of the monitors (Mod+Keypad 1..8) and I would like to use the same keybindings on both monitors (each one has 8 workspaces).

Considering i3 cannot bind keys twice, I would instead use a script that detects the monitor, and sends the correct message through i3-msg. However, I need to know which monitor is focused to do this.

So, is there a way to get the name of the focused monitor in this scenario?


You could use xdotool to get current cursor location:

$ xdotool getmouselocation --shell

In ideal case your monitors will have different screen numbers but if they all are listed under SCREEN=0 you still could use X location to detect current monitor (e.g from 0 to 1919 will be first screen and from 1920 - second screen).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.