![如何在 Ubuntu 18.04(xorg)中从命令行更改显示比例](https://linux22.com/image/900530/%E5%A6%82%E4%BD%95%E5%9C%A8%20Ubuntu%2018.04%EF%BC%88xorg%EF%BC%89%E4%B8%AD%E4%BB%8E%E5%91%BD%E4%BB%A4%E8%A1%8C%E6%9B%B4%E6%94%B9%E6%98%BE%E7%A4%BA%E6%AF%94%E4%BE%8B.png)
我尝试在命令行中获得与从 Gnome 控制中心更改显示比例因子相同的效果。
我尝试了以下命令,但没有任何效果:
gsettings 设置 org.gnome.desktop.interface 缩放因子 2
我需要此命令来构建一种小数比例因子,该比例因子由 xrandx 和 Gnome 控制中心中的缩放因子组合而成。由于 xrandr 的执行会重置 Gnome 控制中心中的缩放因子,因此我需要一个命令来恢复 Gnome 控制中心中的值。
欢迎提出任何建议。提前致谢。
答案1
看看gnome-control-center
源代码,事实证明这是通过 dbus 进行配置的。这是一个在单显示器配置中在 100% 和 200% 之间切换的脚本。
#!/usr/bin/python3
# Note: use system python3, not /usr/bin/env, because whichever python3 is on
# $PATH may not have dbus, but the system python3 does.
"""Toggle display scaling between 100% and 200%.
Based on https://gist.github.com/strycore/ca11203fd63cafcac76d4b04235d8759
For data structure definitions, see
https://gitlab.gnome.org/GNOME/mutter/blob/master/src/org.gnome.Mutter.DisplayConfig.xml
"""
import dbus
namespace = "org.gnome.Mutter.DisplayConfig"
dbus_path = "/org/gnome/Mutter/DisplayConfig"
session_bus = dbus.SessionBus()
obj = session_bus.get_object(namespace, dbus_path)
interface = dbus.Interface(obj, dbus_interface=namespace)
current_state = interface.GetCurrentState()
serial = current_state[0]
connected_monitors = current_state[1]
logical_monitors = current_state[2]
# Multiple monitors are more complicated. For now, since I only use one monitor
# in Ubuntu, everything is hard-coded so that only info about the first monitor
# is used, and only it will be connected after running the script.
#
# If someday updating this script: a logical monitor may appear on mutiple
# connected monitors due to mirroring.
connector = connected_monitors[0][0][0]
current_mode = None
# ApplyMonitorsConfig() needs (connector name, mode ID) for each connected
# monitor of a logical monitor, but GetCurrentState() only returns the
# connector name for each connected monitor of a logical monitor. So iterate
# through the globally connected monitors to find the mode ID.
for mode in connected_monitors[0][1]:
if mode[6].get("is-current", False):
current_mode = mode[0]
updated_connected_monitors = [[connector, current_mode, {}]]
x, y, scale, transform, primary, monitors, props = logical_monitors[0]
scale = 2.0 if scale == 1.0 else 1.0
monitor_config = [[x, y, scale, transform, primary, updated_connected_monitors]]
# Change the 1 to a 2 if you want a "Revert Settings / Keep Changes" dialog
interface.ApplyMonitorsConfig(serial, 1, monitor_config, {})
答案2
通过单独运行 xrandr 来确定你的输出设备(我的是 DP-1),然后使用以下命令:
gsettings set org.gnome.desktop.interface scaling-factor 2
gsettings set org.gnome.settings-daemon.plugins.xsettings overrides "{'Gdk/WindowScalingFactor': <2>}"
xrandr --output DP-1 --scale 1.5x1.5
xrandr --output DP-1 --panning 3840x2160