diff --git a/gst-libs/gst/interfaces/navigation.c b/gst-libs/gst/interfaces/navigation.c index 3462348d68..feb84dfa8f 100644 --- a/gst-libs/gst/interfaces/navigation.c +++ b/gst-libs/gst/interfaces/navigation.c @@ -61,31 +61,31 @@ gst_navigation_class_init (GstNavigationInterface *iface) } void -gst_navigation_send_event (GstNavigation *navigation, GstCaps *caps) +gst_navigation_send_event (GstNavigation *navigation, GstStructure *structure) { GstNavigationInterface *iface = GST_NAVIGATION_GET_IFACE (navigation); if (iface->send_event) { - iface->send_event (navigation, caps); + iface->send_event (navigation, structure); } } void gst_navigation_send_key_event (GstNavigation *navigation, const char *key) { - gst_navigation_send_event (navigation, GST_CAPS_NEW ("key_event", - "application/x-gst-navigation", - "key", GST_PROPS_STRING (key))); + gst_navigation_send_event (navigation, gst_structure_new ( + "application/x-gst-navigation", + "key", G_TYPE_STRING, key, NULL)); } void gst_navigation_send_mouse_event (GstNavigation *navigation, double x, double y) { - gst_navigation_send_event (navigation, GST_CAPS_NEW ("mouse_event", + gst_navigation_send_event (navigation, gst_structure_new ( "application/x-gst-navigation", - "pointer_x", GST_PROPS_FLOAT (x), - "pointer_y", GST_PROPS_FLOAT (y))); + "pointer_x", G_TYPE_DOUBLE, x, + "pointer_y", G_TYPE_DOUBLE, y, NULL)); } diff --git a/gst-libs/gst/interfaces/navigation.h b/gst-libs/gst/interfaces/navigation.h index 5ce3a5c720..22a66632d9 100644 --- a/gst-libs/gst/interfaces/navigation.h +++ b/gst-libs/gst/interfaces/navigation.h @@ -42,7 +42,7 @@ typedef struct _GstNavigationInterface { GTypeInterface g_iface; /* virtual functions */ - void (*send_event) (GstNavigation *navigation, GstCaps *caps); + void (*send_event) (GstNavigation *navigation, GstStructure *structure); GST_CLASS_PADDING } GstNavigationInterface; @@ -50,7 +50,7 @@ typedef struct _GstNavigationInterface { GType gst_navigation_get_type (void); /* virtual class function wrappers */ -void gst_navigation_send_event (GstNavigation *navigation, GstCaps *caps); +void gst_navigation_send_event (GstNavigation *navigation, GstStructure *structure); void gst_navigation_send_key_event (GstNavigation *navigation, const char *key); void gst_navigation_send_mouse_event (GstNavigation *navigation, double x, diff --git a/gst-libs/gst/navigation/navigation.c b/gst-libs/gst/navigation/navigation.c index 3462348d68..feb84dfa8f 100644 --- a/gst-libs/gst/navigation/navigation.c +++ b/gst-libs/gst/navigation/navigation.c @@ -61,31 +61,31 @@ gst_navigation_class_init (GstNavigationInterface *iface) } void -gst_navigation_send_event (GstNavigation *navigation, GstCaps *caps) +gst_navigation_send_event (GstNavigation *navigation, GstStructure *structure) { GstNavigationInterface *iface = GST_NAVIGATION_GET_IFACE (navigation); if (iface->send_event) { - iface->send_event (navigation, caps); + iface->send_event (navigation, structure); } } void gst_navigation_send_key_event (GstNavigation *navigation, const char *key) { - gst_navigation_send_event (navigation, GST_CAPS_NEW ("key_event", - "application/x-gst-navigation", - "key", GST_PROPS_STRING (key))); + gst_navigation_send_event (navigation, gst_structure_new ( + "application/x-gst-navigation", + "key", G_TYPE_STRING, key, NULL)); } void gst_navigation_send_mouse_event (GstNavigation *navigation, double x, double y) { - gst_navigation_send_event (navigation, GST_CAPS_NEW ("mouse_event", + gst_navigation_send_event (navigation, gst_structure_new ( "application/x-gst-navigation", - "pointer_x", GST_PROPS_FLOAT (x), - "pointer_y", GST_PROPS_FLOAT (y))); + "pointer_x", G_TYPE_DOUBLE, x, + "pointer_y", G_TYPE_DOUBLE, y, NULL)); } diff --git a/gst-libs/gst/navigation/navigation.h b/gst-libs/gst/navigation/navigation.h index 5ce3a5c720..22a66632d9 100644 --- a/gst-libs/gst/navigation/navigation.h +++ b/gst-libs/gst/navigation/navigation.h @@ -42,7 +42,7 @@ typedef struct _GstNavigationInterface { GTypeInterface g_iface; /* virtual functions */ - void (*send_event) (GstNavigation *navigation, GstCaps *caps); + void (*send_event) (GstNavigation *navigation, GstStructure *structure); GST_CLASS_PADDING } GstNavigationInterface; @@ -50,7 +50,7 @@ typedef struct _GstNavigationInterface { GType gst_navigation_get_type (void); /* virtual class function wrappers */ -void gst_navigation_send_event (GstNavigation *navigation, GstCaps *caps); +void gst_navigation_send_event (GstNavigation *navigation, GstStructure *structure); void gst_navigation_send_key_event (GstNavigation *navigation, const char *key); void gst_navigation_send_mouse_event (GstNavigation *navigation, double x, diff --git a/sys/ximage/ximagesink.c b/sys/ximage/ximagesink.c index 25d44c099d..9408bd70d1 100644 --- a/sys/ximage/ximagesink.c +++ b/sys/ximage/ximagesink.c @@ -74,13 +74,31 @@ gst_ximagesink_interface_init (GstInterfaceClass *klass) } static void -gst_ximagesink_navigation_send_event (GstNavigation *navigation, GstCaps *caps) +gst_ximagesink_navigation_send_event (GstNavigation *navigation, GstStructure *structure) { GstXImageSink *ximagesink = GST_XIMAGESINK (navigation); + XWindowAttributes attr; GstEvent *event; + double x, y; + + g_mutex_lock (ximagesink->x_lock); + XGetWindowAttributes (ximagesink->xcontext->disp, + ximagesink->xwindow->win, &attr); + g_mutex_unlock (ximagesink->x_lock); event = gst_event_new (GST_EVENT_NAVIGATION); - event->event_data.caps.caps = caps; + event->event_data.structure.structure = structure; + if(gst_structure_get_double(structure, "pointer_x", &x)){ + x *= ximagesink->width; + x /= attr.width; + gst_structure_set(structure, "pointer_x", G_TYPE_DOUBLE, x, NULL); + } + if(gst_structure_get_double(structure, "pointer_y", &y)){ + y *= ximagesink->height; + y /= attr.height; + gst_structure_set(structure, "pointer_y", G_TYPE_DOUBLE, y, NULL); + } + gst_pad_send_event (gst_pad_get_peer (ximagesink->sinkpad), event); } @@ -351,6 +369,7 @@ gst_ximagesink_handle_xevents (GstXImageSink *ximagesink, GstPad *pad) ButtonReleaseMask, &e)) { GstEvent *event = NULL; + KeySym keysym; /* We lock only for the X function call */ g_mutex_unlock (ximagesink->x_lock); @@ -383,13 +402,8 @@ gst_ximagesink_handle_xevents (GstXImageSink *ximagesink, GstPad *pad) events for interactivity/navigation */ GST_DEBUG ("ximagesink pointer moved over window at %d,%d", e.xmotion.x, e.xmotion.y); - event = gst_event_new (GST_EVENT_NAVIGATION); - event->event_data.caps.caps = GST_CAPS_NEW ( - "ximagesink_navigation", - "video/x-raw-rgb", - "pointer_x", GST_PROPS_INT (e.xmotion.x), - "pointer_y", GST_PROPS_INT (e.xmotion.y), - "state", GST_PROPS_INT (e.xmotion.state)); + gst_navigation_send_mouse_event(GST_NAVIGATION(ximagesink), + e.xmotion.x, e.xmotion.y); break; case ButtonPress: case ButtonRelease: @@ -397,29 +411,21 @@ gst_ximagesink_handle_xevents (GstXImageSink *ximagesink, GstPad *pad) events for interactivity/navigation */ GST_DEBUG ("ximagesink button %d pressed over window at %d,%d", e.xbutton.button, e.xbutton.x, e.xbutton.x); - event = gst_event_new (GST_EVENT_NAVIGATION); - event->event_data.caps.caps = GST_CAPS_NEW ( - "ximagesink_navigation", - "video/x-raw-rgb", - "pointer_x", GST_PROPS_INT (e.xbutton.x), - "pointer_y", GST_PROPS_INT (e.xbutton.y), - "button", GST_PROPS_INT (e.xbutton.button), - "state", GST_PROPS_INT (e.xbutton.state)); + gst_navigation_send_mouse_event(GST_NAVIGATION(ximagesink), + e.xmotion.x, e.xmotion.y); break; case KeyPress: case KeyRelease: /* Key pressed/released over our window. We send upstream events for interactivity/navigation */ GST_DEBUG ("ximagesink key %d pressed over window at %d,%d", - e.xbutton.button, e.xbutton.x, e.xbutton.x); - event = gst_event_new (GST_EVENT_NAVIGATION); - event->event_data.caps.caps = GST_CAPS_NEW ( - "ximagesink_navigation", - "video/x-raw-rgb", - "pointer_x", GST_PROPS_INT (e.xkey.x), - "pointer_y", GST_PROPS_INT (e.xkey.y), - "keycode", GST_PROPS_INT (e.xkey.keycode), - "state", GST_PROPS_INT (e.xkey.state)); + e.xkey.keycode, e.xkey.x, e.xkey.x); + keysym = XKeycodeToKeysym(ximagesink->xcontext->disp, + e.xkey.keycode, 0); + gst_navigation_send_key_event (GST_NAVIGATION (ximagesink), + XKeysymToString (keysym)); + gst_navigation_send_key_event(GST_NAVIGATION(ximagesink), + "unknown"); break; default: GST_DEBUG ("ximagesink unhandled X event (%d)", e.type); diff --git a/sys/xvimage/xvimagesink.c b/sys/xvimage/xvimagesink.c index df9dbf3428..53c0071fb1 100644 --- a/sys/xvimage/xvimagesink.c +++ b/sys/xvimage/xvimagesink.c @@ -78,13 +78,31 @@ gst_xvimagesink_interface_init (GstInterfaceClass *klass) } static void -gst_xvimagesink_navigation_send_event (GstNavigation *navigation, GstCaps *caps) +gst_xvimagesink_navigation_send_event (GstNavigation *navigation, GstStructure *structure) { GstXvImageSink *xvimagesink = GST_XVIMAGESINK (navigation); + XWindowAttributes attr; GstEvent *event; + double x,y; + + g_mutex_lock (xvimagesink->x_lock); + XGetWindowAttributes (xvimagesink->xcontext->disp, + xvimagesink->xwindow->win, &attr); + g_mutex_unlock (xvimagesink->x_lock); event = gst_event_new (GST_EVENT_NAVIGATION); - event->event_data.caps.caps = caps; + event->event_data.structure.structure = structure; + if(gst_structure_get_double(structure, "pointer_x", &x)){ + x *= xvimagesink->width; + x /= attr.width; + gst_structure_set(structure, "pointer_x", G_TYPE_DOUBLE, x, NULL); + } + if(gst_structure_get_double(structure, "pointer_y", &y)){ + y *= xvimagesink->height; + y /= attr.height; + gst_structure_set(structure, "pointer_y", G_TYPE_DOUBLE, y, NULL); + } + gst_pad_send_event (gst_pad_get_peer (xvimagesink->sinkpad), event); } @@ -359,6 +377,7 @@ gst_xvimagesink_handle_xevents (GstXvImageSink *xvimagesink, GstPad *pad) ButtonReleaseMask, &e)) { GstEvent *event = NULL; + KeySym keysym; /* We lock only for the X function call */ g_mutex_unlock (xvimagesink->x_lock); @@ -370,43 +389,28 @@ gst_xvimagesink_handle_xevents (GstXvImageSink *xvimagesink, GstPad *pad) events for interactivity/navigation */ GST_DEBUG ("xvimagesink pointer moved over window at %d,%d", e.xmotion.x, e.xmotion.y); - event = gst_event_new (GST_EVENT_NAVIGATION); - event->event_data.caps.caps = GST_CAPS_NEW ( - "xvimagesink_navigation", - "video/x-raw-rgb", - "pointer_x", GST_PROPS_FLOAT (e.xmotion.x), - "pointer_y", GST_PROPS_FLOAT (e.xmotion.y), - "state", GST_PROPS_INT (e.xmotion.state)); + gst_navigation_send_mouse_event (GST_NAVIGATION (xvimagesink), + e.xmotion.x, e.xmotion.y); break; case ButtonPress: case ButtonRelease: /* Mouse button pressed/released over our window. We send upstream events for interactivity/navigation */ GST_DEBUG ("xvimagesink button %d pressed over window at %d,%d", - e.xbutton.button, e.xbutton.x, e.xbutton.x); - event = gst_event_new (GST_EVENT_NAVIGATION); - event->event_data.caps.caps = GST_CAPS_NEW ( - "xvimagesink_navigation", - "video/x-raw-rgb", - "pointer_x", GST_PROPS_FLOAT (e.xbutton.x), - "pointer_y", GST_PROPS_FLOAT (e.xbutton.y), - "button", GST_PROPS_INT (e.xbutton.button), - "state", GST_PROPS_INT (e.xbutton.state)); + e.xbutton.button, e.xbutton.x, e.xbutton.y); + gst_navigation_send_mouse_event (GST_NAVIGATION (xvimagesink), + e.xbutton.x, e.xbutton.y); break; case KeyPress: case KeyRelease: /* Key pressed/released over our window. We send upstream events for interactivity/navigation */ GST_DEBUG ("xvimagesink key %d pressed over window at %d,%d", - e.xbutton.button, e.xbutton.x, e.xbutton.x); - event = gst_event_new (GST_EVENT_NAVIGATION); - event->event_data.caps.caps = GST_CAPS_NEW ( - "xvimagesink_navigation", - "video/x-raw-rgb", - "pointer_x", GST_PROPS_INT (e.xkey.x), - "pointer_y", GST_PROPS_INT (e.xkey.y), - "keycode", GST_PROPS_INT (e.xkey.keycode), - "state", GST_PROPS_INT (e.xkey.state)); + e.xkey.keycode, e.xkey.x, e.xkey.y); + keysym = XKeycodeToKeysym(xvimagesink->xcontext->disp, + e.xkey.keycode, 0); + gst_navigation_send_key_event (GST_NAVIGATION (xvimagesink), + XKeysymToString (keysym)); break; default: GST_DEBUG ("xvimagesink unhandled X event (%d)", e.type);