summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKim Woelders <kim@woelders.dk>2018-05-25 08:27:27 +0200
committerKim Woelders <kim@woelders.dk>2018-08-12 16:35:30 +0200
commitceebebe2b7d2f78317c96540bd4c42d02f63ab3c (patch)
tree1ebd9ae369bc5c88e7e1f064c5e1b93640539f71
parentabf858b222d46e97fc9c3107ec055e7c22bb3946 (diff)
Rewrite e_cb_key_change(), eliminating use of deprecated gdk_flush()
-rw-r--r--viewer.c57
1 files changed, 27 insertions, 30 deletions
diff --git a/viewer.c b/viewer.c
index e349e91..e96cc72 100644
--- a/viewer.c
+++ b/viewer.c
@@ -1,16 +1,12 @@
1#include "config.h" 1#include "config.h"
2 2
3#include <gtk/gtk.h>
4#include <ctype.h> 3#include <ctype.h>
5#include <locale.h> 4#include <locale.h>
6#include <stdio.h> 5#include <stdio.h>
7#include <stdlib.h> 6#include <stdlib.h>
8#include <string.h> 7#include <string.h>
9#include <sys/stat.h>
10#include <X11/Xlib.h>
11#include <X11/XKBlib.h>
12#include <gdk/gdkx.h> 8#include <gdk/gdkx.h>
13#include <unistd.h> 9#include <gtk/gtk.h>
14 10
15#include "e16keyedit.h" 11#include "e16keyedit.h"
16 12
@@ -277,6 +273,30 @@ clist_row_moveto(GtkWidget * widget, int row)
277} 273}
278 274
279static void 275static void
276on_popup_clicked(GtkWidget * win, GdkEventKey * ev)
277{
278 char *key;
279
280 key = gdk_keyval_name(ev->keyval);
281 gtk_entry_set_text(GTK_ENTRY(act_key), key);
282 clist_row_current_set_value(clist, 1, key);
283
284 gtk_widget_destroy(win);
285}
286
287static void
288on_popup_mapped(GtkWidget * win, gpointer data __UNUSED__)
289{
290#if USE_GTK == 2
291 gdk_keyboard_grab(gtk_widget_get_window(win), FALSE, GDK_CURRENT_TIME);
292#else
293 gdk_seat_grab(gdk_display_get_default_seat(gtk_widget_get_display(win)),
294 gtk_widget_get_window(win), GDK_SEAT_CAPABILITY_KEYBOARD,
295 FALSE, NULL, NULL, NULL, NULL);
296#endif
297}
298
299static void
280e_cb_key_change(GtkWidget * widget __UNUSED__, gpointer data __UNUSED__) 300e_cb_key_change(GtkWidget * widget __UNUSED__, gpointer data __UNUSED__)
281{ 301{
282 GtkWidget *win, *frame, *vbox, *label; 302 GtkWidget *win, *frame, *vbox, *label;
@@ -294,32 +314,9 @@ e_cb_key_change(GtkWidget * widget __UNUSED__, gpointer data __UNUSED__)
294 gtk_container_add(GTK_CONTAINER(vbox), label); 314 gtk_container_add(GTK_CONTAINER(vbox), label);
295 gtk_container_set_border_width(GTK_CONTAINER(vbox), 32); 315 gtk_container_set_border_width(GTK_CONTAINER(vbox), 32);
296 gtk_widget_show_all(win); 316 gtk_widget_show_all(win);
297 while (gtk_events_pending())
298 gtk_main_iteration();
299 gdk_flush();
300 while (gtk_events_pending())
301 gtk_main_iteration();
302 317
303 { 318 g_signal_connect(win, "map-event", G_CALLBACK(on_popup_mapped), NULL);
304 char *key; 319 g_signal_connect(win, "key-press-event", G_CALLBACK(on_popup_clicked), NULL);
305 XEvent ev;
306
307#define WIDGET_XID(widget) GDK_WINDOW_XID(gtk_widget_get_window(widget))
308 gdk_window_set_events(gtk_widget_get_window(win), GDK_KEY_PRESS_MASK);
309 XGrabKeyboard(gdk_x11_get_default_xdisplay(), WIDGET_XID(win),
310 False, GrabModeAsync, GrabModeAsync, CurrentTime);
311 XSetInputFocus(gdk_x11_get_default_xdisplay(), WIDGET_XID(win),
312 RevertToPointerRoot, CurrentTime);
313 XWindowEvent(gdk_x11_get_default_xdisplay(), WIDGET_XID(win),
314 KeyPressMask, &ev);
315 XUngrabKeyboard(gdk_x11_get_default_xdisplay(), CurrentTime);
316 key = XKeysymToString(XkbKeycodeToKeysym(gdk_x11_get_default_xdisplay(),
317 ev.xkey.keycode, 0, 0));
318 gtk_entry_set_text(GTK_ENTRY(act_key), key);
319 clist_row_current_set_value(clist, 1, key);
320 }
321
322 gtk_widget_destroy(win);
323} 320}
324 321
325static void 322static void