简体   繁体   中英

Use Python to resize the active window to half the screen size in Linux?

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?

The lag you getting is caused by xrandr command it's going to be slow anyway. You can reduce this time by parsing output of xdpyinfo | grep 'dimensions:' xdpyinfo | grep 'dimensions:' . From python you could call this command using subprocess.Popen.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM