我的意思是,每當我嘗試在視窗上移動指標時,視窗都應該移動。我有一個“模擬時鐘螢幕小程式”和“文件進度對話框”,我對其進行了調整,以保持與 CCSM 的其他視窗“始終位於頂部”,但有時它們會妨礙執行操作。
如果這是不可能的,那麼是否有任何方法可以在我將指標移到它們上時隱藏它們,以便我可以直接單擊下面的應用程式?
此外,如果這是不可能的,那麼我們可以讓視窗表現得好像它們不存在一樣嗎?我的意思是我會看到該窗口,但指針不應該識別它,並且應該在其下面的應用程式上正常工作。我將改變應用程式的透明度,並使其發揮作用(如果可能的話)?
答案1
Bash 腳本和 xdotool == cursophobia.sh
概述
我想我有一個適合您的解決方案。它是一個 bash 腳本,允許您選擇一個視窗。選擇視窗後,腳本會依預先定義的時間間隔連續輪詢視窗和遊標位置。如果遊標太近,視窗就會移開。
依賴性
該腳本取決於xdotool
.要安裝,請運行sudo apt-get install xdotool
腳本:cursophobia.sh
使用以下內容建立一個新的 bash 腳本並使其可執行。
#!/bin/bash
windowSelectionDelay=5 # How long to wait for user to select a window?
buffer=10 # How close do we need to be to border to get scared?
jump=20 # How far do we jump away from pointer when scared?
poll=.25 # How often in seconds should we poll window and mouse?
# locations. Increasing poll should lighten CPU load.
# ask user which window to make phobic
for s in $(seq 0 $((windowSelectionDelay - 1)))
do
clear
echo "Activate the window that you want to be cursophobic: $((windowSelectionDelay - s))"
sleep 1
done
wID=$(xdotool getactivewindow)
# find some boundary info and adjustments
# determine where the window is now
info=$(xdotool getwindowgeometry $wID)
base=$(grep -oP "[\d]+,[\d]+" <<< "$info")
# move the window to 0 0 and get real location
xdotool windowmove $wID 0 0
info=$(xdotool getwindowgeometry $wID)
realMins=$(grep -oP "[\d]+,[\d]+" <<< "$info")
xMin=$(cut -f1 -d, <<< "$realMins")
yMin=$(cut -f2 -d, <<< "$realMins")
# find offset values for no movement. This is necessary because moving 0,0
# relative to the current position sometimes actually moves the window
xdotool windowmove --relative $wID 0 0
info=$(xdotool getwindowgeometry $wID)
diff=$(grep -oP "[\d]+,[\d]+" <<< "$info")
xOffset=$[xMin - $(cut -f1 -d, <<< "$diff")]
yOffset=$[yMin- $(cut -f2 -d, <<< "$diff")]
# move window back to original location
x=$(cut -f1 -d, <<< "$base")
y=$(cut -f2 -d, <<< "$base")
xdotool windowmove $wID $[x + xOffset] $[y + yOffset]
dispSize=$(xdotool getdisplaygeometry)
xMax=$(cut -f1 -d ' ' <<< "$dispSize")
yMax=$(cut -f2 -d ' ' <<< "$dispSize")
clear
echo "You can minimize this window, but don't close it, or your window will overcome its cursophobia"
# start an infinite loop polling to see if we need to move the window.
while :
do
# get information about where the window is
info=$(xdotool getwindowgeometry $wID)
position=$(grep -oP "[\d]+,[\d]+" <<< "$info")
geometry=$(grep -oP "[\d]+x[\d]+" <<< "$info")
height=$(cut -f2 -dx <<< "$geometry")
width=$(cut -f1 -dx <<< "$geometry")
top=$(cut -f2 -d, <<< "$position")
left=$(cut -f1 -d, <<< "$position")
bottom=$((top + height))
right=$((left + width))
# save mouse coordinates to x & y
eval "$(xdotool getmouselocation | cut -f 1-2 -d ' ' | tr ' :' '\n=')"
# If the mouse is too close to the window, move the window
if [ $x -gt $((left - buffer)) ] && [ $x -lt $((right + buffer)) ] && [ $y -gt $((top - buffer)) ] && [ $y -lt $((bottom + buffer)) ]; then
#figure out what side we're closest to so we know which direction to move the window
t="$((y - top)):0 $((jump + (y - top)))"
l="$((x - left)):$((jump + (x - left))) 0"
b="$((bottom - y)):0 -$((jump + (bottom - y)))"
r="$((right - x)):-$((jump + (right - x))) 0"
coord="$(echo -e "$t\n$l\n$b\n$r" | sort -n | head -n 1 | cut -f2 -d:)"
# set the offset values for x and y
newX=$(cut -f1 -d ' ' <<< "$coord")
newY=$(cut -f2 -d ' ' <<< "$coord")
#check to make sure we're not out of bounds
if [ $((right + newX)) -gt $xMax ]; then
newX=$((-1 * left + xOffset))
elif [ $((left + newX)) -lt $xMin ]; then
newX=$((xMax - width))
fi
if [ $((bottom + newY)) -gt $yMax ]; then
newY=$((-1 * top + yOffset))
elif [ $((top + newY)) -lt $yMin ]; then
newY=$((yMax - height))
fi
# move the window if it has focus
[ $(xdotool getactivewindow) -eq $wID ] && xdotool windowmove --relative $wID $((newX + xOffset)) $((newY + yOffset))
fi
sleep $poll
done
不要忘記根據您的喜好編輯最頂部的四個變數。如果此腳本正在為您的 CPU 指派任務,請嘗試將poll
變數增加到更大的值。
Cursophobia.sh 的行動
建立腳本並使其可執行後,運行它。它會要求您選擇一個視窗。點擊您想要恐嚇的窗口,然後等待倒數結束。倒數結束後,您選擇的視窗將變得恐懼。當您準備好幫助視窗克服對遊標的恐懼時,請關閉終端機視窗或使用Ctrl+從終端視窗終止腳本c
多個顯示器
請注意,這會將遊標視窗限制為單一顯示。我願意進行編輯,使其能夠在多個顯示器上運行。