2 * Copyright (C) 2003-2010 Neverball authors
4 * NEVERBALL is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published
6 * by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
18 #include <SDL_video.h>
19 #include <SDL_syswm.h>
22 #include "base_config.h"
26 /*---------------------------------------------------------------------------*/
28 void set_SDL_icon(const char *filename)
30 #if !defined(__APPLE__) && !defined(_WIN32)
33 if ((icon = load_surface(filename)))
35 SDL_WM_SetIcon(icon, NULL);
37 SDL_FreeSurface(icon);
43 void set_EWMH_icon(const char *filename)
45 #if SDL_VIDEO_DRIVER_X11 && !SDL_VIDEO_DRIVER_QUARTZ && !ENABLE_OPENGLES
54 SDL_VERSION(&info.version);
56 if (SDL_GetWMInfo(&info) != 1)
58 fprintf(stderr, L_("Failed to get WM info: %s\n"), SDL_GetError());
62 if (info.subsystem != SDL_SYSWM_X11)
65 dpy = info.info.x11.display;
66 window = info.info.x11.wmwindow;
69 * This code loads an image and sets it as the _NET_WM_ICON window
70 * property, as described in the Extended Window Manager Hints
71 * specification[*]. From the spec: "This is an array of 32-bit packed
72 * CARDINAL ARGB with high byte being A, low byte being B. The first two
73 * cardinals are width, height. Data is in rows, left to right and top to
76 * [*] http://standards.freedesktop.org/wm-spec/latest/
79 if ((p = image_load(filename, &w, &h, &b)))
83 if ((data = calloc(2 + w * h, sizeof (long))))
90 for (r = 0; r < h; r++)
91 for (c = 0; c < w; c++)
93 long *dp = &data[2 + r * w + c];
94 unsigned char *pp = &p[(h - r - 1) * w * b + c * b];
99 *dp |= *(pp + 1) << 24;
101 *dp |= *(pp + 0) << 16;
102 *dp |= *(pp + 0) << 8;
103 *dp |= *(pp + 0) << 0;
108 *dp |= *(pp + 3) << 24;
110 *dp |= *(pp + 0) << 16;
111 *dp |= *(pp + 1) << 8;
112 *dp |= *(pp + 2) << 0;
116 info.info.x11.lock_func();
118 Atom icon = XInternAtom(dpy, "_NET_WM_ICON", False);
120 XChangeProperty(dpy, window, icon, XA_CARDINAL, 32,
121 PropModeReplace, (unsigned char *) data,
124 info.info.x11.unlock_func();
129 fputs(L_("Failed to allocate memory for EWMH icon data.\n"), stderr);
138 /*---------------------------------------------------------------------------*/