# HG changeset patch # User Sam Lantinga # Date 1279167915 25200 # Node ID 3ce59cbecaa3e62e3c57f0e74073fa07392c9862 # Parent c04dd942610d6a71e9f4d9203f4990c67454f5de Added support for testing window manager icons diff -r c04dd942610d -r 3ce59cbecaa3 test/common.c --- a/test/common.c Wed Jul 14 07:48:35 2010 -0700 +++ b/test/common.c Wed Jul 14 21:25:15 2010 -0700 @@ -6,7 +6,7 @@ #include "common.h" #define VIDEO_USAGE \ -"[--video driver] [--renderer driver] [--info all|video|modes|render|event] [--display N] [--fullscreen | --windows N] [--title title] [--center | --position X,Y] [--geometry WxH] [--depth N] [--refresh R] [--vsync] [--noframe] [--resize] [--minimize] [--maximize] [--grab] [--double] [--triple]" +"[--video driver] [--renderer driver] [--info all|video|modes|render|event] [--display N] [--fullscreen | --windows N] [--title title] [--icon icon.bmp] [--center | --position X,Y] [--geometry WxH] [--depth N] [--refresh R] [--vsync] [--noframe] [--resize] [--minimize] [--maximize] [--grab] [--double] [--triple]" #define AUDIO_USAGE \ "[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]" @@ -192,6 +192,14 @@ state->window_title = argv[index]; return 2; } + if (SDL_strcasecmp(argv[index], "--icon") == 0) { + ++index; + if (!argv[index]) { + return -1; + } + state->window_icon = argv[index]; + return 2; + } if (SDL_strcasecmp(argv[index], "--center") == 0) { state->window_x = SDL_WINDOWPOS_CENTERED; state->window_y = SDL_WINDOWPOS_CENTERED; @@ -611,6 +619,30 @@ } } +static SDL_Surface * +LoadIcon(const char *file) +{ + SDL_Surface *icon; + + /* Load the icon surface */ + icon = SDL_LoadBMP(file); + if (icon == NULL) { + fprintf(stderr, "Couldn't load %s: %s\n", file, SDL_GetError()); + return (NULL); + } + + if (icon->format->palette == NULL) { + fprintf(stderr, "Icon must have a palette!\n"); + SDL_FreeSurface(icon); + return (NULL); + } + + /* Set the colorkey */ + SDL_SetColorKey(icon, 1, *((Uint8 *) icon->pixels)); + + return (icon); +} + SDL_bool CommonInit(CommonState * state) { @@ -791,6 +823,15 @@ SDL_GetError()); return SDL_FALSE; } + + if (state->window_icon) { + SDL_Surface *icon = LoadIcon(state->window_icon); + if (icon) { + SDL_SetWindowIcon(state->windows[i], icon); + SDL_FreeSurface(icon); + } + } + SDL_ShowWindow(state->windows[i]); if (!state->skip_renderer diff -r c04dd942610d -r 3ce59cbecaa3 test/common.h --- a/test/common.h Wed Jul 14 07:48:35 2010 -0700 +++ b/test/common.h Wed Jul 14 21:25:15 2010 -0700 @@ -24,6 +24,7 @@ const char *videodriver; int display; const char *window_title; + const char *window_icon; Uint32 window_flags; int window_x; int window_y;