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 / 问题 / 568716
Accepted
719016
719016
Asked: 2015-01-05 04:16:26 +0800 CST2015-01-05 04:16:26 +0800 CST 2015-01-05 04:16:26 +0800 CST

两个屏幕水平设置中的 Ubuntu 14.10 Aero snap?

  • 772

我设法让Aero snap 在 metacity Ubuntu 14.10 中左右工作,现在我想提出正确的winctrl命令,以便我可以在两个屏幕设置上模拟相同的效果,其中两个屏幕水平放置在每个屏幕旁边其他如下图。我希望它能在 Metacity(GNOME 经典)上运行,我根本不愿意转移到其他窗口管理器,因为我知道其中一些已经内置了这些功能。因此,这是一个专门针对 Metacity GNOME 经典环境尝试寻找答案的问题:

在此处输入图像描述

我想要的是扩展我当前的winctrl命令。他们目前的工作方式是在屏幕总长度的左侧或右侧使用屏幕总宽度的一半。键入Super_L+left将使活动窗口使用左半部分,键入Super_L+right将使活动窗口使用总水平像素的右半部分。

[hpenvy15 ~] $ cat > ~/bin/left.sh
#!/bin/bash
sleep 0.1 && wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz && wmctrl -r :ACTIVE: -e 0,0,0,`xwininfo -root | grep Width | awk '{ print (($2/2))}'`,`xwininfo -root | grep Height | awk '{ print $2 }'`
^C
[hpenvy15 ~] $ cat > ~/bin/right.sh
#!/bin/bash
sleep 0.1 && wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz && wmctrl -r :ACTIVE: -e 0,`xwininfo -root | grep Width | awk '{ print (($2/2)+5) ",0," (($2/2)) }'`,`xwininfo -root | grep Height | awk '{ print $2 }'`
^C

在具有两个屏幕的新设置中,我有 1920+1920 像素宽。理想的窗宽是1920的一半,即1920/2=960。我想要新的left和right命令来计算当前找到的窗口在哪里,然后如果left键入,则转到最近的 960 宽像素块,在两个屏幕中存在的 4 个块中的任何一个,1920 + 1920 配置,但也适用于单屏 1920 配置中最近的 960 宽块。如下图所示:

这是当我在 1 和 2 中有外部屏幕,在 3 和 4 中有笔记本电脑屏幕时的配置。目前,单击Super_L+left 会将窗口移动到屏幕的 TotalWidth/2 左半部分,这太大了,将1+2。

我希望第一个left命令将它移动到窗格 3,然后下一个left命令将它移动到 2,然后下一个命令将它移动到 1。

   +-------------------++-------------------++-------------------++-------------------+
   |                   ||                   ||                   || +------------+    |
   |                   ||                   ||                   || |            |    |
   |                   ||                   ||           <-------++-+            |    |
   |                   ||                   ||                   || |            |    |
   |         1         ||         2         ||         3         || |       4    |    |
   |                   ||                   ||                   || |            |    |
   |                   ||                   ||                   || +------------+    |
   |                   ||                   ||                   ||                   |
   |                   ||                   ||                   ||                   |
   +-------------------++-------------------++-------------------++-------------------+

这是当我只有两半 960 像素宽的笔记本电脑屏幕时的配置。

目前,单击Super_L+right会将窗口移动到屏幕的 TotalWidth/2 右半部分,对应于数字 4。

   +-------------------++-------------------+
   | +------------+    ||                   |
   | |            |    ||                   |
   | |            |    ||                   |
   | |            |----++--->               |
   | |       3    |    ||         4         |
   | |            |    ||                   |
   | |            |    ||                   |
   | +------------+    ||                   |
   |                   ||                   |
   +-------------------++-------------------+

这是wmctrl两个屏幕打开时的输出:

wmctrl -d
0  * DG: 3840x1080  VP: 0,0  WA: 0,0 3840x1080  Workspace 1
1  - DG: 3840x1080  VP: N/A  WA: 0,0 3840x1080  Workspace 2
2  - DG: 3840x1080  VP: N/A  WA: 0,0 3840x1080  Workspace 3
3  - DG: 3840x1080  VP: N/A  WA: 0,0 3840x1080  Workspace 4

这是xrandr同时打开两个屏幕时的输出:

[hpenvy15 ~] $ xrandr
Screen 0: minimum 8 x 8, current 3840 x 1080, maximum 32767 x 32767
eDP1 connected primary 1920x1080+1920+0 (normal left inverted right x axis y axis) 344mm x 193mm
   1920x1080      60.1*+   59.9     40.0  
   1680x1050      60.0     59.9  
   1600x1024      60.2  
   1400x1050      60.0  
   1280x1024      60.0  
   1440x900       59.9  
   1280x960       60.0  
   1360x768       59.8     60.0  
   1152x864       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 1920x1080+0+0 (normal left inverted right x axis y axis) 521mm x 293mm
   1920x1080      60.0*+   50.0     59.9     30.0     25.0     24.0     30.0     24.0  
   1920x1080i     60.1     50.0     60.0  
   1680x1050      59.9  
   1600x900       60.0  
   1280x1024      75.0     60.0  
   1440x900       59.9  
   1366x768       59.8  
   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  
   720x576        50.0  
   720x480        60.0     59.9  
   640x480        75.0     72.8     66.7     60.0     59.9  
   720x400        70.1  
