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
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 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 const xcb_button_press_event_t *ev)
46 vout_display_SendEventMousePressed (vd, ev->detail - 1);
49 static void HandleButtonRelease (vout_display_t *vd,
50 const xcb_button_release_event_t *ev)
52 vout_display_SendEventMouseReleased (vd, ev->detail - 1);
55 static void HandleMotionNotify (vout_display_t *vd, xcb_connection_t *conn,
56 const xcb_motion_notify_event_t *ev)
58 vout_display_place_t place;
60 /* show the default cursor */
61 xcb_change_window_attributes (conn, ev->event, XCB_CW_CURSOR,
62 &(uint32_t) { XCB_CURSOR_NONE });
64 /* TODO it could be saved */
65 vout_display_PlacePicture (&place, &vd->source, vd->cfg, false);
67 if (place.width <= 0 || place.height <= 0)
70 const int x = vd->source.i_x_offset +
71 (int64_t)(ev->event_x - place.x) * vd->source.i_visible_width / place.width;
72 const int y = vd->source.i_y_offset +
73 (int64_t)(ev->event_y - place.y) * vd->source.i_visible_height/ place.height;
75 if (x >= vd->source.i_x_offset && x < vd->source.i_x_offset + vd->source.i_visible_width &&
76 y >= vd->source.i_y_offset && y < vd->source.i_y_offset + vd->source.i_visible_height)
77 vout_display_SendEventMouseMoved (vd, x, y);
80 static void HandleVisibilityNotify (vout_display_t *vd, bool *visible,
81 const xcb_visibility_notify_event_t *ev)
83 *visible = ev->state != XCB_VISIBILITY_FULLY_OBSCURED;
84 msg_Dbg (vd, "display is %svisible", *visible ? "" : "not ");
88 HandleParentStructure (vout_display_t *vd,
89 const xcb_configure_notify_event_t *ev)
91 if (ev->width != vd->cfg->display.width ||
92 ev->height != vd->cfg->display.height)
93 vout_display_SendEventDisplaySize (vd, ev->width, ev->height, vd->cfg->is_fullscreen);
97 * Process an X11 event.
99 static int ProcessEvent (vout_display_t *vd, xcb_connection_t *conn,
100 bool *visible, xcb_generic_event_t *ev)
102 switch (ev->response_type & 0x7f)
104 case XCB_BUTTON_PRESS:
105 HandleButtonPress (vd, (xcb_button_press_event_t *)ev);
108 case XCB_BUTTON_RELEASE:
109 HandleButtonRelease (vd, (xcb_button_release_event_t *)ev);
112 case XCB_MOTION_NOTIFY:
113 HandleMotionNotify (vd, conn, (xcb_motion_notify_event_t *)ev);
116 case XCB_VISIBILITY_NOTIFY:
117 HandleVisibilityNotify (vd, visible,
118 (xcb_visibility_notify_event_t *)ev);
121 case XCB_CONFIGURE_NOTIFY:
122 HandleParentStructure (vd, (xcb_configure_notify_event_t *)ev);
125 /* FIXME I am not sure it is the right one */
126 case XCB_DESTROY_NOTIFY:
127 vout_display_SendEventClose (vd);
130 case XCB_MAPPING_NOTIFY:
134 msg_Dbg (vd, "unhandled event %"PRIu8, ev->response_type);
142 * Process incoming X events.
144 int ManageEvent (vout_display_t *vd, xcb_connection_t *conn, bool *visible)
146 xcb_generic_event_t *ev;
148 while ((ev = xcb_poll_for_event (conn)) != NULL)
149 ProcessEvent (vd, conn, visible, ev);
151 if (xcb_connection_has_error (conn))
153 msg_Err (vd, "X server failure");