#!/usr/bin/python3 -u

# Copyright (C) 2013, Daniel Narvaez
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

import argparse

import gi
gi.require_version('SugarRunner', '1.0')
from gi.repository import SugarRunner

xid_printed = False

parser = argparse.ArgumentParser(description="A window for Xephyr")
parser.add_argument("--resolution", help="screen resolution")
args = parser.parse_args()

if args.resolution:
    width, height = args.resolution.strip().split("x")
    fullscreen = False
else:
    width, height = 1, 1
    fullscreen = True

SugarRunner.window_create(int(width), int(height), fullscreen)

while SugarRunner.window_wait():
    if not fullscreen or SugarRunner.window_is_fullscreen():
        if not xid_printed:
            print (SugarRunner.window_get_xid())
            xid_printed = True
