Added missing properties.
[AROS.git] / arch / all-hosted / hidd / sdl / event.c
blob03a2bef05d479dade76074f51270cdda7e40e2a0
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 <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>
20 #ifdef __THROW
21 #undef __THROW
22 #endif
23 #ifdef __CONCAT
24 #undef __CONCAT
25 #endif
27 #include "sdl_intern.h"
29 #define DEBUG 0
30 #include <aros/debug.h>
32 #define MAX_EVENTS (64)
34 AROS_INTH1(tick_handler, struct Task *,task)
36 AROS_INTFUNC_INIT
38 Signal(task, SIGBREAKF_CTRL_D);
40 return FALSE;
42 AROS_INTFUNC_EXIT
46 VOID sdl_event_task(struct Task *creator, ULONG sync, LIBBASETYPEPTR LIBBASE) {
47 struct Interrupt tick_int;
48 SDL_Event e[MAX_EVENTS];
49 int nevents, i;
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"));
66 while (1) {
67 Uint8 active = 1;
69 Wait(SIGBREAKF_CTRL_D);
71 SV(SDL_PumpEvents);
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++) {
76 switch (e[i].type) {
77 case SDL_ACTIVEEVENT:
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);
84 break;
85 case SDL_MOUSEMOTION:
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 */
91 if (active) {
92 D(bug("[sdl] got mouse event, sending to mouse hidd\n"));
94 if (LIBBASE->mousehidd)
95 Hidd_SDLMouse_HandleEvent(LIBBASE->mousehidd, &e[i]);
97 break;
99 case SDL_KEYUP:
100 case SDL_KEYDOWN:
101 D(bug("[sdl] got keyboard event, sending to keyboard hidd\n"));
103 if (LIBBASE->kbdhidd)
104 Hidd_SDLMouse_HandleEvent(LIBBASE->kbdhidd, &e[i]);
106 break;
113 int sdl_event_init(LIBBASETYPEPTR LIBBASE) {
114 struct Task *task;
115 APTR stack;
116 ULONG sync;
118 D(bug("[sdl] creating event loop task\n"));
120 if ((task = AllocMem(sizeof(struct Task), MEMF_PUBLIC | MEMF_CLEAR)) == NULL) {
121 D(bug("[sdl] couldn't allocate task memory\n"));
122 return FALSE;
125 if ((stack = AllocMem(AROS_STACKSIZE, MEMF_PUBLIC)) == NULL) {
126 D(bug("[sdl] couldn't allocate task stack memory\n"));
127 FreeMem(task, sizeof(struct Task));
128 return FALSE;
131 task->tc_Node.ln_Type = NT_TASK;
132 task->tc_Node.ln_Name = "sdl.hidd event task";
133 task->tc_Node.ln_Pri = 50;
135 NEWLIST(&task->tc_MemEntry);
137 task->tc_SPLower = stack;
138 task->tc_SPUpper = (UBYTE *) stack + AROS_STACKSIZE;
140 #if AROS_STACK_GROWS_DOWNWARDS
141 task->tc_SPReg = (UBYTE *) task->tc_SPUpper - SP_OFFSET;
142 #else
143 task->tc_SPReg = (UBYTE *) task->tc_SPLower + SP_OFFSET;
144 #endif
146 sync = SIGF_BLIT;
147 SetSignal(0, sync);
149 if (NewAddTask(task, sdl_event_task, NULL, TAGLIST(TASKTAG_ARG1, (IPTR)FindTask(NULL),
150 TASKTAG_ARG2, (IPTR)sync,
151 TASKTAG_ARG3, (IPTR)LIBBASE)) == NULL) {
152 D(bug("[sdl] new task creation failed\n"));
153 FreeMem(stack, AROS_STACKSIZE);
154 FreeMem(task, sizeof(struct Task));
155 return FALSE;
158 D(bug("[sdl] task created, waiting for it to start up\n"));
160 Wait(sync);
162 D(bug("[sdl] event loop task up and running\n"));
164 LIBBASE->eventtask = task;
166 return TRUE;
169 void sdl_event_expunge(LIBBASETYPEPTR LIBBASE)
171 RemTask(LIBBASE->eventtask);
172 LIBBASE->eventtask = NULL;