src/video/x11/SDL_x11wm.c
branchSDL-1.2
changeset 6561 ea34ef329509
parent 6137 4720145f848b
child 6563 ba187d0466e6
equal deleted inserted replaced
6460:2a971ffe1fad 6561:ea34ef329509
    41 	return x;
    41 	return x;
    42 }
    42 }
    43 
    43 
    44 void X11_SetIcon(_THIS, SDL_Surface *icon, Uint8 *mask)
    44 void X11_SetIcon(_THIS, SDL_Surface *icon, Uint8 *mask)
    45 {
    45 {
       
    46 	Atom _NET_WM_ICON = XInternAtom(SDL_Display, "_NET_WM_ICON", False);
    46 	SDL_Surface *sicon;
    47 	SDL_Surface *sicon;
    47 	XWMHints *wmhints;
    48 	XWMHints *wmhints;
    48 	XImage *icon_image;
    49 	XImage *icon_image;
    49 	Pixmap icon_pixmap;
    50 	Pixmap icon_pixmap;
    50 	Pixmap mask_pixmap;
    51 	Pixmap mask_pixmap;
    57 	Visual *dvis;
    58 	Visual *dvis;
    58 	char *p;
    59 	char *p;
    59 	int masksize;
    60 	int masksize;
    60 
    61 
    61 	SDL_Lock_EventThread();
    62 	SDL_Lock_EventThread();
       
    63 
       
    64 	if (_NET_WM_ICON) {   /* better interface for modern systems. */
       
    65 		SDL_PixelFormat format;
       
    66 		SDL_Surface *surface;
       
    67 		int propsize;
       
    68 		long *propdata;
       
    69 
       
    70 		/* Convert the icon to ARGB for modern window managers */
       
    71 		SDL_memset(&format, 0, sizeof (format));
       
    72 		format.BitsPerPixel = 32;
       
    73 		format.BytesPerPixel = 4;
       
    74 		#if SDL_BYTEORDER == SDL_BIG_ENDIAN
       
    75 		format.Rshift = 8;
       
    76 		format.Gshift = 16;
       
    77 		format.Bshift = 24;
       
    78 		format.Ashift = 0;
       
    79 		#else
       
    80 		format.Rshift = 16;
       
    81 		format.Gshift = 8;
       
    82 		format.Bshift = 0;
       
    83 		format.Ashift = 24;
       
    84 		#endif
       
    85 		format.Rmask = 0xFF << format.Rshift;
       
    86 		format.Gmask = 0xFF << format.Gshift;
       
    87 		format.Bmask = 0xFF << format.Bshift;
       
    88 		format.Amask = 0xFF << format.Ashift;
       
    89 		format.alpha = SDL_ALPHA_OPAQUE;
       
    90 
       
    91 		surface = SDL_ConvertSurface(icon, &format, 0);
       
    92 		if (!surface) {
       
    93 			return;
       
    94 		}
       
    95 
       
    96 		/* Set the _NET_WM_ICON property */
       
    97 		propsize = 2 + (icon->w * icon->h);
       
    98 		propdata = SDL_malloc(propsize * sizeof(long));
       
    99 		if (propdata) {
       
   100 			const Uint32 alpha = format.Amask;
       
   101 			int x, y;
       
   102 			Uint32 *src;
       
   103 			long *dst;
       
   104 
       
   105 			propdata[0] = icon->w;
       
   106 			propdata[1] = icon->h;
       
   107 			dst = &propdata[2];
       
   108 
       
   109 			size_t maskidx = 0;
       
   110 			for (y = 0; y < icon->h; ++y) {
       
   111 				src = (Uint32*)((Uint8*)surface->pixels + y * surface->pitch);
       
   112 				for (x = 0; x < icon->w; ++x) {
       
   113 					const Uint32 pixel = *(src++);
       
   114 					if (mask[maskidx / 8] & (1<<(7-(maskidx % 8)))) {
       
   115 						*dst++ = pixel | alpha;
       
   116 					} else {
       
   117 						*dst++ = pixel & ~alpha;
       
   118 					}
       
   119 					maskidx++;
       
   120 				}
       
   121 			}
       
   122 
       
   123 			XChangeProperty(SDL_Display, WMwindow, _NET_WM_ICON, XA_CARDINAL,
       
   124 			                32, PropModeReplace, (unsigned char *) propdata,
       
   125 			                propsize);
       
   126 		}
       
   127 
       
   128 		SDL_FreeSurface(surface);
       
   129 		SDL_free(propdata);
       
   130 
       
   131 		SDL_Unlock_EventThread();
       
   132 
       
   133 		return;
       
   134 	}
       
   135 
       
   136 	/* Do it the old way... */
    62 
   137 
    63 	/* The icon must use the default visual, depth and colormap of the
   138 	/* The icon must use the default visual, depth and colormap of the
    64 	   screen, so it might need a conversion */
   139 	   screen, so it might need a conversion */
    65 	dvis = DefaultVisual(SDL_Display, SDL_Screen);
   140 	dvis = DefaultVisual(SDL_Display, SDL_Screen);
    66 	dbpp = DefaultDepth(SDL_Display, SDL_Screen);
   141 	dbpp = DefaultDepth(SDL_Display, SDL_Screen);