comparison src/video/riscos/SDL_wimppoll.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents a30f8553eeb1
children 4da1ee79c9af
comparison
equal deleted inserted replaced
1661:281d3f4870e5 1662:782fd950bd46
48 #if !SDL_THREADS_DISABLED 48 #if !SDL_THREADS_DISABLED
49 #include <pthread.h> 49 #include <pthread.h>
50 #endif 50 #endif
51 51
52 /* Local functions */ 52 /* Local functions */
53 void WIMP_Poll(_THIS, int waitTime); 53 void WIMP_Poll (_THIS, int waitTime);
54 void WIMP_SetFocus(int win); 54 void WIMP_SetFocus (int win);
55 55
56 /* SDL_riscossprite functions */ 56 /* SDL_riscossprite functions */
57 void WIMP_PlotSprite(_THIS, int x, int y); 57 void WIMP_PlotSprite (_THIS, int x, int y);
58 void WIMP_ModeChanged(_THIS); 58 void WIMP_ModeChanged (_THIS);
59 void WIMP_PaletteChanged(_THIS); 59 void WIMP_PaletteChanged (_THIS);
60 60
61 61
62 extern void WIMP_PollMouse(_THIS); 62 extern void WIMP_PollMouse (_THIS);
63 extern void RISCOS_PollKeyboard(); 63 extern void RISCOS_PollKeyboard ();
64 64
65 #if SDL_THREADS_DISABLED 65 #if SDL_THREADS_DISABLED
66 /* Timer running function */ 66 /* Timer running function */
67 extern void RISCOS_CheckTimer(); 67 extern void RISCOS_CheckTimer ();
68 #else 68 #else
69 extern int riscos_using_threads; 69 extern int riscos_using_threads;
70 #endif 70 #endif
71 71
72 /* Mouse cursor handling */ 72 /* Mouse cursor handling */
73 extern void WIMP_ReshowCursor(_THIS); 73 extern void WIMP_ReshowCursor (_THIS);
74 extern void WIMP_RestoreWimpCursor(); 74 extern void WIMP_RestoreWimpCursor ();
75 75
76 int hasFocus = 0; 76 int hasFocus = 0;
77 int mouseInWindow = 0; 77 int mouseInWindow = 0;
78 78
79 /* Flag to ensure window is correct size after a mode change */ 79 /* Flag to ensure window is correct size after a mode change */
80 static int resizeOnOpen = 0; 80 static int resizeOnOpen = 0;
81 81
82 void WIMP_PumpEvents(_THIS) 82 void
83 WIMP_PumpEvents (_THIS)
83 { 84 {
84 WIMP_Poll(this, 0); 85 WIMP_Poll (this, 0);
85 if (hasFocus) RISCOS_PollKeyboard(); 86 if (hasFocus)
86 if (mouseInWindow) WIMP_PollMouse(this); 87 RISCOS_PollKeyboard ();
88 if (mouseInWindow)
89 WIMP_PollMouse (this);
87 #if SDL_THREADS_DISABLED 90 #if SDL_THREADS_DISABLED
88 if (SDL_timer_running) RISCOS_CheckTimer(); 91 if (SDL_timer_running)
92 RISCOS_CheckTimer ();
89 #endif 93 #endif
90 } 94 }
91 95
92 96
93 void WIMP_Poll(_THIS, int waitTime) 97 void
98 WIMP_Poll (_THIS, int waitTime)
94 { 99 {
95 _kernel_swi_regs regs; 100 _kernel_swi_regs regs;
96 int message[64]; 101 int message[64];
97 unsigned int code; 102 unsigned int code;
98 int pollMask = 0; 103 int pollMask = 0;
99 int doPoll = 1; 104 int doPoll = 1;
100 int sysEvent; 105 int sysEvent;
101 int sdlWindow = this->hidden->window_handle; 106 int sdlWindow = this->hidden->window_handle;
102 107
103 if (this->PumpEvents != WIMP_PumpEvents) return; 108 if (this->PumpEvents != WIMP_PumpEvents)
104 109 return;
105 if (waitTime > 0) 110
106 { 111 if (waitTime > 0) {
107 _kernel_swi(OS_ReadMonotonicTime, &regs, &regs); 112 _kernel_swi (OS_ReadMonotonicTime, &regs, &regs);
108 waitTime += regs.r[0]; 113 waitTime += regs.r[0];
109 } 114 }
110 115
111 while (doPoll) 116 while (doPoll) {
112 {
113 #if !SDL_THREADS_DISABLED 117 #if !SDL_THREADS_DISABLED
114 /* Stop thread callbacks while program is paged out */ 118 /* Stop thread callbacks while program is paged out */
115 if (riscos_using_threads) __pthread_stop_ticker(); 119 if (riscos_using_threads)
116 #endif 120 __pthread_stop_ticker ();
117 121 #endif
118 if (waitTime <= 0) 122
119 { 123 if (waitTime <= 0) {
120 regs.r[0] = pollMask; /* Poll Mask */ 124 regs.r[0] = pollMask; /* Poll Mask */
121 /* For no wait time mask out null event so we wait until something happens */ 125 /* For no wait time mask out null event so we wait until something happens */
122 if (waitTime < 0) regs.r[0] |= 1; 126 if (waitTime < 0)
123 regs.r[1] = (int)message; 127 regs.r[0] |= 1;
124 _kernel_swi(Wimp_Poll, &regs, &regs); 128 regs.r[1] = (int) message;
125 } else 129 _kernel_swi (Wimp_Poll, &regs, &regs);
126 { 130 } else {
127 regs.r[0] = pollMask; 131 regs.r[0] = pollMask;
128 regs.r[1] = (int)message; 132 regs.r[1] = (int) message;
129 regs.r[2] = waitTime; 133 regs.r[2] = waitTime;
130 _kernel_swi(Wimp_PollIdle, &regs, &regs); 134 _kernel_swi (Wimp_PollIdle, &regs, &regs);
131 } 135 }
132 136
133 /* Flag to specify if we post a SDL_SysWMEvent */ 137 /* Flag to specify if we post a SDL_SysWMEvent */
134 sysEvent = 0; 138 sysEvent = 0;
135 139
136 code = (unsigned int)regs.r[0]; 140 code = (unsigned int) regs.r[0];
137 141
138 switch(code) 142 switch (code) {
139 { 143 case 0: /* Null Event - drop out for standard processing */
140 case 0: /* Null Event - drop out for standard processing*/ 144 doPoll = 0;
141 doPoll = 0; 145 break;
142 break; 146
143 147 case 1: /* Redraw window */
144 case 1: /* Redraw window */ 148 _kernel_swi (Wimp_RedrawWindow, &regs, &regs);
145 _kernel_swi(Wimp_RedrawWindow, &regs,&regs); 149 if (message[0] == sdlWindow) {
146 if (message[0] == sdlWindow) 150 while (regs.r[0]) {
147 { 151 WIMP_PlotSprite (this, message[1], message[2]);
148 while (regs.r[0]) 152 _kernel_swi (Wimp_GetRectangle, &regs, &regs);
149 { 153 }
150 WIMP_PlotSprite(this, message[1], message[2]); 154 } else {
151 _kernel_swi(Wimp_GetRectangle, &regs, &regs); 155 /* TODO: Currently we just eat them - we may need to pass them on */
152 } 156 while (regs.r[0]) {
153 } else 157 _kernel_swi (Wimp_GetRectangle, &regs, &regs);
154 { 158 }
155 /* TODO: Currently we just eat them - we may need to pass them on */ 159 }
156 while (regs.r[0]) 160 break;
157 { 161
158 _kernel_swi(Wimp_GetRectangle, &regs, &regs); 162 case 2: /* Open window */
159 } 163 if (resizeOnOpen && message[0] == sdlWindow) {
160 } 164 /* Ensure window is correct size */
161 break; 165 resizeOnOpen = 0;
162 166 message[3] =
163 case 2: /* Open window */ 167 message[1] + (this->screen->w << this->hidden->xeig);
164 if ( resizeOnOpen && message[0] == sdlWindow) 168 message[4] =
165 { 169 message[2] + (this->screen->h << this->hidden->yeig);
166 /* Ensure window is correct size */ 170 }
167 resizeOnOpen = 0; 171 _kernel_swi (Wimp_OpenWindow, &regs, &regs);
168 message[3] = message[1] + (this->screen->w << this->hidden->xeig); 172 break;
169 message[4] = message[2] + (this->screen->h << this->hidden->yeig); 173
170 } 174 case 3: /* Close window */
171 _kernel_swi(Wimp_OpenWindow, &regs, &regs); 175 if (message[0] == sdlWindow) {
172 break; 176 /* Documentation makes it looks as if the following line is correct:
173 177 ** if (SDL_PrivateQuit() == 1) _kernel_swi(Wimp_CloseWindow, &regs, &regs);
174 case 3: /* Close window */ 178 ** However some programs don't process this message and so sit there invisibly
175 if (message[0] == sdlWindow) 179 ** in the background so I just post the quit message and hope the application
176 { 180 ** does the correct thing.
177 /* Documentation makes it looks as if the following line is correct: 181 */
178 ** if (SDL_PrivateQuit() == 1) _kernel_swi(Wimp_CloseWindow, &regs, &regs); 182 SDL_PrivateQuit ();
179 ** However some programs don't process this message and so sit there invisibly 183 } else
180 ** in the background so I just post the quit message and hope the application 184 sysEvent = 1;
181 ** does the correct thing. 185 doPoll = 0;
182 */ 186 break;
183 SDL_PrivateQuit(); 187
184 } else 188 case 4: /* Pointer_Leaving_Window */
185 sysEvent = 1; 189 if (message[0] == sdlWindow) {
186 doPoll = 0; 190 mouseInWindow = 0;
187 break; 191 //TODO: Lose buttons / dragging
188 192 /* Reset to default pointer */
189 case 4: /* Pointer_Leaving_Window */ 193 WIMP_RestoreWimpCursor ();
190 if (message[0] == sdlWindow) 194 SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS);
191 { 195 } else
192 mouseInWindow = 0; 196 sysEvent = 1;
193 //TODO: Lose buttons / dragging 197 break;
194 /* Reset to default pointer */ 198
195 WIMP_RestoreWimpCursor(); 199 case 5: /* Pointer_Entering_Window */
196 SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS); 200 if (message[0] == sdlWindow) {
197 } else 201 mouseInWindow = 1;
198 sysEvent = 1; 202 WIMP_ReshowCursor (this);
199 break; 203 SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS);
200 204 } else
201 case 5: /* Pointer_Entering_Window */ 205 sysEvent = 1;
202 if (message[0] == sdlWindow) 206 break;
203 { 207
204 mouseInWindow = 1; 208 case 6: /* Mouse_Click */
205 WIMP_ReshowCursor(this); 209 if (hasFocus == 0) {
206 SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS); 210 /* First click gives focus if it's not a menu */
207 } else sysEvent = 1; 211 /* we only count non-menu clicks on a window that has the focus */
208 break; 212 WIMP_SetFocus (message[3]);
209 213 } else
210 case 6: /* Mouse_Click */ 214 doPoll = 0; // So PollMouse gets a chance to pick it up
211 if (hasFocus == 0) 215 break;
212 { 216
213 /* First click gives focus if it's not a menu */ 217 case 7: /* User_Drag_Box - Used for mouse release */
214 /* we only count non-menu clicks on a window that has the focus */ 218 //TODO: May need to implement this in the future
215 WIMP_SetFocus(message[3]); 219 sysEvent = 1;
216 } else 220 break;
217 doPoll = 0; // So PollMouse gets a chance to pick it up 221
218 break; 222 case 8: /* Keypressed */
219 223 doPoll = 0; /* PollKeyboard should pick it up */
220 case 7: /* User_Drag_Box - Used for mouse release */ 224 if (message[0] != sdlWindow)
221 //TODO: May need to implement this in the future 225 sysEvent = 1;
222 sysEvent = 1; 226 /*TODO: May want to always pass F12 etc to the wimp
223 break; 227 {
224 228 regs.r[0] = message[6];
225 case 8: /* Keypressed */ 229 _kernel_swi(Wimp_ProcessKey, &regs, &regs);
226 doPoll = 0; /* PollKeyboard should pick it up */ 230 }
227 if (message[0] != sdlWindow) sysEvent = 1; 231 */
228 /*TODO: May want to always pass F12 etc to the wimp 232 break;
229 { 233
230 regs.r[0] = message[6]; 234 case 11: /* Lose Caret */
231 _kernel_swi(Wimp_ProcessKey, &regs, &regs); 235 hasFocus = 0;
232 } 236 if (message[0] == sdlWindow)
233 */ 237 SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS);
234 break; 238 else
235 239 sysEvent = 1;
236 case 11: /* Lose Caret */ 240 break;
237 hasFocus = 0; 241
238 if (message[0] == sdlWindow) SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS); 242 case 12: /* Gain Caret */
239 else sysEvent = 1; 243 hasFocus = 1;
240 break; 244 if (message[0] == sdlWindow)
241 245 SDL_PrivateAppActive (1, SDL_APPINPUTFOCUS);
242 case 12: /* Gain Caret */ 246 else
243 hasFocus = 1; 247 sysEvent = 1;
244 if (message[0] == sdlWindow) SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS); 248 break;
245 else sysEvent = 1; 249
246 break; 250 case 17:
247 251 case 18:
248 case 17: 252 sysEvent = 1; /* All messages are passed on */
249 case 18: 253
250 sysEvent = 1; /* All messages are passed on */ 254 switch (message[4]) {
251 255 case 0: /* Quit Event */
252 switch(message[4]) 256 /* No choice - have to quit */
253 { 257 SDL_Quit ();
254 case 0: /* Quit Event */ 258 exit (0);
255 /* No choice - have to quit */ 259 break;
256 SDL_Quit(); 260
257 exit(0); 261 case 8: /* Pre Quit */
258 break; 262 SDL_PrivateQuit ();
259 263 break;
260 case 8: /* Pre Quit */ 264
261 SDL_PrivateQuit(); 265 case 0x400c1: /* Mode change */
262 break; 266 WIMP_ModeChanged (this);
263 267 resizeOnOpen = 1;
264 case 0x400c1: /* Mode change */ 268 break;
265 WIMP_ModeChanged(this); 269
266 resizeOnOpen = 1; 270 case 9: /* Palette changed */
267 break; 271 WIMP_PaletteChanged (this);
268 272 break;
269 case 9: /* Palette changed */ 273 }
270 WIMP_PaletteChanged(this); 274 break;
271 break; 275
272 } 276 default:
273 break; 277 /* Pass unknown events on */
274 278 sysEvent = 1;
275 default: 279 break;
276 /* Pass unknown events on */ 280 }
277 sysEvent = 1; 281
278 break; 282 if (sysEvent) {
279 } 283 SDL_SysWMmsg wmmsg;
280 284
281 if (sysEvent) 285 SDL_VERSION (&wmmsg.version);
282 { 286 wmmsg.eventCode = code;
283 SDL_SysWMmsg wmmsg; 287 SDL_memcpy (wmmsg.pollBlock, message, 64 * sizeof (int));
284 288
285 SDL_VERSION(&wmmsg.version); 289 /* Fall out of polling loop if message is successfully posted */
286 wmmsg.eventCode = code; 290 if (SDL_PrivateSysWMEvent (&wmmsg))
287 SDL_memcpy(wmmsg.pollBlock, message, 64 * sizeof(int)); 291 doPoll = 0;
288 292 }
289 /* Fall out of polling loop if message is successfully posted */
290 if (SDL_PrivateSysWMEvent(&wmmsg)) doPoll = 0;
291 }
292 #if !SDL_THREADS_DISABLED 293 #if !SDL_THREADS_DISABLED
293 if (riscos_using_threads) 294 if (riscos_using_threads) {
294 { 295 /* Restart ticker here so other thread can not interfere
295 /* Restart ticker here so other thread can not interfere 296 with the Redraw processing */
296 with the Redraw processing */ 297 if (riscos_using_threads)
297 if (riscos_using_threads) __pthread_start_ticker(); 298 __pthread_start_ticker ();
298 /* Give other threads a better chance of running */ 299 /* Give other threads a better chance of running */
299 pthread_yield(); 300 pthread_yield ();
300 } 301 }
301 #endif 302 #endif
302 } 303 }
303 } 304 }
304 305
305 /* Set focus to specified window */ 306 /* Set focus to specified window */
306 void WIMP_SetFocus(int win) 307 void
308 WIMP_SetFocus (int win)
307 { 309 {
308 _kernel_swi_regs regs; 310 _kernel_swi_regs regs;
309 311
310 regs.r[0] = win; 312 regs.r[0] = win;
311 regs.r[1] = -1; /* Icon handle */ 313 regs.r[1] = -1; /* Icon handle */
312 regs.r[2] = 0; /* X-offset we just put it at position 0 */ 314 regs.r[2] = 0; /* X-offset we just put it at position 0 */
313 regs.r[3] = 0; /* Y-offset as above */ 315 regs.r[3] = 0; /* Y-offset as above */
314 regs.r[4] = 1 << 25; /* Caret is invisible */ 316 regs.r[4] = 1 << 25; /* Caret is invisible */
315 regs.r[5] = 0; /* index into string */ 317 regs.r[5] = 0; /* index into string */
316 318
317 _kernel_swi(Wimp_SetCaretPosition, &regs, &regs); 319 _kernel_swi (Wimp_SetCaretPosition, &regs, &regs);
318 } 320 }
319 321
320 /** Run background task while in a sleep command */ 322 /** Run background task while in a sleep command */
321 void RISCOS_BackgroundTasks(void) 323 void
324 RISCOS_BackgroundTasks (void)
322 { 325 {
323 if (current_video && current_video->hidden->window_handle) 326 if (current_video && current_video->hidden->window_handle) {
324 { 327 WIMP_Poll (current_video, 0);
325 WIMP_Poll(current_video, 0); 328 }
326 }
327 #if SDL_THREADS_DISABLED 329 #if SDL_THREADS_DISABLED
328 if (SDL_timer_running) RISCOS_CheckTimer(); 330 if (SDL_timer_running)
331 RISCOS_CheckTimer ();
329 #endif 332 #endif
330 } 333 }
334
335 /* vi: set ts=4 sw=4 expandtab: */