如何在同一显示器中打开文件我正在工作?

我已将液晶显示器连接到笔记本电脑。 当我尝试在Nautilus中打开文件时,目标应用程序将在我的笔记本电脑显示屏中打开,而不是第二个显示(nautilus窗口打开)。

我不想更改默认显示。 我想在我正在使用的显示器中打开窗口。如果我的文件管理器在笔记本电脑显示器中,我希望应用程序在笔记本电脑显示器中打开。 如果我的文件管理器在外部显示,我希望在那里打开文件。

xrandr的输出

 Screen 0: minimum 320 x 200, current 3286 x 1080, maximum 32767 x 32767 eDP1 connected 1366x768+0+0 (normal left inverted right x axis y axis) 256mm x 144mm 1366x768 60.1*+ 1360x768 59.8 60.0 1024x768 60.0 800x600 60.3 56.2 640x480 59.9 VGA1 disconnected (normal left inverted right x axis y axis) HDMI1 connected primary 1920x1080+1366+0 (normal left inverted right x axis y axis) 527mm x 296mm 1920x1080 60.0* 50.0 59.9 1920x1080i 60.1 50.0 60.0 1680x1050 59.9 1280x1024 75.0 60.0 1440x900 59.9 1280x960 60.0 1280x800 59.9 1152x864 75.0 1280x720 60.0 50.0 59.9 1440x576i 50.1 1024x768 75.1 70.1 60.0 1440x480i 60.1 60.1 832x624 74.6 800x600 72.2 75.0 60.3 56.2 720x576 50.0 720x480 60.0 59.9 640x480 75.0 72.8 66.7 60.0 59.9 720x400 70.1 DP1 disconnected (normal left inverted right x axis y axis) HDMI2 disconnected (normal left inverted right x axis y axis) VIRTUAL1 disconnected (normal left inverted right x axis y axis) 

您描述的行为(在当前屏幕上打开窗口) 应该是默认行为,在我的14.04上就是这样。

由于与某些图形驱动程序/ GPU组合的轻微不兼容性,在某些情况下可能会出现“特性”。 如果没有可用的“干净”选项(修复),您可以使用下面的解决方法。
它存在一个后台脚本,寻找要出现的新窗口。 如果存在新窗口,脚本会将窗口位置与当前鼠标位置进行比较。 如果鼠标和新窗口不在同一屏幕上,则使用xdotool windowmove`命令移动窗口。

背景脚本是个坏主意吗?

如果您不需要后台脚本,请不要使用它。
同时:如果它增加了重要的function和/或节省了你的时间, 如果脚本组织良好并因此“燃料不足”,那将是愚蠢的。

作为参考:在我的笔记本电脑和桌面上,我经常运行至少 5个后台脚本+偶尔会有一些额外的脚本用于测试目的,而不另行通知。

如何节省燃料:

  1. 该脚本具有可变循环周期
    每10秒一次,脚本会检查要连接的第二个屏幕。 如果没有,脚本将跳过整个窗口检查程序并在10秒后重新检查。 这意味着只有连接了第二个屏幕时,脚本才会起作用。 连接第二个屏幕后,在10秒内,循环将更改为2秒的时间段。
  2. 脚本采取的所有(下一步)操作都是有条件的
    例如, 只有 有新窗口等的情况下才会检查鼠标位置

总之,在我的系统上,由于脚本,我无法注意到或测量任何额外的负载。

剧本

 #!/usr/bin/env python3 import subprocess import time def get(cmd): try: return subprocess.check_output(cmd).decode("utf-8").strip() except subprocess.CalledProcessError: pass def screen_limit(): screendata = [s for s in get("xrandr").split() if s.count("+") == 2] if len(screendata) == 2: return int([s.split("x")[0] for s in screendata if "+0+0" in s][0]) wd1 = get(["wmctrl", "-lG"]) t = 0 while True: time.sleep(2) # once per 10 seconds, check for a second screen if t == 0: while True: rightside = screen_limit() # if no second screen, skip the procedure if rightside == None: time.sleep(10) else: break wd2 = get(["wmctrl", "-lG"]) # check for buggy wmctrl if all([wd2 != None, wd1 != None]): wins = [w.split() for w in wd2.splitlines()] # check for new windows relevant = [w for w in wins if not w[0] in wd1] if relevant: # if new windows appeared, see if they match the mouse pos mousepos = int(get([ "xdotool", "getmouselocation" ]).split()[0].split(":")[1]) for w in relevant: check = [mousepos < rightside, int(w[2]) < rightside] if check[0] != check[1]: # if mouse and window are not on the same screen > move if check[0] == False: cmd = ["xdotool", "windowmove", w[0], str(int(w[2]) + rightside), w[3]] else: cmd = ["xdotool", "windowmove", w[0], str(int(w[2]) - rightside), w[3]] subprocess.Popen(cmd) wd1 = wd2 t = 0 if t == 10 else t t += 1 

如何使用

  1. 该脚本需要wmctrlxdotool 。 在终端中运行:

     sudo apt-get install xdotool wmctrl 
  2. 将脚本复制到空文件中,将其另存为move_windows.py
  3. 通过以下命令测试脚本:

     python3 /path/to/move_windows.py 
  4. 如果一切正常,请将其添加到启动应用程序:Dash>启动应用程序>添加。 添加命令:

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