src/video/x11/SDL_x11wm.c
changeset 1558 b46bb79cc197
parent 1505 4d005dfbb7f5
child 1575 3ba88cb7eb1b
equal deleted inserted replaced
1557:61c237f69076 1558:b46bb79cc197
   241 }
   241 }
   242 
   242 
   243 void X11_SetCaption(_THIS, const char *title, const char *icon)
   243 void X11_SetCaption(_THIS, const char *title, const char *icon)
   244 {
   244 {
   245 	XTextProperty titleprop, iconprop;
   245 	XTextProperty titleprop, iconprop;
       
   246 	Status status;
       
   247 
       
   248 #ifdef X_HAVE_UTF8_STRING
       
   249 	Atom _NET_WM_NAME;
       
   250 	Atom _NET_WM_ICON_NAME;
       
   251 
       
   252 	/* Look up some useful Atoms */
       
   253 	_NET_WM_NAME = pXInternAtom(SDL_Display, "_NET_WM_NAME", False);
       
   254 	_NET_WM_ICON_NAME = pXInternAtom(SDL_Display, "_NET_WM_ICON_NAME", False);
       
   255 #endif
   246 
   256 
   247 	/* Lock the event thread, in multi-threading environments */
   257 	/* Lock the event thread, in multi-threading environments */
   248 	SDL_Lock_EventThread();
   258 	SDL_Lock_EventThread();
   249 
   259 
   250 	if ( title != NULL ) {
   260 	if ( title != NULL ) {
   251 		int error = XLocaleNotSupported;
   261 		char *title_latin1 = SDL_iconv_utf8_latin1((char *)title);
       
   262 		if ( !title_latin1 ) {
       
   263 			SDL_OutOfMemory();
       
   264 			return;
       
   265 		}
       
   266 		status = pXStringListToTextProperty(&title_latin1, 1, &titleprop);
       
   267 		SDL_free(title_latin1);
       
   268 		if ( status ) {
       
   269 			pXSetTextProperty(SDL_Display, WMwindow, &titleprop, XA_WM_NAME);
       
   270 			pXFree(titleprop.value);
       
   271 		}
   252 #ifdef X_HAVE_UTF8_STRING
   272 #ifdef X_HAVE_UTF8_STRING
   253 		error = pXutf8TextListToTextProperty(SDL_Display,
   273 		status = pXutf8TextListToTextProperty(SDL_Display,
   254 				(char **)&title, 1, XUTF8StringStyle,
   274 				(char **)&title, 1, XUTF8StringStyle, &titleprop);
   255 				&titleprop);
   275 		if ( status == Success ) {
       
   276 			pXSetTextProperty(SDL_Display, WMwindow, &titleprop, _NET_WM_NAME);
       
   277 			pXFree(titleprop.value);
       
   278 		}
   256 #endif
   279 #endif
   257 		if ( error != Success ) {
       
   258 			char *title_latin1 = SDL_iconv_utf8_latin1((char *)title);
       
   259 			if ( !title_latin1 ) {
       
   260 				SDL_OutOfMemory();
       
   261 				return;
       
   262 			}
       
   263 			pXStringListToTextProperty(&title_latin1, 1, &titleprop);
       
   264 			SDL_free(title_latin1);
       
   265 		}
       
   266 		pXSetWMName(SDL_Display, WMwindow, &titleprop);
       
   267 		pXFree(titleprop.value);
       
   268 	}
   280 	}
   269 	if ( icon != NULL ) {
   281 	if ( icon != NULL ) {
   270 		int error = XLocaleNotSupported;
   282 		char *icon_latin1 = SDL_iconv_utf8_latin1((char *)icon);
       
   283 		if ( !icon_latin1 ) {
       
   284 			SDL_OutOfMemory();
       
   285 			return;
       
   286 		}
       
   287 		status = pXStringListToTextProperty(&icon_latin1, 1, &iconprop);
       
   288 		SDL_free(icon_latin1);
       
   289 		if ( status ) {
       
   290 			pXSetTextProperty(SDL_Display, WMwindow, &iconprop, XA_WM_ICON_NAME);
       
   291 			pXFree(iconprop.value);
       
   292 		}
   271 #ifdef X_HAVE_UTF8_STRING
   293 #ifdef X_HAVE_UTF8_STRING
   272 		error = pXutf8TextListToTextProperty(SDL_Display,
   294 		status = pXutf8TextListToTextProperty(SDL_Display,
   273 				(char **)&icon, 1, XUTF8StringStyle, &iconprop);
   295 				(char **)&icon, 1, XUTF8StringStyle, &iconprop);
       
   296 		if ( status == Success ) {
       
   297 			pXSetTextProperty(SDL_Display, WMwindow, &iconprop, _NET_WM_ICON_NAME);
       
   298 			pXFree(iconprop.value);
       
   299 		}
   274 #endif
   300 #endif
   275 		if ( error != Success ) {
       
   276 			char *icon_latin1 = SDL_iconv_utf8_latin1((char *)title);
       
   277 			if ( !icon_latin1 ) {
       
   278 				SDL_OutOfMemory();
       
   279 				return;
       
   280 			}
       
   281 			pXStringListToTextProperty(&icon_latin1, 1, &iconprop);
       
   282 			SDL_free(icon_latin1);
       
   283 		}
       
   284 		pXSetWMIconName(SDL_Display, WMwindow, &iconprop);
       
   285 		pXFree(iconprop.value);
       
   286 	}
   301 	}
   287 	pXSync(SDL_Display, False);
   302 	pXSync(SDL_Display, False);
   288 
   303 
   289 	SDL_Unlock_EventThread();
   304 	SDL_Unlock_EventThread();
   290 }
   305 }