我正在运行 Ubuntu 23.10,有时喜欢使用 100% 显示缩放,有时喜欢使用 125% 缩放。如果可能的话,我希望能够使用键盘快捷键在两者之间切换。
我尝试gsettings list-recursively > before
通过“设置”菜单执行更新缩放设置,然后执行gsettings list-recursively > after
并对文件进行差异分析,两个文件似乎相同。这让我想到缩放设置必须在其他地方存储/管理。
是否有人知道是否可以在不通过设置菜单的情况下更改缩放设置?
答案1
编辑:以下方法用于更改文本(字体)缩放比例,而不是屏幕缩放比例。但是,我保留此答案,以防它对其他人有所帮助。
将以下脚本放入文件中,例如~/binb/tog_scale.sh
:
#!/bin/bash
if [[ "$(gsettings get org.gnome.desktop.interface text-scaling-factor)" != "1.0" ]] ; then
gsettings reset org.gnome.desktop.interface text-scaling-factor
else
gsettings set org.gnome.desktop.interface text-scaling-factor 1.25
fi
使文件可执行:
chmod +x ~/binb/tog_scale.sh
然后,转到gnome-control-center
→键盘→键盘快捷键→(在窗口底部)查看和自定义快捷方式 → (底部)自定义快捷方式→+并输入以下内容:
姓名:tog_scale
命令: binb/tog_scale.sh
捷径:您喜欢的任意组合,例如Ctrl+ Alt+ V。
之后,您可以使用键盘快捷键在两种缩放比例之间切换。
答案2
我改编了上面 FedKad 链接的脚本:
#!/usr/bin/python3
# https://dbus.freedesktop.org/doc/dbus-python/tutorial.html
# https://github.com/GNOME/mutter/blob/b5f99bd12ebc483e682e39c8126a1b51772bc67d/data/dbus-interfaces/org.gnome.Mutter.DisplayConfig.xml
# https://discussion.fedoraproject.org/t/change-scaling-resolution-of-primary-monitor-from-bash-terminal/19892
import dbus
bus = dbus.SessionBus()
display_config_well_known_name = "org.gnome.Mutter.DisplayConfig"
display_config_object_path = "/org/gnome/Mutter/DisplayConfig"
display_config_proxy = bus.get_object(display_config_well_known_name, display_config_object_path)
display_config_interface = dbus.Interface(display_config_proxy, dbus_interface=display_config_well_known_name)
serial, physical_monitors, logical_monitors, properties = display_config_interface.GetCurrentState()
updated_logical_monitors=[]
for x, y, scale, transform, primary, linked_monitors_info, props in logical_monitors:
physical_monitors_config = []
print(scale)
new_scale = 1.25 if scale == 1 else 1
for linked_monitor_connector, linked_monitor_vendor, linked_monitor_product, linked_monitor_serial in linked_monitors_info:
for monitor_info, monitor_modes, monitor_properties in physical_monitors:
monitor_connector, monitor_vendor, monitor_product, monitor_serial = monitor_info
if linked_monitor_connector == monitor_connector:
for mode_id, mode_width, mode_height, mode_refresh, mode_preferred_scale, mode_supported_scales, mode_properties in monitor_modes:
if mode_properties.get("is-current", False): # ( mode_properties provides is-current, is-preferred, is-interlaced, and more)
physical_monitors_config.append(dbus.Struct([monitor_connector, mode_id, {}]))
# print(linked_monitor_connector)
# reset x for single monitor
# if linked_monitor_connector == 'HDMI-2':
# x = 0
updated_logical_monitor_struct = dbus.Struct([dbus.Int32(x), dbus.Int32(y), dbus.Double(new_scale), dbus.UInt32(transform), dbus.Boolean(primary), physical_monitors_config])
updated_logical_monitors.append(updated_logical_monitor_struct)
properties_to_apply = { "layout_mode": properties.get("layout-mode")}
method = 1 # 2 means show a prompt before applying settings; 1 means instantly apply settings without prompt
display_config_interface.ApplyMonitorsConfig(dbus.UInt32(serial), dbus.UInt32(method), updated_logical_monitors, properties_to_apply)
对于我的用例,我使用三元表达式来决定新的比例:
new_scale = 1.25 if scale == 1 else 1
如果当前比例为 1,则此操作将比例更改为 1.25;如果比例不是 1,则此操作将比例更改为 1。