You are not logged in.

#1 2021-11-20 04:58:42

itsfarseen
Member
Registered: 2021-11-20
Posts: 1

Adjusting DPI on the fly for GTK and a bunch of other apps under X11.

TLDR;
If you have two different DPI screens (for ex: Laptop and external monitor) and you only use one at a time, 
use this script https://gist.github.com/itsfarseen/ae2a … 3e34ef2559

--

I have an external 4K 32" monitor and my laptop is 14" 1080P.
I tend to switch between the external monitor and my laptop multiple times during the day.
I would get up from my chair, disconnect the monitor, take my laptop to the bed and work from there for a while.

Because my monitor is further away from me than my laptop screen, I needed a larger font size on my monitor.
I thought in X11, DPI once set can't be changed without restarting the session.
Although there's an xrandr --dpi option, setting it seemed to have no effect.
Then I discovered Xft.dpi setting in Xresources.
I can set it in ~/.Xresources and do `xrdb -merge ~/.Xresources` or run `echo "Xft.dpi: 130" | xrdb -override -` to have it update without editing the file.
But this setting will only be picked up when you restart a Gtk app.

That's when I found out that Gtk apps, and even electron apps listen for an update signal from `gnome-settings-daemon`.
Then I found a lightweight alternative to gsd, `xsettingsd`. Now if I edit the DPI in `~/.xsettingsd` file and call `killall -HUP xsettingsd`,
it will read the new DPI and propagate it to all the running apps smile

That's what the script is mostly, plus it also adjusts the config file for apps that don't listen to this signal, but will autoreload on the fly if I edit their configs.
For example, alacritty and polybar.

It took me quite some time to figure out all these and I'm quite proud of the results smile

Thanks for reading,
Farseen

Offline

Board footer

Powered by FluxBB