2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2009 Sam Lantinga
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "SDL_config.h"
25 File added by Alan Buckley (alan_baa@hotmail.com) for RISC OS compatability
28 Implements Pumping of events and WIMP polling
32 #include "SDL_syswm.h"
33 #include "../../events/SDL_sysevents.h"
34 #include "../../events/SDL_events_c.h"
35 #include "SDL_riscosvideo.h"
36 #include "SDL_riscosevents_c.h"
37 #include "SDL_riscosmouse_c.h"
38 #include "../../timer/SDL_timer_c.h"
46 #include "unixlib/os.h"
48 #if !SDL_THREADS_DISABLED
53 void WIMP_Poll(_THIS, int waitTime);
54 void WIMP_SetFocus(int win);
56 /* SDL_riscossprite functions */
57 void WIMP_PlotSprite(_THIS, int x, int y);
58 void WIMP_ModeChanged(_THIS);
59 void WIMP_PaletteChanged(_THIS);
62 extern void WIMP_PollMouse(_THIS);
63 extern void RISCOS_PollKeyboard();
65 #if SDL_THREADS_DISABLED
66 /* Timer running function */
67 extern void RISCOS_CheckTimer();
69 extern int riscos_using_threads;
72 /* Mouse cursor handling */
73 extern void WIMP_ReshowCursor(_THIS);
74 extern void WIMP_RestoreWimpCursor();
77 int mouseInWindow = 0;
79 /* Flag to ensure window is correct size after a mode change */
80 static int resizeOnOpen = 0;
82 void WIMP_PumpEvents(_THIS)
85 if (hasFocus) RISCOS_PollKeyboard();
86 if (mouseInWindow) WIMP_PollMouse(this);
87 #if SDL_THREADS_DISABLED
88 if (SDL_timer_running) RISCOS_CheckTimer();
93 void WIMP_Poll(_THIS, int waitTime)
95 _kernel_swi_regs regs;
101 int sdlWindow = this->hidden->window_handle;
103 if (this->PumpEvents != WIMP_PumpEvents) return;
107 _kernel_swi(OS_ReadMonotonicTime, ®s, ®s);
108 waitTime += regs.r[0];
113 #if !SDL_THREADS_DISABLED
114 /* Stop thread callbacks while program is paged out */
115 if (riscos_using_threads) __pthread_stop_ticker();
120 regs.r[0] = pollMask; /* Poll Mask */
121 /* For no wait time mask out null event so we wait until something happens */
122 if (waitTime < 0) regs.r[0] |= 1;
123 regs.r[1] = (int)message;
124 _kernel_swi(Wimp_Poll, ®s, ®s);
127 regs.r[0] = pollMask;
128 regs.r[1] = (int)message;
129 regs.r[2] = waitTime;
130 _kernel_swi(Wimp_PollIdle, ®s, ®s);
133 /* Flag to specify if we post a SDL_SysWMEvent */
136 code = (unsigned int)regs.r[0];
140 case 0: /* Null Event - drop out for standard processing*/
144 case 1: /* Redraw window */
145 _kernel_swi(Wimp_RedrawWindow, ®s,®s);
146 if (message[0] == sdlWindow)
150 WIMP_PlotSprite(this, message[1], message[2]);
151 _kernel_swi(Wimp_GetRectangle, ®s, ®s);
155 /* TODO: Currently we just eat them - we may need to pass them on */
158 _kernel_swi(Wimp_GetRectangle, ®s, ®s);
163 case 2: /* Open window */
164 if ( resizeOnOpen && message[0] == sdlWindow)
166 /* Ensure window is correct size */
168 message[3] = message[1] + (this->screen->w << this->hidden->xeig);
169 message[4] = message[2] + (this->screen->h << this->hidden->yeig);
171 _kernel_swi(Wimp_OpenWindow, ®s, ®s);
174 case 3: /* Close window */
175 if (message[0] == sdlWindow)
177 /* Documentation makes it looks as if the following line is correct:
178 ** if (SDL_PrivateQuit() == 1) _kernel_swi(Wimp_CloseWindow, ®s, ®s);
179 ** However some programs don't process this message and so sit there invisibly
180 ** in the background so I just post the quit message and hope the application
181 ** does the correct thing.
189 case 4: /* Pointer_Leaving_Window */
190 if (message[0] == sdlWindow)
193 //TODO: Lose buttons / dragging
194 /* Reset to default pointer */
195 WIMP_RestoreWimpCursor();
196 SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
201 case 5: /* Pointer_Entering_Window */
202 if (message[0] == sdlWindow)
205 WIMP_ReshowCursor(this);
206 SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
210 case 6: /* Mouse_Click */
213 /* First click gives focus if it's not a menu */
214 /* we only count non-menu clicks on a window that has the focus */
215 WIMP_SetFocus(message[3]);
217 doPoll = 0; // So PollMouse gets a chance to pick it up
220 case 7: /* User_Drag_Box - Used for mouse release */
221 //TODO: May need to implement this in the future
225 case 8: /* Keypressed */
226 doPoll = 0; /* PollKeyboard should pick it up */
227 if (message[0] != sdlWindow) sysEvent = 1;
228 /*TODO: May want to always pass F12 etc to the wimp
230 regs.r[0] = message[6];
231 _kernel_swi(Wimp_ProcessKey, ®s, ®s);
236 case 11: /* Lose Caret */
238 if (message[0] == sdlWindow) SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);
242 case 12: /* Gain Caret */
244 if (message[0] == sdlWindow) SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
250 sysEvent = 1; /* All messages are passed on */
254 case 0: /* Quit Event */
255 /* No choice - have to quit */
260 case 8: /* Pre Quit */
264 case 0x400c1: /* Mode change */
265 WIMP_ModeChanged(this);
269 case 9: /* Palette changed */
270 WIMP_PaletteChanged(this);
276 /* Pass unknown events on */
285 SDL_VERSION(&wmmsg.version);
286 wmmsg.eventCode = code;
287 SDL_memcpy(wmmsg.pollBlock, message, 64 * sizeof(int));
289 /* Fall out of polling loop if message is successfully posted */
290 if (SDL_PrivateSysWMEvent(&wmmsg)) doPoll = 0;
292 #if !SDL_THREADS_DISABLED
293 if (riscos_using_threads)
295 /* Restart ticker here so other thread can not interfere
296 with the Redraw processing */
297 if (riscos_using_threads) __pthread_start_ticker();
298 /* Give other threads a better chance of running */
305 /* Set focus to specified window */
306 void WIMP_SetFocus(int win)
308 _kernel_swi_regs regs;
311 regs.r[1] = -1; /* Icon handle */
312 regs.r[2] = 0; /* X-offset we just put it at position 0 */
313 regs.r[3] = 0; /* Y-offset as above */
314 regs.r[4] = 1 << 25; /* Caret is invisible */
315 regs.r[5] = 0; /* index into string */
317 _kernel_swi(Wimp_SetCaretPosition, ®s, ®s);
320 /** Run background task while in a sleep command */
321 void RISCOS_BackgroundTasks(void)
323 if (current_video && current_video->hidden->window_handle)
325 WIMP_Poll(current_video, 0);
327 #if SDL_THREADS_DISABLED
328 if (SDL_timer_running) RISCOS_CheckTimer();