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
    • 最新
    • 标签
主页 / unix / 问题 / 559589
Accepted
400 the Cat
400 the Cat
Asked: 2019-12-31 11:38:08 +0800 CST2019-12-31 11:38:08 +0800 CST 2019-12-31 11:38:08 +0800 CST

如何设置登录脚本来运行 xrandr?

  • 772

我正在使用 3 台显示器,其中 2 台正在旋转。

我无法成功配置xorg.conf以旋转 2 个监视器,但我找到了一个xrandr可以在我的登录管理器启动后使用的命令:

xrandr --output DisplayPort-1 --rotate right --left-of DisplayPort-0
xrandr --output DisplayPort-2 --rotate left --right-of DisplayPort-0

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

我应该把这些放在哪里,以便我的显示器在登录时旋转。另外,我可以在全球范围内进行吗?这样当我以其他用户身份登录时,显示器就会旋转。还是每个用户在登录后都需要用户脚本来执行此操作?

xrandr x-server
  • 4 4 个回答
  • 6774 Views

4 个回答

  • Voted
  1. Best Answer
    Pierre-Alain TORET
    2020-01-03T03:16:10+08:002020-01-03T03:16:10+08:00

    我正在使用与您的有点相似的 2 屏幕布局,我的是右侧的常规屏幕和左侧的纵向屏幕。通过我的设置,我可以让 X 在我的 2 个屏幕上完美运行。

    这是我针对您自己的案例的建议(很难测试,因为我没有相同的屏幕并且没有 3 个屏幕),但这应该足以让您获得有效的 X 设置。

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

    30-screen-dport0.conf
    30-screen-dport1.conf
    30-screen-dport2.conf
    

    内容如下:

    30-screen-dportcenter.conf

    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-屏幕-dportleft.conf

    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

    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

    Section "ServerLayout"
        Identifier   "Main"
        Screen       0 "DPL"
        Screen       1 "DPC"
        Screen       2 "DPR
    EndSection
    

    Xserver 的坐标按以下方式工作

     0                 X
    + -----------------> X-axis 
    |0
    |
    |
    |
    |
    | 
    | Y
    V Y-axis  
    

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

    20-nvidia.conf

    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
  2. ajgringo619
    2020-01-02T11:58:14+08:002020-01-02T11:58:14+08:00

    我使用用户级 systemd 服务(完整路径 = $HOME/.config/systemd/user/set-display.service)来处理我的 QEMU VM 上的类似情况,这些 VM 使用 XFCE 并且不会自动填充屏幕(由于 conky 而缩短):

    [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
    

    我使用 sleep 命令来确保 DE 已满载;我在 SSD 上的虚拟机在 5 秒或更短的时间内总是很好,而 HDD 有时需要更多。只需创建一个运行两个 xrandr 命令的脚本,将其替换为ExecStart=(类似ExecStart=/path/to/your/script),然后启用它(systemctl --user enable set-display)。

    更新:在 Debian Buster 上作为系统服务进行的测试不起作用,即使在登录后手动运行该服务(以 root 和普通用户身份尝试)也是如此。

    • 3
  3. Arkadiusz Drabczyk
    2020-01-08T11:37:07+08:002020-01-08T11:37:07+08:00

    您必须将这两行放在登录管理器或窗口管理器启动时执行的文件之一中。哪个文件完全取决于您使用的登录管理器和窗口管理器以及您的系统本地设置。

    例如,如果您使用slim登录管理器,您应该将启动命令放在login_cmd配置中指定的文件中。以 Debian 为例:

    $ grep '^login_cmd ' /etc/slim.conf
    login_cmd           exec /bin/bash -login /etc/X11/Xsession %session
    

    但在 Slackware 上:

    $ grep '^login_cmd ' /etc/slim.conf
    login_cmd           exec /bin/bash -login ~/.xinitrc %session
    

    在 Debian 上,我认为最好的地方是在 /etc/X11/Xsession.d 中创建一个新文件,例如90xrandr包含以下内容:

    xrandr --output DisplayPort-1 --rotate right --left-of DisplayPort-0
    xrandr --output DisplayPort-2 --rotate left --right-of DisplayPort-0
    

    您没有使其可执行或添加 shebang,因为它的来源是/etc/X11/Xsession:

    # use run-parts to source every file in the session directory; we source
    # instead of executing so that the variables and functions defined above
    # are available to the scripts, and so that they can pass variables to each
    # other
    SESSIONFILES=$(run-parts --list $SYSSESSIONDIR)
    if [ -n "$SESSIONFILES" ]; then
      set +e
      for SESSIONFILE in $SESSIONFILES; do
        . $SESSIONFILE
      done
      set -e
    fi
    

    另请注意,它在用户登录后login_cmd运行,因此每次启动时您都必须在默认监视器设置中使用。slim

    • 2
  4. intika
    2020-01-07T16:06:09+08:002020-01-07T16:06:09+08:00

    从命令行(如果你使用 nano,否则用 vim 替换)

    sudo nano /etc/xdg/autostart/rotate-screen-1.desktop
    

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

    [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
    

    然后第二个屏幕也一样

    sudo nano /etc/xdg/autostart/rotate-screen-2.desktop
    

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

    [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

相关问题

  • 在双显示器上校准触摸屏(一触一非)

  • 试图避免显示损坏的 Xrandr 问题

  • Intel-virtual-output - 高温导致 Linux 崩溃

  • 如何使用 Arch Linux 禁用 tty1 和背光

  • 旋转网络摄像头和屏幕(纵向模式)

Sidebar

Stats

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

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve