Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Added support for testing window manager icons
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Jul 15, 2010
1 parent 37b18d6 commit 7fad52d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
43 changes: 42 additions & 1 deletion test/common.c
Expand Up @@ -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]"
Expand Down Expand Up @@ -192,6 +192,14 @@ CommonArg(CommonState * state, int index)
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;
Expand Down Expand Up @@ -611,6 +619,30 @@ PrintRenderer(SDL_RendererInfo * info)
}
}

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)
{
Expand Down Expand Up @@ -791,6 +823,15 @@ CommonInit(CommonState * state)
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
Expand Down
1 change: 1 addition & 0 deletions test/common.h
Expand Up @@ -24,6 +24,7 @@ typedef struct
const char *videodriver;
int display;
const char *window_title;
const char *window_icon;
Uint32 window_flags;
int window_x;
int window_y;
Expand Down

0 comments on commit 7fad52d

Please sign in to comment.