[pygtk] How to get window decoration sizes?

Jason Grant expires07 at logular.com
Sat Nov 15 13:59:31 WST 2008


Hi,

There has been a bug for some time relating to wnck set_geometry() not
placing windows as specified.  (See my post in June
"wnck.window.set_geometry() misbehaving" and gnome bug 518606).

Alas, this bug still remains, and so as a work-around, I need to
determine the width/height of the decorations surrounding a window.  I
am new to python and GTK, and it is not clear to me how to make a query
for these sizes.

I'm including my code below that illustrates how the new geometry
differs from the requested geometry.

Thanks for any tips,

Jason.

==========================

The following little program prints:

Requested: 1, 50, 550, 250
New      : 4, 71, 548, 246

==========================

pygtk.require('2.0')
import gtk
import gobject
import wnck

class WindowPlacer:

    def report(self, screen):
      # Compare new geometry with requested geometry
      window=screen.get_active_window()
      geom = window.get_geometry()
      print "New     : " + repr(geom[0]) + ", " + repr(geom[1]) + ", " + repr(geom[2]) + ", " + repr(geom[3])

      # Quit the main loop
      gtk.main_quit()

    def place(self, screen):
      window=screen.get_active_window()

      # Indicate that we want to change all geometry params
      flags=wnck.WINDOW_CHANGE_X  | wnck.WINDOW_CHANGE_Y | wnck.WINDOW_CHANGE_WIDTH | wnck.WINDOW_CHANGE_HEIGHT

      # Set the geometry, flush pending events, and force an update
      left=1
      top=50
      width=550
      height=250
      window.set_geometry(wnck.WINDOW_GRAVITY_NORTHWEST, flags, left, top, width, height)
      print "Requested: " + repr(left) + ", " + repr(top) + ", " + repr(width) + ", " + repr(height)

      # Quit the main loop
      gtk.main_quit()
    
    def main(self):
      # register a callback to be invoked when main loop is idle
      screen=wnck.screen_get_default()
      gobject.idle_add(self.place, screen)
      gtk.main()
      screen.force_update()
      # while gtk.events_pending() : gtk.main_iteration()
      gobject.idle_add(self.report, screen)
      gtk.main()

# This is the entry point if we are invoked on the command-line
if __name__ == "__main__":
  windowPlacer = WindowPlacer()
  windowPlacer.main()



More information about the pygtk mailing list