Managing Windows Across Multiple Monitors with Python?

Discuss official and unofficial Compiz Development

Managing Windows Across Multiple Monitors with Python?

Postby detrate » Sun Jul 04, 2010 5:48 pm

I'm not really sure where to look for the answer for this. It seems to be a very specialized area of development. I'm trying to figure out what windows are on which monitor in my multi-head setup.

I found this great applet called DockbarX, which more or less emulates the Windows 7 Superbar. I like it better than the "Window List" applet in all ways except one. The way it handles dual monitors. DockbarX assumes one instance of itself and collects windows from the entire "X Screen". In my case, I'm using Nvidia TwinView, which defines both monitors as one "X Screen" and gives "hints" to the WM about drawing widnows. All of these tools (wnck, xrandr, xwminfo) are seeing both monitors as screen0 and do not seem to have any knowledge about these hints.

$ xprop -root #(truncated)
Code: Select all
_NET_NUMBER_OF_DESKTOPS(CARDINAL) = 1
_NET_CURRENT_DESKTOP(CARDINAL) = 0
_NET_DESKTOP_GEOMETRY(CARDINAL) = 7680, 2400
_NET_DESKTOP_VIEWPORT(CARDINAL) = 0, 1200


Here I can see I have 1 desktop (as defined by xorg) but I only have 4 viewports (2 x 1920x1200). I need to be able to differentiate the monitors.

I suppose a work around here would be to change my setup to xinerama but that would be going in the wrong direction. This should be possible with TwinView, I'm just not sure how.

The current code uses the wnck module which seems to be ignorant of multi monitors.

Thanks to the PyGTK docs, I was able to put together a proof of concept in distinguishing the monitors through code but I'm not sure how to create a list of window objects from it.

Code: Select all
#!/usr/bin/python
import gtk

screen = gtk.gdk.screen_get_default()
print screen.get_n_monitors()
print screen.get_monitor_geometry(0)


The above will get me proper output, (2 monitors, proper geometry for monitor 0) but the screen object is different than wnck's so I cannot just replace:

Code: Select all
self.screen = wnck.screen_get_default()

with
Code: Select all
self.screen = gtk.gdk.screen_get_default()


Any suggestions, hints or tips are very much appreciated. I had a hint that maybe I can use XineramaQueryScreens() somehow but I'm not really sure how'd I'd be able to do that without coding a c program that gets called by python (if that would even work). Also had a hint that maybe dbus could be used... but I still have the problem with being able to distinguish the difference in monitors.
detrate
Junior Member
 
Posts: 3
Joined: Thu Jan 07, 2010 3:41 am

Re: Managing Windows Across Multiple Monitors with Python?

Postby detrate » Tue Jul 06, 2010 11:31 pm

I've been able to figure out which monitor a window is on with python.

Code: Select all
#!/usr/bin/python
# Print some information about the X environment, the monitor setup, currently active window and cursor position
import gtk.gdk

screen = gtk.gdk.screen_get_default()
print "X default screen size: %d x %d" % (screen.get_width(), screen.get_height())
print "xid of root window: %d" % screen.get_root_window().xid

monitors = int(screen.get_n_monitors())
print "== %d monitors ==" % monitors
for m in range(0, monitors):
    print " - geometry of monitor %d: %s" % (m, screen.get_monitor_geometry(m))

window = screen.get_active_window()
win_x, win_y, win_w, win_h, win_bit_depth = window.get_geometry()
print "active window on monitor: %d" % screen.get_monitor_at_point((win_x+(win_w/2)),(win_y+(win_h/2)))
print "window geometry (x,y,w,h): %d, %d, %d, %d" % (win_x,win_y,win_w,win_h)

display = gtk.gdk.display_get_default()
pointer = display.get_pointer()
print "cursor position (x, y): %d, %d" % (pointer[1], pointer[2])
print "cursor on monitor: %d" % screen.get_monitor_at_point(pointer[1],pointer[2])


However, I think this is a change that should really be handled in the X layer (via virtual trees), compiz or extending libwnck to understand monitors. Which are all probably beyond my expertise.
detrate
Junior Member
 
Posts: 3
Joined: Thu Jan 07, 2010 3:41 am


Return to Compiz Development

Who is online

Users browsing this forum: No registered users and 1 guest