Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question
    
Just brainstorming: What about multi-monitor setups with different sizes? –  Vilmantas Baranauskas Jun 20 '12 at 12:16
    
It seems like using the screen size here is the wrong solution. Are there good screenshots of the windows where this is a problem? –  dobey Jun 20 '12 at 13:30
    

3 Answers 3

from gi.repository import Gdk
s = Gdk.Screen.get_default()
print s.get_width(), 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...

share|improve this answer
    
You actually need to poke at the Display rather than the Screen, for getting individual display sizes, IIRC. –  dobey Jun 20 '12 at 13:24

I would say what you want is the answer to the following question:

How big would a window be if it was maximized?

Because beside the multiple screen setup there are also other problems like the size of the top panel, bottom panels (no longer in Ubuntu, but maybe other distros), window decorators,... This is actually not handled by Gtk but by the window manager. So I don't see any way to get this number unless you let the windowmanager actually do the maximization.

Therefore the answer to this question is easy:

from gi.repository import Gtk, GObject
w = Gtk.Window()
w.maximize()
def p():
    print w.get_size()
GObject.timeout_add(1000, p)
w.show()
Gtk.main()

So you could create a window, maximize it and then start to populate it with reasonable sized widgets.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.