This question is a follow up to: Manipulate window size in linux via compiled code?
Per the title, I want to resize the active window to half the screen size (either on the left or the right of the screen. I can do this with a bash script as follows (per the answer to the previous question):
#!/bin/bash
w_h=$(xrandr | awk '/\*/{sub(/[0-9\.\*\+]*$/, ""); sub("x", " "); $1=$1/2; print}')
w=${w_h% *} ; h=${w_h#* }
wmctrl -r :ACTIVE: -b remove,maximized_horz,maximized,vert
wmctrl -r :ACTIVE: -e 0,${w},0,${w},${h}
However, this method has a noticeable but not severe lag of 0.25 seconds on my laptop that I would like to get down to 0.1 seconds. How can I achieve the same affect as the above bash script in python?