可以在gnome 3中保存当前分辨率,壁纸和桌面排列设置

每次我从笔记本电脑上断开我的三个外接显示器,或者当我重新插入时,所有分辨率和扩展桌面设置都搞砸了。 我将不得不更改设置以使其再次正确。

我在Ubuntu 16.04上使用gnome 3.18.5。 我有英特尔高清显卡530和Nvidia 960M与nvidia驱动程序版本375.39。 我还安装了名为“Fix-Multi-Monitors”的gnome shell扩展,它确实修复了一系列问题,例如Windows只在窗口移动快捷方式的三个监视器中移动。

无论如何,我想要做的是以某种方式保存设置,当我插入所有三个显示器时,所以我可以简单地运行一个单独的脚本或设置,所以它立即加载我想要的方式,甚至可能当检测到三个显示时,这会自动发生。 我应该补充一点,我总是以同样的方式插入监视器。

令我困扰的是,我启用了这个壁纸,它跨越了所有三个显示器,但当它们断开连接时,壁纸在笔记本电脑显示器上变成一条细线,屏幕的其余部分变黑。 我希望在这种情况下只能看到该壁纸的中间部分,或者在外部显示器断开连接时自动加载另一个壁纸。 我希望有人可以帮助我,或指导我以正确的方式使我们获得更好的体验。

我找到了一个名为disper的命令行工具,我已经阅读了手册页并尝试了一堆命令,但我认为它不能做我想要的。

我的壁纸的路径是:

/home/olm/Pictures/Wallpapers/3monitorwallpaper.jpg /home/olm/Pictures/Wallpapers/1monitorwallpaper.jpg

1.如果连接了四个屏幕,则运行命令的脚本

下面的脚本是此脚本的编辑版本。

它能做什么

每五秒钟一次,它会检查已连接屏幕的数量。 如果数字改变, 并且连接的屏幕总数为4,它将运行我们在评论中找到的xrandr命令。

如何使用

  1. 将脚本复制到空文件中,将其另存为four_screens.py
  2. 使用以下命令从终端测试运行脚本:

     python3 /path/to/four_screens.py 

    并连接你的屏幕。 连接第四个后,应进行屏幕设置。

  3. 如果一切正常,请将脚本添加到“启动应用程序:虚拟”>“启动应用程序”>“添加”。 添加命令:

     python3 /path/to/four_screens.py 
 #!/usr/bin/env python3 import subprocess import time #--- set both commands (connect / disconnect) below connect_command = "xrandr --output DP-2 --pos 0x0 --mode 1920x1200 "\ "&& xrandr --output HDMI-0 --pos 1920x0 --mode 1920x1200 "\ "&& xrandr --output DP-3 --pos 3840x0 --mode 1920x1200 "\ "&& xrandr --output eDP-1-1 --off" disconnect_command = "" #--- while True: time.sleep(5) try: subprocess.Popen(["xrandr"]) except: pass else: break # function to get the output of xrandr def get(cmd): return subprocess.check_output(cmd).decode("utf-8") # - to count the occurrenc of " connected " def count_screens(xr): return xr.count(" connected ") # - to run the connect / disconnect command(s) def run_command(cmd): subprocess.Popen(["/bin/bash", "-c", cmd]) # first count xr1 = None while True: time.sleep(5) # second count xr2 = count_screens(get(["xrandr"])) # check if there is a change in the screen state if xr2 != xr1: if xr2 == 4: # command to run if connected (two screens) run_command(connect_command) elif xr2 == 1: # command to run if disconnected (one screen) # uncomment run_command(disconnect_command) to enable, then also comment out pass pass # run_command(disconnect_command) # set the second count as initial state for the next loop xr1 = xr2 

笔记

  1. 该剧本的果汁极低,它没有任何明显的负担。
  2. 在同一个脚本中,我们可以运行壁纸更改,但为此,请将两个壁纸的(路径)发布到您的问题中。

2.或者,快捷方式

无论出于何种原因,如果您不想运行后台脚本,可以通过键盘快捷方式运行相同的命令:

选择:系统设置>“键盘”>“快捷方式”>“自定义快捷方式”。 单击“+”并添加命令:

 /bin/bash -c "xrandr --output DP-2 --pos 0x0 --mode 1920x1200 && xrandr --output HDMI-0 --pos 1920x0 --mode 1920x1200 && xrandr --output DP-3 --pos 3840x0 --mode 1920x1200 && xrandr --output eDP-1-1 --off" 

与此同时,我也发现了这个方便的命令来改变gnome中的壁纸。

 gsettings set org.gnome.desktop.background picture-uri file:///path/to/wallpaper.jpg 

因此,现在我将它与脚本中的Xrandr命令一起使用,以便在每次将显示器连接到笔记本电脑时设置我的桌面。