如何使用命令行获取显示器分辨率?

如何使用命令行获取显示器分辨率?

我想找到最适合我的分辨率的壁纸。如何通过在命令行中输入命令来获取分辨率?

答案1

取自这个答案

xdpyinfo | grep dimensions

或者只获取分辨率:

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

或者

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

答案2

我只会使用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 单行程序:

$ 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

答案3

该请求是为了解决. 即

xdpyinfo | grep resolution

答案4

在没有 X 的树莓派上,我可以通过运行以下命令来获取屏幕分辨率:

fbset -s

相关内容