using Gtk;

int main (string[] args) {
    Gtk.init (ref args);

    var window = new Window ();
    window.title = "Gtk Present test";
    window.border_width = 10;
    window.window_position = WindowPosition.CENTER;
    window.set_default_size (350, 70);
    window.destroy.connect (Gtk.main_quit);

    var cb_hack = new CheckButton.with_label("Use user time hack!");
    cb_hack.active = false;

    var button = new Button.with_label ("Present me every 2 seconds!");
    button.clicked.connect (() => {
        button.label = "Presenting every 2 seconds...";
        button.set_sensitive(false);

        Timeout.add (2000, () => {
            var server_time = Gdk.x11_get_server_time (window.get_window());
            var display_time = Gdk.X11Display.get_user_time (Gdk.Display.get_default());

            message(@"Presenting with hack: $(cb_hack.get_active()), server time: $server_time, display time: $display_time");

            if (cb_hack.get_active()) {
                window.present_with_time(server_time);
            } else {
                // By default GTK uses the display time, so it's like presenting with time display_time
                window.present();
            }

            return true;
        });
    });

    var box = new Box(Orientation.VERTICAL, 5);
    box.add (button);
    box.add (cb_hack);
    window.add (box);
    window.show_all ();

    Gtk.main ();
    return 0;
}