Jac*_*ijm 58
使用 的另一个选项xrandr是命令:
xrandr | grep ' connected'
Run Code Online (Sandbox Code Playgroud)
输出:
DVI-I-1 connected primary 1680x1050+0+0 (normal left inverted right x axis y axis) 473mm x 296mm
VGA-1 connected 1280x1024+1680+0 (normal left inverted right x axis y axis) 376mm x 301mm
Run Code Online (Sandbox Code Playgroud)
(注意前面的空格connected,否则disconnected将包括在内)
xdpyinfo和之间的重要区别xrandrxrandr单独列出屏幕(在多台显示器的情况下),xdpyinfo为所有屏幕一起输出一组尺寸(“桌面尺寸”而不是屏幕尺寸)正如@agold 所注意到的,两者之间存在(相当)差异,这似乎太大而不能成为简单的舍入差异:
xrandr: 473mm x 296mm
xdpyinfo: 445x278
Run Code Online (Sandbox Code Playgroud)使用下面的小脚本;它以英寸为单位输出屏幕的大小;宽度/高度/对角线(英寸)
xrandr | grep ' connected'
Run Code Online (Sandbox Code Playgroud)
将脚本复制到一个空文件中,另存为get_dimensions.py,通过命令运行:
python3 /path/to/get_dimensions.py
Run Code Online (Sandbox Code Playgroud)
在我的两个屏幕上输出:
width - height - diagonal (inches)
[18.6, 11.7, 22.0]
[14.8, 11.9, 19.0]
Run Code Online (Sandbox Code Playgroud)
相同脚本的花式版本(有一些改进和更好的输出),看起来像:
DVI-I-1 connected primary 1680x1050+0+0 (normal left inverted right x axis y axis) 473mm x 296mm
VGA-1 connected 1280x1024+1680+0 (normal left inverted right x axis y axis) 376mm x 301mm
Run Code Online (Sandbox Code Playgroud)
xrandr: 473mm x 296mm
xdpyinfo: 445x278
Run Code Online (Sandbox Code Playgroud)
“某种”应要求(在评论中),现代化/更高级/改进(无系统调用,无解析,但使用 Gdk.Display)版本,几乎完全相同:
#!/usr/bin/env python3
import subprocess
# change the round factor if you like
r = 1
screens = [l.split()[-3:] for l in subprocess.check_output(
["xrandr"]).decode("utf-8").strip().splitlines() if " connected" in l]
for s in screens:
w = float(s[0].replace("mm", "")); h = float(s[2].replace("mm", "")); d = ((w**2)+(h**2))**(0.5)
print([round(n/25.4, r) for n in [w, h, d]])
Run Code Online (Sandbox Code Playgroud)
输出:
python3 /path/to/get_dimensions.py
Run Code Online (Sandbox Code Playgroud)
我会留下原来的答案,因为在这么长时间之后删除答案似乎不合适,这会产生现有的投票。
phr*_*nel 18
以防万一你想要一个更一般的答案,你可以解决这个问题,并为此使用一个非极客的物理尺子。根据这个 wiki,“屏幕的大小通常由其对角线的长度来描述”:
1 cm = 0.393701 in
(or 2.54 cm = 1 in)
Run Code Online (Sandbox Code Playgroud)
因此,如果您的标尺尺寸为30 厘米,则您的屏幕为11.811英寸。您还可以使用google查询表单30 cm to in。
图片来源:https ://en.wikipedia.org/wiki/File: Display_size_measurements.png
这个怎么样:
xrandr | awk '/ connected/{print sqrt( ($(NF-2)/10)^2 + ($NF/10)^2 )/2.54" inches"}'
Xdpyinfo是用于显示有关 X 服务器的信息的实用程序。它用于检查服务器的功能、用于客户端和服务器之间通信的各种参数的预定义值,以及可用的不同类型的屏幕和视觉效果。
获取监视器大小的命令是:
xdpyinfo | grep dimensions
Run Code Online (Sandbox Code Playgroud)
结果
dimensions: 1366x768 pixels (361x203 millimeters)
Run Code Online (Sandbox Code Playgroud)