[cosmetic] cleanup copyright headers
[vuplus_xbmc] / xbmc / windowing / wayland / Pointer.cpp
1 /*
2  *      Copyright (C) 2011-2013 Team XBMC
3  *      http://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 <sstream>
21 #include <iostream>
22 #include <stdexcept>
23
24 #include <wayland-client.h>
25
26 #include "windowing/DllWaylandClient.h"
27 #include "windowing/WaylandProtocol.h"
28 #include "Pointer.h"
29
30 namespace xw = xbmc::wayland;
31
32 const struct wl_pointer_listener xw::Pointer::m_listener =
33 {
34   Pointer::HandleEnterCallback,
35   Pointer::HandleLeaveCallback,
36   Pointer::HandleMotionCallback,
37   Pointer::HandleButtonCallback,
38   Pointer::HandleAxisCallback
39 };
40
41 xw::Pointer::Pointer(IDllWaylandClient &clientLibrary,
42                      struct wl_pointer *pointer,
43                      IPointerReceiver &receiver) :
44   m_clientLibrary(clientLibrary),
45   m_pointer(pointer),
46   m_receiver(receiver)
47 {
48   protocol::AddListenerOnWaylandObject(m_clientLibrary,
49                                        pointer,
50                                        &m_listener,
51                                        this);
52 }
53
54 xw::Pointer::~Pointer()
55 {
56   protocol::DestroyWaylandObject(m_clientLibrary,
57                                  m_pointer);
58 }
59
60 void xw::Pointer::SetCursor(uint32_t serial,
61                             struct wl_surface *surface,
62                             int32_t hotspot_x,
63                             int32_t hotspot_y)
64 {
65   protocol::CallMethodOnWaylandObject(m_clientLibrary,
66                                       m_pointer,
67                                       WL_POINTER_SET_CURSOR,
68                                       serial,
69                                       surface,
70                                       hotspot_x,
71                                       hotspot_y);
72 }
73
74 void xw::Pointer::HandleEnterCallback(void *data,
75                                       struct wl_pointer *pointer,
76                                       uint32_t serial,
77                                       struct wl_surface *surface,
78                                       wl_fixed_t x,
79                                       wl_fixed_t y)
80 {
81   static_cast<Pointer *>(data)->HandleEnter(serial,
82                                             surface,
83                                             x,
84                                             y);
85 }
86
87 void xw::Pointer::HandleLeaveCallback(void *data,
88                                       struct wl_pointer *pointer,
89                                       uint32_t serial,
90                                       struct wl_surface *surface)
91 {
92   static_cast<Pointer *>(data)->HandleLeave(serial, surface);
93 }
94
95 void xw::Pointer::HandleMotionCallback(void *data,
96                                        struct wl_pointer *pointer,
97                                        uint32_t time,
98                                        wl_fixed_t x,
99                                        wl_fixed_t y)
100 {
101   static_cast<Pointer *>(data)->HandleMotion(time,
102                                              x,
103                                              y);
104 }
105
106 void xw::Pointer::HandleButtonCallback(void *data,
107                                        struct wl_pointer * pointer,
108                                        uint32_t serial,
109                                        uint32_t time,
110                                        uint32_t button,
111                                        uint32_t state)
112 {
113   static_cast<Pointer *>(data)->HandleButton(serial,
114                                              time,
115                                              button,
116                                              state);
117 }
118
119 void xw::Pointer::HandleAxisCallback(void *data,
120                                      struct wl_pointer *pointer,
121                                      uint32_t time,
122                                      uint32_t axis,
123                                      wl_fixed_t value)
124 {
125   static_cast<Pointer *>(data)->HandleAxis(time,
126                                            axis,
127                                            value);
128 }
129
130 void xw::Pointer::HandleEnter(uint32_t serial,
131                               struct wl_surface *surface,
132                               wl_fixed_t surfaceXFixed,
133                               wl_fixed_t surfaceYFixed)
134 {
135   m_receiver.Enter(surface,
136                    wl_fixed_to_double(surfaceXFixed),
137                    wl_fixed_to_double(surfaceYFixed));
138 }
139
140 void xw::Pointer::HandleLeave(uint32_t serial,
141                               struct wl_surface *surface)
142 {
143 }
144
145 void xw::Pointer::HandleMotion(uint32_t time,
146                                wl_fixed_t surfaceXFixed,
147                                wl_fixed_t surfaceYFixed)
148 {
149   m_receiver.Motion(time,
150                     wl_fixed_to_double(surfaceXFixed),
151                     wl_fixed_to_double(surfaceYFixed));
152 }
153
154 void xw::Pointer::HandleButton(uint32_t serial,
155                                uint32_t time,
156                                uint32_t button,
157                                uint32_t state)
158 {
159   m_receiver.Button(serial,
160                     time,
161                     button,
162                     static_cast<enum wl_pointer_button_state>(state));
163 }
164
165 void xw::Pointer::HandleAxis(uint32_t time,
166                              uint32_t axis,
167                              wl_fixed_t value)
168 {
169   m_receiver.Axis(time,
170                   axis,
171                   wl_fixed_to_double(value));
172 }