A small Python script to set display scaling on GNOME/Mutter via D-Bus — no GUI needed.
If you run Ubuntu in a VM (particularly UTM/QEMU on macOS), spice-vdagent likes to reset your display scaling whenever the resolution changes — e.g. when you resize the VM window. This script sets it back to 200% from the command line by calling Mutter's DisplayConfig D-Bus API directly, the same API that GNOME Settings uses.
python3 fix_scale.pyNo dependencies beyond python3-dbus, which ships with Ubuntu by default.
# Add an alias
echo 'alias fixdpi="python3 ~/fix_scale.py"' >> ~/.bashrcmkdir -p ~/.config/autostart
cat > ~/.config/autostart/fix-scale.desktop << 'EOF'
[Desktop Entry]
Type=Application
Name=Fix HiDPI Scale
Exec=/bin/bash -c "sleep 3 && python3 /path/to/fix_scale.py"
X-GNOME-Autostart-enabled=true
EOFThe sleep 3 gives spice-vdagent time to do its thing before we override it.
- Connects to Mutter's
org.gnome.Mutter.DisplayConfigD-Bus interface - Reads the current display state (resolution, mode, connected monitors)
- Reapplies the current configuration with scale forced to
2.0
The script reads the current resolution dynamically, so it works regardless of what resolution UTM/SPICE has set.
Edit this line in fix_scale.py:
dbus.Double(2.0), # change to 1.0, 1.5, etc.Supported values depend on your display — run the debug snippet below to check.
To inspect your current display state:
#!/usr/bin/env python3
import dbus
bus = dbus.SessionBus()
proxy = bus.get_object("org.gnome.Mutter.DisplayConfig",
"/org/gnome/Mutter/DisplayConfig")
iface = dbus.Interface(proxy, "org.gnome.Mutter.DisplayConfig")
serial, physical_monitors, logical_monitors, properties = iface.GetCurrentState()
for pm in physical_monitors:
connector = pm[0][0]
print(f"Connector: {connector}")
for mode in pm[1]:
if mode[6].get("is-current", False):
print(f" Current mode: {mode[0]} ({mode[1]}x{mode[2]} @ {mode[3]:.2f}Hz)")
print(f" Supported scales: {list(mode[5])}")
for x, y, scale, transform, primary, linked, props in logical_monitors:
print(f" Scale: {scale}, Primary: {primary}")- Ubuntu 24.04 (GNOME/Wayland) running in UTM on macOS