Possibility to set a window always on top by shortcuts?

Hello,

i would like to have a keyboard shortcut to set the selected window always on top, for example the KeepassX-window.
I searched the option in compiz config settings manager but there seems to be no possibility.

Do you have an idea? Is there a command for this on linux systems?

Thank you!

1 Like

Very interesting question.

With a quick search and some compositing around the answers I've found, I came up with a command that activates "always on top" for the terminal in which it's run:

wmctrl -i -r `wmctrl -lp | grep $(xprop -root | grep _NET_ACTIVE_WINDOW | head -1 | cut -d' ' -f5 | sed 's/,//' | sed 's/^0x/0x0/') | cut -d ' ' -f1` -b add,above,sticky

(Yeah, it's a mouthful)
Note: this works in Marco+Compton, not sure in compiz.

I'm gonna read up on xprop because I'm not familiar with it and maybe check if this can be used in a shortcut script.

[details=Edit: I found a really complicated way to do this, better check out @Bill_MI's post below for the simple built-in solution ]OK!

sudo apt install wmctrl xprop

Save the following script into a file for example named "stick.sh" in your home folder in a subfolder named "bin":

#! /bin/bash

# Get active window id from xprop
ACTIVE_ID=`xprop -root | grep -m1 "ACTIVE_WINDOW" | egrep -o "[^ ]+$"`

# Note: -m1 -> limit output to first line matching
# Note: -o "[^ ]+$" -> get only last word (the id)

# Next: format window id in order to pass it to wmctrl
ACTIVE_ID=`sed s/"0x"/"0x0"/ <<< $ACTIVE_ID`

# Use wmctrl to activate "Above" property and make it sticky
wmctrl -ir $ACTIVE_ID  -b add,above,sticky

Then make it executable using:

chmod +x ~/bin/stick.sh

Then define your shortcut, in the command field give the full name of the file for example:

/home/you/bin/stick.sh

Decide on a key combination, and you should be set.
Now, If you need to then toogle this off, this is gonna be another ball game.
[/details]

Hi @Etamuk, As a keyboard navigator I must admit I rarely do this but the window settings dialog is very useful:

Alt+Space, t

That ‘t’ is underlined which is the clue. Or you can arrow down to the feature and just hit Enter to toggle and close the dialog.

I’m running Compiz so it’s possible it may differ with Marco. Just my 2 cents.

4 Likes

Thanks a lot for your ideas.

@ouroumov Your script doenst work for me. I dont know why.
@Bill_MI Thank you. Your idea works for me too.
This is what i figured out:
When i press ATL + Right-click the window settings dialog appears. This maybe useful. So i have not to go to the window borders. I can apply it on every area in the window.

Oh, I forgot to mention you need to install wmctrl and xprop, sorry.

1 Like

No need to be sure, Compiz (via CCSM) has this shortcut already to my knowledge.