memory-leaks

Still reachable: lots of words in many pages.
git clone https://git.kevinlegouguec.net/memory-leaks
Log | Files | Refs | README | LICENSE

pgtk-shift-space.c (2027B)


      1 /* -*- compile-command: "gcc -g $(pkg-config --cflags gtk+-3.0) pgtk-shift-space.c $(pkg-config --libs gtk+-3.0)" -*- */
      2 #include <stdio.h>
      3 
      4 #include <gtk/gtk.h>
      5 
      6 static gboolean
      7 show_key (GtkWidget *widget, GdkEventKey *event, gpointer data)
      8 {
      9   const int mods[] = {GDK_SHIFT_MASK, GDK_CONTROL_MASK, GDK_MOD1_MASK};
     10   char const * const mods_names[] = {"shift", "control", "alt"};
     11 
     12   fprintf(stderr, "press:\t'%d'", event->keyval);
     13 
     14   for (size_t i=0; i<sizeof(mods)/sizeof(mods[0]); i++)
     15     if (event->state & mods[i])
     16       fprintf(stderr, " +%s", mods_names[i]);
     17 
     18   fprintf(stderr, "\n");
     19 
     20   if (gtk_im_context_filter_keypress (data, event))
     21     fprintf(stderr, "handled by gtkim\n");
     22 
     23   fprintf(stderr, "\n");
     24 
     25   return TRUE;
     26 }
     27 
     28 static void
     29 show_commit (GtkIMContext *ctx, gchar *str, gpointer data)
     30 {
     31   fprintf(stderr, "commit: \"%s\"\n", str);
     32 }
     33 
     34 static void
     35 activate (GtkApplication *app, gpointer user_data)
     36 {
     37   GtkWidget *window;
     38 
     39   window = gtk_application_window_new (app);
     40   gtk_window_set_title (GTK_WINDOW (window), "GTK key scratchpad");
     41   gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
     42   gtk_widget_show_all (window);
     43 
     44   GtkIMContext *im_context = gtk_im_context_simple_new();
     45   gtk_im_context_set_client_window(im_context, gtk_widget_get_window(window));
     46 
     47   gtk_widget_add_events (window, GDK_KEY_PRESS_MASK);
     48 
     49   g_signal_connect (G_OBJECT (window), "key_press_event", G_CALLBACK (show_key),    im_context);
     50   g_signal_connect (im_context,        "commit",          G_CALLBACK (show_commit), NULL);
     51 }
     52 
     53 int
     54 main (int argc, char **argv)
     55 {
     56   GtkApplication *app;
     57   int status;
     58 
     59   app = gtk_application_new ("org.gtk.key-scratchpad",
     60 #if GLIB_CHECK_VERSION(2, 74, 0)
     61                              G_APPLICATION_DEFAULT_FLAGS
     62 #else
     63                              G_APPLICATION_FLAGS_NONE
     64 #endif
     65                              );
     66   g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
     67   status = g_application_run (G_APPLICATION (app), argc, argv);
     68   g_object_unref (app);
     69 
     70   return status;
     71 }