3 * Copyright (C) 2005-2014 Team XBMC
6 * This Program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This Program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with XBMC; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
27 #include "input/linux/LIRC.h"
29 #if defined(HAS_IRSERVERSUITE)
30 #include "input/windows/IRServerSuite.h"
33 #include "windowing/XBMC_events.h"
34 #include "input/KeyboardStat.h"
35 #include "input/MouseStat.h"
36 #include "settings/lib/ISettingCallback.h"
37 #include "threads/CriticalSection.h"
43 class IKeyboardHandler
;
46 class CInputManager
: public ISettingCallback
50 CInputManager(const CInputManager
&);
51 CInputManager
const& operator=(CInputManager
const&);
52 virtual ~CInputManager() { };
55 /*! \brief static method to get the current instance of the class. Creates a new instance the first time it's called.
57 static CInputManager
& GetInstance();
59 /*! \brief decode an input event from remote controls.
61 \param windowId Currently active window
62 \return true if event is handled, false otherwise
64 bool ProcessRemote(int windowId
);
66 /*! \brief decode a mouse event and reset idle timers.
68 \param windowId Currently active window
69 \return true if event is handled, false otherwise
71 bool ProcessMouse(int windowId
);
73 /*! \brief decode an event from the event service, this can be mouse, key, joystick, reset idle timers.
75 \param windowId Currently active window
76 \param frameTime Time in seconds since last call
77 \return true if event is handled, false otherwise
79 bool ProcessEventServer(int windowId
, float frameTime
);
81 /*! \brief decode an event from peripherals.
83 \param frameTime Time in seconds since last call
84 \return true if event is handled, false otherwise
86 bool ProcessPeripherals(float frameTime
);
88 /*! \brief Dispatch actions queued since the last call to Process()
90 void ProcessQueuedActions();
92 /*! \brief Queue an action to be processed on the next call to Process()
94 void QueueAction(const CAction
& action
);
96 /*! \brief Process all inputs
98 * \param windowId Currently active window
99 * \param frameTime Time in seconds since last call
100 * \return true on success, false otherwise
102 bool Process(int windowId
, float frameTime
);
105 * \brief Call once during application startup to initialize peripherals that need it
107 void InitializeInputs();
109 /*! \brief Enable or disable the joystick
111 * \param enabled true to enable joystick, false to disable
114 void SetEnabledJoystick(bool enabled
= true);
116 /*! \brief Handle an input event
118 * \param newEvent event details
119 * \return true on succesfully handled event
122 bool OnEvent(XBMC_Event
& newEvent
);
124 /*! \brief Control if the mouse is actively used or not
126 * \param[in] active sets mouse active or inactive
128 void SetMouseActive(bool active
= true);
130 /*! \brief Control if we should use a mouse or not
132 * \param[in] mouseEnabled sets mouse enabled or disabled
134 void SetMouseEnabled(bool mouseEnabled
= true);
136 /*! \brief Set the current state of the mouse such as click, drag operation
138 * \param[in] mouseState which state the mouse should be set to
141 void SetMouseState(MOUSE_STATE mouseState
);
143 /*! \brief Check if the mouse is currently active
145 * \return true if active, false otherwise
147 bool IsMouseActive();
149 /*! \brief Get the current state of the mouse, such as click or drag operation
151 * \return the current state of the mouse as a value from MOUSE_STATE
154 MOUSE_STATE
GetMouseState();
156 /*! \brief Get the current mouse positions x and y coordinates
158 * \return a struct containing the x and y coordinates
161 MousePosition
GetMousePosition();
163 /*! \brief Set the current screen resolution and pointer speed
165 * \param[in] maxX screen width
166 * \param[in] maxY screen height
167 * \param[in] speedX mouse speed in x dimension
168 * \param[in] speedY mouse speed in y dimension
171 void SetMouseResolution(int maxX
, int maxY
, float speedX
, float speedY
);
173 /*! \brief Enable the remote control
176 void EnableRemoteControl();
178 /*! \brief Disable the remote control
181 void DisableRemoteControl();
183 /*! \brief Try to connect to a remote control to listen for commands
186 void InitializeRemoteControl();
188 /*! \brief Check if the remote control is enabled
190 * \return true if remote control is enabled, false otherwise
192 bool IsRemoteControlEnabled();
194 /*! \brief Check if the remote control is initialized
196 * \return true if initialized, false otherwise
198 bool IsRemoteControlInitialized();
200 /*! \brief Set the device name to use with LIRC, does nothing
201 * if IRServerSuite is used
203 * \param[in] name Name of the device to use with LIRC
205 void SetRemoteControlName(const std::string
& name
);
207 /*! \brief Returns whether or not we can handle a given built-in command. */
209 bool HasBuiltin(const std::string
& command
);
211 /*! \brief Parse a builtin command and execute any input action
212 * currently only LIRC commands implemented
214 * \param[in] execute Command to execute
215 * \param[in] params parameters that was passed to the command
216 * \return 0 on success, -1 on failure
218 int ExecuteBuiltin(const std::string
& execute
, const std::vector
<std::string
>& params
);
220 virtual void OnSettingChanged(const CSetting
*setting
) override
;
222 void RegisterKeyboardHandler(KEYBOARD::IKeyboardHandler
* handler
);
223 void UnregisterKeyboardHandler(KEYBOARD::IKeyboardHandler
* handler
);
227 /*! \brief Process keyboard event and translate into an action
229 * \param CKey keypress details
230 * \return true on succesfully handled event
233 bool OnKey(const CKey
& key
);
235 /*! \brief Process key up event
237 * \param CKey details of released key
240 void OnKeyUp(const CKey
& key
);
242 /*! \brief Determine if an action should be processed or just
243 * cancel the screensaver
245 * \param action Action that is about to be processed
246 * \return true on any poweractions such as shutdown/reboot/sleep/suspend, false otherwise
249 bool AlwaysProcess(const CAction
& action
);
251 /*! \brief Send the Action to CApplication for further handling,
252 * play a sound before or after sending the action.
254 * \param action Action to send to CApplication
255 * \return result from CApplication::OnAction
258 bool ExecuteInputAction(const CAction
&action
);
260 CKeyboardStat m_Keyboard
;
264 #if defined(HAS_LIRC) || defined(HAS_IRSERVERSUITE)
265 CRemoteControl m_RemoteControl
;
268 #if defined(HAS_EVENT_SERVER)
269 std::map
<std::string
, std::map
<int, float> > m_lastAxisMap
;
272 std::vector
<CAction
> m_queuedActions
;
273 CCriticalSection m_actionMutex
;
275 std::vector
<KEYBOARD::IKeyboardHandler
*> m_keyboardHandlers
;