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 / 问题 / 587077
Accepted
Fetts Vett
Fetts Vett
Asked: 2015-02-19 12:23:07 +0800 CST2015-02-19 12:23:07 +0800 CST 2015-02-19 12:23:07 +0800 CST

每个工作空间的屏幕分辨率不同?

  • 772

我在我的 ubuntu 笔记本电脑上使用 i3-wm。我的屏幕尺寸是 3200x1800。这对某些事情来说很棒,但对其他事情来说却很糟糕。(Netflix 与 gvim)。

我想更改我的一个或多个工作空间的分辨率。但我不知道这是否可能......我可以使用康普顿来做这个或其他程序吗?

unity
  • 2 2 个回答
  • 1884 Views

2 个回答

  • Voted
  1. Best Answer
    Jacob Vlijm
    2015-02-20T01:16:58+08:002015-02-20T01:16:58+08:00

    1. 假设您使用的是 Unity

    下面的脚本应该会根据 Unity 中的当前视口更改您的分辨率。我在几台电脑上测试了一段时间,运行没有报错。

    但是,我建议也对其进行一段时间的测试,看看它是否可以不间断地运行;重复wmctrl的命令有时会偶然退出“非零”。如果是这样,我们需要构建一个try / except.

    笔记

    • 我在单显示器设置上对其进行了测试。多个监视器可能需要另一种方法来解析xrandr.
    • 在脚本的头部,您需要为每个视口设置所需的分辨率,我按照您的评论中提到的那样设置,但您可以随时更改。使用格式:

      resolutions = [[<horizontal>, <vertical], [<horizontal>, <vertical], ......]
      

      就像它在脚本中显示的那样。

    • 无需说明您应该使用受支持的分辨率,就像xrandr您的显示器的输出一样。

    如何使用

    1. 该脚本需要wmctrl:

      sudo apt-get install wmctrl
      
    2. 将下面的脚本复制到一个空文件中,另存为screen_res.py

    3. 通过以下命令在终端窗口中测试运行一段时间:

      python3 screen_res.py
      
    4. 如果一切正常,请将其添加到您的启动应用程序中:Dash > Startup Applications > Add...

    剧本

    #!/usr/bin/env python3
    import subprocess
    import time
    
    # list of resolution per viewport, for each viewport a separate [hor, vert]
    # I pre- entered your viewports. quite some! listing takes more space than the script :)
    resolutions = [
        [3200, 1800],
        [3200, 1800],
        [3200, 1800],
        [3200, 1800],
        [3200, 1800],
        [3200, 1800],
        [3200, 1800],
        [1920, 1080],
        [1920, 1080],
        [1920, 1080],
        ]
    
    def get_xr():
        return subprocess.check_output(["xrandr"]).decode("utf-8").split()
    
    check = get_xr()
    plus = 2 if check[check.index("connected")+1] == "primary" else 1
    
    while True:
        # resolution:
        xr = get_xr()    
        res = [int(n) for n in xr[xr.index("connected")+plus].split("+")[0].split("x")]
        # get current viewport
        vp_data = subprocess.check_output(["wmctrl", "-d"]).decode("utf-8").split()
        dt = [int(n) for n in vp_data[3].split("x")]
        cols = int(dt[0]/res[0])
        curr_vpdata = [int(n) for n in vp_data[5].split(",")]
        curr_col = int(curr_vpdata[0]/res[0])+1; curr_row = int(curr_vpdata[1]/res[1])
        curr_vp = curr_col+curr_row*cols
        # check and change resolution if needed
        if res != resolutions[curr_vp-1]:
            new_res = ("x").join([str(n) for n in resolutions[curr_vp-1]])
            subprocess.call(["xrandr", "-s", new_res])
        time.sleep(1)
    

    解释

    • 在循环中,脚本首先通过以下命令检查屏幕的当前分辨率:

      xrandr
      
    • 随后,脚本通过以下命令检查桌面总大小(所有视口):

      wmctrl -d
      
    • 然后,根据总桌面大小的分辨率 icw,它计算列数,这等于总桌面大小除以水平分辨率。

    • 在 的输出中wmctrl -d还有当前视口在跨越桌面上的位置:例如:VP: 1680,0。
    • 有了这些信息,我们就可以得出我们所在的列和行的结论,并检查当前设置的分辨率是否与我们在脚本头部的列表中定义的分辨率相匹配。
      如果不是,脚本会给出使用以下命令更改分辨率的命令:

      xrandr -s <xres>x<yres>
      

    2.XFCE版本

    • 像上面的版本一样设置(也需要wmctrl)
    #!/usr/bin/env python3
    import subprocess
    import time
    
    # list of resolution per viewport, for each viewport a separate [hor, vert]
    # below just an example! set resolutions for your own screen
    resolutions = [
        [1280, 1024],
        [1280, 960],
        [1280, 1024],
        [1280, 1024],
        ]
    
    def get_xr():
        return subprocess.check_output(["xrandr"]).decode("utf-8").split()
    
    check = get_xr()
    plus = 2 if check[check.index("connected")+1] == "primary" else 1
    
    while True:
        # resolution:
        xr = get_xr()    
        res = [int(n) for n in xr[xr.index("connected")+plus].split("+")[0].split("x")]
        # get current workspace
        vp_data = subprocess.check_output(["wmctrl", "-d"]).decode("utf-8").splitlines()
        curr_ws = int([l.split()[0] for l in vp_data if "*" in l][0])
        # check and change resolution if needed
        if res != resolutions[curr_ws]:
            new_res = ("x").join([str(n) for n in resolutions[curr_ws]])
            subprocess.call(["xrandr", "-s", new_res])
        time.sleep(1)
    
    • 2
  2. biomatic
    2019-10-28T10:39:25+08:002019-10-28T10:39:25+08:00

    我为 XFCE 实现了@Jacob Vlijm 的 python 脚本。除了通过 wine 运行的旧Windows 程序外,它运行良好。每次脚本循环时,它都会冻结鼠标光标不到一秒钟。检查 1x/sec 意味着很多口吃。我将它移植到一个 bash 脚本,将其修改为每次检查仅调用 wmctrl 一次,并且仅在需要更改分辨率时调用 xrandr。请注意,它确实需要安装 wmctrl。

    #!/usr/bin/env bash
    #Tested in XFCE 4.12.3 on Ubuntu 18.04
    #Requires wmctrl. Install with:
    #$ sudo apt-get install wmctrl
    
    #Note: This checks current workspace res 1x/sec. To change rate, change "sleep" parameter below
    
    #Enter appropriate resolution for each workspace, in order, in the same format as below.
    RESOLUTIONS=('1920x1080' '1368x768')
    
    check_and_change_res() {
      #echo "Parsing wmctrl -d"
      while read line; do
        #example line from wmctrl:
        #$ wmctrl -d
        #0  - DG: 1368x768  VP: N/A  WA: 0,25 1368x743  1
        #1  * DG: 1368x768  VP: 0,0  WA: 0,25 1368x743  2
        #If your line does not have a "DG:" (desktop geometry) preceding the current resolution, you
        #  will need to change the regex below.
        if [[ ${line} =~ ([[:digit:]]+)[[:space:]]+\*[[:space:]]+DG:[[:space:]]+([[:alnum:]]+) ]]; then
          current_ws="${BASH_REMATCH[1]}"
          current_res="${BASH_REMATCH[2]}"
          target_res="${RESOLUTIONS[current_ws]}"
          #echo "Current workspace: ${current_ws}; Current resolution: ${current_res}; Target resolution: ${target_res}"
          if [[ ! ${current_res} =~ ${target_res} ]]; then
            #echo "Switching resolution to ${target_res}."
            xrandr -s ${target_res}
          fi
        fi
      done
    }
    
    while true
    do
      check_and_change_res < <(wmctrl -d)
      #This waits for 1 second between checks. To change to a 5-second delay (e.g. performance), use:
      #sleep 5
      sleep 1
    done
    
    • 1

相关问题

  • 如何将 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