garbear / xbmc

XBMC Main Repository
http://xbmc.org
Other
134 stars 53 forks source link

Mouse support for game add-ons #66

Closed garbear closed 7 years ago

garbear commented 7 years ago

I'll outline mouse support for anyone who would like to work on this, I know @fetzerch was interested.

Mouse support is fully implemented in game.libretro. The libretro API requests mouse input via RETRO_DEVICE_ID_MOUSE_X/Y here. This reads mouse data; the data is written by the Game API event GAME_INPUT_EVENT_RELATIVE_POINTER here. The challenge is to implement this mouse event in Kodi.

Fortunately, a solution exists in the form of keyboard input. 99% of mouse implementation will be copying keyboard code. I'll start at the GAME_INPUT_EVENT_KEY event here and work backwards to see what we need for mouse input.

The GAME_INPUT_EVENT_KEY is generated by CGameClientKeyboard here. This means we need a CGameClientMouse class.

CGameClientKeyboard implements the KEYBOARD::IKeyboardHandler interface at xbmc/input/keyboard/IKeyboardHandler.h interface. Similarly, we'll need to create a MOUSE::IMouseHandler interface at xbmc/input/mouse/IMouseHandler.h. Count yourself lucky - not everyone gets to create a new source code folder in Kodi :wink:

When a game is opened, if <supports_keyboard> is true, then CGameClient::OpenKeyboard() is called. We need a <supports_mouse> parameter and a corresponding CGameClient::OpenMouse() function.

When OpenKeyboard() is called, the keyboard handler is created and registers itself via CInputManager::RegisterKeyboardHandler() here. We need a CInputManager::RegisterMouseHandler() function and a vector to store mouse handlers.

100% of key presses pass through CInputManager::OnKey() here. We need to find a location where all mouse events pass (hint: CInputManager::ProcessMouse()). Then, similar to key presses, if a registered mouse handler returns true, we prevent the input from reaching Kodi.

And that's basically it. Keyboard input required some refactoring (#6779), so expect CInputManager to need some refactoring for mouse hooking as well. This will probably be the most difficult part, as everything else is very straight-forward.

fetzerch commented 7 years ago

Thanks for this great guide. Started work in https://github.com/fetzerch/xbmc/tree/retroplayer-17beta4 and https://github.com/fetzerch/game.libretro.scummvm/tree/mouse.

garbear commented 7 years ago

closed by https://github.com/garbear/xbmc/pull/67