VIRTUAL1 disconnected (normal left inverted right x axis y axis)
multiple-monitors
  • 1 1 个回答
  • 1558 Views

1 个回答

  • Voted
  1. Best Answer
    Jacob Vlijm
    2015-01-11T02:15:34+08:002015-01-11T02:15:34+08:00

    我在 Ubuntu (Gnome) Classic 和 Gnome Flashback (Metacity) 14.04 上测试了下面的脚本。xdotool和的“混合”应用程序wmctrl是必要的,因为我在为 Metacity 编写脚本时遇到了一些特殊情况。

    解决方案

    由于我希望脚本能够:

    • 确定哪个是左/右屏幕
    • 计算两个显示器的分辨率
    • 如果两个屏幕的分辨率不同(并计算窗口的位置和目标大小),也可以正常工作
    • 如果连接或不连接第二个屏幕,工作正常

    -- 脚本比我预见的要更广泛一些。

    它能做什么:

    如果连接了第二台显示器:
    它的工作原理与您描述的差不多:

    • 它将两个屏幕分成四个区域,每个区域都是它所在屏幕大小的一半(如上所述,也有不同的分辨率)
    • 使用“左”或“右”选项运行它:
      • 它将窗口移动到窗口左侧/右侧的区域
      • 将其水平调整为目标屏幕尺寸的一半
      • 垂直最大化窗口

    如果没有连接第二台显示器:
    它以传统方式工作:

    • 使用“左”选项运行,它在屏幕的左半部分垂直最大化最前面的窗口
    • 使用“右”选项运行,它在屏幕的右半部分垂直最大化最前面的窗口

    如何使用它

    • 同时安装xdotool和wmctrl:

      sudo apt-get install wmctrl
      sudo apt-get install xdotool
      
    • 将脚本复制到一个空文件中,将其保存为aero.py通过命令运行

      python3 /path/to/aero.py left
      python3 /path/to/aero.py right
      

    剧本

    #!/usr/bin/env python3
    import subprocess
    import sys
    
    move = sys.argv[1]
    
    def get(cmd):
        return subprocess.check_output(["/bin/bash", "-c", cmd]).decode("utf-8")
    def execute(cmd):
        subprocess.call(["/bin/bash", "-c", cmd])
    
    # screen resolutions ("raw")  
    wds = [s for s in get("xrandr").split() if s.endswith("+0")]
    # x-res left/right)
    left = [scr.split("x")[0] for scr in wds if scr.endswith("+0+0")]
    right = [scr.split("x")[0] for scr in wds if not scr.endswith("+0+0")]
    # x-positions areas
    left_pos = [0, int(int(left[0])/2), int(left[0])]
    right_pos = [int(int(left[0])+int(right[0])/2)] if len(right) != 0 else []
    x_positions = left_pos+right_pos
    # frontmost window pos
    frontmost =get("printf 0x%x "+get("xdotool getwindowfocus").strip())
    frontmost = frontmost[:2]+"0"+frontmost[2:]
    f_data = [l.split() for l in get("wmctrl -lG").splitlines() if frontmost in l][0][:6]
    curr_pos = int(f_data[2])
    area = len([x for x in x_positions if x <= curr_pos])
    if move == "left":
        i = area-2; target_pos = x_positions[i] if i >= 0 else 0 
    elif move == "right":
        i = area; target_pos = x_positions[area] if area < len(x_positions) else x_positions[-1]
    if i >= 2:
        perc = int((100*(x_positions[-1]-x_positions[-2])/sum([int(it) for it in left+right])))
    else:
        perc = int((100*(x_positions[1]-x_positions[0])/sum([int(it) for it in left+right])))
    # execute actions
    cmd1 = "wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz"
    cmd2 = "wmctrl -ir "+f_data[0]+" -e 0,"+str(target_pos)+","+"30,300,300"
    cmd3 = "xdotool windowsize $(xdotool getactivewindow) "+str(perc)+"% 100%"
    for cmd in [cmd1, cmd2, cmd3]:
        execute(cmd)
    

    也发布在gist.gisthub(最新版本)

    • 3

相关问题

  • 如何设置一纵一横两屏?

  • gnome-mplayer 使用 xineramascreen 选项在第二个屏幕上播放

  • 使用带有两屏设置的 Ubuntu

  • 自 10.04 起,笔记本电脑的扩展显示器显示摇晃/波动的图像 [关闭]

  • 有没有办法在 Ubuntu a la Windows 中拥有扩展桌面?[关闭]

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