]> git.sesse.net Git - vlc/blob - modules/video_output/xcb/events.c
XCB: trigger the pop-up menu
[vlc] / modules / video_output / xcb / events.c
1 /**
2  * @file events.c
3  * @brief X C Bindings VLC video output events handling
4  */
5 /*****************************************************************************
6  * Copyright © 2009 Rémi Denis-Courmont
7  *
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.
12  *
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.
17  *
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  ****************************************************************************/
22
23 #ifdef HAVE_CONFIG_H
24 # include <config.h>
25 #endif
26
27 #include <inttypes.h>
28
29 #include <xcb/xcb.h>
30
31 #include <vlc_common.h>
32 #include <vlc_vout.h>
33
34 #include "xcb_vlc.h"
35
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...
39  */
40
41 static void HandleButtonPress (vout_thread_t *vout,
42                                xcb_button_press_event_t *ev)
43 {
44     unsigned buttons = var_GetInteger (vout, "mouse-button-down");
45     buttons |= (1 << (ev->detail - 1));
46     var_SetInteger (vout, "mouse-button-down", buttons);
47 }
48
49 static void HandleButtonRelease (vout_thread_t *vout,
50                                  xcb_button_release_event_t *ev)
51 {
52     unsigned buttons = var_GetInteger (vout, "mouse-button-down");
53     buttons &= ~(1 << (ev->detail - 1));
54     var_SetInteger (vout, "mouse-button-down", buttons);
55
56     switch (ev->detail)
57     {
58         case 1: /* left mouse button */
59             var_SetBool (vout, "mouse-clicked", true);
60             var_SetBool (vout->p_libvlc, "intf-popupmenu", false);
61             break;
62         case 3:
63             var_SetBool (vout->p_libvlc, "intf-popupmenu", true);
64             break;
65     }
66 }
67
68 static void HandleMotionNotify (vout_thread_t *vout,
69                                 xcb_motion_notify_event_t *ev)
70 {
71     unsigned x, y, width, height;
72     int v;
73
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);
78     if (v < 0)
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);
83
84     v = vout->fmt_in.i_y_offset
85         + ((ev->event_y - y) * vout->fmt_in.i_visible_height / height);
86     if (v < 0)
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);
91 }
92
93 /**
94  * Process an X11 event.
95  */
96 int ProcessEvent (vout_thread_t *vout, xcb_generic_event_t *ev)
97 {
98     switch (ev->response_type & 0x7f)
99     {
100         case XCB_BUTTON_PRESS:
101             HandleButtonPress (vout, (xcb_button_press_event_t *)ev);
102             break;
103
104         case XCB_BUTTON_RELEASE:
105             HandleButtonRelease (vout, (xcb_button_release_event_t *)ev);
106             break;
107
108         case XCB_MOTION_NOTIFY:
109             HandleMotionNotify (vout, (xcb_motion_notify_event_t *)ev);
110             break;
111
112         default:
113             msg_Dbg (vout, "unhandled event %02x", (unsigned)ev->response_type);
114     }
115
116     free (ev);
117     return VLC_SUCCESS;
118 }