Fractional scaling with bash script

I would like to change the screen scaling (sometimes called fractional scaling) in Fedora Linux 42 Workstation from 100% to 175% using a keyboard shortcut. If the screen scaling is set to 175%, it should be reset to 100% using a keyboard shortcut (same as before). In other words, a toggle function.

I have created a bash script that only scales the font size. However, the scaling of image elements and dock is also desired.

#!/bin/bash

#Toggle scaling between 100% and 175%
current_scale=$(gsettings get org.gnome.desktop.interface text-scaling-factor)

if (( $(echo "$current_scale == 1.0" | bc -l) )); then
    # Aktuelle Skalierung ist 100%, wechsle zu 175%
    gsettings set org.gnome.desktop.interface text-scaling-factor 1.75
    notify-send "Bildschirm-Skalierung" "Auf 175% gesetzt" -i display
else
    # Aktuelle Skalierung ist nicht 100%, wechsle zu 100%
    gsettings set org.gnome.desktop.interface text-scaling-factor 1.0
    notify-send "Bildschirm-Skalierung" "Auf 100% gesetzt" -i display
fi

The GNOME version is 48, the window manager is Wayland.

Does anyone know how to change the fractional scaling in a bash script?

Thank you for your help

Hi and welcome to :fedora: !

It seems that the scaling is not stored in the dconf database, but rather configured via dbus. You might be able to use some xrandr commands in your script for this purpose.

Indeed, I came to the same conclusion. A trick for you to see that: run dconf watch /. Then perform the change in Settings, and you see that no keys are updated. Now, we need a trick to find out which dbus command may effectuate the setting…
xrandr most linkely will not work, because we are on Wayland here…

2 Likes

In this case, using D-Bus directly is difficult, see:

busctl --user monitor

Here’s an easier way that works for me:

sudo dnf install gnome-monitor-config
mkdir -p -Z ~/.local/bin
tee ~/.local/bin/monitor-scale-toggle << "EOF" > /dev/null
#!/usr/bin/awk -f
BEGIN{while("gnome-monitor-config list"|getline){
if(/^Monitor\s/&&!monitor){gsub(/.*\[\s|\s\].*/,"");monitor=$0}
if(/\sCURRENT$/&&!mode){gsub(/.*id:\s\x27|\x27.*/,"");mode=$0}
if(/^Logical\s/&&!scale){gsub(/.*\sscale\s=\s|,.*/,"");scale=$0}}
if(scale>=1.1){scale=1}else{scale=1.75}
system("gnome-monitor-config set -L -p -M "monitor" -m "mode" -s "scale)}
EOF
chmod +x ~/.local/bin/*

You may need to adjust the code for your setup.

2 Likes

you guys are great. your work is fantastic.
Thank you very much

1 Like