[recipes] Add some keynav to the image viewer



commit c9ed63173e810957e9fd17a681ede507e4019174
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Dec 15 21:46:17 2016 -0500

    Add some keynav to the image viewer
    
    It is not perfect, but it is a start.

 src/gr-image-viewer.c  |   46 ++++++++++++++++++++++++++++++++++++++++++++--
 src/gr-image-viewer.ui |    1 +
 2 files changed, 45 insertions(+), 2 deletions(-)
---
diff --git a/src/gr-image-viewer.c b/src/gr-image-viewer.c
index e521921..d08a216 100644
--- a/src/gr-image-viewer.c
+++ b/src/gr-image-viewer.c
@@ -24,6 +24,7 @@
 #include "gr-image-editor.h"
 #include "gr-utils.h"
 
+
 struct _GrImageViewer
 {
         GtkEventBox parent_instance;
@@ -134,6 +135,13 @@ hide_buttons (GrImageViewer *viewer)
 }
 
 static void
+show_preview (GrImageViewer *viewer)
+{
+        if (!gtk_revealer_get_child_revealed (GTK_REVEALER (viewer->preview_revealer)))
+                gtk_revealer_set_reveal_child (GTK_REVEALER (viewer->preview_revealer), TRUE);
+}
+
+static void
 hide_preview (GrImageViewer *viewer)
 {
         if (gtk_revealer_get_child_revealed (GTK_REVEALER (viewer->preview_revealer)))
@@ -159,6 +167,13 @@ hide_controls (GrImageViewer *viewer)
         hide_preview (viewer);
 }
 
+static void
+show_controls (GrImageViewer *viewer)
+{
+        show_buttons (viewer);
+        show_preview (viewer);
+}
+
 static gboolean
 hide_timeout (gpointer data)
 {
@@ -213,6 +228,7 @@ static void
 button_press (GrImageViewer *viewer)
 {
         toggle_preview (viewer);
+        gtk_widget_grab_focus (viewer->event_box);
 }
 
 static void
@@ -245,6 +261,33 @@ preview_selected (GrImageViewer *viewer)
         set_current_image (viewer);
 }
 
+static gboolean
+key_press_event (GtkWidget     *widget,
+                 GdkEvent      *event,
+                 GrImageViewer *viewer)
+{
+        GdkEventKey *key = (GdkEventKey *)event;
+
+        if (key->keyval == GDK_KEY_space) {
+                show_controls (viewer);
+                return TRUE;
+        }
+        if (key->keyval == GDK_KEY_Escape) {
+                hide_controls (viewer);
+                return TRUE;
+        }
+        else if (key->keyval == GDK_KEY_Left) {
+                prev_image (viewer);
+                return TRUE;
+        }
+        else if (key->keyval == GDK_KEY_Right) {
+                next_image (viewer);
+                return TRUE;
+        }
+
+        return FALSE;
+}
+
 static void
 gr_image_viewer_init (GrImageViewer *self)
 {
@@ -255,12 +298,11 @@ gr_image_viewer_init (GrImageViewer *self)
         g_signal_connect (self->event_box, "enter-notify-event", G_CALLBACK (enter_leave_notify), self);
         g_signal_connect (self->event_box, "leave-notify-event", G_CALLBACK (enter_leave_notify), self);
         g_signal_connect (self->event_box, "motion-notify-event", G_CALLBACK (motion_notify), self);
+        g_signal_connect (self->event_box, "key-press-event", G_CALLBACK (key_press_event), self);
 
-#if 1
         self->gesture = gtk_gesture_multi_press_new (self->event_box);
         gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (self->gesture), GTK_PHASE_BUBBLE);
         g_signal_connect_swapped (self->gesture, "pressed", G_CALLBACK (button_press), self);
-#endif
 }
 
 static void
diff --git a/src/gr-image-viewer.ui b/src/gr-image-viewer.ui
index 0b76930..60eaafc 100644
--- a/src/gr-image-viewer.ui
+++ b/src/gr-image-viewer.ui
@@ -88,6 +88,7 @@
           <object class="GtkEventBox" id="event_box">
             <property name="visible">1</property>
             <property name="above-child">1</property>
+            <property name="can-focus">1</property>
             <child>
               <object class="GtkImage" id="image">
                 <property name="visible">1</property>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]