Where does GTK get its DPI from in X11?

I have noticed that X11 calculates its DPI per monitor. We can read that by querying xdpyinfo | grep -B2 resolution.
But this doesn’t seem to be propagated to GTK as GTK always have same DPI for all monitors.
So I was wondering where does GTK obtain its DPI settings from?
I was thinking maybe I can hook into this process somehow and have multi DPI settings for my monitors?
For example if GTK asks the WM the DPI I could patch the WM to return some hardcoded values depending on which monitor the window is in?

This was discussed a few times already:

1 Like

I found a different way to fix my problem. I only use either one of my laptop screen or external screen at a time. But I would switch between the two multiple times during a day.

So all I needed was to find a way to update DPI on the fly when I’m switching monitors.

Here’s a script that I made to help me do that while also tweaking a few non Gtk apps separately to scale correctly:

I’m using i3 WM, and not Gnome DE. So I have xsettingsd in the script instead of gnome-settings-daemon. If you are adapting this script for Gnome DE, you would need to change that accordingly.