Added initial support for displaying on Wayland compositors.
[vuplus_xbmc] / xbmc / windowing / WinEventsWayland.cpp
1 /*
2 *      Copyright (C) 2005-2013 Team XBMC
3 *      http://www.xbmc.org
4 *
5 *  This Program is free software; you can redistribute it and/or modify
6 *  it under the terms of the GNU General Public License as published by
7 *  the Free Software Foundation; either version 2, or (at your option)
8 *  any later version.
9 *
10 *  This Program is distributed in the hope that it will be useful,
11 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 *  GNU General Public License for more details.
14 *
15 *  You should have received a copy of the GNU General Public License
16 *  along with XBMC; see the file COPYING.  If not, see
17 *  <http://www.gnu.org/licenses/>.
18 *
19 */
20 #include "system.h"
21
22 #if defined (HAVE_WAYLAND)
23
24 #include <memory>
25 #include <sstream>
26
27 #include <boost/noncopyable.hpp>
28 #include <boost/scope_exit.hpp>
29 #include <boost/scoped_ptr.hpp>
30
31 #include <sys/mman.h>
32
33 #include <wayland-client.h>
34 #include <xkbcommon/xkbcommon.h>
35
36 #include "Application.h"
37 #include "WindowingFactory.h"
38 #include "WinEvents.h"
39 #include "WinEventsWayland.h"
40
41 #include "DllWaylandClient.h"
42 #include "DllXKBCommon.h"
43 #include "WaylandProtocol.h"
44
45 namespace
46 {
47 IDllWaylandClient *g_clientLibrary = NULL;
48 struct wl_display *g_display = NULL;
49 }
50
51 CWinEventsWayland::CWinEventsWayland()
52 {
53 }
54
55 void CWinEventsWayland::RefreshDevices()
56 {
57 }
58
59 bool CWinEventsWayland::IsRemoteLowBattery()
60 {
61   return false;
62 }
63
64 /* This function reads the display connection and dispatches
65  * any events through the specified object listeners */
66 bool CWinEventsWayland::MessagePump()
67 {
68   if (!g_display)
69     return false;
70
71   /* It is very important that these functions occurr in this order.
72    * Deadlocks might occurr otherwise.
73    * 
74    * The first function dispatches any pending events that have been
75    * determined from prior reads of the event queue without *also*
76    * reading the event queue.
77    * 
78    * The second function flushes the output buffer of any requests
79    * to be made to the server, including requests that should have
80    * been made in response to just-dispatched events earlier.
81    * 
82    * The third function reads the input buffer and dispatches any events
83    * that occurred.
84    * 
85    * If the functions are not called in this order, you might run into
86    * a situation where pending-dispatch events might have generated a
87    * write to the event queue in order to keep us awake (frame events
88    * are a particular culprit here), or where events that we need to
89    * dispatch in order to keep going are never read.
90    */
91   g_clientLibrary->wl_display_dispatch_pending(g_display);
92   g_clientLibrary->wl_display_flush(g_display);
93   g_clientLibrary->wl_display_dispatch(g_display);
94
95   return true;
96 }
97
98 size_t CWinEventsWayland::GetQueueSize()
99 {
100   /* We can't query the size of the queue */
101   return 0;
102 }
103
104 void CWinEventsWayland::SetWaylandDisplay(IDllWaylandClient *clientLibrary,
105                                           struct wl_display *d)
106 {
107   g_clientLibrary = clientLibrary;
108   g_display = d;
109 }
110
111 void CWinEventsWayland::DestroyWaylandDisplay()
112 {
113   /* We should make sure that everything else is gone first before
114    * destroying the display */
115   MessagePump();
116   g_display = NULL;
117 }
118
119 #endif