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

Abd*_*red 69 xfce wallpaper command-line resolution

我想找到最适合我的分辨率的壁纸。如何仅通过在命令行中编写命令来获得分辨率?

agu*_*slr 99

取自这个答案

xdpyinfo | grep dimensions
Run Code Online (Sandbox Code Playgroud)

或者只获得分辨率:

xdpyinfo | awk '/dimensions/{print $2}'
Run Code Online (Sandbox Code Playgroud)

或者

xdpyinfo  | grep -oP 'dimensions:\s+\K\S+'
Run Code Online (Sandbox Code Playgroud)

  • 它适用于单个显示器设置,但有两个显示器,它可以将两个尺寸相加,对我来说,我的两个屏幕返回:`3520x1200 像素` (11认同)
  • 好点子。另一方面,如果他正在搜索跨越所有显示器的单个墙纸,这仍然很有用。 (4认同)
  • @Jos,我知道这个命令会返回 4000x1000,也就是说,它将两个显示器并排放置。例如,Sylvain 有两台显示器(1600x900 和 1920x1200),他得到 3520x1200。 (4认同)

Syl*_*eau 39

我只会使用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)
Run Code Online (Sandbox Code Playgroud)

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

  • 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
Run Code Online (Sandbox Code Playgroud)

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

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


小智 10

请求是为了决议。这是由

xdpyinfo | grep resolution
Run Code Online (Sandbox Code Playgroud)

  • 通常,人们使用分辨率来表示尺寸。DPI 不像维度那么受关注。 (4认同)

Bil*_*adj 5

您还可以使用:

 xrandr | grep ' connected'
Run Code Online (Sandbox Code Playgroud)

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

LVDS connected primary 1366x768+0+0 (normal left inverted right x axis y axis) 344mm x 193mm
Run Code Online (Sandbox Code Playgroud)


小智 5

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

fbset -s
Run Code Online (Sandbox Code Playgroud)