4

I'm using Python PyGTK library on OS Linux based (suse, ubuntu) Working on devices with multiple Display Monitors.

I'm trying to put a Full Screen Window (in python, gtk.Window) on a Specific Display monitor connected to the Device.

I'm using the following code:

n_monitors = gtk.gdk.Screen.get_n_monitors()  # Get number of monitors. 
gtk.gdk.Screen.get_monitor_geometry(*monitor_number*)  # Get the size of a specific monitor. 

The second api returns the monitor size and offset information. gtk.Window.move(offset_x, offse_y) can be used for moving a window on a specific monitor.

Though this doesn't seem to work all the time. It looks like the window has an affinity to the mouse location or if the monitor resolutions are not the same this does not work.

Is there any property of the gtk.Window which would help mitigate this issue. I tried playing with following which didn't help :

gtk.Window.set_position(gtk.WIN_POS_NONE)
gtk.Window.set_gravity(gtk.gdk.GRAVITY_NORTH_WEST)

Any ideas.

Feru
  • 1,151
  • 2
  • 12
  • 23

1 Answers1

6

Your monitors collectively form one screen. You can query a screen to find out about its monitors. You can then position your window on a given monitor by ofsetting the window's (x,y) with that of the monitor.

Assuming your window is window, you can get the screen like this

screen = window.get_screen()

and then get the monitor data like this

monitors = []
for m in range(screen.get_n_monitors())
  monitors.append(screen.get_monitor_geometry(m)

monitors are numbers 0,1,2,... You can get the current monitor, if you need to, like this:

screen.get_monitor_at_window(screen.get_active_window())

To position a window on a monitor, you add the monitor's (x,y) to the window's (x,y). Calculate those x,y values and then move the window:

window.move(x,y)

See a similar answer I provided here.

Community
  • 1
  • 1
starfry
  • 9,273
  • 7
  • 66
  • 96
  • Thanks for answering starfry. I'll look into what you are suggesting and let you know the result. – Feru May 13 '14 at 14:17