[Freeciv-Dev] (PR#10767) Keyboard shorcuts stop working
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=10767 >
This should fix it once and for all.
Index: client/gui-gtk-2.0/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/gui_main.c,v
retrieving revision 1.90
diff -u -r1.90 gui_main.c
--- client/gui-gtk-2.0/gui_main.c 14 Nov 2004 00:35:06 -0000 1.90
+++ client/gui-gtk-2.0/gui_main.c 14 Nov 2004 16:44:13 -0000
@@ -219,19 +219,6 @@
}
/**************************************************************************
- handles main window keyboard events.
-**************************************************************************/
-static gboolean inputline_focus(GtkWidget *w, GdkEventFocus *ev, gpointer data)
-{
- if (GPOINTER_TO_INT(data) != 0) {
- gtk_window_remove_accel_group(GTK_WINDOW(toplevel), toplevel_accel);
- } else {
- gtk_window_add_accel_group(GTK_WINDOW(toplevel), toplevel_accel);
- }
- return FALSE;
-}
-
-/**************************************************************************
...
**************************************************************************/
static gboolean toplevel_focus(GtkWidget *w, GtkDirectionType arg)
@@ -294,6 +281,34 @@
}
/**************************************************************************
+ In GTK+ keyboard events are recursively propagated from the hierarchy
+ parent down to its children. Sometimes this is not what we want.
+ E.g. The inputline is active, the user presses the 's' key, we want it
+ to be sent to the inputline, but because the main menu is further up
+ the hierarchy, it wins and the inputline never gets anything!
+ This function ensures an entry widget (like the inputline) always gets
+ first dibs at handling a keyboard event.
+**************************************************************************/
+static gboolean toplevel_handler(GtkWidget *w, GdkEventKey *ev, gpointer data)
+{
+ GtkWidget *focus;
+
+ focus = gtk_window_get_focus(GTK_WINDOW(toplevel));
+ if (focus) {
+ if (GTK_IS_ENTRY(focus)) {
+ /* Propagate event to currently focused entry widget. */
+ if (gtk_widget_event(focus, (GdkEvent *) ev)) {
+ /* Do not propagate event to our children. */
+ return TRUE;
+ }
+ }
+ }
+
+ /* Continue propagating event to our children. */
+ return FALSE;
+}
+
+/**************************************************************************
...
**************************************************************************/
static gboolean keyboard_handler(GtkWidget *w, GdkEventKey *ev, gpointer data)
@@ -957,14 +972,8 @@
inputline = gtk_entry_new();
gtk_box_pack_start(GTK_BOX(vbox), inputline, FALSE, FALSE, 3);
- g_signal_connect(inputline, "activate", G_CALLBACK(inputline_return), NULL);
-
- g_signal_connect(inputline, "focus_in_event",
- G_CALLBACK(inputline_focus), GINT_TO_POINTER(1));
-
- g_signal_connect(inputline, "focus_out_event",
- G_CALLBACK(inputline_focus), GINT_TO_POINTER(0));
-
+ g_signal_connect(inputline, "activate",
+ G_CALLBACK(inputline_return), NULL);
g_signal_connect(inputline, "key_press_event",
G_CALLBACK(inputline_handler), NULL);
@@ -1040,6 +1049,9 @@
}
toplevel = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ g_signal_connect(toplevel, "key_press_event",
+ G_CALLBACK(toplevel_handler), NULL);
+
gtk_window_set_role(GTK_WINDOW(toplevel), "toplevel");
gtk_widget_realize(toplevel);
gtk_widget_set_name(toplevel, "Freeciv");
|
|