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.
10 #include <exec/types.h>
11 #include <exec/semaphores.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>
29 #include "sdl_intern.h"
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 ..*/
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
));
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
);
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
;
82 mid
= OOP_GetMethodID(IID_Hidd_SDLKbd
, moHidd_SDLKbd_HandleEvent
);
87 OOP_DoMethod(o
, (OOP_Msg
) &msg
);
90 static struct OOP_MethodDescr SDLKbd_Root_descr
[] = {
91 {(OOP_MethodFunc
)SDLKbd__Root__New
, moRoot_New
},
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
},
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
},