Indentation fix, cleanup.
[AROS.git] / arch / all-hosted / hidd / sdl / kbdclass.c
blob80bf345e495d3193a53bb5cd8c28c937629fad7f
1 /*
2 * sdl.hidd - SDL graphics/sound/keyboard for AROS hosted
3 * Copyright (c) 2007 Robert Norris. All rights reserved.
4 * Copyright (c) 2010 The AROS Development Team. All rights reserved.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the same terms as AROS itself.
8 */
10 #include <exec/types.h>
11 #include <exec/semaphores.h>
12 #include <oop/oop.h>
13 #include <proto/exec.h>
14 #include <proto/utility.h>
15 #include <proto/oop.h>
17 #include <hidd/hidd.h>
18 #include <hidd/keyboard.h>
20 #include <devices/inputevent.h>
22 #ifdef __THROW
23 #undef __THROW
24 #endif
25 #ifdef __CONCAT
26 #undef __CONCAT
27 #endif
29 #include "sdl_intern.h"
31 #define DEBUG 0
32 #include <aros/debug.h>
34 OOP_Object *SDLKbd__Root__New(OOP_Class *cl, OOP_Object *o, struct pRoot_New *msg) {
35 struct kbddata *kbddata;
37 D(bug("[sdl] SDLKbd::New\n"));
39 /* we only support one instance ..*/
40 if (xsd.kbdhidd)
41 return NULL;
43 if ((o = (OOP_Object *) OOP_DoSuperMethod(cl, o, (OOP_Msg) msg)) != NULL)
45 kbddata = OOP_INST_DATA(cl, o);
47 kbddata->callback = (APTR)GetTagData(aHidd_Kbd_IrqHandler, 0, msg->attrList);
48 kbddata->callbackdata = (APTR)GetTagData(aHidd_Kbd_IrqHandlerData, 0, msg->attrList);
50 D(bug("[sdl] created keyboard hidd, callback 0x%08x, data 0x%08x\n", kbddata->callback, kbddata->callbackdata));
51 xsd.kbdhidd = o;
54 return (OOP_Object *) o;
57 VOID SDLKbd__Hidd_SDLKbd__HandleEvent(OOP_Class *cl, OOP_Object *o, struct pHidd_SDLKbd_HandleEvent *msg) {
58 struct kbddata *kbddata = OOP_INST_DATA(cl, o);
59 UWORD keycode;
61 D(bug("[sdl] SDLKbd::HandleEvent\n"));
63 D(bug("[sdl] %s event for sdl key 0x%04x\n", msg->e->key.state == SDL_PRESSED ? "PRESS" : "RELEASE",
64 msg->e->key.keysym.sym));
66 keycode = xsd.keycode[msg->e->key.keysym.sym];
68 D(bug("[sdl] converted to keycode 0x%02x\n", keycode));
70 if (msg->e->key.state == SDL_RELEASED)
71 keycode |= IECODE_UP_PREFIX;
73 if (kbddata->callback != NULL)
74 kbddata->callback(kbddata->callbackdata, keycode);
77 VOID Hidd_SDLKbd_HandleEvent(OOP_Object *o, SDL_Event *e) {
78 struct pHidd_SDLKbd_HandleEvent msg;
79 static OOP_MethodID mid;
81 if (!mid)
82 mid = OOP_GetMethodID(IID_Hidd_SDLKbd, moHidd_SDLKbd_HandleEvent);
84 msg.mID = mid;
85 msg.e = e;
87 OOP_DoMethod(o, (OOP_Msg) &msg);
90 static struct OOP_MethodDescr SDLKbd_Root_descr[] = {
91 {(OOP_MethodFunc)SDLKbd__Root__New, moRoot_New},
92 {NULL , 0 }
94 #define NUM_SDLKbd_Root_METHODS 1
96 static struct OOP_MethodDescr SDLKbd_Hidd_SDLKbd_descr[] = {
97 {(OOP_MethodFunc)SDLKbd__Hidd_SDLKbd__HandleEvent, moHidd_SDLKbd_HandleEvent},
98 {NULL, 0}
100 #define NUM_SDLKbd_Hidd_SDLKbd_METHODS 1
102 struct OOP_InterfaceDescr SDLKbd_ifdescr[] = {
103 {SDLKbd_Root_descr , IID_Root , NUM_SDLKbd_Root_METHODS },
104 {SDLKbd_Hidd_SDLKbd_descr, IID_Hidd_SDLKbd, NUM_SDLKbd_Hidd_SDLKbd_METHODS},
105 {NULL , NULL }