3 * @brief X C Bindings VLC video output events handling
5 /*****************************************************************************
6 * Copyright © 2009 Rémi Denis-Courmont
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2.0
11 * of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 ****************************************************************************/
32 #include <vlc_common.h>
33 #include <vlc_vout_display.h>
37 /* NOTE: we assume no other thread will be _setting_ our video output events
38 * variables. Afterall, only this plugin is supposed to know when these occur.
39 * Otherwise, we'd var_OrInteger() and var_NandInteger() functions...
42 /* FIXME we assume direct mapping between XCB and VLC */
43 static void HandleButtonPress (vout_display_t *vd,
44 xcb_button_press_event_t *ev)
46 vout_display_SendEventMousePressed (vd, ev->detail - 1);
49 static void HandleButtonRelease (vout_display_t *vd,
50 xcb_button_release_event_t *ev)
52 vout_display_SendEventMouseReleased (vd, ev->detail - 1);
55 static void HandleMotionNotify (vout_display_t *vd,
56 xcb_motion_notify_event_t *ev)
58 vout_display_place_t place;
60 /* TODO it could be saved */
61 vout_display_PlacePicture (&place, &vd->source, vd->cfg, false);
63 if (place.width <= 0 || place.height <= 0)
66 const int x = vd->source.i_x_offset +
67 (int64_t)(ev->event_x -0*place.x) * vd->source.i_visible_width / place.width;
68 const int y = vd->source.i_y_offset +
69 (int64_t)(ev->event_y -0*place.y) * vd->source.i_visible_height/ place.height;
71 /* TODO show the cursor ? */
72 if (x >= vd->source.i_x_offset && x < vd->source.i_x_offset + vd->source.i_visible_width &&
73 y >= vd->source.i_y_offset && y < vd->source.i_y_offset + vd->source.i_visible_height)
74 vout_display_SendEventMouseMoved (vd, x, y);
78 HandleParentStructure (vout_display_t *vd, xcb_configure_notify_event_t *ev)
80 if (ev->width != vd->cfg->display.width ||
81 ev->height != vd->cfg->display.height)
82 vout_display_SendEventDisplaySize (vd, ev->width, ev->height);
86 * Process an X11 event.
88 static int ProcessEvent (vout_display_t *vd,
89 xcb_window_t window, xcb_generic_event_t *ev)
91 switch (ev->response_type & 0x7f)
93 case XCB_BUTTON_PRESS:
94 HandleButtonPress (vd, (xcb_button_press_event_t *)ev);
97 case XCB_BUTTON_RELEASE:
98 HandleButtonRelease (vd, (xcb_button_release_event_t *)ev);
101 case XCB_MOTION_NOTIFY:
102 HandleMotionNotify (vd, (xcb_motion_notify_event_t *)ev);
105 case XCB_CONFIGURE_NOTIFY:
107 xcb_configure_notify_event_t *cn =
108 (xcb_configure_notify_event_t *)ev;
110 assert (cn->window != window);
111 HandleParentStructure (vd, cn);
115 /* FIXME I am not sure it is the right one */
116 case XCB_DESTROY_NOTIFY:
117 vout_display_SendEventClose (vd);
121 msg_Dbg (vd, "unhandled event %"PRIu8, ev->response_type);
129 * Process incoming X events.
131 int ManageEvent (vout_display_t *vd, xcb_connection_t *conn, xcb_window_t window)
133 xcb_generic_event_t *ev;
135 while ((ev = xcb_poll_for_event (conn)) != NULL)
136 ProcessEvent (vd, window, ev);
138 if (xcb_connection_has_error (conn))
140 msg_Err (vd, "X server failure");