smhk

Debian center window keyboard shortcut

On Debian Stretch (9.5), wanting to add a keyboard shortcut which un-maximises the current window and centers it, making it slightly smaller than the screen resolution, so that some of the background can be seen.

Finds the Mozilla Firefox window and stops it from being maximised:

wmctrl -r "Mozilla Firefox" -b remove,maximized_vert,maximized_horz

Finds the Mozilla Firefox window and sets it to a specific size. Note that if the window is maximised, this will appear to do nothing:

wmctrl -r "Mozilla Firefox" -e 0,210,80,1500,900

Uses xdotool to get the active window rather than hard-coding “Mozilla Firefox”. Combines the above two commands into a one-liner:

wmctrl -ri "$(xdotool getactivewindow)" -b remove,maximized_vert,maximized_horz && wmctrl -ri "$(xdotool getactivewindow)" -e 0,210,80,1500,900

This one-liner can then be bound to a keyboard command.

In Debian, go to Settings → Keyboard, then scroll to the bottom and click the plus sign to add a new keyboard shortcut. I pasted the above command, named it “Center window” and bound it to Ctrl+Super+Down.