summaryrefslogtreecommitdiffstats
path: root/gtk-gui.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-01-01 10:29:18 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-01-01 10:29:18 -0800
commit1c72d90b37d5f362a262a521a86f5b089daf8e62 (patch)
treef538622add1f7a6b40f3865b1293871658a8b69d /gtk-gui.c
parentc2e003975e4d11dbfda032a2d8e0386f75b3cde2 (diff)
parent8f364d0094aa0c2999708dca0e1ac6fefed67837 (diff)
downloadsubsurface-1c72d90b37d5f362a262a521a86f5b089daf8e62.tar.gz
Merge branch 'updown'
Bring in the keyboard handling change
Diffstat (limited to 'gtk-gui.c')
-rw-r--r--gtk-gui.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/gtk-gui.c b/gtk-gui.c
index a6ed46942..2b9068681 100644
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -5,6 +5,7 @@
*/
#include <libintl.h>
#include <glib/gi18n.h>
+#include <gdk/gdkkeysyms.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -1020,6 +1021,13 @@ static void toggle_zoom(GtkWidget *w, gpointer data)
repaint_dive();
}
+static void prev_dc(GtkWidget *w, gpointer data)
+{
+ dc_number--;
+ /* If the dc number underflows, we'll "wrap around" and use the last dc */
+ repaint_dive();
+}
+
static void next_dc(GtkWidget *w, gpointer data)
{
dc_number++;
@@ -1052,7 +1060,8 @@ static GtkActionEntry menu_items[] = {
{ "ViewProfile", NULL, N_("Profile"), CTRLCHAR "2", NULL, G_CALLBACK(view_profile) },
{ "ViewInfo", NULL, N_("Info"), CTRLCHAR "3", NULL, G_CALLBACK(view_info) },
{ "ViewThree", NULL, N_("Three"), CTRLCHAR "4", NULL, G_CALLBACK(view_three) },
- { "NextDC", NULL, N_("Next DC"), CTRLCHAR "C", NULL, G_CALLBACK(next_dc) },
+ { "PrevDC", NULL, N_("Prev DC"), NULL, NULL, G_CALLBACK(prev_dc) },
+ { "NextDC", NULL, N_("Next DC"), NULL, NULL, G_CALLBACK(next_dc) },
};
static gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);
@@ -1094,6 +1103,7 @@ static const gchar* ui_string = " \
<menuitem name=\"Profile\" action=\"ViewProfile\" /> \
<menuitem name=\"Info\" action=\"ViewInfo\" /> \
<menuitem name=\"Paned\" action=\"ViewThree\" /> \
+ <menuitem name=\"PrevDC\" action=\"PrevDC\" /> \
<menuitem name=\"NextDC\" action=\"NextDC\" /> \
</menu> \
</menu> \
@@ -1130,6 +1140,27 @@ 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;
+ case GDK_KEY_Left:
+ prev_dc(NULL, NULL);
+ return TRUE;
+ case GDK_KEY_Right:
+ next_dc(NULL, NULL);
+ return TRUE;
+ }
+ return FALSE;
+}
+
void init_ui(int *argcp, char ***argvp)
{
GtkWidget *win;
@@ -1325,6 +1356,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);