[clutter-gst] sink: send navigation commands on certain key events



commit 28fd3499693110838df61c019968a2a6ea136fef
Author: Thomas Wood <thomas wood intel com>
Date:   Fri Aug 26 14:46:04 2011 +0100

    sink: send navigation commands on certain key events
    
    The up, down, left and right navigation keys cannot be represented as a
    single UTF-8 character and using XKeysymToString to convert the key to a
    string would require clutter-gst to depend on Xlib. Therefore, use
    navigation commands when handling these key events and also send the
    activate command when the return key is pressed.

 clutter-gst/clutter-gst-video-sink.c |   45 +++++++++++++++++++++++----------
 1 files changed, 31 insertions(+), 14 deletions(-)
---
diff --git a/clutter-gst/clutter-gst-video-sink.c b/clutter-gst/clutter-gst-video-sink.c
index 829dc04..f2c79e5 100644
--- a/clutter-gst/clutter-gst-video-sink.c
+++ b/clutter-gst/clutter-gst-video-sink.c
@@ -907,21 +907,38 @@ navigation_event (ClutterActor        *actor,
       gst_navigation_send_mouse_event (GST_NAVIGATION (sink),
                                        type, bevent->button, bevent->x, bevent->y);
     }
-  else if (event->type == CLUTTER_KEY_PRESS ||
-           event->type == CLUTTER_KEY_RELEASE)
+  else if (event->type == CLUTTER_KEY_PRESS)
     {
-      ClutterKeyEvent *kevent = (ClutterKeyEvent *) kevent;
-      const char *type;
-      char *key;
-
-      type = (event->type == CLUTTER_KEY_PRESS) ? "key-press" : "key-release";
-      key = g_ucs4_to_utf8 (&kevent->unicode_value, 1, NULL, NULL, NULL);
-      GST_DEBUG ("Received key %s event (%s)",
-                 (event->type == CLUTTER_KEY_PRESS) ? "press" : "release",
-                 key);
-      gst_navigation_send_key_event (GST_NAVIGATION (sink),
-                                     type, key ? key : "unknown");
-      g_free (key);
+      ClutterKeyEvent *kevent = (ClutterKeyEvent *) event;
+      GstNavigationCommand command;
+
+      switch (kevent->keyval)
+        {
+        case CLUTTER_KEY_Up:
+          command = GST_NAVIGATION_COMMAND_UP;
+          break;
+        case CLUTTER_KEY_Down:
+          command = GST_NAVIGATION_COMMAND_DOWN;
+          break;
+        case CLUTTER_KEY_Left:
+          command = GST_NAVIGATION_COMMAND_LEFT;
+          break;
+        case CLUTTER_KEY_Right:
+          command = GST_NAVIGATION_COMMAND_RIGHT;
+          break;
+        case CLUTTER_KEY_Return:
+          command = GST_NAVIGATION_COMMAND_ACTIVATE;
+          break;
+        default:
+          command = GST_NAVIGATION_COMMAND_INVALID;
+        }
+
+      if (command != GST_NAVIGATION_COMMAND_INVALID)
+        {
+          gst_navigation_send_command (GST_NAVIGATION (sink), command);
+
+          return TRUE;
+        }
     }
 
   return FALSE;



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