使用Python在Linux中将活动窗口的大小调整为屏幕大小的一半吗? [英] Use Python to resize the active window to half the screen size in Linux?

查看:315
本文介绍了使用Python在Linux中将活动窗口的大小调整为屏幕大小的一半吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题是针对以下问题的后续措施:在linux中操作窗口大小通过编译的代码?

This question is a follow up to: Manipulate window size in linux via compiled code?

对于每个标题,我想将活动窗口的大小调整为屏幕大小的一半(在屏幕的左侧或右侧.我可以使用bash脚本执行以下操作(根据上一个问题的答案) :

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}

但是,此方法在我的笔记本电脑上有0.25秒的明显但不严重的滞后,我希望降至0.1秒.如何获得与上述bash脚本在python中相同的效果?

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?

推荐答案

您得到的延迟是由xrandr命令引起的,无论如何它都会变慢.您可以通过解析xdpyinfo | grep 'dimensions:'的输出来减少此时间.在python中,您可以使用subprocess.Popen调用此命令.

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.

这篇关于使用Python在Linux中将活动窗口的大小调整为屏幕大小的一半吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