test/testwm.c
changeset 1895 c121d94672cb
parent 1779 67fc81efcfc3
child 2060 866052b01ee5
     1.1 --- a/test/testwm.c	Thu Jul 06 18:01:37 2006 +0000
     1.2 +++ b/test/testwm.c	Mon Jul 10 21:04:37 2006 +0000
     1.3 @@ -10,367 +10,374 @@
     1.4  /* Is the cursor visible? */
     1.5  static int visible = 1;
     1.6  
     1.7 -static Uint8  video_bpp;
     1.8 +static Uint8 video_bpp;
     1.9  static Uint32 video_flags;
    1.10  
    1.11  /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    1.12 -static void quit(int rc)
    1.13 +static void
    1.14 +quit(int rc)
    1.15  {
    1.16 -	SDL_Quit();
    1.17 -	exit(rc);
    1.18 +    SDL_Quit();
    1.19 +    exit(rc);
    1.20  }
    1.21  
    1.22 -int SetVideoMode(int w, int h)
    1.23 +int
    1.24 +SetVideoMode(int w, int h)
    1.25  {
    1.26 -	SDL_Surface *screen;
    1.27 -	int i;
    1.28 -	Uint8 *buffer;
    1.29 -	SDL_Color palette[256];
    1.30 +    SDL_Surface *screen;
    1.31 +    int i;
    1.32 +    Uint8 *buffer;
    1.33 +    SDL_Color palette[256];
    1.34  
    1.35 -	screen = SDL_SetVideoMode(w, h, video_bpp, video_flags);
    1.36 -	if (  screen == NULL ) {
    1.37 -		fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n",
    1.38 -					w, h, video_bpp, SDL_GetError());
    1.39 -		return(-1);
    1.40 -	}
    1.41 -	printf("Running in %s mode\n", screen->flags & SDL_FULLSCREEN ?
    1.42 -						"fullscreen" : "windowed");
    1.43 +    screen = SDL_SetVideoMode(w, h, video_bpp, video_flags);
    1.44 +    if (screen == NULL) {
    1.45 +        fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n",
    1.46 +                w, h, video_bpp, SDL_GetError());
    1.47 +        return (-1);
    1.48 +    }
    1.49 +    printf("Running in %s mode\n", screen->flags & SDL_FULLSCREEN ?
    1.50 +           "fullscreen" : "windowed");
    1.51  
    1.52 -	/* Set the surface pixels and refresh! */
    1.53 -	for ( i=0; i<256; ++i ) {
    1.54 -		palette[i].r = 255-i;
    1.55 -		palette[i].g = 255-i;
    1.56 -		palette[i].b = 255-i;
    1.57 -	}
    1.58 -	SDL_SetColors(screen, palette, 0, 256);
    1.59 -	if ( SDL_LockSurface(screen) < 0 ) {
    1.60 -		fprintf(stderr, "Couldn't lock display surface: %s\n",
    1.61 -							SDL_GetError());
    1.62 -		return(-1);
    1.63 -	}
    1.64 -	buffer = (Uint8 *)screen->pixels;
    1.65 -	for ( i=0; i<screen->h; ++i ) {
    1.66 -		memset(buffer,(i*255)/screen->h,
    1.67 -				screen->w*screen->format->BytesPerPixel);
    1.68 -		buffer += screen->pitch;
    1.69 -	}
    1.70 -	SDL_UnlockSurface(screen);
    1.71 -	SDL_UpdateRect(screen, 0, 0, 0, 0);
    1.72 +    /* Set the surface pixels and refresh! */
    1.73 +    for (i = 0; i < 256; ++i) {
    1.74 +        palette[i].r = 255 - i;
    1.75 +        palette[i].g = 255 - i;
    1.76 +        palette[i].b = 255 - i;
    1.77 +    }
    1.78 +    SDL_SetColors(screen, palette, 0, 256);
    1.79 +    if (SDL_LockSurface(screen) < 0) {
    1.80 +        fprintf(stderr, "Couldn't lock display surface: %s\n",
    1.81 +                SDL_GetError());
    1.82 +        return (-1);
    1.83 +    }
    1.84 +    buffer = (Uint8 *) screen->pixels;
    1.85 +    for (i = 0; i < screen->h; ++i) {
    1.86 +        memset(buffer, (i * 255) / screen->h,
    1.87 +               screen->w * screen->format->BytesPerPixel);
    1.88 +        buffer += screen->pitch;
    1.89 +    }
    1.90 +    SDL_UnlockSurface(screen);
    1.91 +    SDL_UpdateRect(screen, 0, 0, 0, 0);
    1.92  
    1.93 -	return(0);
    1.94 +    return (0);
    1.95  }
    1.96  
    1.97 -SDL_Surface *LoadIconSurface(char *file, Uint8 **maskp)
    1.98 +SDL_Surface *
    1.99 +LoadIconSurface(char *file, Uint8 ** maskp)
   1.100  {
   1.101 -	SDL_Surface *icon;
   1.102 -	Uint8       *pixels;
   1.103 -	Uint8       *mask;
   1.104 -	int          mlen, i, j;
   1.105 +    SDL_Surface *icon;
   1.106 +    Uint8 *pixels;
   1.107 +    Uint8 *mask;
   1.108 +    int mlen, i, j;
   1.109 +
   1.110 +    *maskp = NULL;
   1.111  
   1.112 -	*maskp = NULL;
   1.113 +    /* Load the icon surface */
   1.114 +    icon = SDL_LoadBMP(file);
   1.115 +    if (icon == NULL) {
   1.116 +        fprintf(stderr, "Couldn't load %s: %s\n", file, SDL_GetError());
   1.117 +        return (NULL);
   1.118 +    }
   1.119  
   1.120 -	/* Load the icon surface */
   1.121 -	icon = SDL_LoadBMP(file);
   1.122 -	if ( icon == NULL ) {
   1.123 -		fprintf(stderr, "Couldn't load %s: %s\n", file, SDL_GetError());
   1.124 -		return(NULL);
   1.125 -	}
   1.126 +    /* Check width and height 
   1.127 +       if ( (icon->w%8) != 0 ) {
   1.128 +       fprintf(stderr, "Icon width must be a multiple of 8!\n");
   1.129 +       SDL_FreeSurface(icon);
   1.130 +       return(NULL);
   1.131 +       }
   1.132 +     */
   1.133 +
   1.134  
   1.135 -	/* Check width and height 
   1.136 -	if ( (icon->w%8) != 0 ) {
   1.137 -		fprintf(stderr, "Icon width must be a multiple of 8!\n");
   1.138 -		SDL_FreeSurface(icon);
   1.139 -		return(NULL);
   1.140 -	}
   1.141 -*/
   1.142 -    
   1.143 -    
   1.144 -	if ( icon->format->palette == NULL ) {
   1.145 -		fprintf(stderr, "Icon must have a palette!\n");
   1.146 -		SDL_FreeSurface(icon);
   1.147 -		return(NULL);
   1.148 -	}
   1.149 +    if (icon->format->palette == NULL) {
   1.150 +        fprintf(stderr, "Icon must have a palette!\n");
   1.151 +        SDL_FreeSurface(icon);
   1.152 +        return (NULL);
   1.153 +    }
   1.154 +
   1.155 +    /* Set the colorkey */
   1.156 +    SDL_SetColorKey(icon, SDL_SRCCOLORKEY, *((Uint8 *) icon->pixels));
   1.157  
   1.158 -	/* Set the colorkey */
   1.159 -	SDL_SetColorKey(icon, SDL_SRCCOLORKEY, *((Uint8 *)icon->pixels));
   1.160 -
   1.161 -	/* Create the mask */
   1.162 -	pixels = (Uint8 *)icon->pixels;
   1.163 -	printf("Transparent pixel: (%d,%d,%d)\n",
   1.164 -				icon->format->palette->colors[*pixels].r,
   1.165 -				icon->format->palette->colors[*pixels].g,
   1.166 -				icon->format->palette->colors[*pixels].b);
   1.167 -	mlen = (icon->w*icon->h + 7) / 8;
   1.168 -	mask = (Uint8 *)malloc(mlen);
   1.169 -	if ( mask == NULL ) {
   1.170 -		fprintf(stderr, "Out of memory!\n");
   1.171 -		SDL_FreeSurface(icon);
   1.172 -		return(NULL);
   1.173 -	}
   1.174 -	memset(mask, 0, mlen);
   1.175 -	for ( i=0; i < icon->h; i++)
   1.176 -        for (j=0; j < icon->w; j++) {
   1.177 +    /* Create the mask */
   1.178 +    pixels = (Uint8 *) icon->pixels;
   1.179 +    printf("Transparent pixel: (%d,%d,%d)\n",
   1.180 +           icon->format->palette->colors[*pixels].r,
   1.181 +           icon->format->palette->colors[*pixels].g,
   1.182 +           icon->format->palette->colors[*pixels].b);
   1.183 +    mlen = (icon->w * icon->h + 7) / 8;
   1.184 +    mask = (Uint8 *) malloc(mlen);
   1.185 +    if (mask == NULL) {
   1.186 +        fprintf(stderr, "Out of memory!\n");
   1.187 +        SDL_FreeSurface(icon);
   1.188 +        return (NULL);
   1.189 +    }
   1.190 +    memset(mask, 0, mlen);
   1.191 +    for (i = 0; i < icon->h; i++)
   1.192 +        for (j = 0; j < icon->w; j++) {
   1.193              int pindex = i * icon->pitch + j;
   1.194              int mindex = i * icon->w + j;
   1.195 -            if ( pixels[pindex] != *pixels )
   1.196 -                mask[mindex>>3] |= 1 << (7 - (mindex & 7));
   1.197 +            if (pixels[pindex] != *pixels)
   1.198 +                mask[mindex >> 3] |= 1 << (7 - (mindex & 7));
   1.199          }
   1.200 -	*maskp = mask;
   1.201 -	return(icon);
   1.202 +    *maskp = mask;
   1.203 +    return (icon);
   1.204  }
   1.205  
   1.206 -void HotKey_ToggleFullScreen(void)
   1.207 +void
   1.208 +HotKey_ToggleFullScreen(void)
   1.209  {
   1.210 -	SDL_Surface *screen;
   1.211 +    SDL_Surface *screen;
   1.212  
   1.213 -	screen = SDL_GetVideoSurface();
   1.214 -	if ( SDL_WM_ToggleFullScreen(screen) ) {
   1.215 -		printf("Toggled fullscreen mode - now %s\n",
   1.216 -		    (screen->flags&SDL_FULLSCREEN) ? "fullscreen" : "windowed");
   1.217 -	} else {
   1.218 -		printf("Unable to toggle fullscreen mode\n");
   1.219 -		video_flags ^= SDL_FULLSCREEN;
   1.220 -		SetVideoMode(screen->w, screen->h);
   1.221 -	}
   1.222 +    screen = SDL_GetVideoSurface();
   1.223 +    if (SDL_WM_ToggleFullScreen(screen)) {
   1.224 +        printf("Toggled fullscreen mode - now %s\n",
   1.225 +               (screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed");
   1.226 +    } else {
   1.227 +        printf("Unable to toggle fullscreen mode\n");
   1.228 +        video_flags ^= SDL_FULLSCREEN;
   1.229 +        SetVideoMode(screen->w, screen->h);
   1.230 +    }
   1.231  }
   1.232  
   1.233 -void HotKey_ToggleGrab(void)
   1.234 +void
   1.235 +HotKey_ToggleGrab(void)
   1.236  {
   1.237 -	SDL_GrabMode mode;
   1.238 +    SDL_GrabMode mode;
   1.239  
   1.240 -	printf("Ctrl-G: toggling input grab!\n");
   1.241 -	mode = SDL_WM_GrabInput(SDL_GRAB_QUERY);
   1.242 -	if ( mode == SDL_GRAB_ON ) {
   1.243 -		printf("Grab was on\n");
   1.244 -	} else {
   1.245 -		printf("Grab was off\n");
   1.246 -	}
   1.247 -	mode = SDL_WM_GrabInput(mode ? SDL_GRAB_OFF : SDL_GRAB_ON);
   1.248 -	if ( mode == SDL_GRAB_ON ) {
   1.249 -		printf("Grab is now on\n");
   1.250 -	} else {
   1.251 -		printf("Grab is now off\n");
   1.252 -	}
   1.253 +    printf("Ctrl-G: toggling input grab!\n");
   1.254 +    mode = SDL_WM_GrabInput(SDL_GRAB_QUERY);
   1.255 +    if (mode == SDL_GRAB_ON) {
   1.256 +        printf("Grab was on\n");
   1.257 +    } else {
   1.258 +        printf("Grab was off\n");
   1.259 +    }
   1.260 +    mode = SDL_WM_GrabInput(mode ? SDL_GRAB_OFF : SDL_GRAB_ON);
   1.261 +    if (mode == SDL_GRAB_ON) {
   1.262 +        printf("Grab is now on\n");
   1.263 +    } else {
   1.264 +        printf("Grab is now off\n");
   1.265 +    }
   1.266  }
   1.267  
   1.268 -void HotKey_Iconify(void)
   1.269 +void
   1.270 +HotKey_Iconify(void)
   1.271  {
   1.272 -	printf("Ctrl-Z: iconifying window!\n");
   1.273 -	SDL_WM_IconifyWindow();
   1.274 +    printf("Ctrl-Z: iconifying window!\n");
   1.275 +    SDL_WM_IconifyWindow();
   1.276  }
   1.277  
   1.278 -void HotKey_Quit(void)
   1.279 +void
   1.280 +HotKey_Quit(void)
   1.281  {
   1.282 -	SDL_Event event;
   1.283 +    SDL_Event event;
   1.284  
   1.285 -	printf("Posting internal quit request\n");
   1.286 -	event.type = SDL_USEREVENT;
   1.287 -	SDL_PushEvent(&event);
   1.288 +    printf("Posting internal quit request\n");
   1.289 +    event.type = SDL_USEREVENT;
   1.290 +    SDL_PushEvent(&event);
   1.291  }
   1.292  
   1.293 -int SDLCALL FilterEvents(const SDL_Event *event)
   1.294 -{
   1.295 -	static int reallyquit = 0;
   1.296 -
   1.297 -	switch (event->type) {
   1.298 +static int SDLCALL(*old_filterfunc) (void *, SDL_Event *);
   1.299 +static void *old_filterdata;
   1.300  
   1.301 -		case SDL_ACTIVEEVENT:
   1.302 -			/* See what happened */
   1.303 -			printf("App %s ",
   1.304 -				event->active.gain ? "gained" : "lost");
   1.305 -			if ( event->active.state & SDL_APPACTIVE )
   1.306 -				printf("active ");
   1.307 -			if ( event->active.state & SDL_APPINPUTFOCUS )
   1.308 -				printf("input ");
   1.309 -			if ( event->active.state & SDL_APPMOUSEFOCUS )
   1.310 -				printf("mouse ");
   1.311 -			printf("focus\n");
   1.312 +int SDLCALL
   1.313 +FilterEvents(void *userdata, SDL_Event * event)
   1.314 +{
   1.315 +    static int reallyquit = 0;
   1.316 +
   1.317 +    if (old_filterfunc) {
   1.318 +        old_filterfunc(old_filterdata, event);
   1.319 +    }
   1.320 +
   1.321 +    switch (event->type) {
   1.322  
   1.323 -			/* See if we are iconified or restored */
   1.324 -			if ( event->active.state & SDL_APPACTIVE ) {
   1.325 -				printf("App has been %s\n",
   1.326 -					event->active.gain ?
   1.327 -						 "restored" : "iconified");
   1.328 -			}
   1.329 -			return(0);
   1.330 +    case SDL_ACTIVEEVENT:
   1.331 +        /* See what happened */
   1.332 +        printf("App %s ", event->active.gain ? "gained" : "lost");
   1.333 +        if (event->active.state & SDL_APPACTIVE)
   1.334 +            printf("active ");
   1.335 +        if (event->active.state & SDL_APPINPUTFOCUS)
   1.336 +            printf("input ");
   1.337 +        if (event->active.state & SDL_APPMOUSEFOCUS)
   1.338 +            printf("mouse ");
   1.339 +        printf("focus\n");
   1.340  
   1.341 -		/* We want to toggle visibility on buttonpress */
   1.342 -		case SDL_MOUSEBUTTONDOWN:
   1.343 -		case SDL_MOUSEBUTTONUP:
   1.344 -			if ( event->button.state == SDL_PRESSED ) {
   1.345 -				visible = !visible;
   1.346 -				SDL_ShowCursor(visible);
   1.347 -			}
   1.348 -			printf("Mouse button %d has been %s\n",
   1.349 -				event->button.button,
   1.350 -				(event->button.state == SDL_PRESSED) ?
   1.351 -						"pressed" : "released");
   1.352 -			return(0);
   1.353 +        /* See if we are iconified or restored */
   1.354 +        if (event->active.state & SDL_APPACTIVE) {
   1.355 +            printf("App has been %s\n",
   1.356 +                   event->active.gain ? "restored" : "iconified");
   1.357 +        }
   1.358 +        return (0);
   1.359  
   1.360 -		/* Show relative mouse motion */
   1.361 -		case SDL_MOUSEMOTION:
   1.362 +        /* We want to toggle visibility on buttonpress */
   1.363 +    case SDL_MOUSEBUTTONDOWN:
   1.364 +    case SDL_MOUSEBUTTONUP:
   1.365 +        if (event->button.state == SDL_PRESSED) {
   1.366 +            visible = !visible;
   1.367 +            SDL_ShowCursor(visible);
   1.368 +        }
   1.369 +        printf("Mouse button %d has been %s\n",
   1.370 +               event->button.button,
   1.371 +               (event->button.state == SDL_PRESSED) ? "pressed" : "released");
   1.372 +        return (0);
   1.373 +
   1.374 +        /* Show relative mouse motion */
   1.375 +    case SDL_MOUSEMOTION:
   1.376  #if 0
   1.377 -			printf("Mouse motion: {%d,%d} (%d,%d)\n",
   1.378 -				event->motion.x, event->motion.y,
   1.379 -				event->motion.xrel, event->motion.yrel);
   1.380 +        printf("Mouse motion: {%d,%d} (%d,%d)\n",
   1.381 +               event->motion.x, event->motion.y,
   1.382 +               event->motion.xrel, event->motion.yrel);
   1.383  #endif
   1.384 -			return(0);
   1.385 +        return (0);
   1.386  
   1.387 -		case SDL_KEYDOWN:
   1.388 -			if ( event->key.keysym.sym == SDLK_ESCAPE ) {
   1.389 -				HotKey_Quit();
   1.390 -			}
   1.391 -			if ( (event->key.keysym.sym == SDLK_g) &&
   1.392 -			     (event->key.keysym.mod & KMOD_CTRL) ) {
   1.393 -				HotKey_ToggleGrab();
   1.394 -			}
   1.395 -			if ( (event->key.keysym.sym == SDLK_z) &&
   1.396 -			     (event->key.keysym.mod & KMOD_CTRL) ) {
   1.397 -				HotKey_Iconify();
   1.398 -			}
   1.399 -			if ( (event->key.keysym.sym == SDLK_RETURN) &&
   1.400 -			     (event->key.keysym.mod & KMOD_ALT) ) {
   1.401 -				HotKey_ToggleFullScreen();
   1.402 -			}
   1.403 -			return(0);
   1.404 +    case SDL_KEYDOWN:
   1.405 +        if (event->key.keysym.sym == SDLK_ESCAPE) {
   1.406 +            HotKey_Quit();
   1.407 +        }
   1.408 +        if ((event->key.keysym.sym == SDLK_g) &&
   1.409 +            (event->key.keysym.mod & KMOD_CTRL)) {
   1.410 +            HotKey_ToggleGrab();
   1.411 +        }
   1.412 +        if ((event->key.keysym.sym == SDLK_z) &&
   1.413 +            (event->key.keysym.mod & KMOD_CTRL)) {
   1.414 +            HotKey_Iconify();
   1.415 +        }
   1.416 +        if ((event->key.keysym.sym == SDLK_RETURN) &&
   1.417 +            (event->key.keysym.mod & KMOD_ALT)) {
   1.418 +            HotKey_ToggleFullScreen();
   1.419 +        }
   1.420 +        return (0);
   1.421  
   1.422 -		/* Pass the video resize event through .. */
   1.423 -		case SDL_VIDEORESIZE:
   1.424 -			return(1);
   1.425 +        /* Pass the video resize event through .. */
   1.426 +    case SDL_VIDEORESIZE:
   1.427 +        return (1);
   1.428  
   1.429 -		/* This is important!  Queue it if we want to quit. */
   1.430 -		case SDL_QUIT:
   1.431 -			if ( ! reallyquit ) {
   1.432 -				reallyquit = 1;
   1.433 -				printf("Quit requested\n");
   1.434 -				return(0);
   1.435 -			}
   1.436 -			printf("Quit demanded\n");
   1.437 -			return(1);
   1.438 +        /* This is important!  Queue it if we want to quit. */
   1.439 +    case SDL_QUIT:
   1.440 +        if (!reallyquit) {
   1.441 +            reallyquit = 1;
   1.442 +            printf("Quit requested\n");
   1.443 +            return (0);
   1.444 +        }
   1.445 +        printf("Quit demanded\n");
   1.446 +        return (1);
   1.447  
   1.448 -		/* This will never happen because events queued directly
   1.449 -		   to the event queue are not filtered.
   1.450 -		 */
   1.451 -		case SDL_USEREVENT:
   1.452 -			return(1);
   1.453 +        /* This will never happen because events queued directly
   1.454 +           to the event queue are not filtered.
   1.455 +         */
   1.456 +    case SDL_USEREVENT:
   1.457 +        return (1);
   1.458  
   1.459 -		/* Drop all other events */
   1.460 -		default:
   1.461 -			return(0);
   1.462 -	}
   1.463 +        /* Drop all other events */
   1.464 +    default:
   1.465 +        return (0);
   1.466 +    }
   1.467  }
   1.468  
   1.469 -int main(int argc, char *argv[])
   1.470 +int
   1.471 +main(int argc, char *argv[])
   1.472  {
   1.473 -	SDL_Event event;
   1.474 -	char *title;
   1.475 -	SDL_Surface *icon;
   1.476 -	Uint8 *icon_mask;
   1.477 -	int parsed;
   1.478 -	int w, h;
   1.479 +    SDL_Event event;
   1.480 +    char *title;
   1.481 +    SDL_Surface *icon;
   1.482 +    Uint8 *icon_mask;
   1.483 +    int parsed;
   1.484 +    int w, h;
   1.485  
   1.486 -	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
   1.487 -		fprintf(stderr,
   1.488 -			"Couldn't initialize SDL: %s\n", SDL_GetError());
   1.489 -		return(1);
   1.490 -	}
   1.491 +    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
   1.492 +        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
   1.493 +        return (1);
   1.494 +    }
   1.495  
   1.496 -	/* Check command line arguments */
   1.497 -	w = 640;
   1.498 -	h = 480;
   1.499 -	video_bpp = 8;
   1.500 -	video_flags = SDL_SWSURFACE;
   1.501 -	parsed = 1;
   1.502 -	while ( parsed ) {
   1.503 -		if ( (argc >= 2) && (strcmp(argv[1], "-fullscreen") == 0) ) {
   1.504 -			video_flags |= SDL_FULLSCREEN;
   1.505 -			argc -= 1;
   1.506 -			argv += 1;
   1.507 -		} else
   1.508 -		if ( (argc >= 2) && (strcmp(argv[1], "-resize") == 0) ) {
   1.509 -			video_flags |= SDL_RESIZABLE;
   1.510 -			argc -= 1;
   1.511 -			argv += 1;
   1.512 -		} else
   1.513 -		if ( (argc >= 2) && (strcmp(argv[1], "-noframe") == 0) ) {
   1.514 -			video_flags |= SDL_NOFRAME;
   1.515 -			argc -= 1;
   1.516 -			argv += 1;
   1.517 -		} else
   1.518 -		if ( (argc >= 3) && (strcmp(argv[1], "-width") == 0) ) {
   1.519 -			w = atoi(argv[2]);
   1.520 -			argc -= 2;
   1.521 -			argv += 2;
   1.522 -		} else
   1.523 -		if ( (argc >= 3) && (strcmp(argv[1], "-height") == 0) ) {
   1.524 -			h = atoi(argv[2]);
   1.525 -			argc -= 2;
   1.526 -			argv += 2;
   1.527 -		} else
   1.528 -		if ( (argc >= 3) && (strcmp(argv[1], "-bpp") == 0) ) {
   1.529 -			video_bpp = atoi(argv[2]);
   1.530 -			argc -= 2;
   1.531 -			argv += 2;
   1.532 -		} else {
   1.533 -			parsed = 0;
   1.534 -		}
   1.535 -	}
   1.536 +    /* Check command line arguments */
   1.537 +    w = 640;
   1.538 +    h = 480;
   1.539 +    video_bpp = 8;
   1.540 +    video_flags = SDL_SWSURFACE;
   1.541 +    parsed = 1;
   1.542 +    while (parsed) {
   1.543 +        if ((argc >= 2) && (strcmp(argv[1], "-fullscreen") == 0)) {
   1.544 +            video_flags |= SDL_FULLSCREEN;
   1.545 +            argc -= 1;
   1.546 +            argv += 1;
   1.547 +        } else if ((argc >= 2) && (strcmp(argv[1], "-resize") == 0)) {
   1.548 +            video_flags |= SDL_RESIZABLE;
   1.549 +            argc -= 1;
   1.550 +            argv += 1;
   1.551 +        } else if ((argc >= 2) && (strcmp(argv[1], "-noframe") == 0)) {
   1.552 +            video_flags |= SDL_NOFRAME;
   1.553 +            argc -= 1;
   1.554 +            argv += 1;
   1.555 +        } else if ((argc >= 3) && (strcmp(argv[1], "-width") == 0)) {
   1.556 +            w = atoi(argv[2]);
   1.557 +            argc -= 2;
   1.558 +            argv += 2;
   1.559 +        } else if ((argc >= 3) && (strcmp(argv[1], "-height") == 0)) {
   1.560 +            h = atoi(argv[2]);
   1.561 +            argc -= 2;
   1.562 +            argv += 2;
   1.563 +        } else if ((argc >= 3) && (strcmp(argv[1], "-bpp") == 0)) {
   1.564 +            video_bpp = atoi(argv[2]);
   1.565 +            argc -= 2;
   1.566 +            argv += 2;
   1.567 +        } else {
   1.568 +            parsed = 0;
   1.569 +        }
   1.570 +    }
   1.571  
   1.572 -	/* Set the icon -- this must be done before the first mode set */
   1.573 -	icon = LoadIconSurface("icon.bmp", &icon_mask);
   1.574 -	if ( icon != NULL ) {
   1.575 -		SDL_WM_SetIcon(icon, icon_mask);
   1.576 -	}
   1.577 -	if ( icon_mask != NULL )
   1.578 -		free(icon_mask);
   1.579 +    /* Set the icon -- this must be done before the first mode set */
   1.580 +    icon = LoadIconSurface("icon.bmp", &icon_mask);
   1.581 +    if (icon != NULL) {
   1.582 +        SDL_WM_SetIcon(icon, icon_mask);
   1.583 +    }
   1.584 +    if (icon_mask != NULL)
   1.585 +        free(icon_mask);
   1.586  
   1.587 -	/* Set the title bar */
   1.588 -	if ( argv[1] == NULL )
   1.589 -		title = "Testing  1.. 2.. 3...";
   1.590 -	else
   1.591 -		title = argv[1];
   1.592 -	SDL_WM_SetCaption(title, "testwm");
   1.593 +    /* Set the title bar */
   1.594 +    if (argv[1] == NULL)
   1.595 +        title = "Testing  1.. 2.. 3...";
   1.596 +    else
   1.597 +        title = argv[1];
   1.598 +    SDL_WM_SetCaption(title, "testwm");
   1.599  
   1.600 -	/* See if it's really set */
   1.601 -	SDL_WM_GetCaption(&title, NULL);
   1.602 -	if ( title )
   1.603 -		printf("Title was set to: %s\n", title);
   1.604 -	else
   1.605 -		printf("No window title was set!\n");
   1.606 +    /* See if it's really set */
   1.607 +    SDL_WM_GetCaption(&title, NULL);
   1.608 +    if (title)
   1.609 +        printf("Title was set to: %s\n", title);
   1.610 +    else
   1.611 +        printf("No window title was set!\n");
   1.612  
   1.613 -	/* Initialize the display */
   1.614 -	if ( SetVideoMode(w, h) < 0 ) {
   1.615 -		quit(1);
   1.616 -	}
   1.617 +    /* Initialize the display */
   1.618 +    if (SetVideoMode(w, h) < 0) {
   1.619 +        quit(1);
   1.620 +    }
   1.621  
   1.622 -	/* Set an event filter that discards everything but QUIT */
   1.623 -	SDL_SetEventFilter(FilterEvents);
   1.624 +    /* Set an event filter that discards everything but QUIT */
   1.625 +    SDL_GetEventFilter(&old_filterfunc, &old_filterdata);
   1.626 +    SDL_SetEventFilter(FilterEvents, NULL);
   1.627  
   1.628 -	/* Ignore key up events, they don't even get filtered */
   1.629 -	SDL_EventState(SDL_KEYUP, SDL_IGNORE);
   1.630 +    /* Ignore key up events, they don't even get filtered */
   1.631 +    SDL_EventState(SDL_KEYUP, SDL_IGNORE);
   1.632  
   1.633 -	/* Loop, waiting for QUIT */
   1.634 -	while ( SDL_WaitEvent(&event) ) {
   1.635 -		switch (event.type) {
   1.636 -			case SDL_VIDEORESIZE:
   1.637 -				printf("Got a resize event: %dx%d\n",
   1.638 -				       event.resize.w, event.resize.h);
   1.639 -				SetVideoMode(event.resize.w, event.resize.h);
   1.640 -				break;
   1.641 -			case SDL_USEREVENT:
   1.642 -				printf("Handling internal quit request\n");
   1.643 -				/* Fall through to the quit handler */
   1.644 -			case SDL_QUIT:
   1.645 -				printf("Bye bye..\n");
   1.646 -				quit(0);
   1.647 -			default:
   1.648 -				/* This should never happen */
   1.649 -				printf("Warning: Event %d wasn't filtered\n",
   1.650 -								event.type);
   1.651 -				break;
   1.652 -		}
   1.653 -	}
   1.654 -	printf("SDL_WaitEvent() error: %s\n", SDL_GetError());
   1.655 -	SDL_Quit();
   1.656 -	return(255);
   1.657 +    /* Loop, waiting for QUIT */
   1.658 +    while (SDL_WaitEvent(&event)) {
   1.659 +        switch (event.type) {
   1.660 +        case SDL_VIDEORESIZE:
   1.661 +            printf("Got a resize event: %dx%d\n",
   1.662 +                   event.resize.w, event.resize.h);
   1.663 +            SetVideoMode(event.resize.w, event.resize.h);
   1.664 +            break;
   1.665 +        case SDL_USEREVENT:
   1.666 +            printf("Handling internal quit request\n");
   1.667 +            /* Fall through to the quit handler */
   1.668 +        case SDL_QUIT:
   1.669 +            printf("Bye bye..\n");
   1.670 +            quit(0);
   1.671 +        default:
   1.672 +            /* This should never happen */
   1.673 +            printf("Warning: Event %d wasn't filtered\n", event.type);
   1.674 +            break;
   1.675 +        }
   1.676 +    }
   1.677 +    printf("SDL_WaitEvent() error: %s\n", SDL_GetError());
   1.678 +    SDL_Quit();
   1.679 +    return (255);
   1.680  }