[gnome-shell] St: add keyboard support to StClickable and StButton



commit 35f806df4e2671c06552d0c18b79dd6de80a440f
Author: Dan Winship <danw gnome org>
Date:   Wed Oct 13 15:53:42 2010 -0400

    St: add keyboard support to StClickable and StButton
    
    Allow triggering clicks with space/return
    
    https://bugzilla.gnome.org/show_bug.cgi?id=633853

 src/st/st-button.c    |   32 ++++++++++++++++++++++++++++++++
 src/st/st-clickable.c |   33 +++++++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+), 0 deletions(-)
---
diff --git a/src/st/st-button.c b/src/st/st-button.c
index 9095f7e..92624cd 100644
--- a/src/st/st-button.c
+++ b/src/st/st-button.c
@@ -196,6 +196,36 @@ st_button_button_release (ClutterActor       *actor,
 }
 
 static gboolean
+st_button_key_press (ClutterActor    *actor,
+                     ClutterKeyEvent *event)
+{
+  st_widget_hide_tooltip (ST_WIDGET (actor));
+
+  if (event->keyval == CLUTTER_KEY_space ||
+      event->keyval == CLUTTER_KEY_Return)
+    {
+      st_button_press (ST_BUTTON (actor));
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
+static gboolean
+st_button_key_release (ClutterActor    *actor,
+                       ClutterKeyEvent *event)
+{
+  if (event->keyval == CLUTTER_KEY_space ||
+      event->keyval == CLUTTER_KEY_Return)
+    {
+      st_button_release (ST_BUTTON (actor), TRUE);
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
+static gboolean
 st_button_enter (ClutterActor         *actor,
                  ClutterCrossingEvent *event)
 {
@@ -315,6 +345,8 @@ st_button_class_init (StButtonClass *klass)
 
   actor_class->button_press_event = st_button_button_press;
   actor_class->button_release_event = st_button_button_release;
+  actor_class->key_press_event = st_button_key_press;
+  actor_class->key_release_event = st_button_key_release;
   actor_class->enter_event = st_button_enter;
   actor_class->leave_event = st_button_leave;
 
diff --git a/src/st/st-clickable.c b/src/st/st-clickable.c
index 38cc41f..ab49207 100644
--- a/src/st/st-clickable.c
+++ b/src/st/st-clickable.c
@@ -158,6 +158,37 @@ st_clickable_button_release_event (ClutterActor       *actor,
   return TRUE;
 }
 
+static gboolean
+st_clickable_key_press_event (ClutterActor    *actor,
+                              ClutterKeyEvent *event)
+{
+  StClickable *self = ST_CLICKABLE (actor);
+
+  if (event->keyval == CLUTTER_KEY_space ||
+      event->keyval == CLUTTER_KEY_Return)
+    {
+      set_pressed (self, TRUE);
+      return TRUE;
+    }
+  return FALSE;
+}
+
+static gboolean
+st_clickable_key_release_event (ClutterActor    *actor,
+                                ClutterKeyEvent *event)
+{
+  StClickable *self = ST_CLICKABLE (actor);
+
+  if (event->keyval != CLUTTER_KEY_space &&
+      event->keyval != CLUTTER_KEY_Return)
+    return FALSE;
+
+  set_pressed (self, FALSE);
+
+  g_signal_emit (G_OBJECT (self), st_clickable_signals[CLICKED], 0, event);
+  return TRUE;
+}
+
 /**
  * st_clickable_fake_release:
  * @box:
@@ -240,6 +271,8 @@ st_clickable_class_init (StClickableClass *klass)
   actor_class->leave_event = st_clickable_leave_event;
   actor_class->button_press_event = st_clickable_button_press_event;
   actor_class->button_release_event = st_clickable_button_release_event;
+  actor_class->key_press_event = st_clickable_key_press_event;
+  actor_class->key_release_event = st_clickable_key_release_event;
 
   /**
    * StClickable::clicked



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