- How to set a shortcut for «Always on Top» for window?
- 7 Answers 7
- Unity instead of GNOME (Ubuntu before 17.04)
- How to make a window always on top?
- EDIT
- Notice
- How To Use A Keyboard Shortcut To Toggle Always On Top On GNOME, KDE, MATE, Xfce and Cinnamon Desktops
- Set an Always on Top keyboard shortcut on GNOME desktop
- Set an Always on Top (Keep Above Others) keyboard shortcut on KDE Plasma
- Using the built-in keyboard shortcut to toggle Always on Top on MATE, Xfce and Cinnamon desktops
- Using a generic way of setting a window Always on Top (X only)
How to set a shortcut for «Always on Top» for window?
In 12.04 (Unity), I would like to assign a shortcut to the «always on top option» for a window. Probably something like Ctrl + Shift + Home to turn on and Ctrl + Shift + End to turn off, or whatever. Is there an option to do this somewhere in the Compiz Settings Manager? This (old) post claimed that
For compiz, Enable Extra WM Actions. Check the properties, and insert ALT + A to Key field for Toggle Always-On-Top action.
7 Answers 7
It should work on every Ubuntu OS since version 9.04 without installing anything, modifying of creating any shortcuts.
- Alt + Space as the first shortcut brings up the right-click mouse menu
- T selects the «Always On Top» function.
Confirmed working on Unity 14.04. The fact that alt+space activates a pull-down menu helps especially for infrequently-used features.
This was posted 2 years after the question, but now represents the best answer, so I am changing the accepted answer.
Since no one has mentioned this yet, I’ll just leave a solution that worked for me on Ubuntu 12.04.
You could setup a regular keyboard shortcut and use wmctrl to toggle the «Always on Top» option.
Go to System Settings > Keyboard > Shortcuts > Custom Shortcuts. Hit the + and give your shortcut a name. Then enter the following command.
wmctrl -r :ACTIVE: -b toggle,above
If you don’t have it already, you can install wmctrl from the repos using
sudo apt-get install wmctrl
You should have something that looks similar to this.
Hit apply and you should be good to go!
Unity instead of GNOME (Ubuntu before 17.04)
If not install CCSM and extra compiz plugins via:
sudo apt-get install compizconfig-settings-manager compiz-plugins-extra
Be aware please. CCSM can kill Unity3D on some systems.
If you have not had compiz-plugins-extra already installed, you need to restart Compiz to load them (even though they display in CCSM just fine before the restart) with Alt + F2 and
You can see Extra WM Actions under Windows Management section on CCSM as explained in the post you found. You can set the desired action there easily.
Actually, restarting compiz is only needed so that it is aware of the new plugins. Afterwards, you can change the shortcuts on the fly (i.e. you do not need to restart Compiz after every change of a shortcut)
Thank you for the info @sup. I just explained it using the given post. Actually I did not tried it myself.
I tried to use the wmctrl command toggle, but it didn’t work on my Ubuntu set up. The toggle would toggle on, but not toggle off. (I think it might be because I’m using the gnome desktop environment, on which wmctrl is slightly broken AFAIK).
Anyway, after a lot of research and working out how to write proper code in bash, I created a single command that uses the wmctrl commands within a layer of logic to toggle the ‘always on top’ state effectively on the current GNOME desktop. I posted this answer on Ask Unix/Linux, but thought I’d post it here too in case anyone had the same issue.
bash -c 'wmctrl -r :ACTIVE: -b $([[ $(xprop -id $(xprop -root -f _NET_ACTIVE_WINDOW 0x " \$0\\n" _NET_ACTIVE_WINDOW | awk "") _NET_WM_STATE) =~ "ABOVE" ]] && echo "remove" || echo "add"),above'
It checks the active window state property «_NET_WM_STATE» using xprops , and if it contains the text «ABOVE» that means the ‘always on top’ option is active. Then it just runs the wmctrl command with the parameter add or remove as appropriate.
Command breakdown (each command is inserted into the next, replacing the ■ placeholder):
xprop -root -f _NET_ACTIVE_WINDOW 0x " \$0\\n" _NET_ACTIVE_WINDOW | awk ""
This last step in particular took me a very long time to figure out. Until I realised that the keyboard shortcuts weren’t running in bash by default, I had no idea why the commands were working in the console as I was testing them but silently failing when run directly as a keyboard shortcut. It drove me up the wall for ages!
Note: because you need quotes around the command you’re sending to bash, I had to be careful when writing the command that I never went more than one more level deep (using double quotes). Any further nesting of strings in quotes would have required lots of confusing backslashes to escape the quotes.
Further detailed notes: how to create the keyboard shortcut (thanks @rajesh_chaurasiya)
- Install wmctrl using sudo apt-get install wmctrl if you haven’t already
- Go to system settings > keyboard shortcuts. Click the + button to add a custom shortcut.
- Choose a name such as ‘Toggle always on top’ ( it can be anything you like ).
- In the command field add the full command from the top of this answer.
- Record a keybinding to complete the shortcut.
How to make a window always on top?
I have created a frameless Qt/QML window, and I really would like to know any programmatic means of setting its «Always On Top» system menu flag. Clicking ALT+SPACE I can bring up the system menu for the frameless window, and by clicking the «Always On Top» option the window does keep always on top, but I’ve not found a programmatic way of doing the same. The Qt.WindowStaysOnTopHint doesn’t work, and trying wmctrl -r «window name» -b add,above doesn’t work either, even though wmctrl does work for other windows. wmctrl not working for my window of interest apparently has something to do with the N/A for the machine name column on wmctrl -l :
francisco@Ubuntu:~$ wmctrl -l 0x02600006 0 Ubuntu Área de trabalho 0x03c00002 0 Ubuntu XdndCollectionWindowImp 0x03c00005 0 Ubuntu unity-launcher 0x03c00008 0 Ubuntu unity-panel 0x03c0000b 0 Ubuntu unity-dash 0x03c0000c 0 Ubuntu Hud 0x046000b3 0 Ubuntu How to make a window aways on top? - Stack Overflow - Mozilla Firefox 0x0520000b 0 N/A Qt Creator 0x05002396 0 Ubuntu francisco@Ubuntu: ~ 0x0540000b 0 N/A backlight
I’ve also gone through this procedure but as for the user asking, it’s not working for me either, same behavior. The _NET_WM_STATE_ABOVE is set, but focusing the window and then checking the flag again it’s not there anymore, it’s sticky only when clicking through system menu. This is the QML: https://gist.github.com/oblitum/8050586 Related askubuntu question: https://askubuntu.com/questions/394998
EDIT
Notice
In the related askubuntu question, it was found that there should be a bug on wmctrl for targeting certain windows through their names. Using wmctrl -i -r
How To Use A Keyboard Shortcut To Toggle Always On Top On GNOME, KDE, MATE, Xfce and Cinnamon Desktops
This article shows how to use a keyboard shortcut to set a window to be always on top, on GNOME, MATE, Xfce, Cinnamon and KDE Plasma desktops, as well as a generic shortcut that works with any EWMH/NetWM compatible X Window Manager (so this generic solution doesn’t work on Wayland).
Set an Always on Top keyboard shortcut on GNOME desktop
GNOME doesn’t have a default keyboard shortcut for Always on Top any more (it used to have Alt + Space , then t ), but there is an option to set your own keyboard shortcut for this window feature. The option is not exposed in Settings — > Keyboard Shortcuts though.
To access the option that allows setting a keyboard shortcut for Always on Top, open Dconf Editor and go to /org/gnome/desktop/wm/keybindings . There, set a keyboard shortcut for always-on-top in this form (example): [‘1’] , [‘2’] , [‘a’] and so on, but obviously, set it to what you want to use for this. Disable the «Use default value» toggle to be able to enter a shortcut.
Set an Always on Top (Keep Above Others) keyboard shortcut on KDE Plasma
KDE Plasma has an option that you can use set a window Always on Top, called Keep Window Above.
To set a keyboard shortcut to toggle this Keep Window Above option on/off, go to System Settings -> Shortcuts -> Global Shortcuts , search for Keep Window Above , and then you’ll see an option to assign a keyboard shortcut to this option, like in the screenshot above.
Using the built-in keyboard shortcut to toggle Always on Top on MATE, Xfce and Cinnamon desktops
MATE, Xfce and Cinnamon desktops have a built-in keyboard shortcut to toggle the Always on Top window option.
On MATE and Cinnamon, focus a window, then press Alt + Space , then t to set a window to be always on top. Toggle it off using the same key combination. Cinnamon also offers the ability to set a custom shortcut for this: System Settings -> Keyboard -> Shortcuts -> Windows -> Toggle always on top .
For Xfce, toggle Always on Top using Alt + F12 . Or use the same Alt + Space , then t to enable Always on Top; however, to toggle it off, use Alt + Space , then o . Xfce offers the ability to change the key to toggle the window above option: Settings -> Window Manager -> Keyboard -> Toggle above .
Using a generic way of setting a window Always on Top (X only)
If the desktop environment you’re using doesn’t have a way of setting a keyboard shortcut for the Always on Top window option, or you want to use a custom shortcut and the desktop environment you’re using doesn’t support this, you can use wmctrl to set a window always on top.
Here’s the wmctrl official description: wmctrl is a command that can be used to interact with an X Window manager that is compatible with the EWMH/NetWM specification. wmctrl can query the window manager for information, and it can request that certain window management actions be taken.
- Debian / Ubuntu and Linux distributions based on these 2, like Pop!_OS, Zorin OS, Elementary OS, etc.:
sudo zypper install wmctrl
To use wmctrl to set Always on Top, open your desktop environment’s custom keyboard shortcuts dialog, add a new shortcut and use this as the command:
wmctrl -r :ACTIVE: -b toggle,above
This uses wmctrl to toggle the «above» window property, so it sets a window Always on Top if it’s not already, and it turns Always on Top off if it’s active.