Ubuntu – How to detect a computer’s physical screen size in GTK

application-developmentgtkpython

I've come across this bug while writing my app. In short, the app's window size is fixed, which does not work well with smaller screens such as in netbooks.

In those, the lower buttons are off the screen limits and cannot be used. I'd like to take this into account in the user interface, but first of all, I'd like to find out what the standard way to detect screen size is in GTK, if there is one.

So does anyone have any ideas on how to do that?

Best Answer

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...