如何使用命令行获取监视器分辨率?


Answers:


71

这个答案中得出

xdpyinfo | grep dimensions

或仅获得分辨率:

xdpyinfo | awk '/dimensions/{print $2}'

要么

xdpyinfo  | grep -oP 'dimensions:\s+\K\S+'

8
它适用于单个显示器设置,但具有两个显示器时,它们将两个尺寸相加,对我来说,我的两个屏幕都返回:3520x1200 pixels
Sylvain Pineau,2015年

3
好点子。另一方面,如果他正在搜索要在所有监视器上显示的单个墙纸,这仍然很有用。
aguslr 2015年

确实,您是对的,+ 1;)
Sylvain Pineau

@aguslr有什么意义呢?有两个2000x1000的显示器,那么4000x2000的墙纸图像有什么用?
2015年

1
@Jos,我知道此命令将返回4000x1000,也就是说,它将两个监视器彼此相邻放置。例如,西尔万(Sylvain)有两台显示器(1600x900和1920x1200),他得到了3520x1200。
aguslr 2015年

30

我只会用xrandr

$ xrandr 
Screen 0: minimum 320 x 200, current 3520 x 1200, maximum 32767 x 32767
LVDS1 connected 1600x900+1920+0 (normal left inverted right x axis y axis) 310mm x 174mm
   1600x900       60.0*+
   1440x900       59.9  
   1360x768       59.8     60.0  
   1152x864       60.0  
   1024x768       60.0  
   800x600        60.3     56.2  
   640x480        59.9  
VGA1 disconnected (normal left inverted right x axis y axis)
HDMI1 disconnected (normal left inverted right x axis y axis)
DP1 connected primary 1920x1200+0+0 (normal left inverted right x axis y axis) 518mm x 324mm
   1920x1200      60.0*+
   1920x1080      60.0     50.0     59.9     24.0     24.0  
   1920x1080i     60.1     50.0     60.0  
   1600x1200      60.0  
   1280x1024      75.0     60.0  
   1152x864       75.0  
   1280x720       60.0     50.0     59.9  
   1024x768       75.1     60.0  
   800x600        75.0     60.3  
   720x576        50.0  
   720x480        60.0     59.9  
   640x480        75.0     60.0     59.9  
   720x400        70.1  
HDMI2 disconnected (normal left inverted right x axis y axis)
HDMI3 disconnected (normal left inverted right x axis y axis)
DP2 disconnected (normal left inverted right x axis y axis)
DP3 disconnected (normal left inverted right x axis y axis)
VIRTUAL1 disconnected (normal left inverted right x axis y axis)

这里有两个屏幕,分辨率为:

  • 1600x900(笔记本电脑)
  • 1920x1200(显示器)

要仅获取主监视器的分辨率,还可以使用以下python oneliner:

$ python3 -c 'from gi.repository import Gdk; screen=Gdk.Screen.get_default(); \
geo = screen.get_monitor_geometry(screen.get_primary_monitor()); \
print(geo.width, "x", geo.height)'
1920 x 1200

要获得扩展桌面的分辨率(用于多显示器设置):

$ python3 -c 'from gi.repository import Gdk; screen=Gdk.Screen.get_default(); \
print(screen.get_width(), "x", screen.get_height())'
3520 x 1200

xrandr + vesa =无工作人员。
2015年

只是使用中的显示器的分辨率:xrandr | grep " connected\|\*"
Pablo A

10

请求是要解决的。这是由

xdpyinfo | grep resolution

4
通常,人们使用分辨率来表示尺寸。DPI与尺寸无关。
muru 2015年

3

您还可以使用:

 xrandr | grep ' connected'

我的一台机器上的输出示例:

LVDS connected primary 1366x768+0+0 (normal left inverted right x axis y axis) 344mm x 193mm

1

值得一提的是,当在TwinView中使用多个连接的显示器和/或偏移量时,xdpyinfo将为您提供整套显示器的配置方式的分辨率。如果您需要单个显示器或连接到其中一个显示端口的显示器的分辨率,则需要使用xrandr。但是,即使在这种配置下,xrandr也可能不可靠并且无法显示分辨率。请参阅我的X Windows配置文件中的以下示例条目:

Option "MetaModes" "DP-1: 1440x900 +0+0, DP-3: 1440x900 +1568+0, DP-5: 1440x900 +3136+0"

xrandr输出看起来像这样:

DVI-D-0 disconnected primary (normal left inverted right x axis y axis)
HDMI-0 disconnected (normal left inverted right x axis y axis)
DP-0 disconnected (normal left inverted right x axis y axis)
DP-1 connected 1440x900+0+0 (normal left inverted right x axis y axis) 410mm x 256mm
   1440x900      59.89*+
   1280x1024     60.02
   1280x960      60.00
   1280x800      59.81
   1280x720      60.00
   1152x864      75.00
   1024x768      70.07    60.00
   800x600       75.00    60.32    56.25
   640x480       75.00    72.81    59.94
DP-2 disconnected (normal left inverted right x axis y axis)
DP-3 connected (normal left inverted right x axis y axis)
   1440x900      59.89 +  74.98
   1280x1024     60.02
   1280x960      60.00
   1280x800      59.81
   1280x720      60.00
   1152x864      75.00
   1024x768      70.07    60.00
   800x600       75.00    60.32    56.25
   640x480       75.00    72.81    59.94
DP-4 disconnected (normal left inverted right x axis y axis)
DP-5 connected 1440x900+1568+0 (normal left inverted right x axis y axis) 410mm x 256mm
   1440x900      59.89*+
   1280x1024     60.02
   1280x960      60.00
   1280x800      59.81
   1280x720      60.00
   1152x864      75.00
   1024x768      70.07    60.00
   800x600       75.00    60.32    56.25
   640x480       75.00    72.81    59.94

您会看到DP-3在“已连接”的grep显示的行上没有显示分辨率。因此,我发现用于识别任何单个已连接显示器的分辨率的最佳,最一致和可靠的命令是:

/usr/bin/xrandr --query|/usr/bin/grep -A 1 connected|grep -v connected

产生这个:

   1440x900      59.89*+
--
   1440x900      59.89*+  74.98
--
   1440x900      59.89*+

那时,只为一个端口选择不同的分辨率或grep是很简单的。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.