Browse Source

Rewrite e_cb_key_change(), eliminating use of deprecated gdk_flush()

master
Kim Woelders 4 years ago
parent
commit
ceebebe2b7
  1. 57
      viewer.c

57
viewer.c

@ -1,16 +1,12 @@
#include "config.h"
#include <gtk/gtk.h>
#include <ctype.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <X11/Xlib.h>
#include <X11/XKBlib.h>
#include <gdk/gdkx.h>
#include <unistd.h>
#include <gtk/gtk.h>
#include "e16keyedit.h"
@ -276,6 +272,30 @@ clist_row_moveto(GtkWidget * widget, int row)
#endif
}
static void
on_popup_clicked(GtkWidget * win, GdkEventKey * ev)
{
char *key;
key = gdk_keyval_name(ev->keyval);
gtk_entry_set_text(GTK_ENTRY(act_key), key);
clist_row_current_set_value(clist, 1, key);
gtk_widget_destroy(win);
}
static void
on_popup_mapped(GtkWidget * win, gpointer data __UNUSED__)
{
#if USE_GTK == 2
gdk_keyboard_grab(gtk_widget_get_window(win), FALSE, GDK_CURRENT_TIME);
#else
gdk_seat_grab(gdk_display_get_default_seat(gtk_widget_get_display(win)),
gtk_widget_get_window(win), GDK_SEAT_CAPABILITY_KEYBOARD,
FALSE, NULL, NULL, NULL, NULL);
#endif
}
static void
e_cb_key_change(GtkWidget * widget __UNUSED__, gpointer data __UNUSED__)
{
@ -294,32 +314,9 @@ e_cb_key_change(GtkWidget * widget __UNUSED__, gpointer data __UNUSED__)
gtk_container_add(GTK_CONTAINER(vbox), label);
gtk_container_set_border_width(GTK_CONTAINER(vbox), 32);
gtk_widget_show_all(win);
while (gtk_events_pending())
gtk_main_iteration();
gdk_flush();
while (gtk_events_pending())
gtk_main_iteration();
{
char *key;
XEvent ev;
#define WIDGET_XID(widget) GDK_WINDOW_XID(gtk_widget_get_window(widget))
gdk_window_set_events(gtk_widget_get_window(win), GDK_KEY_PRESS_MASK);
XGrabKeyboard(gdk_x11_get_default_xdisplay(), WIDGET_XID(win),
False, GrabModeAsync, GrabModeAsync, CurrentTime);
XSetInputFocus(gdk_x11_get_default_xdisplay(), WIDGET_XID(win),
RevertToPointerRoot, CurrentTime);
XWindowEvent(gdk_x11_get_default_xdisplay(), WIDGET_XID(win),
KeyPressMask, &ev);
XUngrabKeyboard(gdk_x11_get_default_xdisplay(), CurrentTime);
key = XKeysymToString(XkbKeycodeToKeysym(gdk_x11_get_default_xdisplay(),
ev.xkey.keycode, 0, 0));
gtk_entry_set_text(GTK_ENTRY(act_key), key);
clist_row_current_set_value(clist, 1, key);
}
gtk_widget_destroy(win);
g_signal_connect(win, "map-event", G_CALLBACK(on_popup_mapped), NULL);
g_signal_connect(win, "key-press-event", G_CALLBACK(on_popup_clicked), NULL);
}
static void

Loading…
Cancel
Save