2 * Copyright (C) 2005-2013 Team XBMC
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)
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.
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/>.
20 #include <wayland-client.h>
21 #include <xkbcommon/xkbcommon.h>
23 #include "windowing/DllWaylandClient.h"
24 #include "windowing/DllXKBCommon.h"
26 #include "CursorManager.h"
27 #include "EventListener.h"
29 #include "PointerProcessor.h"
31 xbmc::PointerProcessor::PointerProcessor(IEventListener &listener,
32 ICursorManager &manager) :
34 m_cursorManager(manager)
38 void xbmc::PointerProcessor::Motion(uint32_t time,
44 event.type = XBMC_MOUSEMOTION;
45 event.motion.xrel = ::round(x);
46 event.motion.yrel = ::round(y);
47 event.motion.state = 0;
48 event.motion.type = XBMC_MOUSEMOTION;
49 event.motion.which = 0;
50 event.motion.x = event.motion.xrel;
51 event.motion.y = event.motion.yrel;
56 m_listener.OnEvent(event);
59 void xbmc::PointerProcessor::Button(uint32_t serial,
62 enum wl_pointer_button_state state)
64 static const struct ButtonTable
66 unsigned int WaylandButton;
67 unsigned int XBMCButton;
70 { WaylandLeftButton, 1 },
71 { WaylandMiddleButton, 2 },
72 { WaylandRightButton, 3 }
75 size_t buttonTableSize = sizeof(buttonTable) / sizeof(buttonTable[0]);
77 /* Find the xbmc button number that corresponds to the evdev
78 * button that we just received. There may be some buttons we don't
79 * recognize so just ignore them */
80 unsigned int xbmcButton = 0;
82 for (size_t i = 0; i < buttonTableSize; ++i)
83 if (buttonTable[i].WaylandButton == button)
84 xbmcButton = buttonTable[i].XBMCButton;
89 /* Keep track of currently pressed buttons, we need that for
91 if (state & WL_POINTER_BUTTON_STATE_PRESSED)
92 m_currentlyPressedButton |= 1 << button;
93 else if (state & WL_POINTER_BUTTON_STATE_RELEASED)
94 m_currentlyPressedButton &= ~(1 << button);
98 event.type = state & WL_POINTER_BUTTON_STATE_PRESSED ?
99 XBMC_MOUSEBUTTONDOWN : XBMC_MOUSEBUTTONUP;
100 event.button.button = xbmcButton;
101 event.button.state = 0;
102 event.button.type = event.type;
103 event.button.which = 0;
104 event.button.x = ::round(m_lastPointerX);
105 event.button.y = ::round(m_lastPointerY);
107 m_listener.OnEvent(event);
110 void xbmc::PointerProcessor::Axis(uint32_t time,
114 if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL)
117 bool direction = value < 0.0f;
118 int button = direction ? WheelUpButton :
121 /* For axis events we only care about the vector direction
122 * and not the scalar magnitude. Every axis event callback
123 * generates one scroll button event for XBMC */
126 event.type = XBMC_MOUSEBUTTONDOWN;
127 event.button.button = button;
128 event.button.state = 0;
129 event.button.type = XBMC_MOUSEBUTTONDOWN;
130 event.button.which = 0;
131 event.button.x = ::round(m_lastPointerX);
132 event.button.y = ::round(m_lastPointerY);
134 m_listener.OnEvent(event);
136 /* We must also send a button up on the same
138 event.type = XBMC_MOUSEBUTTONUP;
139 event.button.type = XBMC_MOUSEBUTTONUP;
141 m_listener.OnEvent(event);
146 xbmc::PointerProcessor::Enter(struct wl_surface *surface,
150 m_cursorManager.SetCursor(0, NULL, 0, 0);