I'm running Ubuntu 18.04.2 and GNOME 3.28.2.

Like most people I am pretty adept at switching between windows using Alt-tab and Super-tab. But I also play RTS games and I think it would be neat if I could bind whatever window is currently in focus to the number pad on the fly so later I can immediately switch focus back to that window by pressing the bound key. Obviously, if I close the window the key binding should expire.

Does something like this already exist? I've been poking around on the internet to no avail.

In the meantime, I'm trying to build something myself with wmctrl and xbindkeys but it's slow going so if anyone has done something similar and has suggestions I'm all ears.

  • Hi jdly, just curious, but did you notice the answer? Is all clear? May 6, 2019 at 13:56

1 Answer 1


Simpler then you'd think...

  1. Make sure both wmctrl and xdotool are installed

    sudo apt install xdotool wmctrl
  2. Create two shortcuts:

    /bin/bash -c 'xdotool getactivewindow > /tmp/wraise'

    to save the current window, and:

    /bin/bash -c 'wmctrl -ia "$(cat /tmp/wraise)"'

    to raise the window you set with the first one.

To set another window, just press the first shortcut again. Since the window's id is stored in /tmp, it will be automatically forgotten on restart.

That's all!

  • This works almost perfect! I liked the idea of saving the active window to /tmp, quite elegant. The only downside is that whatever service the Ubuntu keyboard shortcut UI uses does not differentiate between numpad keystrokes with numlock on or off. That is, both KP_1 and KP_End activate the shortcut. This means that I can't use the numpad to enter numbers, which isn't a huge deal for me but it might be for others. To that effect, it would also be nice to be able to temporarily disable the shortcuts without deleting them. My problem is solved for now but I might revisit later.
    – jdly
    May 15, 2019 at 21:20
  • Thanks!, You could of course set any shortcut, possibly one with no " double meaning." May 15, 2019 at 21:32
  • You're right, which is why I chose to accept the answer, but at least for me it would be preferable to use only the "non-numlocked" numpad functions because I literally never use them. For now, I'm using Ctrl + numpad to set the window, and Alt + numpad to raise it. As an aside - it looks like fixing the keyboard shortcuts applet would entail patching and rebuilding gnome-settings-daemon from source which is a bit more than I'm willing to take on right now so I'll just have to live with an extraneous keypress in the meantime :).
    – jdly
    May 15, 2019 at 21:46

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.