AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 758003
Accepted
Googlebot
Googlebot
Asked: 2016-04-17 03:48:52 +0800 CST2016-04-17 03:48:52 +0800 CST 2016-04-17 03:48:52 +0800 CST

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

  • 772

我已将 LCD 连接到笔记本电脑。当我尝试在 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)
unity
  • 1 1 个回答
  • 185 Views

1 个回答

  • Voted
  1. Best Answer
    Jacob Vlijm
    2016-04-18T03:00:18+08:002016-04-18T03:00:18+08:00

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

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

    背景脚本是个坏主意吗?

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

    作为参考:在我的笔记本电脑和台式机上,我经常运行至少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. 该脚本同时需要wmctrl和xdotool。在终端中运行:

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

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

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

相关问题

  • 如何将 Web 应用程序放入 Unity Launcher?

  • Ubuntu 上网本 10.10 中没有 Alt+F2?

  • Unity 中的 gnome-do 样式键盘快捷键

  • 在哪里提交 Unity 的错误/愿望清单?

  • Unity 启动器——它可以作为单独的包提供吗?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve