#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <glib.h>

static void
main_window_destroy(GtkAccelGroup *group, GObject *acceleratable,
    guint keyval, GdkModifierType modifier, gpointer user_data)
{
  gtk_widget_destroy(GTK_WIDGET(user_data));
}

void
main_window_bind_keys(GtkWidget *window)
{
  GtkAccelGroup *group = gtk_accel_group_new();

  GClosure *closure = g_cclosure_new(G_CALLBACK(main_window_destroy), window, NULL);
  gtk_accel_group_connect(group, GDK_KEY_q, GDK_CONTROL_MASK, 0, closure);

  gtk_window_add_accel_group(GTK_WINDOW(window), group);
}

GtkWidget *
main_window_create()
{
  GtkWidget *window;

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title(GTK_WINDOW(window), "ghighlighter");

  main_window_bind_keys(window);

  g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

  return window;
}

#include <gtk/gtk.h>

GtkWidget *
main_window_create()
{
  GtkWidget *window;

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title(GTK_WINDOW(window), "ghighlighter");

  g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

  return window;
}

--- 
+++ 
@@ -1,4 +1,24 @@
 #include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
+#include <glib.h>
+
+static void
+main_window_destroy(GtkAccelGroup *group, GObject *acceleratable,
+    guint keyval, GdkModifierType modifier, gpointer user_data)
+{
+  gtk_widget_destroy(GTK_WIDGET(user_data));
+}
+
+void
+main_window_bind_keys(GtkWidget *window)
+{
+  GtkAccelGroup *group = gtk_accel_group_new();
+
+  GClosure *closure = g_cclosure_new(G_CALLBACK(main_window_destroy), window, NULL);
+  gtk_accel_group_connect(group, GDK_KEY_q, GDK_CONTROL_MASK, 0, closure);
+
+  gtk_window_add_accel_group(GTK_WINDOW(window), group);
+}
 
 GtkWidget *
 main_window_create()
@@ -8,6 +28,8 @@
   window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   gtk_window_set_title(GTK_WINDOW(window), "ghighlighter");
 
+  main_window_bind_keys(window);
+
   g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
 
   return window;
Destroy main window on Ctrl+q
