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 ****************************************************************************/
31 #include <vlc_common.h>
36 /* NOTE: we assume no other thread will be _setting_ our video output events
37 * variables. Afterall, only this plugin is supposed to know when these occur.
38 * Otherwise, we'd var_OrInteger() and var_NandInteger() functions...
41 static void HandleButtonPress (vout_thread_t *vout,
42 xcb_button_press_event_t *ev)
44 unsigned buttons = var_GetInteger (vout, "mouse-button-down");
45 buttons |= (1 << (ev->detail - 1));
46 var_SetInteger (vout, "mouse-button-down", buttons);
49 static void HandleButtonRelease (vout_thread_t *vout,
50 xcb_button_release_event_t *ev)
52 unsigned buttons = var_GetInteger (vout, "mouse-button-down");
53 buttons &= ~(1 << (ev->detail - 1));
54 var_SetInteger (vout, "mouse-button-down", buttons);
58 case 1: /* left mouse button */
59 var_SetBool (vout, "mouse-clicked", true);
60 var_SetBool (vout->p_libvlc, "intf-popupmenu", false);
63 var_SetBool (vout->p_libvlc, "intf-popupmenu", true);
68 static void HandleMotionNotify (vout_thread_t *vout,
69 xcb_motion_notify_event_t *ev)
71 unsigned x, y, width, height;
74 vout_PlacePicture (vout, vout->output.i_width, vout->output.i_height,
75 &x, &y, &width, &height);
76 v = vout->fmt_in.i_x_offset
77 + ((ev->event_x - x) * vout->fmt_in.i_visible_width / width);
79 v = 0; /* to the left of the picture */
80 else if ((unsigned)v > vout->fmt_in.i_width)
81 v = vout->fmt_in.i_width; /* to the right of the picture */
82 var_SetInteger (vout, "mouse-x", v);
84 v = vout->fmt_in.i_y_offset
85 + ((ev->event_y - y) * vout->fmt_in.i_visible_height / height);
87 v = 0; /* above the picture */
88 else if ((unsigned)v > vout->fmt_in.i_height)
89 v = vout->fmt_in.i_height; /* below the picture */
90 var_SetInteger (vout, "mouse-y", v);
94 * Process an X11 event.
96 int ProcessEvent (vout_thread_t *vout, xcb_generic_event_t *ev)
98 switch (ev->response_type & 0x7f)
100 case XCB_BUTTON_PRESS:
101 HandleButtonPress (vout, (xcb_button_press_event_t *)ev);
104 case XCB_BUTTON_RELEASE:
105 HandleButtonRelease (vout, (xcb_button_release_event_t *)ev);
108 case XCB_MOTION_NOTIFY:
109 HandleMotionNotify (vout, (xcb_motion_notify_event_t *)ev);
113 msg_Dbg (vout, "unhandled event %02x", (unsigned)ev->response_type);