src/video/gem/SDL_gemevents.c
changeset 1895 c121d94672cb
parent 1857 417f2af2bd52
child 2019 d20f4510c718
     1.1 --- a/src/video/gem/SDL_gemevents.c	Thu Jul 06 18:01:37 2006 +0000
     1.2 +++ b/src/video/gem/SDL_gemevents.c	Mon Jul 10 21:04:37 2006 +0000
     1.3 @@ -36,7 +36,7 @@
     1.4  #include "../../events/SDL_events_c.h"
     1.5  #include "SDL_gemvideo.h"
     1.6  #include "SDL_gemevents_c.h"
     1.7 -#include "../ataricommon/SDL_atarikeys.h"	/* for keyboard scancodes */
     1.8 +#include "../ataricommon/SDL_atarikeys.h"       /* for keyboard scancodes */
     1.9  #include "../ataricommon/SDL_atarievents_c.h"
    1.10  #include "../ataricommon/SDL_xbiosevents_c.h"
    1.11  #include "../ataricommon/SDL_ataridevmouse_c.h"
    1.12 @@ -56,387 +56,405 @@
    1.13  
    1.14  /* Functions prototypes */
    1.15  
    1.16 -static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym,
    1.17 -	SDL_bool pressed);
    1.18 +static SDL_keysym *TranslateKey(int scancode, int asciicode,
    1.19 +                                SDL_keysym * keysym, SDL_bool pressed);
    1.20  static int do_messages(_THIS, short *message);
    1.21  static void do_keyboard(short kc, short ks);
    1.22  static void do_mouse(_THIS, short mx, short my, short mb, short ks);
    1.23  
    1.24  /* Functions */
    1.25  
    1.26 -static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym,
    1.27 -	SDL_bool pressed)
    1.28 +static SDL_keysym *
    1.29 +TranslateKey(int scancode, int asciicode, SDL_keysym * keysym,
    1.30 +             SDL_bool pressed)
    1.31  {
    1.32 -	/* Set the keysym information */
    1.33 -	keysym->scancode = scancode;
    1.34 +    /* Set the keysym information */
    1.35 +    keysym->scancode = scancode;
    1.36  
    1.37 -	if (asciicode)
    1.38 -		keysym->sym = asciicode;		
    1.39 -	else
    1.40 -		keysym->sym = keymap[scancode];
    1.41 +    if (asciicode)
    1.42 +        keysym->sym = asciicode;
    1.43 +    else
    1.44 +        keysym->sym = keymap[scancode];
    1.45  
    1.46 -	keysym->mod = KMOD_NONE;
    1.47 -	keysym->unicode = 0;
    1.48 -	if (SDL_TranslateUNICODE && pressed) {
    1.49 -		keysym->unicode = SDL_AtariToUnicodeTable[asciicode];
    1.50 -	}
    1.51 +    keysym->mod = KMOD_NONE;
    1.52 +    keysym->unicode = 0;
    1.53 +    if (SDL_TranslateUNICODE && pressed) {
    1.54 +        keysym->unicode = SDL_AtariToUnicodeTable[asciicode];
    1.55 +    }
    1.56  
    1.57 -	return(keysym);
    1.58 +    return (keysym);
    1.59  }
    1.60  
    1.61 -void GEM_InitOSKeymap(_THIS)
    1.62 +void
    1.63 +GEM_InitOSKeymap(_THIS)
    1.64  {
    1.65 -	int i;
    1.66 +    int i;
    1.67  
    1.68 -	SDL_memset(gem_currentkeyboard, 0, sizeof(gem_currentkeyboard));
    1.69 -	SDL_memset(gem_previouskeyboard, 0, sizeof(gem_previouskeyboard));
    1.70 -	SDL_memset(gem_currentascii, 0, sizeof(gem_currentascii));
    1.71 +    SDL_memset(gem_currentkeyboard, 0, sizeof(gem_currentkeyboard));
    1.72 +    SDL_memset(gem_previouskeyboard, 0, sizeof(gem_previouskeyboard));
    1.73 +    SDL_memset(gem_currentascii, 0, sizeof(gem_currentascii));
    1.74  
    1.75 -	/* Initialize keymap */
    1.76 -	for ( i=0; i<sizeof(keymap); i++ )
    1.77 -		keymap[i] = SDLK_UNKNOWN;
    1.78 +    /* Initialize keymap */
    1.79 +    for (i = 0; i < sizeof(keymap); i++)
    1.80 +        keymap[i] = SDLK_UNKNOWN;
    1.81  
    1.82 -	/* Functions keys */
    1.83 -	for ( i = 0; i<10; i++ )
    1.84 -		keymap[SCANCODE_F1 + i] = SDLK_F1+i;
    1.85 +    /* Functions keys */
    1.86 +    for (i = 0; i < 10; i++)
    1.87 +        keymap[SCANCODE_F1 + i] = SDLK_F1 + i;
    1.88  
    1.89 -	/* Cursor keypad */
    1.90 -	keymap[SCANCODE_HELP] = SDLK_HELP;
    1.91 -	keymap[SCANCODE_UNDO] = SDLK_UNDO;
    1.92 -	keymap[SCANCODE_INSERT] = SDLK_INSERT;
    1.93 -	keymap[SCANCODE_CLRHOME] = SDLK_HOME;
    1.94 -	keymap[SCANCODE_UP] = SDLK_UP;
    1.95 -	keymap[SCANCODE_DOWN] = SDLK_DOWN;
    1.96 -	keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
    1.97 -	keymap[SCANCODE_LEFT] = SDLK_LEFT;
    1.98 +    /* Cursor keypad */
    1.99 +    keymap[SCANCODE_HELP] = SDLK_HELP;
   1.100 +    keymap[SCANCODE_UNDO] = SDLK_UNDO;
   1.101 +    keymap[SCANCODE_INSERT] = SDLK_INSERT;
   1.102 +    keymap[SCANCODE_CLRHOME] = SDLK_HOME;
   1.103 +    keymap[SCANCODE_UP] = SDLK_UP;
   1.104 +    keymap[SCANCODE_DOWN] = SDLK_DOWN;
   1.105 +    keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
   1.106 +    keymap[SCANCODE_LEFT] = SDLK_LEFT;
   1.107  
   1.108 -	/* Special keys */
   1.109 -	keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
   1.110 -	keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
   1.111 -	keymap[SCANCODE_TAB] = SDLK_TAB;
   1.112 -	keymap[SCANCODE_ENTER] = SDLK_RETURN;
   1.113 -	keymap[SCANCODE_DELETE] = SDLK_DELETE;
   1.114 -	keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
   1.115 -	keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
   1.116 -	keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
   1.117 -	keymap[SCANCODE_LEFTALT] = SDLK_LALT;
   1.118 -	keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
   1.119 +    /* Special keys */
   1.120 +    keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
   1.121 +    keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
   1.122 +    keymap[SCANCODE_TAB] = SDLK_TAB;
   1.123 +    keymap[SCANCODE_ENTER] = SDLK_RETURN;
   1.124 +    keymap[SCANCODE_DELETE] = SDLK_DELETE;
   1.125 +    keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
   1.126 +    keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
   1.127 +    keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
   1.128 +    keymap[SCANCODE_LEFTALT] = SDLK_LALT;
   1.129 +    keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
   1.130  
   1.131 -	/* Mouse init */
   1.132 -	GEM_mouse_relative = SDL_FALSE;
   1.133 +    /* Mouse init */
   1.134 +    GEM_mouse_relative = SDL_FALSE;
   1.135  }
   1.136  
   1.137 -void GEM_PumpEvents(_THIS)
   1.138 +void
   1.139 +GEM_PumpEvents(_THIS)
   1.140  {
   1.141 -	short mousex, mousey, mouseb, dummy;
   1.142 -	short kstate, prevkc, prevks;
   1.143 -	int i;
   1.144 -	SDL_keysym	keysym;
   1.145 +    short mousex, mousey, mouseb, dummy;
   1.146 +    short kstate, prevkc, prevks;
   1.147 +    int i;
   1.148 +    SDL_keysym keysym;
   1.149  
   1.150 -	SDL_memset(gem_currentkeyboard,0,sizeof(gem_currentkeyboard));
   1.151 -	prevkc = prevks = 0;
   1.152 -	
   1.153 -	for (;;)
   1.154 -	{
   1.155 -		int quit, resultat, event_mask, mouse_event;
   1.156 -		short buffer[8], kc;
   1.157 -		short x2,y2,w2,h2;
   1.158 +    SDL_memset(gem_currentkeyboard, 0, sizeof(gem_currentkeyboard));
   1.159 +    prevkc = prevks = 0;
   1.160  
   1.161 -		quit =
   1.162 -			mouse_event =
   1.163 -			x2=y2=w2=h2 = 0;
   1.164 +    for (;;) {
   1.165 +        int quit, resultat, event_mask, mouse_event;
   1.166 +        short buffer[8], kc;
   1.167 +        short x2, y2, w2, h2;
   1.168  
   1.169 -		event_mask = MU_MESAG|MU_TIMER|MU_KEYBD;
   1.170 -		if (!GEM_fullscreen && (GEM_handle>=0)) {
   1.171 -			wind_get (GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2);
   1.172 -			event_mask |= MU_M1;
   1.173 -			if ( (SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) {
   1.174 -				mouse_event = MO_LEAVE;				
   1.175 -			} else {
   1.176 -				mouse_event = MO_ENTER;				
   1.177 -			}
   1.178 -		}
   1.179 +        quit = mouse_event = x2 = y2 = w2 = h2 = 0;
   1.180  
   1.181 -		resultat = evnt_multi(
   1.182 -			event_mask,
   1.183 -			0,0,0,
   1.184 -			mouse_event,x2,y2,w2,h2,
   1.185 -			0,0,0,0,0,
   1.186 -			buffer,
   1.187 -			10,
   1.188 -			&dummy,&dummy,&dummy,&kstate,&kc,&dummy
   1.189 -		);
   1.190 +        event_mask = MU_MESAG | MU_TIMER | MU_KEYBD;
   1.191 +        if (!GEM_fullscreen && (GEM_handle >= 0)) {
   1.192 +            wind_get(GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2);
   1.193 +            event_mask |= MU_M1;
   1.194 +            if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS)) {
   1.195 +                mouse_event = MO_LEAVE;
   1.196 +            } else {
   1.197 +                mouse_event = MO_ENTER;
   1.198 +            }
   1.199 +        }
   1.200  
   1.201 -		/* Message event ? */
   1.202 -		if (resultat & MU_MESAG)
   1.203 -			quit = do_messages(this, buffer);
   1.204 +        resultat = evnt_multi(event_mask,
   1.205 +                              0, 0, 0,
   1.206 +                              mouse_event, x2, y2, w2, h2,
   1.207 +                              0, 0, 0, 0, 0,
   1.208 +                              buffer,
   1.209 +                              10,
   1.210 +                              &dummy, &dummy, &dummy, &kstate, &kc, &dummy);
   1.211  
   1.212 -		/* Keyboard event ? */
   1.213 -		if (resultat & MU_KEYBD) {
   1.214 -			if ((prevkc != kc) || (prevks != kstate)) {
   1.215 -				do_keyboard(kc,kstate);
   1.216 -			} else {
   1.217 -				/* Avoid looping, if repeating same key */
   1.218 -				break;
   1.219 -			}
   1.220 -		}
   1.221 +        /* Message event ? */
   1.222 +        if (resultat & MU_MESAG)
   1.223 +            quit = do_messages(this, buffer);
   1.224  
   1.225 -		/* Mouse entering/leaving window */
   1.226 -		if (resultat & MU_M1) {
   1.227 -			if (this->input_grab == SDL_GRAB_OFF) {
   1.228 -				if (SDL_GetAppState() & SDL_APPMOUSEFOCUS) {
   1.229 -					SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
   1.230 -					if (SDL_GetAppState() & SDL_APPINPUTFOCUS) {
   1.231 -						graf_mouse(ARROW, NULL);
   1.232 -					}
   1.233 -				} else {
   1.234 -					SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
   1.235 -					if (SDL_GetAppState() & SDL_APPINPUTFOCUS) {
   1.236 -						if (GEM_cursor == (void *) -1) {
   1.237 -							graf_mouse(M_OFF, NULL);
   1.238 -						} else if (GEM_cursor) {
   1.239 -							graf_mouse(USER_DEF, GEM_cursor->mform_p);
   1.240 -						}
   1.241 -					}
   1.242 -				}
   1.243 -			}
   1.244 -		}
   1.245 +        /* Keyboard event ? */
   1.246 +        if (resultat & MU_KEYBD) {
   1.247 +            if ((prevkc != kc) || (prevks != kstate)) {
   1.248 +                do_keyboard(kc, kstate);
   1.249 +            } else {
   1.250 +                /* Avoid looping, if repeating same key */
   1.251 +                break;
   1.252 +            }
   1.253 +        }
   1.254  
   1.255 -		/* Timer event ? */
   1.256 -		if ((resultat & MU_TIMER) || quit)
   1.257 -			break;
   1.258 -	}
   1.259 +        /* Mouse entering/leaving window */
   1.260 +        if (resultat & MU_M1) {
   1.261 +            if (this->input_grab == SDL_GRAB_OFF) {
   1.262 +                if (SDL_GetAppState() & SDL_APPMOUSEFOCUS) {
   1.263 +                    SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
   1.264 +                } else {
   1.265 +                    SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
   1.266 +                }
   1.267 +            }
   1.268 +        }
   1.269  
   1.270 -	/* Update mouse */
   1.271 -	graf_mkstate(&mousex, &mousey, &mouseb, &kstate);
   1.272 -	do_mouse(this, mousex, mousey, mouseb, kstate);
   1.273 +        /* Timer event ? */
   1.274 +        if ((resultat & MU_TIMER) || quit)
   1.275 +            break;
   1.276 +    }
   1.277  
   1.278 -	/* Now generate keyboard events */
   1.279 -	for (i=0; i<ATARIBIOS_MAXKEYS; i++) {
   1.280 -		/* Key pressed ? */
   1.281 -		if (gem_currentkeyboard[i] && !gem_previouskeyboard[i])
   1.282 -			SDL_PrivateKeyboard(SDL_PRESSED,
   1.283 -				TranslateKey(i, gem_currentascii[i], &keysym, SDL_TRUE));
   1.284 -			
   1.285 -		/* Key unpressed ? */
   1.286 -		if (gem_previouskeyboard[i] && !gem_currentkeyboard[i])
   1.287 -			SDL_PrivateKeyboard(SDL_RELEASED,
   1.288 -				TranslateKey(i, gem_currentascii[i], &keysym, SDL_FALSE));
   1.289 -	}
   1.290 +    /* Update mouse */
   1.291 +    graf_mkstate(&mousex, &mousey, &mouseb, &kstate);
   1.292 +    do_mouse(this, mousex, mousey, mouseb, kstate);
   1.293  
   1.294 -	SDL_memcpy(gem_previouskeyboard,gem_currentkeyboard,sizeof(gem_previouskeyboard));
   1.295 +    /* Now generate keyboard events */
   1.296 +    for (i = 0; i < ATARIBIOS_MAXKEYS; i++) {
   1.297 +        /* Key pressed ? */
   1.298 +        if (gem_currentkeyboard[i] && !gem_previouskeyboard[i])
   1.299 +            SDL_PrivateKeyboard(SDL_PRESSED,
   1.300 +                                TranslateKey(i, gem_currentascii[i],
   1.301 +                                             &keysym, SDL_TRUE));
   1.302  
   1.303 -	/* Refresh window name ? */
   1.304 -	if (GEM_refresh_name) {
   1.305 -		if ( SDL_GetAppState() & SDL_APPACTIVE ) {
   1.306 -			/* Fullscreen/windowed */
   1.307 -			if (GEM_title_name) {
   1.308 -				wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_title_name)>>16),(short)(((unsigned long)GEM_title_name) & 0xffff),0,0);
   1.309 -			}
   1.310 -		} else {
   1.311 -			/* Iconified */
   1.312 -			if (GEM_icon_name) {
   1.313 -				wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_icon_name)>>16),(short)(((unsigned long)GEM_icon_name) & 0xffff),0,0);
   1.314 -			}
   1.315 -		}
   1.316 -		GEM_refresh_name = SDL_FALSE;
   1.317 -	}
   1.318 +        /* Key unpressed ? */
   1.319 +        if (gem_previouskeyboard[i] && !gem_currentkeyboard[i])
   1.320 +            SDL_PrivateKeyboard(SDL_RELEASED,
   1.321 +                                TranslateKey(i, gem_currentascii[i],
   1.322 +                                             &keysym, SDL_FALSE));
   1.323 +    }
   1.324 +
   1.325 +    SDL_memcpy(gem_previouskeyboard, gem_currentkeyboard,
   1.326 +               sizeof(gem_previouskeyboard));
   1.327 +
   1.328 +    /* Refresh window name ? */
   1.329 +    if (GEM_refresh_name) {
   1.330 +        if (SDL_GetAppState() & SDL_APPACTIVE) {
   1.331 +            /* Fullscreen/windowed */
   1.332 +            if (GEM_title_name) {
   1.333 +                wind_set(GEM_handle, WF_NAME,
   1.334 +                         (short) (((unsigned long) GEM_title_name) >>
   1.335 +                                  16),
   1.336 +                         (short) (((unsigned long) GEM_title_name) &
   1.337 +                                  0xffff), 0, 0);
   1.338 +            }
   1.339 +        } else {
   1.340 +            /* Iconified */
   1.341 +            if (GEM_icon_name) {
   1.342 +                wind_set(GEM_handle, WF_NAME,
   1.343 +                         (short) (((unsigned long) GEM_icon_name) >>
   1.344 +                                  16),
   1.345 +                         (short) (((unsigned long) GEM_icon_name) &
   1.346 +                                  0xffff), 0, 0);
   1.347 +            }
   1.348 +        }
   1.349 +        GEM_refresh_name = SDL_FALSE;
   1.350 +    }
   1.351  }
   1.352  
   1.353 -static int do_messages(_THIS, short *message)
   1.354 +static int
   1.355 +do_messages(_THIS, short *message)
   1.356  {
   1.357 -	int quit, posted;
   1.358 -	short x2,y2,w2,h2;
   1.359 +    int quit, posted;
   1.360 +    short x2, y2, w2, h2;
   1.361  
   1.362 -	quit=0;
   1.363 -	switch (message[0]) {
   1.364 -		case WM_CLOSED:
   1.365 -		case AP_TERM:    
   1.366 -			posted = SDL_PrivateQuit();
   1.367 -			quit=1;
   1.368 -			break;
   1.369 -		case WM_MOVED:
   1.370 -			wind_set(message[3],WF_CURRXYWH,message[4],message[5],message[6],message[7]);
   1.371 -			break;
   1.372 -		case WM_TOPPED:
   1.373 -			wind_set(message[3],WF_TOP,message[4],0,0,0);
   1.374 -			/* Continue with TOP event processing */
   1.375 -		case WM_ONTOP:
   1.376 -			SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
   1.377 -			if (VDI_setpalette) {
   1.378 -				VDI_setpalette(this, VDI_curpalette);
   1.379 -			}
   1.380 -			break;
   1.381 -		case WM_REDRAW:
   1.382 -			if (!GEM_lock_redraw) {
   1.383 -				GEM_wind_redraw(this, message[3],&message[4]);
   1.384 -			}
   1.385 -			break;
   1.386 -		case WM_ICONIFY:
   1.387 -		case WM_ALLICONIFY:
   1.388 -			wind_set(message[3],WF_ICONIFY,message[4],message[5],message[6],message[7]);
   1.389 -			/* If we're active, make ourselves inactive */
   1.390 -			if ( SDL_GetAppState() & SDL_APPACTIVE ) {
   1.391 -				/* Send an internal deactivate event */
   1.392 -				SDL_PrivateAppActive(0, SDL_APPACTIVE);
   1.393 -			}
   1.394 -			/* Update window title */
   1.395 -			if (GEM_refresh_name && GEM_icon_name) {
   1.396 -				wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_icon_name)>>16),(short)(((unsigned long)GEM_icon_name) & 0xffff),0,0);
   1.397 -				GEM_refresh_name = SDL_FALSE;
   1.398 -			}
   1.399 -			break;
   1.400 -		case WM_UNICONIFY:
   1.401 -			wind_set(message[3],WF_UNICONIFY,message[4],message[5],message[6],message[7]);
   1.402 -			/* If we're not active, make ourselves active */
   1.403 -			if ( !(SDL_GetAppState() & SDL_APPACTIVE) ) {
   1.404 -				/* Send an internal activate event */
   1.405 -				SDL_PrivateAppActive(1, SDL_APPACTIVE);
   1.406 -			}
   1.407 -			if (GEM_refresh_name && GEM_title_name) {
   1.408 -				wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_title_name)>>16),(short)(((unsigned long)GEM_title_name) & 0xffff),0,0);
   1.409 -				GEM_refresh_name = SDL_FALSE;
   1.410 -			}
   1.411 -			break;
   1.412 -		case WM_SIZED:
   1.413 -			wind_set (message[3], WF_CURRXYWH, message[4], message[5], message[6], message[7]);
   1.414 -			wind_get (message[3], WF_WORKXYWH, &x2, &y2, &w2, &h2);
   1.415 -			GEM_win_fulled = SDL_FALSE;		/* Cancel maximized flag */
   1.416 -			GEM_lock_redraw = SDL_TRUE;		/* Prevent redraw till buffers resized */
   1.417 -			SDL_PrivateResize(w2, h2);
   1.418 -			break;
   1.419 -		case WM_FULLED:
   1.420 -			{
   1.421 -				short x,y,w,h;
   1.422 +    quit = 0;
   1.423 +    switch (message[0]) {
   1.424 +    case WM_CLOSED:
   1.425 +    case AP_TERM:
   1.426 +        posted = SDL_PrivateQuit();
   1.427 +        quit = 1;
   1.428 +        break;
   1.429 +    case WM_MOVED:
   1.430 +        wind_set(message[3], WF_CURRXYWH, message[4], message[5],
   1.431 +                 message[6], message[7]);
   1.432 +        break;
   1.433 +    case WM_TOPPED:
   1.434 +        wind_set(message[3], WF_TOP, message[4], 0, 0, 0);
   1.435 +        /* Continue with TOP event processing */
   1.436 +    case WM_ONTOP:
   1.437 +        SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
   1.438 +        if (VDI_setpalette) {
   1.439 +            VDI_setpalette(this, VDI_curpalette);
   1.440 +        }
   1.441 +        break;
   1.442 +    case WM_REDRAW:
   1.443 +        if (!GEM_lock_redraw) {
   1.444 +            GEM_wind_redraw(this, message[3], &message[4]);
   1.445 +        }
   1.446 +        break;
   1.447 +    case WM_ICONIFY:
   1.448 +    case WM_ALLICONIFY:
   1.449 +        wind_set(message[3], WF_ICONIFY, message[4], message[5],
   1.450 +                 message[6], message[7]);
   1.451 +        /* If we're active, make ourselves inactive */
   1.452 +        if (SDL_GetAppState() & SDL_APPACTIVE) {
   1.453 +            /* Send an internal deactivate event */
   1.454 +            SDL_PrivateAppActive(0, SDL_APPACTIVE);
   1.455 +        }
   1.456 +        /* Update window title */
   1.457 +        if (GEM_refresh_name && GEM_icon_name) {
   1.458 +            wind_set(GEM_handle, WF_NAME,
   1.459 +                     (short) (((unsigned long) GEM_icon_name) >> 16),
   1.460 +                     (short) (((unsigned long) GEM_icon_name) & 0xffff),
   1.461 +                     0, 0);
   1.462 +            GEM_refresh_name = SDL_FALSE;
   1.463 +        }
   1.464 +        break;
   1.465 +    case WM_UNICONIFY:
   1.466 +        wind_set(message[3], WF_UNICONIFY, message[4], message[5],
   1.467 +                 message[6], message[7]);
   1.468 +        /* If we're not active, make ourselves active */
   1.469 +        if (!(SDL_GetAppState() & SDL_APPACTIVE)) {
   1.470 +            /* Send an internal activate event */
   1.471 +            SDL_PrivateAppActive(1, SDL_APPACTIVE);
   1.472 +        }
   1.473 +        if (GEM_refresh_name && GEM_title_name) {
   1.474 +            wind_set(GEM_handle, WF_NAME,
   1.475 +                     (short) (((unsigned long) GEM_title_name) >> 16),
   1.476 +                     (short) (((unsigned long) GEM_title_name) & 0xffff),
   1.477 +                     0, 0);
   1.478 +            GEM_refresh_name = SDL_FALSE;
   1.479 +        }
   1.480 +        break;
   1.481 +    case WM_SIZED:
   1.482 +        wind_set(message[3], WF_CURRXYWH, message[4], message[5],
   1.483 +                 message[6], message[7]);
   1.484 +        wind_get(message[3], WF_WORKXYWH, &x2, &y2, &w2, &h2);
   1.485 +        GEM_win_fulled = SDL_FALSE;     /* Cancel maximized flag */
   1.486 +        GEM_lock_redraw = SDL_TRUE;     /* Prevent redraw till buffers resized */
   1.487 +        SDL_PrivateResize(w2, h2);
   1.488 +        break;
   1.489 +    case WM_FULLED:
   1.490 +        {
   1.491 +            short x, y, w, h;
   1.492  
   1.493 -				if (GEM_win_fulled) {
   1.494 -					wind_get (message[3], WF_PREVXYWH, &x, &y, &w, &h);
   1.495 -					GEM_win_fulled = SDL_FALSE;
   1.496 -				} else {
   1.497 -					x = GEM_desk_x;
   1.498 -					y = GEM_desk_y;
   1.499 -					w = GEM_desk_w;
   1.500 -					h = GEM_desk_h;
   1.501 -					GEM_win_fulled = SDL_TRUE;
   1.502 -				}
   1.503 -				wind_set (message[3], WF_CURRXYWH, x, y, w, h);
   1.504 -				wind_get (message[3], WF_WORKXYWH, &x2, &y2, &w2, &h2);
   1.505 -				GEM_lock_redraw = SDL_TRUE;		/* Prevent redraw till buffers resized */
   1.506 -				SDL_PrivateResize(w2, h2);
   1.507 -			}
   1.508 -			break;
   1.509 -		case WM_BOTTOMED:
   1.510 -			wind_set(message[3],WF_BOTTOM,0,0,0,0);
   1.511 -			/* Continue with BOTTOM event processing */
   1.512 -		case WM_UNTOPPED:
   1.513 -			SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);
   1.514 -			if (VDI_setpalette) {
   1.515 -				VDI_setpalette(this, VDI_oldpalette);
   1.516 -			}
   1.517 -			break;
   1.518 -	}
   1.519 -	
   1.520 -	return quit;
   1.521 +            if (GEM_win_fulled) {
   1.522 +                wind_get(message[3], WF_PREVXYWH, &x, &y, &w, &h);
   1.523 +                GEM_win_fulled = SDL_FALSE;
   1.524 +            } else {
   1.525 +                x = GEM_desk_x;
   1.526 +                y = GEM_desk_y;
   1.527 +                w = GEM_desk_w;
   1.528 +                h = GEM_desk_h;
   1.529 +                GEM_win_fulled = SDL_TRUE;
   1.530 +            }
   1.531 +            wind_set(message[3], WF_CURRXYWH, x, y, w, h);
   1.532 +            wind_get(message[3], WF_WORKXYWH, &x2, &y2, &w2, &h2);
   1.533 +            GEM_lock_redraw = SDL_TRUE; /* Prevent redraw till buffers resized */
   1.534 +            SDL_PrivateResize(w2, h2);
   1.535 +        }
   1.536 +        break;
   1.537 +    case WM_BOTTOMED:
   1.538 +        wind_set(message[3], WF_BOTTOM, 0, 0, 0, 0);
   1.539 +        /* Continue with BOTTOM event processing */
   1.540 +    case WM_UNTOPPED:
   1.541 +        SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);
   1.542 +        if (VDI_setpalette) {
   1.543 +            VDI_setpalette(this, VDI_oldpalette);
   1.544 +        }
   1.545 +        break;
   1.546 +    }
   1.547 +
   1.548 +    return quit;
   1.549  }
   1.550  
   1.551 -static void do_keyboard(short kc, short ks)
   1.552 +static void
   1.553 +do_keyboard(short kc, short ks)
   1.554  {
   1.555 -	int			scancode, asciicode;
   1.556 +    int scancode, asciicode;
   1.557  
   1.558 -	if (kc) {
   1.559 -		scancode=(kc>>8) & 127;
   1.560 -		asciicode=kc & 255;
   1.561 +    if (kc) {
   1.562 +        scancode = (kc >> 8) & 127;
   1.563 +        asciicode = kc & 255;
   1.564  
   1.565 -		gem_currentkeyboard[scancode]=0xFF;
   1.566 -		gem_currentascii[scancode]=asciicode;
   1.567 -	}
   1.568 +        gem_currentkeyboard[scancode] = 0xFF;
   1.569 +        gem_currentascii[scancode] = asciicode;
   1.570 +    }
   1.571  
   1.572 -	/* Read special keys */
   1.573 -	if (ks & K_RSHIFT)
   1.574 -		gem_currentkeyboard[SCANCODE_RIGHTSHIFT]=0xFF;
   1.575 -	if (ks & K_LSHIFT)
   1.576 -		gem_currentkeyboard[SCANCODE_LEFTSHIFT]=0xFF;
   1.577 -	if (ks & K_CTRL)
   1.578 -		gem_currentkeyboard[SCANCODE_LEFTCONTROL]=0xFF;
   1.579 -	if (ks & K_ALT)
   1.580 -		gem_currentkeyboard[SCANCODE_LEFTALT]=0xFF;
   1.581 +    /* Read special keys */
   1.582 +    if (ks & K_RSHIFT)
   1.583 +        gem_currentkeyboard[SCANCODE_RIGHTSHIFT] = 0xFF;
   1.584 +    if (ks & K_LSHIFT)
   1.585 +        gem_currentkeyboard[SCANCODE_LEFTSHIFT] = 0xFF;
   1.586 +    if (ks & K_CTRL)
   1.587 +        gem_currentkeyboard[SCANCODE_LEFTCONTROL] = 0xFF;
   1.588 +    if (ks & K_ALT)
   1.589 +        gem_currentkeyboard[SCANCODE_LEFTALT] = 0xFF;
   1.590  }
   1.591  
   1.592 -static void do_mouse(_THIS, short mx, short my, short mb, short ks)
   1.593 +static void
   1.594 +do_mouse(_THIS, short mx, short my, short mb, short ks)
   1.595  {
   1.596 -	static short prevmousex=0, prevmousey=0, prevmouseb=0;
   1.597 -	short x2, y2, w2, h2;
   1.598 +    static short prevmousex = 0, prevmousey = 0, prevmouseb = 0;
   1.599 +    short x2, y2, w2, h2;
   1.600  
   1.601 -	/* Don't return mouse events if out of window */
   1.602 -	if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS)==0) {
   1.603 -		return;
   1.604 -	}
   1.605 +    /* Don't return mouse events if out of window */
   1.606 +    if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS) == 0) {
   1.607 +        return;
   1.608 +    }
   1.609  
   1.610 -	/* Retrieve window coords, and generate mouse events accordingly */
   1.611 -	x2 = y2 = 0;
   1.612 -	w2 = VDI_w;
   1.613 -	h2 = VDI_h;
   1.614 -	if ((!GEM_fullscreen) && (GEM_handle>=0)) {
   1.615 -		wind_get (GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2);
   1.616 +    /* Retrieve window coords, and generate mouse events accordingly */
   1.617 +    x2 = y2 = 0;
   1.618 +    w2 = VDI_w;
   1.619 +    h2 = VDI_h;
   1.620 +    if ((!GEM_fullscreen) && (GEM_handle >= 0)) {
   1.621 +        wind_get(GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2);
   1.622  
   1.623 -		/* Do not generate mouse button event if out of window working area */
   1.624 -		if ((mx<x2) || (mx>=x2+w2) || (my<y2) || (my>=y2+h2)) {
   1.625 -			mb=prevmouseb;
   1.626 -		}
   1.627 -	}
   1.628 +        /* Do not generate mouse button event if out of window working area */
   1.629 +        if ((mx < x2) || (mx >= x2 + w2) || (my < y2) || (my >= y2 + h2)) {
   1.630 +            mb = prevmouseb;
   1.631 +        }
   1.632 +    }
   1.633  
   1.634 -	/* Mouse motion ? */
   1.635 -	if (GEM_mouse_relative) {
   1.636 -		if (GEM_usedevmouse) {
   1.637 -			SDL_AtariDevMouse_PostMouseEvents(this, SDL_FALSE);
   1.638 -		} else {
   1.639 -			SDL_AtariXbios_PostMouseEvents(this, SDL_FALSE);
   1.640 -		}
   1.641 -	} else {
   1.642 -		if ((prevmousex!=mx) || (prevmousey!=my)) {
   1.643 -			int posx, posy;
   1.644 +    /* Mouse motion ? */
   1.645 +    if (GEM_mouse_relative) {
   1.646 +        if (GEM_usedevmouse) {
   1.647 +            SDL_AtariDevMouse_PostMouseEvents(this, SDL_FALSE);
   1.648 +        } else {
   1.649 +            SDL_AtariXbios_PostMouseEvents(this, SDL_FALSE);
   1.650 +        }
   1.651 +    } else {
   1.652 +        if ((prevmousex != mx) || (prevmousey != my)) {
   1.653 +            int posx, posy;
   1.654  
   1.655 -			/* Give mouse position relative to window position */
   1.656 -			posx = mx - x2;
   1.657 -			if (posx<0) posx = 0;
   1.658 -			if (posx>w2) posx = w2-1;
   1.659 -			posy = my - y2;
   1.660 -			if (posy<0) posy = 0;
   1.661 -			if (posy>h2) posy = h2-1;
   1.662 +            /* Give mouse position relative to window position */
   1.663 +            posx = mx - x2;
   1.664 +            if (posx < 0)
   1.665 +                posx = 0;
   1.666 +            if (posx > w2)
   1.667 +                posx = w2 - 1;
   1.668 +            posy = my - y2;
   1.669 +            if (posy < 0)
   1.670 +                posy = 0;
   1.671 +            if (posy > h2)
   1.672 +                posy = h2 - 1;
   1.673  
   1.674 -			SDL_PrivateMouseMotion(0, 0, posx, posy);
   1.675 -		}
   1.676 -		prevmousex = mx;
   1.677 -		prevmousey = my;
   1.678 -	}
   1.679 +            SDL_PrivateMouseMotion(0, 0, posx, posy);
   1.680 +        }
   1.681 +        prevmousex = mx;
   1.682 +        prevmousey = my;
   1.683 +    }
   1.684  
   1.685 -	/* Mouse button ? */
   1.686 -	if (prevmouseb!=mb) {
   1.687 -		int i;
   1.688 +    /* Mouse button ? */
   1.689 +    if (prevmouseb != mb) {
   1.690 +        int i;
   1.691  
   1.692 -		for (i=0;i<2;i++) {
   1.693 -			int curbutton, prevbutton;
   1.694 -		
   1.695 -			curbutton = mb & (1<<i);
   1.696 -			prevbutton = prevmouseb & (1<<i);
   1.697 -		
   1.698 -			if (curbutton && !prevbutton) {
   1.699 -				SDL_PrivateMouseButton(SDL_PRESSED, i+1, 0, 0);
   1.700 -			}
   1.701 -			if (!curbutton && prevbutton) {
   1.702 -				SDL_PrivateMouseButton(SDL_RELEASED, i+1, 0, 0);
   1.703 -			}
   1.704 -		}
   1.705 -		prevmouseb = mb;
   1.706 -	}
   1.707 +        for (i = 0; i < 2; i++) {
   1.708 +            int curbutton, prevbutton;
   1.709  
   1.710 -	/* Read special keys */
   1.711 -	if (ks & K_RSHIFT)
   1.712 -		gem_currentkeyboard[SCANCODE_RIGHTSHIFT]=0xFF;
   1.713 -	if (ks & K_LSHIFT)
   1.714 -		gem_currentkeyboard[SCANCODE_LEFTSHIFT]=0xFF;
   1.715 -	if (ks & K_CTRL)
   1.716 -		gem_currentkeyboard[SCANCODE_LEFTCONTROL]=0xFF;
   1.717 -	if (ks & K_ALT)
   1.718 -		gem_currentkeyboard[SCANCODE_LEFTALT]=0xFF;
   1.719 +            curbutton = mb & (1 << i);
   1.720 +            prevbutton = prevmouseb & (1 << i);
   1.721 +
   1.722 +            if (curbutton && !prevbutton) {
   1.723 +                SDL_PrivateMouseButton(SDL_PRESSED, i + 1, 0, 0);
   1.724 +            }
   1.725 +            if (!curbutton && prevbutton) {
   1.726 +                SDL_PrivateMouseButton(SDL_RELEASED, i + 1, 0, 0);
   1.727 +            }
   1.728 +        }
   1.729 +        prevmouseb = mb;
   1.730 +    }
   1.731 +
   1.732 +    /* Read special keys */
   1.733 +    if (ks & K_RSHIFT)
   1.734 +        gem_currentkeyboard[SCANCODE_RIGHTSHIFT] = 0xFF;
   1.735 +    if (ks & K_LSHIFT)
   1.736 +        gem_currentkeyboard[SCANCODE_LEFTSHIFT] = 0xFF;
   1.737 +    if (ks & K_CTRL)
   1.738 +        gem_currentkeyboard[SCANCODE_LEFTCONTROL] = 0xFF;
   1.739 +    if (ks & K_ALT)
   1.740 +        gem_currentkeyboard[SCANCODE_LEFTALT] = 0xFF;
   1.741  }
   1.742 +
   1.743 +/* vi: set ts=4 sw=4 expandtab: */