我想创建键绑定(bind),将当前窗口大小设置为水平方向屏幕大小的三分之一和垂直方向最大大小,并将其定位在屏幕的左侧、中间或右侧三分之一处。我怎样才能做到这一点?
最佳答案
xbindkeys 和 xdotool
通过 xbindkeys,您可以独立于窗口管理器使用 Shortctus。 xdotool 允许移动窗口和调整窗口大小。
安装方式:
sudo apt-get install xbindkeys
sudo apt-get install xdotool
默认配置
默认设置显示快捷方式绑定(bind)的外观。创建它并查看文件内容。
xbindkeys --defaults > ~/.xbindkeysrc
使用编辑器编辑~/.xbindkeysrc并输入:
"/bin/bash ~/placewindow.sh left"
control + l
"/bin/bash ~/placewindow.sh middle"
control + m
"/bin/bash ~/placewindow.sh right"
control + r
创建 shell 脚本
使用文本编辑器创建一个 shell 脚本,对于我们的用例,我将其命名为 ~/placewindow.sh:
#!/bin/bash
width=`xdpyinfo | grep dimensions | sed -r 's/^[^0-9]*(([0-9]+)x([0-9]+)).*$/\2/'`
height=`xdpyinfo | grep dimensions | sed -r 's/^[^0-9]*(([0-9]+)x([0-9]+)).*$/\3/'`
case "$1" in
left)
xdotool windowsize `xdotool getactivewindow` `expr $width / 3` $height
xdotool windowmove `xdotool getactivewindow` 0 0
;;
middle)
xdotool windowsize `xdotool getactivewindow` `expr $width / 3` $height
xdotool windowmove `xdotool getactivewindow` `expr $width / 3` 0
;;
right)
xdotool windowsize `xdotool getactivewindow` `expr $width / 3` $height
xdotool windowmove `xdotool getactivewindow` `expr $width \* 2 / 3` 0
;;
esac
使其可执行:
chmod +x placewindow.sh
提示
对 ~/.xbindkeysrc 进行更改后,您需要
killall xbindkeys
xbindkeys
使更改立即生效。
演示
现在按 CTRL+l、CTRL+m 或 CTRL+r 时,事件窗口的大小和位置都会调整。它看起来像这样:
关于resize - gnome 键绑定(bind)三分之一窗口大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53732771/