我怎样才能以最简单的方式旋转显示屏?

我怎样才能以最简单的方式旋转显示屏?

我很幸运拥有一台可以旋转屏幕的旋转显示器,它的屏幕可以(物理)旋转。当我转动显示器时,最简单的方法是什么?

目前,我首先启动“显示”应用程序,然后更改设置并确认。但这实际上是一个相当费力的过程,因为我每分钟要切换几次方向。

那么,有没有一个指示器,或者等效指示器?我可以设置一个键盘快捷键来启动专用命令吗?事实上,我正在考虑一些类似于 Windows 程序的东西旋转

答案1

进入键盘->快捷键,选择“自定义快捷键”,然后按“+”添加新的快捷键。

“名称”是操作的描述性名称(例如“旋转显示器”)。在“命令”中输入快捷方式激活时要运行的自定义命令。

一旦快捷方式出现在列表中,选择其所在行,按 ENTER,然后选择要激活快捷方式的组合键。如果存在冲突,快捷方式管理器会通知您,您可以选择其他组合。

你可以使用快捷键来启用旋转显示,并使用另一个快捷键将其恢复到直立位置。如果你足够了解,你甚至可以编写一个命令来保持状态并在直立/旋转之间切换。

现在,至于您需要使用的命令,它可能是 xrandr:

xrandr --output HDMI1 --rotate left

xrandr --output HDMI1 --rotate normal

输出参数取决于显示器插入的端口。要查看当前的内容,请输入:

xrandr -q

我说:

Screen 0: minimum 320 x 200, current 1366 x 768, maximum 8192 x 8192
LVDS1 connected 1366x768+0+0 (normal left inverted right x axis y axis) 309mm x 174mm
   1366x768       60.0*+
   1360x768       59.8     60.0  
   1024x768       60.0  
   800x600        60.3     56.2  
   640x480        59.9  
VGA2 disconnected (normal left inverted right x axis y axis)
HDMI1 disconnected (normal left inverted right x axis y axis)
DP1 disconnected (normal left inverted right x axis y axis)

在这种情况下,我的输出将是 LVDS1,因为所有其他的都已断开连接。

答案2

非常适合

xrandr --output LVDS1 --rotate left
xrandr --output LVDS1 --rotate right
xrandr --output LVDS1 --rotate inverted
xrandr --output LVDS1 --rotate normal

答案3

这是一个基于传感器输入如何执行此操作的很好的例子: https://linuxappfinder.com/blog/auto_screen_rotation_in_ubuntu

因此,基本上请尝试上述方法来确定您想要看到的旋转屏幕。根据显示器型号,可能会有一个发送信号的传感器?

这对于带有内置旋转传感器的 Lenovo Yoga 2 11 非常有效,并且它也可以移动 Unity Dock。

剧本:

#!/bin/sh
# Auto rotate screen based on device orientation

# Receives input from monitor-sensor (part of iio-sensor-proxy package)
# Screen orientation and launcher location is set based upon accelerometer position
# Launcher will be on the left in a landscape orientation and on the bottom in a portrait orientation
# This script should be added to startup applications for the user

# Clear sensor.log so it doesn't get too long over time
> sensor.log

# Launch monitor-sensor and store the output in a variable that can be parsed by the rest of the script
monitor-sensor >> sensor.log 2>&1 &

# Parse output or monitor sensor to get the new orientation whenever the log file is updated
# Possibles are: normal, bottom-up, right-up, left-up
# Light data will be ignored
while inotifywait -e modify sensor.log; do
# Read the last line that was added to the file and get the orientation
ORIENTATION=$(tail -n 1 sensor.log | grep 'orientation' | grep -oE '[^ ]+$')

# Set the actions to be taken for each possible orientation
case "$ORIENTATION" in
normal)
xrandr --output eDP1 --rotate normal && gsettings set com.canonical.Unity.Launcher launcher-position Left ;;
bottom-up)
xrandr --output eDP1 --rotate inverted && gsettings set com.canonical.Unity.Launcher launcher-position Left ;;
right-up)
xrandr --output eDP1 --rotate right && gsettings set com.canonical.Unity.Launcher launcher-position Bottom ;;
left-up)
xrandr --output eDP1 --rotate left && gsettings set com.canonical.Unity.Launcher launcher-position Bottom ;;
esac
done

以及传感器的先决条件:

sudo apt install iio-sensor-proxy inotify-tools

答案4

我编写了一个 shell 脚本来执行此操作。(需要 xrandr grep awk)

#!/bin/sh
# invert_screen copyright 20170516 alexx MIT Licence ver 1.0
orientation=$(xrandr -q|grep -v dis|grep connected|awk '{print $4}')
display=$(xrandr -q|grep -v dis|grep connected|awk '{print $1}')
if [ "$orientation" == "inverted" ]; then
   xrandr --output $display --rotate normal
else
   xrandr --output $display --rotate inverted
fi

如果你喜欢单行:

[ "$(xrandr -q|grep -v dis|grep con|awk '{print $4}')" == 'inverted' ] && xrandr -o normal || xrandr -o inverted

相关内容