#!/usr/bin/python
from __future__ import print_function
import gi
import os
import sys

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

Gtk.init()
Gdk.Rectangle.__repr__ = lambda r: "{0.width}x{0.height}+{0.x}+{0.y}".format(r)

def printscreen():
    s = Gdk.Screen.get_default()
    print("Screen: {}x{}".format(s.get_width(), s.get_height()))

    r = s.get_root_window()
    print("RootWindow: {!r}".format(r.get_geometry()))

    d = Gdk.Display.get_default()
    for i in range(d.get_n_monitors()):
        m = d.get_monitor(i)
        print("Monitor {}: {!r} scale {} workarea {!r}".
                format(i, m.get_geometry(), m.get_scale_factor(), m.get_workarea()))

printscreen()

if len(sys.argv) == 2:
    monitor_name = sys.argv[1]

    os.system("xrandr --output {} --reflect y".format(monitor_name))
    os.system("xrandr --output {} --reflect normal".format(monitor_name))

    mc = GLib.MainContext.default()
    while mc.iteration(False):
        pass

    printscreen()
