comparison src/video/gem/SDL_gemevents.c @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents 417f2af2bd52
children d20f4510c718
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
34 34
35 #include "../../events/SDL_sysevents.h" 35 #include "../../events/SDL_sysevents.h"
36 #include "../../events/SDL_events_c.h" 36 #include "../../events/SDL_events_c.h"
37 #include "SDL_gemvideo.h" 37 #include "SDL_gemvideo.h"
38 #include "SDL_gemevents_c.h" 38 #include "SDL_gemevents_c.h"
39 #include "../ataricommon/SDL_atarikeys.h" /* for keyboard scancodes */ 39 #include "../ataricommon/SDL_atarikeys.h" /* for keyboard scancodes */
40 #include "../ataricommon/SDL_atarievents_c.h" 40 #include "../ataricommon/SDL_atarievents_c.h"
41 #include "../ataricommon/SDL_xbiosevents_c.h" 41 #include "../ataricommon/SDL_xbiosevents_c.h"
42 #include "../ataricommon/SDL_ataridevmouse_c.h" 42 #include "../ataricommon/SDL_ataridevmouse_c.h"
43 43
44 /* Defines */ 44 /* Defines */
54 /* The translation tables from a console scancode to a SDL keysym */ 54 /* The translation tables from a console scancode to a SDL keysym */
55 static SDLKey keymap[ATARIBIOS_MAXKEYS]; 55 static SDLKey keymap[ATARIBIOS_MAXKEYS];
56 56
57 /* Functions prototypes */ 57 /* Functions prototypes */
58 58
59 static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym, 59 static SDL_keysym *TranslateKey(int scancode, int asciicode,
60 SDL_bool pressed); 60 SDL_keysym * keysym, SDL_bool pressed);
61 static int do_messages(_THIS, short *message); 61 static int do_messages(_THIS, short *message);
62 static void do_keyboard(short kc, short ks); 62 static void do_keyboard(short kc, short ks);
63 static void do_mouse(_THIS, short mx, short my, short mb, short ks); 63 static void do_mouse(_THIS, short mx, short my, short mb, short ks);
64 64
65 /* Functions */ 65 /* Functions */
66 66
67 static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym, 67 static SDL_keysym *
68 SDL_bool pressed) 68 TranslateKey(int scancode, int asciicode, SDL_keysym * keysym,
69 { 69 SDL_bool pressed)
70 /* Set the keysym information */ 70 {
71 keysym->scancode = scancode; 71 /* Set the keysym information */
72 72 keysym->scancode = scancode;
73 if (asciicode) 73
74 keysym->sym = asciicode; 74 if (asciicode)
75 else 75 keysym->sym = asciicode;
76 keysym->sym = keymap[scancode]; 76 else
77 77 keysym->sym = keymap[scancode];
78 keysym->mod = KMOD_NONE; 78
79 keysym->unicode = 0; 79 keysym->mod = KMOD_NONE;
80 if (SDL_TranslateUNICODE && pressed) { 80 keysym->unicode = 0;
81 keysym->unicode = SDL_AtariToUnicodeTable[asciicode]; 81 if (SDL_TranslateUNICODE && pressed) {
82 } 82 keysym->unicode = SDL_AtariToUnicodeTable[asciicode];
83 83 }
84 return(keysym); 84
85 } 85 return (keysym);
86 86 }
87 void GEM_InitOSKeymap(_THIS) 87
88 { 88 void
89 int i; 89 GEM_InitOSKeymap(_THIS)
90 90 {
91 SDL_memset(gem_currentkeyboard, 0, sizeof(gem_currentkeyboard)); 91 int i;
92 SDL_memset(gem_previouskeyboard, 0, sizeof(gem_previouskeyboard)); 92
93 SDL_memset(gem_currentascii, 0, sizeof(gem_currentascii)); 93 SDL_memset(gem_currentkeyboard, 0, sizeof(gem_currentkeyboard));
94 94 SDL_memset(gem_previouskeyboard, 0, sizeof(gem_previouskeyboard));
95 /* Initialize keymap */ 95 SDL_memset(gem_currentascii, 0, sizeof(gem_currentascii));
96 for ( i=0; i<sizeof(keymap); i++ ) 96
97 keymap[i] = SDLK_UNKNOWN; 97 /* Initialize keymap */
98 98 for (i = 0; i < sizeof(keymap); i++)
99 /* Functions keys */ 99 keymap[i] = SDLK_UNKNOWN;
100 for ( i = 0; i<10; i++ ) 100
101 keymap[SCANCODE_F1 + i] = SDLK_F1+i; 101 /* Functions keys */
102 102 for (i = 0; i < 10; i++)
103 /* Cursor keypad */ 103 keymap[SCANCODE_F1 + i] = SDLK_F1 + i;
104 keymap[SCANCODE_HELP] = SDLK_HELP; 104
105 keymap[SCANCODE_UNDO] = SDLK_UNDO; 105 /* Cursor keypad */
106 keymap[SCANCODE_INSERT] = SDLK_INSERT; 106 keymap[SCANCODE_HELP] = SDLK_HELP;
107 keymap[SCANCODE_CLRHOME] = SDLK_HOME; 107 keymap[SCANCODE_UNDO] = SDLK_UNDO;
108 keymap[SCANCODE_UP] = SDLK_UP; 108 keymap[SCANCODE_INSERT] = SDLK_INSERT;
109 keymap[SCANCODE_DOWN] = SDLK_DOWN; 109 keymap[SCANCODE_CLRHOME] = SDLK_HOME;
110 keymap[SCANCODE_RIGHT] = SDLK_RIGHT; 110 keymap[SCANCODE_UP] = SDLK_UP;
111 keymap[SCANCODE_LEFT] = SDLK_LEFT; 111 keymap[SCANCODE_DOWN] = SDLK_DOWN;
112 112 keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
113 /* Special keys */ 113 keymap[SCANCODE_LEFT] = SDLK_LEFT;
114 keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE; 114
115 keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE; 115 /* Special keys */
116 keymap[SCANCODE_TAB] = SDLK_TAB; 116 keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
117 keymap[SCANCODE_ENTER] = SDLK_RETURN; 117 keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
118 keymap[SCANCODE_DELETE] = SDLK_DELETE; 118 keymap[SCANCODE_TAB] = SDLK_TAB;
119 keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL; 119 keymap[SCANCODE_ENTER] = SDLK_RETURN;
120 keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT; 120 keymap[SCANCODE_DELETE] = SDLK_DELETE;
121 keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT; 121 keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
122 keymap[SCANCODE_LEFTALT] = SDLK_LALT; 122 keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
123 keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK; 123 keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
124 124 keymap[SCANCODE_LEFTALT] = SDLK_LALT;
125 /* Mouse init */ 125 keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
126 GEM_mouse_relative = SDL_FALSE; 126
127 } 127 /* Mouse init */
128 128 GEM_mouse_relative = SDL_FALSE;
129 void GEM_PumpEvents(_THIS) 129 }
130 { 130
131 short mousex, mousey, mouseb, dummy; 131 void
132 short kstate, prevkc, prevks; 132 GEM_PumpEvents(_THIS)
133 int i; 133 {
134 SDL_keysym keysym; 134 short mousex, mousey, mouseb, dummy;
135 135 short kstate, prevkc, prevks;
136 SDL_memset(gem_currentkeyboard,0,sizeof(gem_currentkeyboard)); 136 int i;
137 prevkc = prevks = 0; 137 SDL_keysym keysym;
138 138
139 for (;;) 139 SDL_memset(gem_currentkeyboard, 0, sizeof(gem_currentkeyboard));
140 { 140 prevkc = prevks = 0;
141 int quit, resultat, event_mask, mouse_event; 141
142 short buffer[8], kc; 142 for (;;) {
143 short x2,y2,w2,h2; 143 int quit, resultat, event_mask, mouse_event;
144 144 short buffer[8], kc;
145 quit = 145 short x2, y2, w2, h2;
146 mouse_event = 146
147 x2=y2=w2=h2 = 0; 147 quit = mouse_event = x2 = y2 = w2 = h2 = 0;
148 148
149 event_mask = MU_MESAG|MU_TIMER|MU_KEYBD; 149 event_mask = MU_MESAG | MU_TIMER | MU_KEYBD;
150 if (!GEM_fullscreen && (GEM_handle>=0)) { 150 if (!GEM_fullscreen && (GEM_handle >= 0)) {
151 wind_get (GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2); 151 wind_get(GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2);
152 event_mask |= MU_M1; 152 event_mask |= MU_M1;
153 if ( (SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) { 153 if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS)) {
154 mouse_event = MO_LEAVE; 154 mouse_event = MO_LEAVE;
155 } else { 155 } else {
156 mouse_event = MO_ENTER; 156 mouse_event = MO_ENTER;
157 } 157 }
158 } 158 }
159 159
160 resultat = evnt_multi( 160 resultat = evnt_multi(event_mask,
161 event_mask, 161 0, 0, 0,
162 0,0,0, 162 mouse_event, x2, y2, w2, h2,
163 mouse_event,x2,y2,w2,h2, 163 0, 0, 0, 0, 0,
164 0,0,0,0,0, 164 buffer,
165 buffer, 165 10,
166 10, 166 &dummy, &dummy, &dummy, &kstate, &kc, &dummy);
167 &dummy,&dummy,&dummy,&kstate,&kc,&dummy 167
168 ); 168 /* Message event ? */
169 169 if (resultat & MU_MESAG)
170 /* Message event ? */ 170 quit = do_messages(this, buffer);
171 if (resultat & MU_MESAG) 171
172 quit = do_messages(this, buffer); 172 /* Keyboard event ? */
173 173 if (resultat & MU_KEYBD) {
174 /* Keyboard event ? */ 174 if ((prevkc != kc) || (prevks != kstate)) {
175 if (resultat & MU_KEYBD) { 175 do_keyboard(kc, kstate);
176 if ((prevkc != kc) || (prevks != kstate)) { 176 } else {
177 do_keyboard(kc,kstate); 177 /* Avoid looping, if repeating same key */
178 } else { 178 break;
179 /* Avoid looping, if repeating same key */ 179 }
180 break; 180 }
181 } 181
182 } 182 /* Mouse entering/leaving window */
183 183 if (resultat & MU_M1) {
184 /* Mouse entering/leaving window */ 184 if (this->input_grab == SDL_GRAB_OFF) {
185 if (resultat & MU_M1) { 185 if (SDL_GetAppState() & SDL_APPMOUSEFOCUS) {
186 if (this->input_grab == SDL_GRAB_OFF) { 186 SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
187 if (SDL_GetAppState() & SDL_APPMOUSEFOCUS) { 187 } else {
188 SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS); 188 SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
189 if (SDL_GetAppState() & SDL_APPINPUTFOCUS) { 189 }
190 graf_mouse(ARROW, NULL); 190 }
191 } 191 }
192 } else { 192
193 SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS); 193 /* Timer event ? */
194 if (SDL_GetAppState() & SDL_APPINPUTFOCUS) { 194 if ((resultat & MU_TIMER) || quit)
195 if (GEM_cursor == (void *) -1) { 195 break;
196 graf_mouse(M_OFF, NULL); 196 }
197 } else if (GEM_cursor) { 197
198 graf_mouse(USER_DEF, GEM_cursor->mform_p); 198 /* Update mouse */
199 } 199 graf_mkstate(&mousex, &mousey, &mouseb, &kstate);
200 } 200 do_mouse(this, mousex, mousey, mouseb, kstate);
201 } 201
202 } 202 /* Now generate keyboard events */
203 } 203 for (i = 0; i < ATARIBIOS_MAXKEYS; i++) {
204 204 /* Key pressed ? */
205 /* Timer event ? */ 205 if (gem_currentkeyboard[i] && !gem_previouskeyboard[i])
206 if ((resultat & MU_TIMER) || quit) 206 SDL_PrivateKeyboard(SDL_PRESSED,
207 break; 207 TranslateKey(i, gem_currentascii[i],
208 } 208 &keysym, SDL_TRUE));
209 209
210 /* Update mouse */ 210 /* Key unpressed ? */
211 graf_mkstate(&mousex, &mousey, &mouseb, &kstate); 211 if (gem_previouskeyboard[i] && !gem_currentkeyboard[i])
212 do_mouse(this, mousex, mousey, mouseb, kstate); 212 SDL_PrivateKeyboard(SDL_RELEASED,
213 213 TranslateKey(i, gem_currentascii[i],
214 /* Now generate keyboard events */ 214 &keysym, SDL_FALSE));
215 for (i=0; i<ATARIBIOS_MAXKEYS; i++) { 215 }
216 /* Key pressed ? */ 216
217 if (gem_currentkeyboard[i] && !gem_previouskeyboard[i]) 217 SDL_memcpy(gem_previouskeyboard, gem_currentkeyboard,
218 SDL_PrivateKeyboard(SDL_PRESSED, 218 sizeof(gem_previouskeyboard));
219 TranslateKey(i, gem_currentascii[i], &keysym, SDL_TRUE)); 219
220 220 /* Refresh window name ? */
221 /* Key unpressed ? */ 221 if (GEM_refresh_name) {
222 if (gem_previouskeyboard[i] && !gem_currentkeyboard[i]) 222 if (SDL_GetAppState() & SDL_APPACTIVE) {
223 SDL_PrivateKeyboard(SDL_RELEASED, 223 /* Fullscreen/windowed */
224 TranslateKey(i, gem_currentascii[i], &keysym, SDL_FALSE)); 224 if (GEM_title_name) {
225 } 225 wind_set(GEM_handle, WF_NAME,
226 226 (short) (((unsigned long) GEM_title_name) >>
227 SDL_memcpy(gem_previouskeyboard,gem_currentkeyboard,sizeof(gem_previouskeyboard)); 227 16),
228 228 (short) (((unsigned long) GEM_title_name) &
229 /* Refresh window name ? */ 229 0xffff), 0, 0);
230 if (GEM_refresh_name) { 230 }
231 if ( SDL_GetAppState() & SDL_APPACTIVE ) { 231 } else {
232 /* Fullscreen/windowed */ 232 /* Iconified */
233 if (GEM_title_name) { 233 if (GEM_icon_name) {
234 wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_title_name)>>16),(short)(((unsigned long)GEM_title_name) & 0xffff),0,0); 234 wind_set(GEM_handle, WF_NAME,
235 } 235 (short) (((unsigned long) GEM_icon_name) >>
236 } else { 236 16),
237 /* Iconified */ 237 (short) (((unsigned long) GEM_icon_name) &
238 if (GEM_icon_name) { 238 0xffff), 0, 0);
239 wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_icon_name)>>16),(short)(((unsigned long)GEM_icon_name) & 0xffff),0,0); 239 }
240 } 240 }
241 } 241 GEM_refresh_name = SDL_FALSE;
242 GEM_refresh_name = SDL_FALSE; 242 }
243 } 243 }
244 } 244
245 245 static int
246 static int do_messages(_THIS, short *message) 246 do_messages(_THIS, short *message)
247 { 247 {
248 int quit, posted; 248 int quit, posted;
249 short x2,y2,w2,h2; 249 short x2, y2, w2, h2;
250 250
251 quit=0; 251 quit = 0;
252 switch (message[0]) { 252 switch (message[0]) {
253 case WM_CLOSED: 253 case WM_CLOSED:
254 case AP_TERM: 254 case AP_TERM:
255 posted = SDL_PrivateQuit(); 255 posted = SDL_PrivateQuit();
256 quit=1; 256 quit = 1;
257 break; 257 break;
258 case WM_MOVED: 258 case WM_MOVED:
259 wind_set(message[3],WF_CURRXYWH,message[4],message[5],message[6],message[7]); 259 wind_set(message[3], WF_CURRXYWH, message[4], message[5],
260 break; 260 message[6], message[7]);
261 case WM_TOPPED: 261 break;
262 wind_set(message[3],WF_TOP,message[4],0,0,0); 262 case WM_TOPPED:
263 /* Continue with TOP event processing */ 263 wind_set(message[3], WF_TOP, message[4], 0, 0, 0);
264 case WM_ONTOP: 264 /* Continue with TOP event processing */
265 SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS); 265 case WM_ONTOP:
266 if (VDI_setpalette) { 266 SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
267 VDI_setpalette(this, VDI_curpalette); 267 if (VDI_setpalette) {
268 } 268 VDI_setpalette(this, VDI_curpalette);
269 break; 269 }
270 case WM_REDRAW: 270 break;
271 if (!GEM_lock_redraw) { 271 case WM_REDRAW:
272 GEM_wind_redraw(this, message[3],&message[4]); 272 if (!GEM_lock_redraw) {
273 } 273 GEM_wind_redraw(this, message[3], &message[4]);
274 break; 274 }
275 case WM_ICONIFY: 275 break;
276 case WM_ALLICONIFY: 276 case WM_ICONIFY:
277 wind_set(message[3],WF_ICONIFY,message[4],message[5],message[6],message[7]); 277 case WM_ALLICONIFY:
278 /* If we're active, make ourselves inactive */ 278 wind_set(message[3], WF_ICONIFY, message[4], message[5],
279 if ( SDL_GetAppState() & SDL_APPACTIVE ) { 279 message[6], message[7]);
280 /* Send an internal deactivate event */ 280 /* If we're active, make ourselves inactive */
281 SDL_PrivateAppActive(0, SDL_APPACTIVE); 281 if (SDL_GetAppState() & SDL_APPACTIVE) {
282 } 282 /* Send an internal deactivate event */
283 /* Update window title */ 283 SDL_PrivateAppActive(0, SDL_APPACTIVE);
284 if (GEM_refresh_name && GEM_icon_name) { 284 }
285 wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_icon_name)>>16),(short)(((unsigned long)GEM_icon_name) & 0xffff),0,0); 285 /* Update window title */
286 GEM_refresh_name = SDL_FALSE; 286 if (GEM_refresh_name && GEM_icon_name) {
287 } 287 wind_set(GEM_handle, WF_NAME,
288 break; 288 (short) (((unsigned long) GEM_icon_name) >> 16),
289 case WM_UNICONIFY: 289 (short) (((unsigned long) GEM_icon_name) & 0xffff),
290 wind_set(message[3],WF_UNICONIFY,message[4],message[5],message[6],message[7]); 290 0, 0);
291 /* If we're not active, make ourselves active */ 291 GEM_refresh_name = SDL_FALSE;
292 if ( !(SDL_GetAppState() & SDL_APPACTIVE) ) { 292 }
293 /* Send an internal activate event */ 293 break;
294 SDL_PrivateAppActive(1, SDL_APPACTIVE); 294 case WM_UNICONIFY:
295 } 295 wind_set(message[3], WF_UNICONIFY, message[4], message[5],
296 if (GEM_refresh_name && GEM_title_name) { 296 message[6], message[7]);
297 wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_title_name)>>16),(short)(((unsigned long)GEM_title_name) & 0xffff),0,0); 297 /* If we're not active, make ourselves active */
298 GEM_refresh_name = SDL_FALSE; 298 if (!(SDL_GetAppState() & SDL_APPACTIVE)) {
299 } 299 /* Send an internal activate event */
300 break; 300 SDL_PrivateAppActive(1, SDL_APPACTIVE);
301 case WM_SIZED: 301 }
302 wind_set (message[3], WF_CURRXYWH, message[4], message[5], message[6], message[7]); 302 if (GEM_refresh_name && GEM_title_name) {
303 wind_get (message[3], WF_WORKXYWH, &x2, &y2, &w2, &h2); 303 wind_set(GEM_handle, WF_NAME,
304 GEM_win_fulled = SDL_FALSE; /* Cancel maximized flag */ 304 (short) (((unsigned long) GEM_title_name) >> 16),
305 GEM_lock_redraw = SDL_TRUE; /* Prevent redraw till buffers resized */ 305 (short) (((unsigned long) GEM_title_name) & 0xffff),
306 SDL_PrivateResize(w2, h2); 306 0, 0);
307 break; 307 GEM_refresh_name = SDL_FALSE;
308 case WM_FULLED: 308 }
309 { 309 break;
310 short x,y,w,h; 310 case WM_SIZED:
311 311 wind_set(message[3], WF_CURRXYWH, message[4], message[5],
312 if (GEM_win_fulled) { 312 message[6], message[7]);
313 wind_get (message[3], WF_PREVXYWH, &x, &y, &w, &h); 313 wind_get(message[3], WF_WORKXYWH, &x2, &y2, &w2, &h2);
314 GEM_win_fulled = SDL_FALSE; 314 GEM_win_fulled = SDL_FALSE; /* Cancel maximized flag */
315 } else { 315 GEM_lock_redraw = SDL_TRUE; /* Prevent redraw till buffers resized */
316 x = GEM_desk_x; 316 SDL_PrivateResize(w2, h2);
317 y = GEM_desk_y; 317 break;
318 w = GEM_desk_w; 318 case WM_FULLED:
319 h = GEM_desk_h; 319 {
320 GEM_win_fulled = SDL_TRUE; 320 short x, y, w, h;
321 } 321
322 wind_set (message[3], WF_CURRXYWH, x, y, w, h); 322 if (GEM_win_fulled) {
323 wind_get (message[3], WF_WORKXYWH, &x2, &y2, &w2, &h2); 323 wind_get(message[3], WF_PREVXYWH, &x, &y, &w, &h);
324 GEM_lock_redraw = SDL_TRUE; /* Prevent redraw till buffers resized */ 324 GEM_win_fulled = SDL_FALSE;
325 SDL_PrivateResize(w2, h2); 325 } else {
326 } 326 x = GEM_desk_x;
327 break; 327 y = GEM_desk_y;
328 case WM_BOTTOMED: 328 w = GEM_desk_w;
329 wind_set(message[3],WF_BOTTOM,0,0,0,0); 329 h = GEM_desk_h;
330 /* Continue with BOTTOM event processing */ 330 GEM_win_fulled = SDL_TRUE;
331 case WM_UNTOPPED: 331 }
332 SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS); 332 wind_set(message[3], WF_CURRXYWH, x, y, w, h);
333 if (VDI_setpalette) { 333 wind_get(message[3], WF_WORKXYWH, &x2, &y2, &w2, &h2);
334 VDI_setpalette(this, VDI_oldpalette); 334 GEM_lock_redraw = SDL_TRUE; /* Prevent redraw till buffers resized */
335 } 335 SDL_PrivateResize(w2, h2);
336 break; 336 }
337 } 337 break;
338 338 case WM_BOTTOMED:
339 return quit; 339 wind_set(message[3], WF_BOTTOM, 0, 0, 0, 0);
340 } 340 /* Continue with BOTTOM event processing */
341 341 case WM_UNTOPPED:
342 static void do_keyboard(short kc, short ks) 342 SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);
343 { 343 if (VDI_setpalette) {
344 int scancode, asciicode; 344 VDI_setpalette(this, VDI_oldpalette);
345 345 }
346 if (kc) { 346 break;
347 scancode=(kc>>8) & 127; 347 }
348 asciicode=kc & 255; 348
349 349 return quit;
350 gem_currentkeyboard[scancode]=0xFF; 350 }
351 gem_currentascii[scancode]=asciicode; 351
352 } 352 static void
353 353 do_keyboard(short kc, short ks)
354 /* Read special keys */ 354 {
355 if (ks & K_RSHIFT) 355 int scancode, asciicode;
356 gem_currentkeyboard[SCANCODE_RIGHTSHIFT]=0xFF; 356
357 if (ks & K_LSHIFT) 357 if (kc) {
358 gem_currentkeyboard[SCANCODE_LEFTSHIFT]=0xFF; 358 scancode = (kc >> 8) & 127;
359 if (ks & K_CTRL) 359 asciicode = kc & 255;
360 gem_currentkeyboard[SCANCODE_LEFTCONTROL]=0xFF; 360
361 if (ks & K_ALT) 361 gem_currentkeyboard[scancode] = 0xFF;
362 gem_currentkeyboard[SCANCODE_LEFTALT]=0xFF; 362 gem_currentascii[scancode] = asciicode;
363 } 363 }
364 364
365 static void do_mouse(_THIS, short mx, short my, short mb, short ks) 365 /* Read special keys */
366 { 366 if (ks & K_RSHIFT)
367 static short prevmousex=0, prevmousey=0, prevmouseb=0; 367 gem_currentkeyboard[SCANCODE_RIGHTSHIFT] = 0xFF;
368 short x2, y2, w2, h2; 368 if (ks & K_LSHIFT)
369 369 gem_currentkeyboard[SCANCODE_LEFTSHIFT] = 0xFF;
370 /* Don't return mouse events if out of window */ 370 if (ks & K_CTRL)
371 if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS)==0) { 371 gem_currentkeyboard[SCANCODE_LEFTCONTROL] = 0xFF;
372 return; 372 if (ks & K_ALT)
373 } 373 gem_currentkeyboard[SCANCODE_LEFTALT] = 0xFF;
374 374 }
375 /* Retrieve window coords, and generate mouse events accordingly */ 375
376 x2 = y2 = 0; 376 static void
377 w2 = VDI_w; 377 do_mouse(_THIS, short mx, short my, short mb, short ks)
378 h2 = VDI_h; 378 {
379 if ((!GEM_fullscreen) && (GEM_handle>=0)) { 379 static short prevmousex = 0, prevmousey = 0, prevmouseb = 0;
380 wind_get (GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2); 380 short x2, y2, w2, h2;
381 381
382 /* Do not generate mouse button event if out of window working area */ 382 /* Don't return mouse events if out of window */
383 if ((mx<x2) || (mx>=x2+w2) || (my<y2) || (my>=y2+h2)) { 383 if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS) == 0) {
384 mb=prevmouseb; 384 return;
385 } 385 }
386 } 386
387 387 /* Retrieve window coords, and generate mouse events accordingly */
388 /* Mouse motion ? */ 388 x2 = y2 = 0;
389 if (GEM_mouse_relative) { 389 w2 = VDI_w;
390 if (GEM_usedevmouse) { 390 h2 = VDI_h;
391 SDL_AtariDevMouse_PostMouseEvents(this, SDL_FALSE); 391 if ((!GEM_fullscreen) && (GEM_handle >= 0)) {
392 } else { 392 wind_get(GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2);
393 SDL_AtariXbios_PostMouseEvents(this, SDL_FALSE); 393
394 } 394 /* Do not generate mouse button event if out of window working area */
395 } else { 395 if ((mx < x2) || (mx >= x2 + w2) || (my < y2) || (my >= y2 + h2)) {
396 if ((prevmousex!=mx) || (prevmousey!=my)) { 396 mb = prevmouseb;
397 int posx, posy; 397 }
398 398 }
399 /* Give mouse position relative to window position */ 399
400 posx = mx - x2; 400 /* Mouse motion ? */
401 if (posx<0) posx = 0; 401 if (GEM_mouse_relative) {
402 if (posx>w2) posx = w2-1; 402 if (GEM_usedevmouse) {
403 posy = my - y2; 403 SDL_AtariDevMouse_PostMouseEvents(this, SDL_FALSE);
404 if (posy<0) posy = 0; 404 } else {
405 if (posy>h2) posy = h2-1; 405 SDL_AtariXbios_PostMouseEvents(this, SDL_FALSE);
406 406 }
407 SDL_PrivateMouseMotion(0, 0, posx, posy); 407 } else {
408 } 408 if ((prevmousex != mx) || (prevmousey != my)) {
409 prevmousex = mx; 409 int posx, posy;
410 prevmousey = my; 410
411 } 411 /* Give mouse position relative to window position */
412 412 posx = mx - x2;
413 /* Mouse button ? */ 413 if (posx < 0)
414 if (prevmouseb!=mb) { 414 posx = 0;
415 int i; 415 if (posx > w2)
416 416 posx = w2 - 1;
417 for (i=0;i<2;i++) { 417 posy = my - y2;
418 int curbutton, prevbutton; 418 if (posy < 0)
419 419 posy = 0;
420 curbutton = mb & (1<<i); 420 if (posy > h2)
421 prevbutton = prevmouseb & (1<<i); 421 posy = h2 - 1;
422 422
423 if (curbutton && !prevbutton) { 423 SDL_PrivateMouseMotion(0, 0, posx, posy);
424 SDL_PrivateMouseButton(SDL_PRESSED, i+1, 0, 0); 424 }
425 } 425 prevmousex = mx;
426 if (!curbutton && prevbutton) { 426 prevmousey = my;
427 SDL_PrivateMouseButton(SDL_RELEASED, i+1, 0, 0); 427 }
428 } 428
429 } 429 /* Mouse button ? */
430 prevmouseb = mb; 430 if (prevmouseb != mb) {
431 } 431 int i;
432 432
433 /* Read special keys */ 433 for (i = 0; i < 2; i++) {
434 if (ks & K_RSHIFT) 434 int curbutton, prevbutton;
435 gem_currentkeyboard[SCANCODE_RIGHTSHIFT]=0xFF; 435
436 if (ks & K_LSHIFT) 436 curbutton = mb & (1 << i);
437 gem_currentkeyboard[SCANCODE_LEFTSHIFT]=0xFF; 437 prevbutton = prevmouseb & (1 << i);
438 if (ks & K_CTRL) 438
439 gem_currentkeyboard[SCANCODE_LEFTCONTROL]=0xFF; 439 if (curbutton && !prevbutton) {
440 if (ks & K_ALT) 440 SDL_PrivateMouseButton(SDL_PRESSED, i + 1, 0, 0);
441 gem_currentkeyboard[SCANCODE_LEFTALT]=0xFF; 441 }
442 } 442 if (!curbutton && prevbutton) {
443 SDL_PrivateMouseButton(SDL_RELEASED, i + 1, 0, 0);
444 }
445 }
446 prevmouseb = mb;
447 }
448
449 /* Read special keys */
450 if (ks & K_RSHIFT)
451 gem_currentkeyboard[SCANCODE_RIGHTSHIFT] = 0xFF;
452 if (ks & K_LSHIFT)
453 gem_currentkeyboard[SCANCODE_LEFTSHIFT] = 0xFF;
454 if (ks & K_CTRL)
455 gem_currentkeyboard[SCANCODE_LEFTCONTROL] = 0xFF;
456 if (ks & K_ALT)
457 gem_currentkeyboard[SCANCODE_LEFTALT] = 0xFF;
458 }
459
460 /* vi: set ts=4 sw=4 expandtab: */