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

馋奶兔 提交于 2019-12-24 15:27:36

问题


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?


回答1:


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:'. From python you could call this command using subprocess.Popen.



来源:https://stackoverflow.com/questions/5444377/use-python-to-resize-the-active-window-to-half-the-screen-size-in-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!