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

#2 2022-03-15 19:06:29

ThinkPad
Member
Registered: 2019-01-29
Posts: 125

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

`echo "Xft.dpi: 130" | xrdb -override -` is a really neat solution! Thanks!

It's not exactly "on-the-fly" as it requires restarting the apps to take effect. Have you found a truly on-the-fly, immediate solution?

Offline

#3 2022-06-15 11:16:41

brtsos
Member
Registered: 2022-06-15
Posts: 2

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

Hi Farseen!
I registered hier only to say you - thanks you smile That is a very good script and xsettingsd trick should be on HiDPI documentation site wink

Offline

#4 2022-06-15 13:08:24

2ManyDogs
Forum Fellow
Registered: 2012-01-15
Posts: 4,645

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

The OP has not been back since last November, so I am going to consider this thread abandoned and close it.

Offline

Board footer

Powered by FluxBB