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 ****************************************************************************/
31 #ifndef XCB_CURSOR_NONE
32 # define XCB_CURSOR_NONE ((xcb_cursor_t) 0U)
35 #include <vlc_common.h>
36 #include <vlc_vout_display.h>
40 /* NOTE: we assume no other thread will be _setting_ our video output events
41 * variables. Afterall, only this plugin is supposed to know when these occur.
42 * Otherwise, we'd var_OrInteger() and var_NandInteger() functions...
45 /* FIXME we assume direct mapping between XCB and VLC */
46 static void HandleButtonPress (vout_display_t *vd,
47 const xcb_button_press_event_t *ev)
49 vout_display_SendEventMousePressed (vd, ev->detail - 1);
52 static void HandleButtonRelease (vout_display_t *vd,
53 const xcb_button_release_event_t *ev)
55 vout_display_SendEventMouseReleased (vd, ev->detail - 1);
58 static void HandleMotionNotify (vout_display_t *vd, xcb_connection_t *conn,
59 const xcb_motion_notify_event_t *ev)
61 vout_display_place_t place;
63 /* show the default cursor */
64 xcb_change_window_attributes (conn, ev->event, XCB_CW_CURSOR,
65 &(uint32_t) { XCB_CURSOR_NONE });
67 /* TODO it could be saved */
68 vout_display_PlacePicture (&place, &vd->source, vd->cfg, false);
70 if (place.width <= 0 || place.height <= 0)
73 const int x = vd->source.i_x_offset +
74 (int64_t)(ev->event_x - place.x) * vd->source.i_visible_width / place.width;
75 const int y = vd->source.i_y_offset +
76 (int64_t)(ev->event_y - place.y) * vd->source.i_visible_height/ place.height;
78 vout_display_SendEventMouseMoved (vd, x, y);
81 static void HandleVisibilityNotify (vout_display_t *vd, bool *visible,
82 const xcb_visibility_notify_event_t *ev)
84 *visible = ev->state != XCB_VISIBILITY_FULLY_OBSCURED;
85 msg_Dbg (vd, "display is %svisible", *visible ? "" : "not ");
89 HandleParentStructure (vout_display_t *vd,
90 const xcb_configure_notify_event_t *ev)
92 if (ev->width != vd->cfg->display.width ||
93 ev->height != vd->cfg->display.height)
94 vout_display_SendEventDisplaySize (vd, ev->width, ev->height, vd->cfg->is_fullscreen);
98 * Process an X11 event.
100 static int ProcessEvent (vout_display_t *vd, xcb_connection_t *conn,
101 bool *visible, xcb_generic_event_t *ev)
103 switch (ev->response_type & 0x7f)
105 case XCB_BUTTON_PRESS:
106 HandleButtonPress (vd, (xcb_button_press_event_t *)ev);
109 case XCB_BUTTON_RELEASE:
110 HandleButtonRelease (vd, (xcb_button_release_event_t *)ev);
113 case XCB_MOTION_NOTIFY:
114 HandleMotionNotify (vd, conn, (xcb_motion_notify_event_t *)ev);
117 case XCB_VISIBILITY_NOTIFY:
118 HandleVisibilityNotify (vd, visible,
119 (xcb_visibility_notify_event_t *)ev);
122 case XCB_CONFIGURE_NOTIFY:
123 HandleParentStructure (vd, (xcb_configure_notify_event_t *)ev);
126 /* FIXME I am not sure it is the right one */
127 case XCB_DESTROY_NOTIFY:
128 vout_display_SendEventClose (vd);
131 case XCB_MAPPING_NOTIFY:
135 msg_Dbg (vd, "unhandled event %"PRIu8, ev->response_type);
143 * Process incoming X events.
145 int ManageEvent (vout_display_t *vd, xcb_connection_t *conn, bool *visible)
147 xcb_generic_event_t *ev;
149 while ((ev = xcb_poll_for_event (conn)) != NULL)
150 ProcessEvent (vd, conn, visible, ev);
152 if (xcb_connection_has_error (conn))
154 msg_Err (vd, "X server failure");