我在工作时使用两个屏幕设置,尽管它通常带来的好处多于伤害,但我有一些问题。
其中之一是跟踪焦点出现问题-有时我在错误的屏幕上键入错误(焦点在我的光标后面,但是当您匆忙执行操作时,总是不容易注意到光标在其他屏幕上)。当我不打字而导致大量不同的动作(雷鸟中的一键快捷方式)时,这非常烦人。
有没有一种方法可以更好地突出显示活动屏幕或窗口(例如,使用容易看到的边框-即使是最大化的窗口)?
编辑:
我认为,当窗口获得焦点时,一种不错的解决方案是一种简短的动画。
我在工作时使用两个屏幕设置,尽管它通常带来的好处多于伤害,但我有一些问题。
其中之一是跟踪焦点出现问题-有时我在错误的屏幕上键入错误(焦点在我的光标后面,但是当您匆忙执行操作时,总是不容易注意到光标在其他屏幕上)。当我不打字而导致大量不同的动作(雷鸟中的一键快捷方式)时,这非常烦人。
有没有一种方法可以更好地突出显示活动屏幕或窗口(例如,使用容易看到的边框-即使是最大化的窗口)?
编辑:
我认为,当窗口获得焦点时,一种不错的解决方案是一种简短的动画。
Answers:
在并排双显示器设置(左右)中,下面的脚本将带有焦点窗口的显示器的亮度设置为“正常”(100%),而其他显示器则变暗为60%。
如果焦点改变,亮度将跟随焦点:
#!/usr/bin/env python3
"""
In a side-by-side dual monitor setup (left-right), the script below will set
the brightness of the monitor with the focussed window to "normal" (100%),
while other one is dimmed to 60%. If the focus changes, the brightness will
follow the focus
"""
import subprocess
import time
def get_wposition():
# get the position of the currently frontmost window
try:
w_data = subprocess.check_output(["wmctrl", "-lG"]).decode("utf-8").splitlines()
frontmost = subprocess.check_output(["xprop", "-root", "_NET_ACTIVE_WINDOW"]).decode("utf-8").split()[-1].strip()
z = 10-len(frontmost); frontmost = frontmost[:2]+z*"0"+frontmost[2:]
return [int(l.split()[2]) for l in w_data if frontmost in l][0]
except subprocess.CalledProcessError:
pass
def get_onscreen():
# get the size of the desktop, the names of both screens and the x-resolution of the left screen
resdata = subprocess.check_output(["xrandr"]).decode("utf-8")
if resdata.count(" connected") == 2:
resdata = resdata.splitlines()
r = resdata[0].split(); span = int(r[r.index("current")+1])
screens = [l for l in resdata if " connected" in l]
lr = [[(l.split()[0], int([s.split("x")[0] for s in l.split() if "+0+0" in s][0])) for l in screens if "+0+0" in l][0],
[l.split()[0] for l in screens if not "+0+0" in l][0]]
return [span, lr]
else:
print("no second screen seems to be connected")
def scr_position(span, limit, pos):
# determine if the frontmost window is on the left- or right screen
if limit < pos < span:
return [right_scr, left_scr]
else:
return [left_scr, right_scr]
def highlight(scr1, scr2):
# highlight the "active" window, dim the other one
action1 = "xrandr", "--output", scr1, "--brightness", "1.0"
action2 = "xrandr", "--output", scr2, "--brightness", "0.6"
for action in [action1, action2]:
subprocess.Popen(action)
# determine the screen setup
screendata = get_onscreen()
left_scr = screendata[1][0][0]; right_scr = screendata[1][1]
limit = screendata[1][0][1]; span = screendata[0]
# set initial highlight
oncurrent1 = scr_position(span, limit, get_wposition())
highlight(oncurrent1[0], oncurrent1[1])
while True:
time.sleep(0.5)
pos = get_wposition()
# bypass possible incidental failures of the wmctrl command
if pos != None:
oncurrent2 = scr_position(span, limit, pos)
# only set highlight if there is a change in active window
if oncurrent2 != oncurrent1:
highlight(oncurrent1[1], oncurrent1[0])
oncurrent1 = oncurrent2
该脚本需要wmctrl
:
sudo apt-get install wmctrl
将脚本复制到一个空文件中,另存为 highlight_focus.py
通过以下命令对其进行测试:
python3 /path/to/highlight_focus.py
连接第二台监视器后,测试脚本是否按预期工作。
如果一切正常,请将其添加到启动应用程序:Dash>启动应用程序>添加命令:
/bin/bash -c "sleep 15 && python3 /path/to/highlight_focus.py"
该脚本资源极少。要“节省燃油”,屏幕设置;在脚本启动过程中,分辨率,跨度大小等仅读取一次(不包含在循环中)。这意味着,如果您连接/断开第二台监视器,则必须重新启动脚本。
如果将其添加到启动应用程序,则意味着您必须在更改监视器配置后注销/登录。
如果您希望在变暗的屏幕上使用其他亮度百分比,请更改以下行中的值:
action2 = "xrandr", "--output", scr2, "--brightness", "0.6"
该值可以介于0,0
(黑屏)和1.0
(100%)之间。
在脚本启动时,它将确定:
然后,在一个循环中(每秒一次),它:
使用以下命令检查活动窗口的位置:
wmctrl -lG
(获取窗口及其位置的列表)xprop -root _NET_ACTIVE_WINDOW
(获取最前面的窗口的ID)如果窗口的(x-)位置大于左屏幕的x分辨率,则该窗口显然在右屏幕上,除非它大于两个屏幕的跨度大小(然后它将在工作区上正确的)。因此:
if limit < pos < span:
确定窗口是否在右侧屏幕上(此处limit
是左侧屏幕pos
的x 分辨率,是窗口的x位置,span
还是两个屏幕的组合x分辨率)。
如果最前面的窗口(在左屏幕或右屏幕上)的位置发生了变化,该脚本将使用以下xrandr
命令设置两个屏幕的亮度:
xrandr --output <screen_name> --brightness <value>
根据评论和聊天中的要求,在脚本的一个版本下面,该脚本在新聚焦的屏幕上发出简短的暗淡闪烁:
#!/usr/bin/env python3
"""
In a side-by-side dual monitor setup (left-right), the script below will give
a short dim- flash on the newly focussed screen if the focussed screen changes
"""
import subprocess
import time
def get_wposition():
# get the position of the currently frontmost window
try:
w_data = subprocess.check_output(["wmctrl", "-lG"]).decode("utf-8").splitlines()
frontmost = subprocess.check_output(["xprop", "-root", "_NET_ACTIVE_WINDOW"]).decode("utf-8").split()[-1].strip()
z = 10-len(frontmost); frontmost = frontmost[:2]+z*"0"+frontmost[2:]
return [int(l.split()[2]) for l in w_data if frontmost in l][0]
except subprocess.CalledProcessError:
pass
def get_onscreen():
# get the size of the desktop, the names of both screens and the x-resolution of the left screen
resdata = subprocess.check_output(["xrandr"]).decode("utf-8")
if resdata.count(" connected") == 2:
resdata = resdata.splitlines()
r = resdata[0].split(); span = int(r[r.index("current")+1])
screens = [l for l in resdata if " connected" in l]
lr = [[(l.split()[0], int([s.split("x")[0] for s in l.split() if "+0+0" in s][0])) for l in screens if "+0+0" in l][0],
[l.split()[0] for l in screens if not "+0+0" in l][0]]
return [span, lr]
else:
print("no second screen seems to be connected")
def scr_position(span, limit, pos):
# determine if the frontmost window is on the left- or right screen
if limit < pos < span:
return [right_scr, left_scr]
else:
return [left_scr, right_scr]
def highlight(scr1):
# highlight the "active" window, dim the other one
subprocess.Popen([ "xrandr", "--output", scr1, "--brightness", "0.3"])
time.sleep(0.1)
subprocess.Popen([ "xrandr", "--output", scr1, "--brightness", "1.0"])
# determine the screen setup
screendata = get_onscreen()
left_scr = screendata[1][0][0]; right_scr = screendata[1][1]
limit = screendata[1][0][1]; span = screendata[0]
# set initial highlight
oncurrent1 = []
while True:
time.sleep(0.5)
pos = get_wposition()
# bypass possible incidental failures of the wmctrl command
if pos != None:
oncurrent2 = scr_position(span, limit, pos)
# only set highlight if there is a change in active window
if oncurrent2 != oncurrent1:
highlight(oncurrent2[0])
oncurrent1 = oncurrent2
limit < pos < span
以limit <= pos < span
使其正常运行。无论如何,这真的很好。但是我不确定是否要以这种方式工作(调暗另一个屏幕)。我将尝试对其进行修改,以便在更改活动屏幕时发出单个明亮的“脉冲”。