#include <gtk/gtk.h>

static gboolean
key_press_event_cb (GtkWidget *widget,
    GdkEventKey *event,
    gpointer user_data);

static gboolean fullscreen;

void
toggle_fullscreen (GtkWidget *widget)
{
  fullscreen = !fullscreen;

  if (fullscreen)
    gtk_window_fullscreen (GTK_WINDOW (widget));
  else
    gtk_window_unfullscreen (GTK_WINDOW (widget));
}

static gboolean
key_press_event_cb (GtkWidget *widget,
    GdkEventKey *event,
    gpointer user_data)
{
  if (event->keyval == GDK_KEY_F11)
    {
      toggle_fullscreen (widget);
    }
  else if (event->keyval == GDK_KEY_Escape && fullscreen)
    {
      fullscreen = FALSE;
      gtk_window_unfullscreen (GTK_WINDOW (widget));
    }
  else if (event->keyval == GDK_KEY_q && (event->state & GDK_CONTROL_MASK))
    {
      gtk_main_quit ();
    }

  return FALSE;
}

int
main (int argc, char *argv[])
{
  GtkWidget *window;

  gtk_init (&argc, &argv);

  fullscreen = TRUE;
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_fullscreen (GTK_WINDOW (window));

  g_signal_connect (window, "destroy",
      G_CALLBACK (gtk_main_quit), NULL);
  g_signal_connect (window, "key-press-event",
      G_CALLBACK (key_press_event_cb), NULL);

  gtk_widget_show (window);

  gtk_main ();

  return 0;
}
