summaryrefslogtreecommitdiff
path: root/itches/emacs/pgtk-shift-space.c
diff options
context:
space:
mode:
authorKévin Le Gouguec <kevin.legouguec@gmail.com>2023-07-02 16:40:21 +0200
committerKévin Le Gouguec <kevin.legouguec@gmail.com>2023-07-02 16:40:21 +0200
commit26dd17feaa66b942fd2f1f582615041197c5e105 (patch)
treea66707713215fe66907cf4bb13bf6ddc49f7fa87 /itches/emacs/pgtk-shift-space.c
parent763bcd72998d58e69afaa25e231e807882f356ec (diff)
downloadmemory-leaks-26dd17feaa66b942fd2f1f582615041197c5e105.tar.xz
Add notes on the PGTK S-SPC vs SPC confusion
Diffstat (limited to 'itches/emacs/pgtk-shift-space.c')
-rw-r--r--itches/emacs/pgtk-shift-space.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/itches/emacs/pgtk-shift-space.c b/itches/emacs/pgtk-shift-space.c
new file mode 100644
index 0000000..dcfef21
--- /dev/null
+++ b/itches/emacs/pgtk-shift-space.c
@@ -0,0 +1,82 @@
+#include <stdio.h>
+
+#include <gtk/gtk.h>
+
+static gboolean show_key (
+ GtkWidget *widget,
+ GdkEventKey *event,
+ gpointer data
+) {
+ int mods[] = {GDK_SHIFT_MASK, GDK_CONTROL_MASK, GDK_MOD1_MASK};
+ char* mods_names[] = {"shift", "control", "alt"};
+ char mods_desc[64] = {'\0'};
+
+ for (size_t i=0; i<sizeof(mods)/sizeof(mods[0]); i++)
+ {
+ if (! (event->state & mods[i]))
+ continue;
+
+ if (mods_desc[0])
+ strcat(mods_desc, ":");
+
+ strcat(mods_desc, mods_names[i]);
+ }
+ if (! mods_desc[0])
+ strcpy(mods_desc, "∅");
+
+ fprintf(stderr, "key pressed: '%d' (mods: %s)\n", event->keyval, mods_desc);
+
+ if (gtk_im_context_filter_keypress ((GtkIMContext*)data, event))
+ fprintf(stderr, "\t(handled by gtkim)\n");
+
+ return TRUE;
+}
+
+static void show_commit (
+ GtkIMContext *ctx,
+ gchar *str,
+ gpointer data
+) {
+ fprintf(stderr, "\tcommitting: \"%s\"\n", str);
+}
+
+static void
+activate (GtkApplication* app,
+ gpointer user_data)
+{
+ GtkWidget *window;
+
+ window = gtk_application_window_new (app);
+ gtk_window_set_title (GTK_WINDOW (window), "Window");
+ gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
+ gtk_widget_show_all (window);
+
+ GtkIMContext *im_context = gtk_im_context_simple_new();
+ gtk_im_context_set_client_window(
+ im_context, gtk_widget_get_window(window)
+ );
+
+ gtk_widget_add_events (window, GDK_KEY_PRESS_MASK);
+
+ g_signal_connect (
+ G_OBJECT (window), "key_press_event", G_CALLBACK (show_key), im_context
+ );
+ g_signal_connect (
+ im_context, "commit", G_CALLBACK (show_commit), NULL
+ );
+}
+
+int
+main (int argc,
+ char **argv)
+{
+ GtkApplication *app;
+ int status;
+
+ app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
+ g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
+ status = g_application_run (G_APPLICATION (app), argc, argv);
+ g_object_unref (app);
+
+ return status;
+}