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 <aros/symbolsets.h>
11 #include <aros/libcall.h>
13 #include <exec/types.h>
14 #include <exec/tasks.h>
15 #include <exec/lists.h>
16 #include <hardware/intbits.h>
17 #include <proto/exec.h>
18 #include <proto/graphics.h>
27 #include "sdl_intern.h"
30 #include <aros/debug.h>
32 #define MAX_EVENTS (64)
34 AROS_INTH1(tick_handler
, struct Task
*,task
)
38 Signal(task
, SIGBREAKF_CTRL_D
);
46 VOID
sdl_event_task(struct Task
*creator
, ULONG sync
, LIBBASETYPEPTR LIBBASE
) {
47 struct Interrupt tick_int
;
48 SDL_Event e
[MAX_EVENTS
];
51 D(bug("[sdl] event loop task starting up\n"));
53 tick_int
.is_Code
= (VOID_FUNC
)tick_handler
;
54 tick_int
.is_Data
= FindTask(NULL
);
55 tick_int
.is_Node
.ln_Name
= "SDL event tick";
56 tick_int
.is_Node
.ln_Pri
= 0;
57 tick_int
.is_Node
.ln_Type
= NT_INTERRUPT
;
58 AddIntServer(INTB_VERTB
, &tick_int
);
60 D(bug("[sdl] event loop task running, signalling creator\n"));
62 Signal(creator
, sync
);
64 D(bug("[sdl] entering loop\n"));
69 Wait(SIGBREAKF_CTRL_D
);
72 if ((nevents
= S(SDL_PeepEvents
, e
, MAX_EVENTS
, SDL_GETEVENT
, SDL_MOUSEEVENTMASK
|SDL_KEYEVENTMASK
|SDL_ACTIVEEVENTMASK
)) > 0) {
73 D(bug("[sdl] %d events pending\n", nevents
));
75 for (i
= 0; i
< nevents
; i
++) {
78 if (e
[i
].active
.state
& SDL_APPINPUTFOCUS
) {
79 active
= e
[i
].active
.gain
;
80 D(bug("[sdl] Window active: %u\n", active
));
81 if (active
&& LIBBASE
->cb
)
82 LIBBASE
->cb(LIBBASE
->cbdata
, NULL
);
86 case SDL_MOUSEBUTTONDOWN
:
87 case SDL_MOUSEBUTTONUP
:
88 /* We report mouse events only if our window is active.
89 Some OSes (MS Windows) otherwise report mouse movements
90 for inactive windows too, this can confuse Intuition */
92 D(bug("[sdl] got mouse event, sending to mouse hidd\n"));
94 if (LIBBASE
->mousehidd
)
95 Hidd_SDLMouse_HandleEvent(LIBBASE
->mousehidd
, &e
[i
]);
101 D(bug("[sdl] got keyboard event, sending to keyboard hidd\n"));
103 if (LIBBASE
->kbdhidd
)
104 Hidd_SDLKbd_HandleEvent(LIBBASE
->kbdhidd
, &e
[i
]);
113 int sdl_event_init(LIBBASETYPEPTR LIBBASE
) {
117 D(bug("[sdl] creating event loop task\n"));
122 if ((task
= NewCreateTask(TASKTAG_PC
, sdl_event_task
,
123 TASKTAG_STACKSIZE
, AROS_STACKSIZE
,
124 TASKTAG_NAME
, "sdl.hidd event task",
126 TASKTAG_ARG1
, (IPTR
)FindTask(NULL
),
127 TASKTAG_ARG2
, (IPTR
)sync
,
128 TASKTAG_ARG3
, (IPTR
)LIBBASE
,
131 D(bug("[sdl] new task creation failed\n"));
135 D(bug("[sdl] task created, waiting for it to start up\n"));
139 D(bug("[sdl] event loop task up and running\n"));
141 LIBBASE
->eventtask
= task
;
146 void sdl_event_expunge(LIBBASETYPEPTR LIBBASE
)
148 RemTask(LIBBASE
->eventtask
);
149 LIBBASE
->eventtask
= NULL
;