/* Compile me with:
 * $ gcc $(pkg-config --libs --cflags gtk+-3.0) -o bug_ctrl_space_1 bug_ctrl_space_1.c
 */

#include <gtk/gtk.h>
#include <glib/gprintf.h>

static void
on_select_all (GtkTextView *text_view,
               gboolean     select,
               gpointer     user_data)
{
  g_printf ("select all\n");
}

int
main (int argc, char *argv[])
{
  GtkWidget *window;
  GtkWidget *text_view;
  GtkBindingSet *binding_set;
  guint accel_key;
  GdkModifierType accel_mods;

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  g_signal_connect (G_OBJECT (window),
                    "destroy",
                    G_CALLBACK (gtk_main_quit),
                    NULL);

  gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);

  text_view = gtk_text_view_new ();
  gtk_container_add (GTK_CONTAINER (window), text_view);

  /* Choose the "select-all" signal for the test */
  g_signal_connect (G_OBJECT (text_view),
                    "select-all",
                    G_CALLBACK (on_select_all),
                    NULL);

  /* If there is a warning, then gtk_accelerator_parse() is buggy.
   * But it's not the case, there is no warning.
   */

  gtk_accelerator_parse ("<Control>space", &accel_key, &accel_mods);

  if (accel_key != GDK_KEY_space)
    g_warning ("bad accel_key: %u", accel_key);

  if (accel_mods != GDK_CONTROL_MASK)
    g_warning ("bad accel_mods");

  /* Emit the "select-all" signal on Ctrl+space.
   * There is no bug with the fr-oss layout, if we type a space, the signal is
   * not emitted.
   */

  binding_set = gtk_binding_set_find ("GtkTextView");

  gtk_binding_entry_add_signal (binding_set,
                                accel_key, accel_mods,
                                "select-all", 1,
                                G_TYPE_BOOLEAN, TRUE);

  gtk_widget_show_all (window);
  gtk_main ();
  return 0;
}
