From 91ca0d2cf669881f40a71c2ec9f05b7e5caba509 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Tue, 1 Jan 2013 08:22:46 -0800 Subject: First step towards grabbing keys and handling them ourselves This commit steals the cursor up and down keys away from gtk so regardless where gtk thinks the focus may be, we can still use the keys to change between dives. In the current UI design where all editing happens in separate windows this works as expected, as we only grab the keys for the main window. If we manage to re-enable in-place editing then we need to make sure that this doesn't cause problems (as gtk uses up/down for the ability to change drop down selections in combo boxes or values in spin buttons. So we must make sure that we stop stealing these keys once we start editing something (in which case simply switching to the next/prev dive wouldn't be a good thing, anyway). Signed-off-by: Dirk Hohndel --- gtk-gui.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'gtk-gui.c') diff --git a/gtk-gui.c b/gtk-gui.c index a6ed46942..f241fd313 100644 --- a/gtk-gui.c +++ b/gtk-gui.c @@ -5,6 +5,7 @@ */ #include #include +#include #include #include #include @@ -1130,6 +1131,21 @@ static void switch_page(GtkNotebook *notebook, gint arg1, gpointer user_data) repaint_dive(); } +static gboolean on_key_press(GtkWidget *w, GdkEventKey *event, GtkWidget *divelist) +{ + if (event->type != GDK_KEY_PRESS) + return FALSE; + switch (event->keyval) { + case GDK_KEY_Up: + select_prev_dive(); + return TRUE; + case GDK_KEY_Down: + select_next_dive(); + return TRUE; + } + return FALSE; +} + void init_ui(int *argcp, char ***argvp) { GtkWidget *win; @@ -1325,6 +1341,9 @@ void init_ui(int *argcp, char ***argvp) nb_page = total_stats_widget(); gtk_notebook_append_page(GTK_NOTEBOOK(notebook), nb_page, gtk_label_new(_("Stats"))); + /* handle some keys globally (to deal with gtk focus issues) */ + g_signal_connect (G_OBJECT (win), "key_press_event", G_CALLBACK (on_key_press), dive_list); + gtk_widget_set_app_paintable(win, TRUE); gtk_widget_show_all(win); -- cgit v1.2.3-70-g09d2