Flu*_*ffy 15 shortcut-keys multiple-monitors
我的 PC 上有 2 个显示器 - 一个 IDE 在一个显示器上全屏打开,而 Firefox 在另一个显示器上全屏打开。
由于我主要使用键盘,因此必须一直抓住鼠标才能将焦点切换到 Firefox 并返回到 IDE,这很烦人。
如果焦点位于显示器 1 中的某处,是否有快捷方式可用于将焦点切换到显示器 2 上的“最大窗口”,反之亦然?
Flu*_*ffy 13
今天我对这个问题投了赞成票,所以我发布了我一直使用一年多的解决方案,并且对此感到非常满意。
第 1 步:制作 bash 脚本(例如将其写入~/swap.sh并使其可执行)以将焦点设置到位于另一个显示器中间的窗口:
#!/bin/bash
getwindowat() {
# move mouse to coordinates provided, get window id beneath it, move mouse back
eval `xdotool mousemove $1 $2 getmouselocation --shell mousemove restore`
echo $WINDOW
}
# get active app
active=`xdotool getactivewindow`
# get coordinates of an active app
eval `xdotool getwindowgeometry --shell $active`
# if left border of an app is less than display width
# (e.g. one display is 1920px wide, app has x = 200 - means it's 200px to the right from the left border of left monitor
# if it has x = 1920 or more, it's on the right window), it's on screen 0, and we need to focus to screen 1, otherwise to screen 0
(( $X >= $WIDTH )) && focustoscreen=0 || focustoscreen=1;
# get coordinates of the middle of the screen we want to switch
searchx=$[ ($WIDTH / 2) + $focustoscreen * $WIDTH ]
searchy=$[ $HEIGHT / 2 ]
# get window in that position
window=`getwindowat $searchx $searchy`
# activate it
xdotool windowactivate $window
Run Code Online (Sandbox Code Playgroud)
第2步:添加一个键盘快捷键来调用这个脚本,我把我的 Super-Tab
第3步:使用快捷方式像老板一样切换显示