/* * \brief Genode-specific event backend * \author Stefan Kalkowski * \date 2008-12-12 */ /* * Copyright (c) <2008> Stefan Kalkowski * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, * copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following * conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. */ #include #include #include #include extern "C" { #include #include "SDL_events_c.h" #include "SDL_sysevents.h" #include "SDL_genode_fb_events.h" static Input::Connection *input = 0; static Input::Event *ev_buf = 0; static const int KEYNUM_MAX = 512; static SDLKey keymap[KEYNUM_MAX]; static int buttonmap[KEYNUM_MAX]; inline SDL_keysym *Genode_Fb_TranslateKey(int keycode, SDL_keysym *k) { k->scancode = keycode; k->sym = keymap[keycode]; k->mod = SDL_GetModState(); k->unicode = keymap[keycode]; return k; } void Genode_Fb_PumpEvents(SDL_VideoDevice *t) { if (!input->is_pending()) return; int num_ev = input->flush(); for (int src_ev_cnt = 0; src_ev_cnt < num_ev; src_ev_cnt++) { Input::Event curr = ev_buf[src_ev_cnt]; SDL_keysym ksym; switch(curr.type()) { case Input::Event::MOTION: if (curr.is_absolute_motion()) SDL_PrivateMouseMotion(0, 0, curr.ax(), curr.ay()); else SDL_PrivateMouseMotion(0, 1, curr.rx(), curr.ry()); break; case Input::Event::PRESS: if(curr.code() >= Input::BTN_MISC && curr.code() <= Input::BTN_GEAR_UP) SDL_PrivateMouseButton(SDL_PRESSED, buttonmap[curr.code()], 0, 0); else SDL_PrivateKeyboard(SDL_PRESSED, Genode_Fb_TranslateKey(curr.code(), &ksym)); break; case Input::Event::RELEASE: if(curr.code() >= Input::BTN_MISC && curr.code() <= Input::BTN_GEAR_UP) SDL_PrivateMouseButton(SDL_RELEASED, buttonmap[curr.code()], 0, 0); else SDL_PrivateKeyboard(SDL_RELEASED, Genode_Fb_TranslateKey(curr.code(), &ksym)); break; case Input::Event::WHEEL: PWRN("Mouse wheel, not implemented yet!"); break; default: break; } } } void Genode_Fb_InitOSKeymap(SDL_VideoDevice *t) { using namespace Input; input = new(Genode::env()->heap()) Connection(); if(!input->cap().valid()) { PERR("No input driver available!"); return; } /* Attach event buffer to address space */ ev_buf = Genode::env()->rm_session()->attach(input->dataspace()); /* Prepare button mappings */ for (int i=0; i