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 / 问题 / 6137
In Process
Oscar Godson
Oscar Godson
Asked: 2010-10-12 13:05:58 +0800 CST2010-10-12 13:05:58 +0800 CST 2010-10-12 13:05:58 +0800 CST

保存显示器设置?

  • 772

有没有办法保存我的显示器设置?我有一个外接显示器在工作,但每天早上我都必须把它插上电源,重新排列窗户,从并排到彼此重叠。我可以保存这个吗?

multiple-monitors lenovo hardware thinkpad settings
  • 10 10 个回答
  • 36251 Views

10 个回答

  • Voted
  1. Alessandro Cuttin
    2016-01-05T01:25:33+08:002016-01-05T01:25:33+08:00

    长话短说(即:按照Nicolas Bernaerts 的建议进行操作,但我不详述细节):监视器配置实际上保存在 中~/.config/monitors.xml,但在启动/登录时并未应用。

    克服这个问题的步骤是:

    使用错误的监视器配置登录。

    删除当前监视器配置:

    cd .config
    mv monitors.xml{,.bak}
    

    使用Displays应用程序根据需要排列显示器(我将一侧显示器逆时针旋转)。 随心所欲地安排你的显示器

    一旦你按下Apply,就会创建一个新monitors.xml的。

    现在,根据新创建的配置文件,下载并执行强制监控配置的脚本和启动器:

    $ sudo wget -O /usr/local/sbin/update-monitor-position https://raw.githubusercontent.com/NicolasBernaerts/ubuntu-scripts/master/ubuntugnome/update-monitor-position
    $ sudo chmod +x /usr/local/sbin/update-monitor-position
    $ sudo wget -O /usr/share/applications/update-monitor-position.desktop https://raw.githubusercontent.com/NicolasBernaerts/ubuntu-scripts/master/ubuntugnome/update-monitor-position.desktop
    $ sudo chmod +x /usr/share/applications/update-monitor-position.desktop
    

    此时,可以通过启动更新监视器位置应用程序来修复监视器的配置。

    如果您希望这是自动的,只需添加一个启动应用程序,其中包含以下条目:

    • 姓名:Update Monitors Position
    • 命令:update-monitor-position 5
    • 评论:Force monitors position 5 seconds after login

    在此处输入图像描述

    • 15
  2. RAOF
    2010-10-12T17:15:59+08:002010-10-12T17:15:59+08:00

    所有显示器的配置(无论是否热插拔)都应该$HOME/.config/monitors.xml由xrandr插件存储在中gnome-settings-daemon,这实际上是应用您在 Monitors capplet 中所做的配置。

    由于这似乎不适用于每个人,因此某处显然存在错误。呃。

    • 6
  3. user8361
    2011-01-05T16:36:39+08:002011-01-05T16:36:39+08:00

    前三个步骤以您想要的方式连接外接显示器,第四步是保存设置。

    1. 连接您的外接显示器并检查其支持的分辨率:

      xrandr -q
      
    2. 给出以下命令(这将禁用您的笔记本电脑显示器):

      xrandr --output LVDS1 --off --output TV1 --off --output VGA1 --mode 1280x1024 --pos 0x0 --rotate normal
      
    3. 如果您希望同时启用笔记本电脑和外部设备:

      xrandr --output LVDS1 --mode yyyyXzzzz --pos 0x0 --rotate normal --output TV1 --off --output VGA1 --mode 1280x1024 --pos 0x0 --rotate normal
      

      (yyyyXzzzz - 你的笔记本电脑分辨率。)

      上述配置将克隆您的屏幕。如果需要,请使用“ --right-of/ ”选项。--left-of

    4. 如果您在登录时需要此设置,请添加签入/etc/X11/Xsession.d/45custom_xrandr-settings(您可能需要创建一个)。

      xrandr |grep VGA1 | grep " connected " | if [ $? -eq 0 ]; then xrandr --output LVDS1 --off --output TV1 --off --output VGA1 --mode 1280x1024 --pos 0x0 --rotate normal  #Change the way u need ; fi
      
    • 4
  4. jay
    2018-01-09T07:22:18+08:002018-01-09T07:22:18+08:00

    在办公室,我的笔记本电脑上有 3 台显示器,家里有 2 台。其中两台办公室显示器垂直放置,而其他显示器则处于正常方向。

    A. monitor.xml 在 ~/.config 中。

    1. 删除它
    2. 在办公室设置中设置显示
    3. 将刚刚创建的“monitors.xml”重命名为“monitors-office.xml”。

    B. 获取 shell 脚本,“update-monitor-position”。

    1. 将“MONITOR_XML”定义“monitors.xml”更改为“monitors-office.xml”。

    2. 将其保存为“update-monitor-position-office”,在可执行路径 (/usr/local/sbin/) 中。

    3. 触摸权限->“我”可执行。

    C. 获取桌面快捷方式,“update-monitor-position.desktop”

    1. 将“Exec”定义,“update-monitor-position”更改为
      “update-monitor-position-office”。
    2. 将其保存为“update-monitor-position-office.desktop”
    3. 触摸权限->“我”可执行。

    更新监视器位置office.desktop:

    [Desktop Entry]
    Type=Application
    Exec=update-monitor-position-office
    Hidden=false
    NoDisplay=false
    X-GNOME-Autostart-enabled=true
    Name[en_US]=Office Monitors Position
    Name=Office Monitors Position
    Comment[en_US]=Force monitors position from monitor-office.xml
    Comment=Force monitors position from monitor-office.xml
    Icon=display
    

    Shell 脚本,update-monitor-position-office

    #!/bin/bash
    # -------------------------------------------------
    #  Get monitors configuration from monitor.xml and apply it for current user session.
    #  In case of multiple definitions in monitor.xml only first one is used.
    #
    #  See http://bernaerts.dyndns.org/linux/74-ubuntu/309-ubuntu-dual-display-monitor-position-lost
    #  for instructions
    #
    #  Parameters :
    #    $1 : waiting time in sec. before forcing configuration (optional)
    #
    #  Revision history :
    #    19/04/2014, V1.0 - Creation by N. Bernaerts
    #    10/07/2014, V1.1 - Wait 5 seconds for X to fully initialize
    #    01/09/2014, V1.2 - Correct NULL file bug (thanks to Ivan Harmady) and handle rotation
    #    07/10/2014, V1.3 - Add monitors size and rate handling (idea from jescalante)
    #    08/10/2014, V1.4 - Handle primary display parameter
    #    08/12/2014, V1.5 - Waiting time in seconds becomes a parameter
    # -------------------------------------------------
    
    # monitor.xml path
    MONITOR_XML="$HOME/.config/monitors-office.xml"
    
    # get number of declared monitors
    NUM=$(xmllint --xpath 'count(//monitors/configuration['1']/output)' $MONITOR_XML)
    
    # loop thru declared monitors to create the command line parameters
    for (( i=1; i<=$NUM; i++)); do
      # get attributes of current monitor (name and x & y positions)
      NAME=$(xmllint --xpath 'string(//monitors/configuration['1']/output['$i']/@name)' $MONITOR_XML 2>/dev/null)
      POS_X=$(xmllint --xpath '//monitors/configuration['1']/output['$i']/x/text()' $MONITOR_XML 2>/dev/null)
      POS_Y=$(xmllint --xpath '//monitors/configuration['1']/output['$i']/y/text()' $MONITOR_XML 2>/dev/null)
      ROTATE=$(xmllint --xpath '//monitors/configuration['1']/output['$i']/rotation/text()' $MONITOR_XML 2>/dev/null)
      WIDTH=$(xmllint --xpath '//monitors/configuration['1']/output['$i']/width/text()' $MONITOR_XML 2>/dev/null)
      HEIGHT=$(xmllint --xpath '//monitors/configuration['1']/output['$i']/height/text()' $MONITOR_XML 2>/dev/null)
      RATE=$(xmllint --xpath '//monitors/configuration['1']/output['$i']/rate/text()' $MONITOR_XML 2>/dev/null)
      PRIMARY=$(xmllint --xpath '//monitors/configuration['1']/output['$i']/primary/text()' $MONITOR_XML 2>/dev/null)
    
      # if position is defined for current monitor, add its position and orientation to command line parameters
      [ -n "$POS_X" ] && PARAM_ARR=("${PARAM_ARR[@]}" "--output" "$NAME" "--pos" "${POS_X}x${POS_Y}" "--fbmm" "${WIDTH}x${HEIGHT}" "--rate" "$RATE" "--rotate" "$ROTATE")
    
      # if monitor is defined as primary, adds it to command line parameters
      [ "$PRIMARY" = "yes" ] && PARAM_ARR=("${PARAM_ARR[@]}" "--primary")
    done
    
    # if needed, wait for some seconds (for X to finish initialisation)
    [ -n "$1" ] && sleep $1
    
    # position all monitors
    xrandr "${PARAM_ARR[@]}"
    
    • 4
  5. Alex Tomko
    2018-11-15T14:41:30+08:002018-11-15T14:41:30+08:00

    我更喜欢从终端运行这个脚本,因为我在登录后首先打开了一个。

    首次使用错误配置登录 - 未正确放置监视器:

    cd ~/.config
    mv ~/.config/monitors.xml{,.bak}
    

    现在使用系统设置设置您的显示器,以创建~/.config/monitors.xml具有适当设置的新文件。

    从我的仓库复制 Nicolas Bernaerts 的固定脚本:https ://raw.githubusercontent.com/alextomko/monitors/master/monitors并将其放在从终端运行的路径中。

    $ ls -l ~/bin
    # if you don't have this directory then create it - do not be logged in as root here.
    
    $ mkdir /home/$USER/bin
    
    $ echo $PATH
    # should show /home/username/bin if the dir existed or if you had to create.
    
    $ wget -P ~/bin https://raw.githubusercontent.com/alextomko/monitors/master/monitors
    $ chmod +x ~/bin/monitors
    
    # Log out, lock, reboot or whatever it takes to make monitor settings lost for you and run the script.
    $ monitors
    
    • 2
  6. Jens
    2013-08-16T10:38:18+08:002013-08-16T10:38:18+08:00

    Ubuntu 12.04 会记住热插拔显示器设置。但它们仅在您重新打开系统配置 > 显示小程序时应用。至少对我来说是这样,这绝对是一个错误。

    • 1
  7. Chris
    2018-11-14T14:27:45+08:002018-11-14T14:27:45+08:00

    杰伊的回答几乎对我有用,但我需要做几个额外的步骤。我会对他的回答发表评论,但我没有声誉。

    在文件 update-monitor-position-office 中:

    1. 我的 bash (4.3.48) 版本抱怨第 28 行的“i++”后面缺少空格。
    2. 我的 xrandr (1.5) 版本无法识别第 40 行的“--fbmm”选项。我不得不将其更改为“--mode”。这很难诊断,因为 xrandr 实际上并没有给我一个错误,它只是执行了命令而不做任何事情。
    • 1
  8. maco
    2010-10-12T13:12:29+08:002010-10-12T13:12:29+08:00

    不,没有办法在热插拔显示器上保存配置。如果您在启动前插入,GNOME 应该记住每次启动时基于每个设备的配置(即,连接到工作时的显示器而不是家里的显示器)。

    • 0
  9. SteelTrap
    2020-04-09T15:33:41+08:002020-04-09T15:33:41+08:00

    谢谢你指点我的 ~/.config/monitors.xml 文件。

    我发现在我指定我想要的布局时创建了一个,还有一些备份, monitors.xml~ 这与我想要更改的特性不同。

    如果我只是简单地删除了这个备份文件,我发现我新创建的一个在我下次重新启动机器时生效。无需下载任何脚本。

    我想,如果有一个错误,它已经被修复了。

    另外猜测,我猜测备份文件以某种方式重新恢复,但随着它的消失,主文件仍然是唯一有效的文件。

    这适用于运行 Ubu 16.04 的设置和运行 19.10 的设置

    再次感谢您指点我的文件。

    • 0
  10. grssnbchr
    2020-06-18T23:00:44+08:002020-06-18T23:00:44+08:00

    请注意,在 Ubuntu 18.04 中,monitors.xml 布局似乎有所不同,因此某些 xpath 查询不再起作用。我调整了@jay 发布的 shell 脚本以相应地工作:

    #!/bin/bash
    # -------------------------------------------------
    #  Get monitors configuration from monitor.xml and apply it for current user session.
    #  In case of multiple definitions in monitor.xml only first one is used.
    #
    #  See http://bernaerts.dyndns.org/linux/74-ubuntu/309-ubuntu-dual-display-monitor-position-lost
    #  for instructions
    #
    #  Parameters :
    #    $1 : waiting time in sec. before forcing configuration (optional)
    #
    #  Revision history :
    #    19/04/2014, V1.0 - Creation by N. Bernaerts
    #    10/07/2014, V1.1 - Wait 5 seconds for X to fully initialize
    #    01/09/2014, V1.2 - Correct NULL file bug (thanks to Ivan Harmady) and handle rotation
    #    07/10/2014, V1.3 - Add monitors size and rate handling (idea from jescalante)
    #    08/10/2014, V1.4 - Handle primary display parameter
    #    08/12/2014, V1.5 - Waiting time in seconds becomes a parameter
    #    06/17/2020, V1.6 - Adapted to new monitors version = 2 (see https://askubuntu.com/a/993592/93077)
    # -------------------------------------------------
    
    # monitor.xml path
    MONITOR_XML="$HOME/.config/monitors-office.xml"
    
    # get number of declared monitors
    NUM=$(xmllint --xpath 'count(//monitors/configuration['1']/logicalmonitor)' $MONITOR_XML)
    # loop thru declared monitors to create the command line parameters
    for (( i=1; i<=$NUM; i++)); do
      # get attributes of current monitor (name and x & y positions)
      NAME=$(xmllint --xpath 'string(//monitors/configuration['1']/logicalmonitor['$i']//connector/text())' $MONITOR_XML 2>/dev/null)
      POS_X=$(xmllint --xpath '//monitors/configuration['1']/logicalmonitor['$i']/x/text()' $MONITOR_XML 2>/dev/null)
      POS_Y=$(xmllint --xpath '//monitors/configuration['1']/logicalmonitor['$i']/y/text()' $MONITOR_XML 2>/dev/null)
      #ROTATE=$(xmllint --xpath '//monitors/configuration['1']/logicalmonitor['$i']/rotation/text()' $MONITOR_XML 2>/dev/null)
      WIDTH=$(xmllint --xpath '//monitors/configuration['1']/logicalmonitor['$i']//width/text()' $MONITOR_XML 2>/dev/null)
      HEIGHT=$(xmllint --xpath '//monitors/configuration['1']/logicalmonitor['$i']//height/text()' $MONITOR_XML 2>/dev/null)
      RATE=$(xmllint --xpath '//monitors/configuration['1']/logicalmonitor['$i']//rate/text()' $MONITOR_XML 2>/dev/null)
      PRIMARY=$(xmllint --xpath '//monitors/configuration['1']/logicalmonitor['$i']/primary/text()' $MONITOR_XML 2>/dev/null)
      # if position is defined for current monitor, add its position and orientation to command line parameters
      [ -n "$POS_X" ] && PARAM_ARR=("${PARAM_ARR[@]}" "--output" "$NAME" "--pos" "${POS_X}x${POS_Y}" "--fbmm" "${WIDTH}x${HEIGHT}" "--rate" "$RATE" "--rotate" "normal")
      # if monitor is defined as primary, adds it to command line parameters
      [ "$PRIMARY" = "yes" ] && PARAM_ARR=("${PARAM_ARR[@]}" "--primary")
    done
    # if needed, wait for some seconds (for X to finish initialisation)
    [ -n "$1" ] && sleep $1
    
    # position all monitors
    xrandr "${PARAM_ARR[@]}"
    
    • 0

