如何突出显示当前屏幕(或窗口)?

我在工作中使用两个屏幕设置,虽然它通常比疼痛更有帮助,但我有一些问题。

其中一个是尾随焦点的问题 – 有时候我错误地在错误的屏幕上打字(焦点是拖尾我的光标,但是当你匆忙做事时,并不总是很容易注意到光标在其他屏幕上)。 这非常烦人,而不是键入我导致大量不同的行为(雷鸟中的一键快捷键)。

有没有办法更好地突出活动屏幕或窗口(例如使用容易看见的边框 – 即使是最大化的窗口)?

编辑:

我认为好的解决方案是当窗口获得焦点时的某种短动画。

突出显示对焦屏幕(或在对焦更改时调暗,请参阅下面的编辑)

在并排双显示器设置(左 – 右)中,下面的脚本将显示器的亮度设置为“正常”(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 

如何使用

  1. 该脚本需要wmctrl

     sudo apt-get install wmctrl 
  2. 将脚本复制到空文件中,将其另存为highlight_focus.py

  3. 测试 - 通过命令运行它:

     python3 /path/to/highlight_focus.py 

    连接第二台显示器后 ,测试脚本是否按预期工作。

  4. 如果一切正常,请将其添加到启动应用程序:Dash> Startup Applications>添加命令:

     /bin/bash -c "sleep 15 && python3 /path/to/highlight_focus.py" 

笔记

  • 该脚本的资源非常少。 为了“节省燃料”,屏幕设置; 在脚本启动期间(不包括在循环中),只读取一次分辨率,跨度大小等。 这意味着如果连接/断开第二台显示器,则必须重新启动脚本。

  • 如果将其添加到启动应用程序,则意味着您必须在更改监视器配置后注销。

  • 如果您更喜欢灰度屏幕的其他亮度百分比,请更改该行中的值:

     action2 = "xrandr", "--output", scr2, "--brightness", "0.6" 

该值可以在0,0 (黑屏)和1.0 (100%)之间。

说明

在此处输入图像描述

在启动脚本时,它确定:

  • 两个屏幕的跨越分辨率
  • 左侧屏幕的x分辨率
  • 两个屏幕的名称

然后,在循环中(每秒一次),它:

  • 使用以下命令检查活动窗口的位置:

    • wmctrl -lG (获取窗口列表及其位置)
    • xprop -root _NET_ACTIVE_WINDOW (获取最前面窗口的id)

如果窗口的(x-)位置大于左侧屏幕的x分辨率,则窗口显然位于右侧屏幕上, 除非它大于两个屏幕的跨越大小(然后它将位于工作区上)正确的)。 因此:

 if limit < pos < span: 

确定窗口是否在右侧屏幕上(其中limit是左侧屏幕的x-res, pos是窗口的x位置, span是两个屏幕的组合x-res)。

如果最前面的窗口(左侧屏幕或右侧屏幕)的位置发生变化,脚本将使用xrandr命令设置两个屏幕的亮度:

 xrandr --output  --brightness  

编辑

将聚焦的屏幕调暗,而不是永久调暗的“无聚焦”屏幕

根据评论和聊天中的要求,在脚本的一个版本下面,在新聚焦的屏幕上提供短暂的闪光:

 #!/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 

我还找到了另一个解决方案,它与我想要的一点点有点不同,但也可以正常工作。

  1. 安装compizconfig-settings-manager compiz-plugins
  2. 运行ccsm
  3. 在“ Effects部分中启用Animations插件
  4. Focus Animation编辑并选择所需的动画。

只有波浪效应才有效……所以,如果你不喜欢它,你将会像我一样悲伤。