I’d like to know how to do it in both GTK3 and GTK4, please.
What I’m looking for is to get notified when the user clicks on the different scale factor in the Settings → Display panel, or move the application window to a different monitor that is HighDPI or back.
Use the GObject::notify signal for those properties to get notifications.
In general, what you’re asking is entirely immaterial: GTK will take care of it for you, and adjust all the coordinates and sizes depending on the scale factor from the system. The only time you have to care is if you’re dealing with direct OpenGL rendering.