Answers:
长话短说(即:执行Nicolas Bernaerts的建议,但我为您保留了详细信息):监视器配置实际上保存在中~/.config/monitors.xml
,但在启动/登录时未应用。
解决此问题的步骤是:
使用错误的监视器配置登录。
删除当前的监视器配置:
cd .config
mv monitors.xml{,.bak}
使用“ 显示器”应用程序按需要布置显示器(我将一侧显示器逆时针旋转)。
按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
按照所需方式连接外部显示器的前三个步骤,第四个步骤是保存设置。
连接外接显示器并检查其支持的分辨率:
xrandr -q
输入以下命令(这将禁用笔记本电脑的显示器):
xrandr --output LVDS1 --off --output TV1 --off --output VGA1 --mode 1280x1024 --pos 0x0 --rotate normal
如果要同时启用笔记本电脑和外部设备:
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
”选项播放。
如果您在登录时需要此设置,请添加检查/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
在办公室,我的笔记本电脑上有3台显示器,家里有2台显示器。两个办公室监视器设置为垂直,而其他监视器则处于垂直方向。
答:monitors.xml在〜/ .config中。
B.获取外壳脚本“ update-monitor-position”。
将“ MONITOR_XML”定义“ monitors.xml”更改为“ monitors-office.xml”。
将其另存为“ update-monitor-position-office”,位于可执行路径(/ usr / local / sbin /)中。
C.获取桌面快捷方式“ update-monitor-position.desktop”
update-monitor-position-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[@]}"
我更喜欢从终端运行此脚本,因为我在登录后首先打开了一个脚本。
首次登录时配置错误-监视器放置不正确:
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
不可以,无法在热插拔的显示器上保存配置。如果在启动前插入电源,GNOME应该记住每个设备在每次启动时的配置(即,在工作时连接到显示器,而在家中则连接到显示器)。
~/.config/monitors.xml
,但在启动时未应用