使用:Linux Mint 13(Maya)64 Cinnamon 2.0.14,wmctrl v.1.07
由于身体残疾,我希望能够使用键盘移动和调整窗口大小,但调整大小和移动跳跃要比使用标准移动和调整大小所实现的微小增量大得多键盘控制。
为了达到这个目的,我写了一个Bash脚本,根据给出的参数,它会增大或缩小窗口的宽度或高度,或者向上,向下,向左或向右移动窗口。该脚本由各种全球Cinnamon热键调用,每个热键都用不同的参数调用脚本。
使用wmctrl调整窗口大小,增加或减少高度或宽度,效果很好。没问题。
我遇到的问题是当我向上,向下,向左或向右移动窗口时。当我使用wmctrl向上或向下移动窗口时,窗口也会稍微向左移动,当向左或向右移动时,窗口也会略微向上移动。此外,100像素的移动值也不受尊重。
Values are: x, y, width, height.
XPOS_LEFT
WmCtrl (before move) : 560, 291, 795, 681
WmCtrl (after move) : 463, 283, 795, 681 [-97, -8] should be [-100, 0]
XPOS_RIGHT
WmCtrl (before move) : 764, 289, 795, 681
WmCtrl (after move) : 867, 281, 795, 681 [+103, -8] should be [+100, 0]
YPOS_UP
WmCtrl (before move) : 770, 273, 795, 681
WmCtrl (after move) : 763, 197, 795, 681 [-7, -76] should be [0, -100]
YPOS_DOWN
WmCtrl (before move) : 763, 197, 795, 681
WmCtrl (after move) : 756, 321, 795, 681 [-7, +124] should be [0, +100]
Growing and shrinking the width and height work perfectly.
最初我认为问题可能是我使用wmctrl检索的初始窗口位置值。所以我编写了代码来使用xwininfo检索窗口的位置。由于某种原因,使用wmctrl和xwininfo检索的x,y位置值略有不同,但错误移动的数量保持不变,无论我使用wmctrl还是xwininfo初始位置值,它都没有任何区别 - 相同问题持续存在相同的数量。
请注意,我使用wmctrl -e的-1值表示不改变,使用" -e 0,$ xPos,$ yPos,$ width,$解决了这种情况高度"实际上,这样做会使事情变得更糟,因为在调整窗口大小时,窗口的位置会发生类似的问题。
通过为XPOS_LEFT和XPOS_RIGHT添加或减去额外的3来手动补偿,并通过为YPOS_UP和YPOS_DOWN添加或减去额外的24来获得移动值为100,应该如此。但是当+8或+7被添加到适当的xPos或yPos值并且更改wmctrl命令以使用" -e 0,$ xPos,$ yPos,-1时,相反轴中的-8和-7仍然存在,-1"
有人可以向我解释发生了什么以及如何解决这个问题吗?
非常感谢。
#!/bin/bash
# commandArg ($1) can have any of the following values:
# HEIGHT_GROW, HEIGHT_SHRINK, WIDTH_GROW, WIDTH_SHRINK,
# YPOS_UP, YPOS_DOWN, XPOS_LEFT, XPOS_RIGHT
commandArg="$1"
amountToResize="50"
amountToMove="100"
# Get Window ID of the currently active window using xprop.
winID=$(xprop -root '_NET_ACTIVE_WINDOW' | grep --only-matching '0x.*')
# Alter $winID for usage with wmctrl because it requires a leading 0
# in the hex number. e.g. 0x2600006 --> 0x02600006
winIDForWmCtrl=$(echo $winID | sed 's/^0x/0x0/g')
# Get position and dimensions using wmctrl.
xPos=$(wmctrl -G -l | grep $winIDForWmCtrl | awk '{ print $3 }')
yPos=$(wmctrl -G -l | grep $winIDForWmCtrl | awk '{ print $4 }')
width=$(wmctrl -G -l | grep $winIDForWmCtrl | awk '{ print $5 }')
height=$(wmctrl -G -l | grep $winIDForWmCtrl | awk '{ print $6 }')
# Alter the appropriate dimension or positional value and call wmctrl,
# depending of which argument was used when calling the script.
if [ "$commandArg" = "HEIGHT_GROW" ]; then
let 'height = height + amountToResize'
wmctrl -ir $winIDForWmCtrl -e 0,-1,-1,-1,$height
elif [ "$commandArg" = "HEIGHT_SHRINK" ]; then
let 'height = height - amountToResize'
wmctrl -ir $winIDForWmCtrl -e 0,-1,-1,-1,$height
elif [ "$commandArg" = "WIDTH_GROW" ]; then
let 'width = width + amountToResize'
wmctrl -ir $winIDForWmCtrl -e 0,-1,-1,$width,-1
elif [ "$commandArg" = "WIDTH_SHRINK" ]; then
let 'width = width - amountToResize'
wmctrl -ir $winIDForWmCtrl -e 0,-1,-1,$width,-1
elif [ "$commandArg" = "YPOS_UP" ]; then
let 'yPos = yPos - amountToMove'
wmctrl -ir $winIDForWmCtrl -e 0,-1,$yPos,-1,-1
elif [ "$commandArg" = "YPOS_DOWN" ]; then
let 'yPos = yPos + amountToMove'
wmctrl -ir $winIDForWmCtrl -e 0,-1,$yPos,-1,-1
elif [ "$commandArg" = "XPOS_LEFT" ]; then
let 'xPos = xPos - amountToMove'
wmctrl -ir $winIDForWmCtrl -e 0,$xPos,-1,-1,-1
elif [ "$commandArg" = "XPOS_RIGHT" ]; then
let 'xPos = xPos + amountToMove'
wmctrl -ir $winIDForWmCtrl -e 0,$xPos,-1,-1,-1
fi
exit 0