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

我在我的ubuntu笔记本电脑上使用i3-wm。 我的屏幕尺寸是3200×1800。 对于其他东西来说这是件好事但对其他东西来说很可怕 (Netflix vs gvim)。

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

1.假设你在Unity上

下面的脚本应该更改您的分辨率,具体取决于Unity中的当前视口。 我在几台计算机上测试了一段时间,它运行没有错误。

然而,我建议也要测试它一段时间,看它是否没有一次断裂; 重复的wmctrl命令有时会偶然退出“非零”。 如果是这样,我们需要构建一个try / except

笔记

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

     resolutions = [[, ,  

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

  • 无需说您应该使用支持的分辨率,就像显示器的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
  • 有了这些信息,我们可以得出我们所在的列和行,并检查当前设置的分辨率是否与我们在脚本的head部分的列表中定义的分辨率相匹配。
    如果没有,脚本会给出命令以使用以下命令更改分辨率:

     xrandr -s x 

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)