How to detect a computer's physical screen size in GTK

from gi.repository import Gdk
s = Gdk.Screen.get_default()
print(s.get_width())
print(s.get_height())

Of course, if you have multiple screens, this gives the size of a rectangle enclosing them both. This stuff is harder than it sounds, in a world with multiple screens in it...


Here is what I came up with:

from gi.repository import Gdk, Gtk

# Replace w with the GtkWindow of your application
w = Gtk.Window()
# Get the screen from the GtkWindow
s = w.get_screen()
# Using the screen of the Window, the monitor it's on can be identified
m = s.get_monitor_at_window(s.get_active_window())
# Then get the geometry of that monitor
monitor = s.get_monitor_geometry(m)
# This is an example output
print("Heigh: %s, Width: %s" % (monitor.height, monitor.width))

I'm not sure that would be called 'standard,' but I hope that it helps.