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