如何确定哪些显示器已启用/禁用

Col*_*lin 5 x11 xrandr display

我可以使用以下命令启用或禁用我的 LVDS 显示

xrandr --output LVDS --auto
xrandr --output LVDS --off
Run Code Online (Sandbox Code Playgroud)

分别,但如何以编程方式确定是否启用显示?

xrandr -q无论启用/禁用状态如何,均显示 LVDS 已连接。

Seb*_*ian 1

根据@derobert 的评论:

VGA-0 关闭:

VGA-0 connected (normal left inverted right x axis y axis)
1280x1024     60.02 +  75.02 
...
Run Code Online (Sandbox Code Playgroud)

VGA-0 开启:

VGA-0 connected 1280x1024+1680+0 (normal left inverted right x axis y axis) 380mm x 300mm
1280x1024     60.02*+  75.02 
...
Run Code Online (Sandbox Code Playgroud)

因此,您可以检查此安静的返回值grep以查看它是否实际上已启用(当然您可以将其简化为更通用的正则表达式)

grep -q 'VGA-0 connected 1280x1024+1680+0 (normal left inverted right x axis y axis) 380mm x 300' \
&& echo "connected AND enabled"
Run Code Online (Sandbox Code Playgroud)

或者,对于您的输出(取自上面的评论):

grep -q 'LVDS connected 1680x1050+0+0 (normal left inverted right x axis y axis) 331mm x 207mm' \
  && echo "connected AND enabled"
Run Code Online (Sandbox Code Playgroud)