summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorEdward Hervey <edward@centricular.com>2015-04-02 16:16:58 +0200
committerEdward Hervey <bilboed@bilboed.com>2015-04-29 15:47:49 +0200
commitbba3f57c8bce3095a47d97fd201dd4a3ccca2dfb (patch)
treedd11be9a9ca1a12dd11e29bbe6b82cc0e99109db /tools
parentc90a3ac468fcb99587b10cd77efae2acfb17d7fa (diff)
tools: Add mouse/keyboard handling from messages
Allows the user to control playback with the window in focus https://bugzilla.gnome.org/show_bug.cgi?id=747245
Diffstat (limited to 'tools')
-rw-r--r--tools/gst-play.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/tools/gst-play.c b/tools/gst-play.c
index 860e45199..3e90e7c1b 100644
--- a/tools/gst-play.c
+++ b/tools/gst-play.c
@@ -29,6 +29,7 @@
#include <gst/gst.h>
#include <gst/gst-i18n-app.h>
#include <gst/audio/audio.h>
+#include <gst/video/video.h>
#include <gst/pbutils/pbutils.h>
#include <gst/math-compat.h>
#include <stdlib.h>
@@ -95,6 +96,9 @@ static void play_set_relative_volume (GstPlay * play, gdouble volume_step);
static void gst_play_printf (const gchar * format, ...) G_GNUC_PRINTF (1, 2);
/* *INDENT-ON* */
+static void keyboard_cb (const gchar * key_input, gpointer user_data);
+static void relative_seek (GstPlay * play, gdouble percent);
+
static void
gst_play_printf (const gchar * format, ...)
{
@@ -367,6 +371,48 @@ play_bus_msg (GstBus * bus, GstMessage * msg, gpointer user_data)
}
break;
}
+ case GST_MESSAGE_ELEMENT:
+ {
+ GstNavigationMessageType mtype = gst_navigation_message_get_type (msg);
+ if (mtype == GST_NAVIGATION_MESSAGE_EVENT) {
+ GstEvent *ev;
+ if (gst_navigation_message_parse_event (msg, &ev)) {
+ GstNavigationEventType e_type = gst_navigation_event_get_type (ev);
+ switch (e_type) {
+ case GST_NAVIGATION_EVENT_KEY_PRESS:
+ {
+ const gchar *key;
+ if (gst_navigation_event_parse_key_event (ev, &key)) {
+ if (strcmp (key, "Left") == 0)
+ key = GST_PLAY_KB_ARROW_LEFT;
+ else if (strcmp (key, "Right") == 0)
+ key = GST_PLAY_KB_ARROW_RIGHT;
+ keyboard_cb (key, user_data);
+ }
+ break;
+ }
+ case GST_NAVIGATION_EVENT_MOUSE_BUTTON_PRESS:
+ {
+ gint button;
+ if (gst_navigation_event_parse_mouse_button_event (ev, &button,
+ NULL, NULL)) {
+ if (button == 4) {
+ /* wheel up */
+ relative_seek (play, +0.08);
+ } else if (button == 5) {
+ /* wheel down */
+ relative_seek (play, -0.01);
+ }
+ }
+ break;
+ }
+ default:
+ break;
+ }
+ }
+ }
+ break;
+ }
default:
if (gst_is_missing_plugin_message (msg)) {
gchar *desc;