select certain monitor for going fullscreen with gtk
<p>I intend to change the monitor where I show a fullscreen window.
This is especially interesting when having a projector hooked up.</p>

<p>I've tried to use <a href="https://developer.gnome.org/gtk3/stable/GtkWindow.html#gtk-window-fullscreen-on-monitor" rel="nofollow"><code>fullscreen_on_monitor</code></a> but that doesn't produce any visible changes.</p>

<p>Here is a non-working example:</p>

<pre><code>#!/usr/bin/env python
import sys

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from gi.repository import Gdk

w = Gtk.Window()

screen = Gdk.Screen.get_default()
print ("Montors: %d" % screen.get_n_monitors())
if len(sys.argv) &gt; 1:
    n = int(sys.argv[1])
else:
    n = 0

l = Gtk.Button(label="Hello, %d monitors!" % screen.get_n_monitors())
w.add(l)
w.show_all()

w.fullscreen_on_monitor(screen, n)
l.connect("clicked", Gtk.main_quit)
w.connect("destroy", Gtk.main_quit)
Gtk.main()
</code></pre>

<p>I get to see the window on the very same monitor (out of 3), regardless of the value I provide.</p>

<p>My question is: how do I make the fullscreen window appear on a different monitor?</p>

<p>The problem seems to be that Gtk just ignores the monitor number, it will always fullscreen the window on the monitor on which the window currently is positioned. This sucks, but we can use that to make it work the way we want to.</p>

<p>But first some theory about multiple monitors, they aren't actually separate monitors for your pc. It considers them to collectively form one screen which share the same global origin. On that global screen each monitor has a origin relative to the global origin, just like windows. </p>

<p>Because we know that Gtk will always fullscreen on the monitor on which the window is we can simply move the window to the origin of the monitor using <code>window.move(x,y)</code> and then call <code>window.fullscreen()</code>. </p>

<p>(The <code>move</code> function will move the window to a position <code>(x,y)</code> relative to it's parent, which in the case of the main window is the global screen.)</p>

<p>Combining all this we get this, which works perfectly on Windows 10:</p>

<pre><code>def fullscreen_at_monitor(window, n):
    screen = Gdk.Screen.get_default()

    monitor_n_geo = screen.get_monitor_geometry(n)
    x = monitor_n_geo.x
    y = monitor_n_geo.y

    window.move(x,y)

    window.fullscreen()
</code></pre>

python gtk fullscreen gtk3