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>
40 int CheckError (vout_display_t
*vd
, xcb_connection_t
*conn
,
41 const char *str
, xcb_void_cookie_t ck
)
43 xcb_generic_error_t
*err
;
45 err
= xcb_request_check (conn
, ck
);
48 msg_Err (vd
, "%s: X11 error %d", str
, err
->error_code
);
56 * Gets the size of an X window.
58 int GetWindowSize (struct vout_window_t
*wnd
, xcb_connection_t
*conn
,
59 unsigned *restrict width
, unsigned *restrict height
)
61 xcb_get_geometry_cookie_t ck
= xcb_get_geometry (conn
, wnd
->handle
.xid
);
62 xcb_get_geometry_reply_t
*geo
= xcb_get_geometry_reply (conn
, ck
, NULL
);
68 *height
= geo
->height
;
74 * Create a blank cursor.
75 * Note that the pixmaps are leaked (until the X disconnection). Hence, this
76 * function should be called no more than once per X connection.
77 * @param conn XCB connection
78 * @param scr target XCB screen
80 xcb_cursor_t
CreateBlankCursor (xcb_connection_t
*conn
,
81 const xcb_screen_t
*scr
)
83 xcb_cursor_t cur
= xcb_generate_id (conn
);
84 xcb_pixmap_t pix
= xcb_generate_id (conn
);
86 xcb_create_pixmap (conn
, 1, pix
, scr
->root
, 1, 1);
87 xcb_create_cursor (conn
, cur
, pix
, pix
, 0, 0, 0, 0, 0, 0, 1, 1);
92 * (Try to) register to mouse events on a window if needed.
94 void RegisterMouseEvents (vlc_object_t
*obj
, xcb_connection_t
*conn
,
97 /* Subscribe to parent window resize events */
98 uint32_t value
= XCB_EVENT_MASK_POINTER_MOTION
99 | XCB_EVENT_MASK_STRUCTURE_NOTIFY
;
100 xcb_change_window_attributes (conn
, wnd
, XCB_CW_EVENT_MASK
, &value
);
101 /* Try to subscribe to click events */
102 /* (only one X11 client can get them, so might not work) */
103 if (var_InheritBool (obj
, "mouse-events"))
105 value
|= XCB_EVENT_MASK_BUTTON_PRESS
106 | XCB_EVENT_MASK_BUTTON_RELEASE
;
107 xcb_change_window_attributes (conn
, wnd
,
108 XCB_CW_EVENT_MASK
, &value
);
112 /* NOTE: we assume no other thread will be _setting_ our video output events
113 * variables. Afterall, only this plugin is supposed to know when these occur.
114 * Otherwise, we'd var_OrInteger() and var_NandInteger() functions...
117 /* FIXME we assume direct mapping between XCB and VLC */
118 static void HandleButtonPress (vout_display_t
*vd
,
119 const xcb_button_press_event_t
*ev
)
121 vout_display_SendEventMousePressed (vd
, ev
->detail
- 1);
124 static void HandleButtonRelease (vout_display_t
*vd
,
125 const xcb_button_release_event_t
*ev
)
127 vout_display_SendEventMouseReleased (vd
, ev
->detail
- 1);
130 static void HandleMotionNotify (vout_display_t
*vd
, xcb_connection_t
*conn
,
131 const xcb_motion_notify_event_t
*ev
)
133 vout_display_place_t place
;
135 /* show the default cursor */
136 xcb_change_window_attributes (conn
, ev
->event
, XCB_CW_CURSOR
,
137 &(uint32_t) { XCB_CURSOR_NONE
});
139 /* TODO it could be saved */
140 vout_display_PlacePicture (&place
, &vd
->source
, vd
->cfg
, false);
142 if (place
.width
<= 0 || place
.height
<= 0)
145 const int x
= vd
->source
.i_x_offset
+
146 (int64_t)(ev
->event_x
- place
.x
) * vd
->source
.i_visible_width
/ place
.width
;
147 const int y
= vd
->source
.i_y_offset
+
148 (int64_t)(ev
->event_y
- place
.y
) * vd
->source
.i_visible_height
/ place
.height
;
150 vout_display_SendEventMouseMoved (vd
, x
, y
);
153 static void HandleVisibilityNotify (vout_display_t
*vd
, bool *visible
,
154 const xcb_visibility_notify_event_t
*ev
)
156 *visible
= ev
->state
!= XCB_VISIBILITY_FULLY_OBSCURED
;
157 msg_Dbg (vd
, "display is %svisible", *visible
? "" : "not ");
161 HandleParentStructure (vout_display_t
*vd
,
162 const xcb_configure_notify_event_t
*ev
)
164 vout_display_SendEventDisplaySize (vd
, ev
->width
, ev
->height
, vd
->cfg
->is_fullscreen
);
168 * Process an X11 event.
170 static int ProcessEvent (vout_display_t
*vd
, xcb_connection_t
*conn
,
171 bool *visible
, xcb_generic_event_t
*ev
)
173 switch (ev
->response_type
& 0x7f)
175 case XCB_BUTTON_PRESS
:
176 HandleButtonPress (vd
, (xcb_button_press_event_t
*)ev
);
179 case XCB_BUTTON_RELEASE
:
180 HandleButtonRelease (vd
, (xcb_button_release_event_t
*)ev
);
183 case XCB_MOTION_NOTIFY
:
184 HandleMotionNotify (vd
, conn
, (xcb_motion_notify_event_t
*)ev
);
187 case XCB_VISIBILITY_NOTIFY
:
188 HandleVisibilityNotify (vd
, visible
,
189 (xcb_visibility_notify_event_t
*)ev
);
192 case XCB_CONFIGURE_NOTIFY
:
193 HandleParentStructure (vd
, (xcb_configure_notify_event_t
*)ev
);
196 /* FIXME I am not sure it is the right one */
197 case XCB_DESTROY_NOTIFY
:
198 vout_display_SendEventClose (vd
);
201 case XCB_MAPPING_NOTIFY
:
205 msg_Dbg (vd
, "unhandled event %"PRIu8
, ev
->response_type
);
213 * Process incoming X events.
215 int ManageEvent (vout_display_t
*vd
, xcb_connection_t
*conn
, bool *visible
)
217 xcb_generic_event_t
*ev
;
219 while ((ev
= xcb_poll_for_event (conn
)) != NULL
)
220 ProcessEvent (vd
, conn
, visible
, ev
);
222 if (xcb_connection_has_error (conn
))
224 msg_Err (vd
, "X server failure");