首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我如何设置一个登录脚本,运行xrandr?

我如何设置一个登录脚本,运行xrandr?
EN

Unix & Linux用户
提问于 2019-12-30 19:38:08
回答 3查看 7.7K关注 0票数 6

我使用的是3台显示器,其中2台是旋转的。

我无法成功地将xorg.conf配置为旋转2监视器,但在启动登录管理器之后,我找到了一个xrandr命令:

代码语言:javascript
复制
xrandr --output DisplayPort-1 --rotate right --left-of DisplayPort-0
xrandr --output DisplayPort-2 --rotate left --right-of DisplayPort-0

目前,我正在手动运行这些命令登录后。

我应该把这些放在哪里,以便我的显示器在登录时旋转。还有,我可以在全球范围内做吗?这样,当我作为其他用户登录时,监视器就会被旋转。或者每个用户在登录后都需要一个用户脚本来完成这个任务?

EN

回答 3

Unix & Linux用户

回答已采纳

发布于 2020-01-02 11:16:10

我使用的是两个屏幕布局,有点类似你的,我的是一个正常的屏幕在右边和肖像导向的一个在左边。与我的设置,我有X完美地工作在我的2个屏幕。

这是我为您自己的情况提出的建议(很难测试,因为我没有相同的屏幕,也没有3个屏幕),但这应该足以让您获得一个工作的X设置。

将以下文件放入/etc/X11/xorg.conf.d/

代码语言:javascript
复制
30-screen-dport0.conf
30-screen-dport1.conf
30-screen-dport2.conf

有以下内容:

30-screen-dportcenter.conf

代码语言:javascript
复制
Section "Monitor"
  Identifier   "DisplayPort-0"
  Option       "Primary" "true"
  Option       "PreferredMode"   "3840x2160" # Adapt this if you resolution is not the same
  Option       "Position"        "1200 0" 
EndSection

Section "Screen"
  Identifier   "DPC"
  Device       "nVidia" # here you choose your driver
  Monitor      "DisplayPort-0"
EndSection

30-screen-dportleft.conf

代码语言:javascript
复制
Section "Monitor"
  Identifier   "DisplayPort-1 "
  Option       "LeftOf" "DisplayPort-0"
  Option       "Rotate" "left" 
  Option       "PreferredMode"   "1920x1200"
  Option       "Position"        "0 0"
EndSection

Section "Screen"
  Identifier   "DPL"
  Device       "nVidia"
  Monitor      "DisplayPort-1"
EndSection

30-screen-dportright.conf

代码语言:javascript
复制
Section "Monitor"
  Identifier   "DisplayPort-2"
  Option       "RightOf" "DisplayPort-0"
  Option       "Rotate" "right" 
  Option       "PreferredMode"   "1920x1200"
  Option       "Position"        "5040 0" # 1200 + 3840
EndSection

Section "Screen"
  Identifier   "DPR"
  Device       "nVidia"
  Monitor      "DisplayPort-2"
EndSection

90-serverlayout.conf

代码语言:javascript
复制
Section "ServerLayout"
    Identifier   "Main"
    Screen       0 "DPL"
    Screen       1 "DPC"
    Screen       2 "DPR
EndSection

Xserver的坐标以下列方式工作

代码语言:javascript
复制
 0                 X
+ -----------------> X-axis 
|0
|
|
|
|
| 
| Y
V Y-axis  

nVidia标识符是对在文件中定义的视频卡的引用。

20-nvidia.conf

代码语言:javascript
复制
Section "Device"
  Identifier  "nVidia"
  Driver      "nouveau"
  Option      "AccelMethod"  "sna"
  Option      "GLXVBlank"    "true"
  # Need to flag this as only referring to one output on the card
  Screen      0

EndSection
票数 4
EN

Unix & Linux用户

发布于 2020-01-01 19:58:14

我使用用户土地系统服务(full path = $HOME/.config/systemd/user/set-display.service)在我的QEMU上处理类似的情况,这些VM使用XFCE,并且不会自动填充屏幕(由于conky而被切断):

代码语言:javascript
复制
[Unit]
Description=Set Display Resolution

[Service]
ExecStartPre=/bin/sleep 5
Type=oneshot
ExecStart=/usr/bin/xrandr --output Virtual-0 --mode 1499x996

[Install]
WantedBy=default.target

我使用睡眠命令来确保DE是完全加载的;我在SSD上的VM总是在5秒或更短的时间内很好,有时HDD还需要更多。只需创建一个脚本,运行您的xrandr命令,在ExecStart=上替换它(类似于ExecStart=/path/to/your/script),然后启用它(systemctl --user enable set-display)。

更新: Debian上的系统服务测试不起作用,即使在登录后手动运行服务(尝试作为root用户和普通用户)。

票数 3
EN

Unix & Linux用户

发布于 2020-01-07 00:06:09

从命令行(如果您正在使用nano替换为vim)

代码语言:javascript
复制
sudo nano /etc/xdg/autostart/rotate-screen-1.desktop

然后粘贴以下内容并保存:

代码语言:javascript
复制
[Desktop Entry]
Version=1.0
Encoding=UTF-8
Type=Application
Name=Xrandr Screen 1 Rotation
Icon=preferences-desktop-screensaver
Exec=xrandr --output DisplayPort-1 --rotate right --left-of DisplayPort-0
Terminal=false
OnlyShowIn=LXDE;OPENBOX;GNOME;KDE;
Categories=System;Security;Utility;
StartupNotify=false
X-KDE-autostart-after=panel
X-OPENBOX-Autostart-enabled=true

那么第二个屏幕也是一样的。

代码语言:javascript
复制
sudo nano /etc/xdg/autostart/rotate-screen-2.desktop

然后粘贴以下内容并保存:

代码语言:javascript
复制
[Desktop Entry]
Version=1.0
Encoding=UTF-8
Type=Application
Name=Xrandr Screen 2 Rotation
Icon=preferences-desktop-screensaver
Exec=xrandr --output DisplayPort-2 --rotate left --right-of DisplayPort-0
Terminal=false
OnlyShowIn=LXDE;OPENBOX;GNOME;KDE;
Categories=System;Security;Utility;
StartupNotify=false
X-KDE-autostart-after=panel
X-OPENBOX-Autostart-enabled=true

重新启动后,屏幕应自动旋转。

票数 1
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/559589

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档