2

There is a shortcut to snap window to either half of the screen Ctrl + Super + Left or Ctrl + Super + Right. My first question is how this shortcut is defined in the system? All default shortcuts are defined in gsettings but this is not there.

Now coming to main question. Above shortcut snaps to half screen. I want the shortcut to snap it to 75%. How can I do this? And if I want to define a new shortcut to snap to 75%, then what will be the way?

1 Answers1

1

I was able to make it work using wmctrl and xdotool . Both are window manipulation tool.

#!/bin/bash
WIN=$(xdotool getactivewindow)
eval $(xdotool getwindowgeometry --shell $WIN)
WIDTH=$(calc "int($WIDTH*0.75)")
wmctrl -r :ACTIVE: -b remove,maximized_horz,sticky
wmctrl -r :ACTIVE: -e "0,0,24,$WIDTH,-1"

Above script snap window to 75 % to its size to left side. Save above script in a file and assign shortcut to the file.

Similarly following script snap window to 25% width to the right.

#!/bin/bash
WIN=$(xdotool getactivewindow)
eval $(xdotool getwindowgeometry --shell $WIN)
X=$(calc "int($WIDTH-$WIDTH*0.25)")
WIDTH=$(calc "int($WIDTH*0.25)")
wmctrl -i -r $WINDOW -b remove,maximized_horz
wmctrl -i -r $WINDOW -e "0,$X,-1,$WIDTH,-1"

Check wmctrl and xdotool manpages and tutorials to find how they work. Install dependencies using

sudo apt-get install apcalc wmctrl xdotool

Note: The resizing works relative to current window position and size. To make it relative to screen size, maximize the window then execute the script.