src/video/photon/SDL_ph_wm.c
changeset 315 3333b6e68289
parent 297 f6ffac90895c
child 571 8e3ce997621c
     1.1 --- a/src/video/photon/SDL_ph_wm.c	Fri Mar 22 18:11:56 2002 +0000
     1.2 +++ b/src/video/photon/SDL_ph_wm.c	Sat Mar 23 20:19:44 2002 +0000
     1.3 @@ -48,207 +48,47 @@
     1.4  
     1.5  void ph_SetIcon(_THIS, SDL_Surface *icon, Uint8 *mask)
     1.6  {
     1.7 -
     1.8 -#if 0 /*big*/
     1.9 -	int ncolors;
    1.10 -	PhImage_t *image;
    1.11 -	PgColor_t* palette;
    1.12 -
    1.13 -	image = PhCreateImage( image,
    1.14 -                          	icon->w,
    1.15 -                          	icon->h,
    1.16 -                          	Pg_IMAGE_DIRECT_888,
    1.17 -                          	NULL, 0, 0 );
    1.18 -
    1.19 -/* ---------------------------------------- */
    1.20 -	SDL_Surface *sicon;
    1.21 -//	XWMHints *wmhints;
    1.22 -//	XImage *icon_image;
    1.23 -//	Pixmap icon_pixmap;
    1.24 -//	Pixmap mask_pixmap;
    1.25 -//	GC GC;
    1.26 -//	XGCValues GCvalues;
    1.27 -	int i, b, dbpp;
    1.28 -	SDL_Rect bounds;
    1.29 -	Uint8 *LSBmask, *color_tried;
    1.30 -	Visual *dvis;
    1.31 -
    1.32 -	/* Lock the event thread, in multi-threading environments */
    1.33 -	SDL_Lock_EventThread();
    1.34 -
    1.35 -	/* The icon must use the default visual, depth and colormap of the
    1.36 -	   screen, so it might need a conversion */
    1.37 -// ?	dbpp = DefaultDepth(SDL_Display, SDL_Screen);
    1.38 -	switch(dbpp) {
    1.39 -	case 15:
    1.40 -	    dbpp = 16; break;
    1.41 -	case 24:
    1.42 -	    dbpp = 32; break;
    1.43 -	}
    1.44 -	dvis = DefaultVisual(SDL_Display, SDL_Screen);
    1.45 -
    1.46 -	/* The Visual struct is supposed to be opaque but we cheat a little */
    1.47 -	sicon = SDL_CreateRGBSurface(SDL_SWSURFACE, icon->w, icon->h,
    1.48 -				     dbpp,
    1.49 -				     dvis->red_mask, dvis->green_mask,
    1.50 -				     dvis->blue_mask, 0);
    1.51 -
    1.52 -	if ( sicon == NULL ) {
    1.53 -		goto done;
    1.54 -	}
    1.55 -	/* If we already have allocated colours from the default colormap,
    1.56 -	   copy them */
    1.57 -	if(SDL_Visual == dvis && SDL_XColorMap == SDL_DisplayColormap
    1.58 -	   && this->screen->format->palette && sicon->format->palette) {
    1.59 -	    memcpy(sicon->format->palette->colors,
    1.60 -		   this->screen->format->palette->colors,
    1.61 -		   this->screen->format->palette->ncolors * sizeof(SDL_Color));
    1.62 -	}
    1.63 -
    1.64 -	bounds.x = 0;
    1.65 -	bounds.y = 0;
    1.66 -	bounds.w = icon->w;
    1.67 -	bounds.h = icon->h;
    1.68 -	if ( SDL_LowerBlit(icon, &bounds, sicon, &bounds) < 0 )
    1.69 -		goto done;
    1.70 -
    1.71 -	/* Lock down the colors used in the colormap */
    1.72 -	color_tried = NULL;
    1.73 -	if ( sicon->format->BitsPerPixel == 8 ) {
    1.74 -		SDL_Palette *palette;
    1.75 -		Uint8 *p;
    1.76 -		XColor wanted;
    1.77 -
    1.78 -		palette = sicon->format->palette;
    1.79 -		color_tried = malloc(palette->ncolors);
    1.80 -		if ( color_tried == NULL ) {
    1.81 -			goto done;
    1.82 -		}
    1.83 -		if ( SDL_iconcolors != NULL ) {
    1.84 -			free(SDL_iconcolors);
    1.85 -		}
    1.86 -		SDL_iconcolors = malloc(palette->ncolors
    1.87 -					* sizeof(*SDL_iconcolors));
    1.88 -		if ( SDL_iconcolors == NULL ) {
    1.89 -			free(color_tried);
    1.90 -			goto done;
    1.91 -		}
    1.92 -		memset(color_tried, 0, palette->ncolors);
    1.93 -		memset(SDL_iconcolors, 0,
    1.94 -		       palette->ncolors * sizeof(*SDL_iconcolors));
    1.95 -
    1.96 -		p = (Uint8 *)sicon->pixels; 
    1.97 -		for ( i = sicon->w*sicon->h; i > 0; --i, ++p ) {
    1.98 -			if ( ! color_tried[*p] ) {
    1.99 -				wanted.pixel = *p;
   1.100 -				wanted.red   = (palette->colors[*p].r<<8);
   1.101 -				wanted.green = (palette->colors[*p].g<<8);
   1.102 -				wanted.blue  = (palette->colors[*p].b<<8);
   1.103 -				wanted.flags = (DoRed|DoGreen|DoBlue);
   1.104 -				if (XAllocColor(SDL_Display,
   1.105 -						SDL_DisplayColormap, &wanted)) {
   1.106 -					++SDL_iconcolors[wanted.pixel];
   1.107 -				}
   1.108 -				color_tried[*p] = 1;
   1.109 -			}
   1.110 -		}
   1.111 -	}
   1.112 -	if ( color_tried != NULL ) {
   1.113 -		free(color_tried);
   1.114 -	}
   1.115 -
   1.116 -	/* Translate mask data to LSB order and set the icon mask */
   1.117 -	i = (sicon->w/8)*sicon->h;
   1.118 -	LSBmask = (Uint8 *)malloc(i);
   1.119 -	if ( LSBmask == NULL ) {
   1.120 -		goto done;
   1.121 -	}
   1.122 -	memset(LSBmask, 0, i);
   1.123 -	while ( --i >= 0 ) {
   1.124 -		for ( b=0; b<8; ++b )
   1.125 -			LSBmask[i] |= (((mask[i]>>b)&0x01)<<(7-b));
   1.126 -	}
   1.127 -	mask_pixmap = XCreatePixmapFromBitmapData(SDL_Display, WMwindow,
   1.128 -					LSBmask, sicon->w, sicon->h, 1L, 0L, 1);
   1.129 -
   1.130 -	/* Transfer the image to an X11 pixmap */
   1.131 -	icon_image = XCreateImage(SDL_Display,
   1.132 -			DefaultVisual(SDL_Display, SDL_Screen),
   1.133 -			DefaultDepth(SDL_Display, SDL_Screen),
   1.134 -			ZPixmap, 0, (char *)sicon->pixels, sicon->w, sicon->h,
   1.135 -			((sicon->format)->BytesPerPixel == 3) ? 32 :
   1.136 -				(sicon->format)->BytesPerPixel*8, 0);
   1.137 -	icon_pixmap = XCreatePixmap(SDL_Display, SDL_Root, sicon->w, sicon->h,
   1.138 -			DefaultDepth(SDL_Display, SDL_Screen));
   1.139 -	GC = XCreateGC(SDL_Display, icon_pixmap, 0, &GCvalues);
   1.140 -	XPutImage(SDL_Display, icon_pixmap, GC, icon_image,
   1.141 -					0, 0, 0, 0, sicon->w, sicon->h);
   1.142 -	XFreeGC(SDL_Display, GC);
   1.143 -	XDestroyImage(icon_image);
   1.144 -	free(LSBmask);
   1.145 -	sicon->pixels = NULL;
   1.146 -
   1.147 -#ifdef USE_ICON_WINDOW
   1.148 -	/* Create an icon window and set the pixmap as its background */
   1.149 -	icon_window = XCreateSimpleWindow(SDL_Display, SDL_Root,
   1.150 -					0, 0, sicon->w, sicon->h, 0,
   1.151 -					CopyFromParent, CopyFromParent);
   1.152 -	XSetWindowBackgroundPixmap(SDL_Display, icon_window, icon_pixmap);
   1.153 -	XClearWindow(SDL_Display, icon_window);
   1.154 -#endif
   1.155 -
   1.156 -	/* Set the window icon to the icon pixmap (and icon window) */
   1.157 -	wmhints = XAllocWMHints();
   1.158 -	wmhints->flags = (IconPixmapHint | IconMaskHint);
   1.159 -	wmhints->icon_pixmap = icon_pixmap;
   1.160 -	wmhints->icon_mask = mask_pixmap;
   1.161 -#ifdef USE_ICON_WINDOW
   1.162 -	wmhints->flags |= IconWindowHint;
   1.163 -	wmhints->icon_window = icon_window;
   1.164 -#endif
   1.165 -	XSetWMHints(SDL_Display, WMwindow, wmhints);
   1.166 -	XFree(wmhints);
   1.167 -	XSync(SDL_Display, False);
   1.168 -
   1.169 -  done:
   1.170 -	SDL_Unlock_EventThread();
   1.171 -	if ( sicon != NULL ) {
   1.172 -		SDL_FreeSurface(sicon);
   1.173 -	}
   1.174 -	
   1.175 -#endif /*big*/
   1.176 -	return;
   1.177 +    return;
   1.178  }
   1.179  
   1.180  /* Set window caption */
   1.181  void ph_SetCaption(_THIS, const char *title, const char *icon)
   1.182  {
   1.183 -	SDL_Lock_EventThread();
   1.184 -	if ( title != NULL ) {
   1.185 -		PtSetResource(window, Pt_ARG_WINDOW_TITLE, title, 0);
   1.186 -	}
   1.187 -	SDL_Unlock_EventThread();
   1.188 +    SDL_Lock_EventThread();
   1.189 +
   1.190 +    /* check for set caption call before window init */
   1.191 +    if (window!=NULL)
   1.192 +    {
   1.193 +        PtSetResource(window, Pt_ARG_WINDOW_TITLE, title, 0);
   1.194 +    }
   1.195 +    else
   1.196 +    {
   1.197 +        captionflag=1;
   1.198 +    }
   1.199 +
   1.200 +    SDL_Unlock_EventThread();
   1.201  }
   1.202  
   1.203  /* Iconify current window */
   1.204  int ph_IconifyWindow(_THIS)
   1.205  {
   1.206 -	PhWindowEvent_t windowevent;
   1.207 +    PhWindowEvent_t windowevent;
   1.208 +
   1.209 +    SDL_Lock_EventThread();
   1.210  
   1.211 -	SDL_Lock_EventThread();
   1.212 -	memset( &windowevent, 0, sizeof (event) );
   1.213 -	windowevent.event_f = Ph_WM_HIDE;
   1.214 -	windowevent.event_state = Ph_WM_EVSTATE_HIDE;
   1.215 -	windowevent.rid = PtWidgetRid( window );
   1.216 -	PtForwardWindowEvent( &windowevent );
   1.217 -	SDL_Unlock_EventThread();
   1.218 -        
   1.219 -        return 0;
   1.220 +    memset( &windowevent, 0, sizeof (event) );
   1.221 +    windowevent.event_f = Ph_WM_HIDE;
   1.222 +    windowevent.event_state = Ph_WM_EVSTATE_HIDE;
   1.223 +    windowevent.rid = PtWidgetRid( window );
   1.224 +    PtForwardWindowEvent( &windowevent );
   1.225 +    SDL_Unlock_EventThread();
   1.226 +
   1.227 +    return 0;
   1.228  }
   1.229  
   1.230  SDL_GrabMode ph_GrabInputNoLock(_THIS, SDL_GrabMode mode)
   1.231  {
   1.232 -   return(mode);
   1.233 +    return(mode);
   1.234  }
   1.235  
   1.236  SDL_GrabMode ph_GrabInput(_THIS, SDL_GrabMode mode)
   1.237 @@ -280,14 +120,14 @@
   1.238  
   1.239  int ph_GetWMInfo(_THIS, SDL_SysWMinfo *info)
   1.240  {
   1.241 -   if (info->version.major <= SDL_MAJOR_VERSION)
   1.242 -   {
   1.243 -      return 1;
   1.244 -   }
   1.245 -   else
   1.246 -   {
   1.247 -      SDL_SetError("Application not compiled with SDL %d.%d\n",
   1.248 -                    SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
   1.249 -      return -1;
   1.250 -   }
   1.251 +    if (info->version.major <= SDL_MAJOR_VERSION)
   1.252 +    {
   1.253 +        return 1;
   1.254 +    }
   1.255 +    else
   1.256 +    {
   1.257 +        SDL_SetError("Application not compiled with SDL %d.%d\n",
   1.258 +                      SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
   1.259 +        return -1;
   1.260 +    }
   1.261  }