相关问题

  • 当我关闭它们时,如何让我的窗户“燃烧”?

  • 您如何在 Num Lock 开启的情况下在登录屏幕中启动?[复制]

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

  • 类似于 Eyefinity 的东西?

  • 我在哪里可以找到保证与 Ubuntu 一起工作的计算机列表?

Sidebar

Stats

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

    如何安装 .run 文件?

    • 7 个回答
  • Marko Smith

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

    • 24 个回答
  • Marko Smith

    如何获得 CPU 温度?

    • 21 个回答
  • Marko Smith

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

    • 25 个回答
  • Marko Smith

    如何使用命令行将用户添加为新的 sudoer?

    • 7 个回答
  • Marko Smith

    更改文件夹权限和所有权

    • 9 个回答
  • Marko Smith

    你如何重新启动Apache?

    • 13 个回答
  • Marko Smith

    如何卸载软件?

    • 11 个回答
  • Marko Smith

    如何删除 PPA?

    • 26 个回答
  • Martin Hope
    NES 如何启用或禁用服务? 2010-12-30 13:03:32 +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
    Olivier Lalonde 如何在结束 ssh 会话后保持进程运行? 2010-10-22 04:09:13 +0800 CST
  • Martin Hope
    David B 如何使用命令行将用户添加为新的 sudoer? 2010-10-16 04:02:45 +0800 CST
  • Martin Hope
    Hans 如何删除旧内核版本以清理启动菜单? 2010-08-21 19:37:01 +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