如何在 Ubuntu 18.04 (xorg) 中从命令行更改显示比例

Fer*_*ndo 4 xorg scaling gnome-control-center hdpi 18.04

我试图在命令行中获得与从 Gnome 控制中心更改显示比例因子相同的效果。

我尝试过以下命令,但没有任何效果:

gsettings 设置 org.gnome.desktop.interface 缩放因子 2

我需要这个命令来结合 xrandx 和 Gnome 控制中心中的缩放因子来构建一种分数缩放因子。由于 xrandr 的执行会重置 Gnome 控制中心中的缩放因子,因此我需要一个命令来恢复 Gnome 控制中心中的值。

请,欢迎任何建议。提前致谢。

and*_*rew 5

查看gnome-control-center源代码,结果是通过 dbus 进行配置的。Here\xe2\x80\x99 是一个在单显示器配置中在 100% 和 200% 之间切换的脚本。

\n
#!/usr/bin/python3\n# Note: use system python3, not /usr/bin/env, because whichever python3 is on\n# $PATH may not have dbus, but the system python3 does.\n\n"""Toggle display scaling between 100% and 200%.\n\nBased on https://gist.github.com/strycore/ca11203fd63cafcac76d4b04235d8759\n\nFor data structure definitions, see\nhttps://gitlab.gnome.org/GNOME/mutter/blob/master/src/org.gnome.Mutter.DisplayConfig.xml\n"""\n\nimport dbus\n\nnamespace = "org.gnome.Mutter.DisplayConfig"\ndbus_path = "/org/gnome/Mutter/DisplayConfig"\n\nsession_bus = dbus.SessionBus()\nobj = session_bus.get_object(namespace, dbus_path)\ninterface = dbus.Interface(obj, dbus_interface=namespace)\n\ncurrent_state = interface.GetCurrentState()\nserial = current_state[0]\nconnected_monitors = current_state[1]\nlogical_monitors = current_state[2]\n\n# Multiple monitors are more complicated. For now, since I only use one monitor\n# in Ubuntu, everything is hard-coded so that only info about the first monitor\n# is used, and only it will be connected after running the script.\n#\n# If someday updating this script: a logical monitor may appear on mutiple\n# connected monitors due to mirroring.\nconnector = connected_monitors[0][0][0]\ncurrent_mode = None\n# ApplyMonitorsConfig() needs (connector name, mode ID) for each connected\n# monitor of a logical monitor, but GetCurrentState() only returns the\n# connector name for each connected monitor of a logical monitor. So iterate\n# through the globally connected monitors to find the mode ID.\nfor mode in connected_monitors[0][1]:\n    if mode[6].get("is-current", False):\n        current_mode = mode[0]\nupdated_connected_monitors = [[connector, current_mode, {}]]\n\nx, y, scale, transform, primary, monitors, props = logical_monitors[0]\nscale = 2.0 if scale == 1.0 else 1.0\n\nmonitor_config = [[x, y, scale, transform, primary, updated_connected_monitors]]\n\n# Change the 1 to a 2 if you want a "Revert Settings / Keep Changes" dialog\ninterface.ApplyMonitorsConfig(serial, 1, monitor_config, {})\n
Run Code Online (Sandbox Code Playgroud)\n