]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
PROPERLY load the icon in SDL/X11
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 27 Aug 2010 16:48:41 +0000 (16:48 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 27 Aug 2010 16:48:41 +0000 (16:48 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10424 d7cf8633-e32d-0410-b094-e92efae38249

BSDmakefile
makefile
makefile.inc
vid_sdl.c

index 24012acb4743f5d8e7e6b1a33a3d4973b8da4cbb..5c7e050ff539209892f34290c042ff6f61880936 100644 (file)
@@ -31,9 +31,9 @@ LDFLAGS_CL=$(LDFLAGS_BSDCL)
 LDFLAGS_SV=$(LDFLAGS_BSDSV)
 LDFLAGS_SDL=$(LDFLAGS_BSDSDL)
 
-SDLCONFIG_CFLAGS=$(SDLCONFIG_UNIXCFLAGS)
-SDLCONFIG_LIBS=$(SDLCONFIG_UNIXLIBS)
-SDLCONFIG_STATICLIBS=$(SDLCONFIG_UNIXSTATICLIBS)
+SDLCONFIG_CFLAGS=$(SDLCONFIG_UNIXCFLAGS) $(SDLCONFIG_UNIXCFLAGS_X11)
+SDLCONFIG_LIBS=$(SDLCONFIG_UNIXLIBS) $(SDLCONFIG_UNIXLIBS_X11)
+SDLCONFIG_STATICLIBS=$(SDLCONFIG_UNIXSTATICLIBS) $(SDLCONFIG_UNIXSTATICLIBS_X11)
 
 EXE_CL=$(EXE_UNIXCL)
 EXE_SV=$(EXE_UNIXSV)
index ee88a37c4dabea2a868fa31a66fc7d03b981b4ee..7d3f73a3f29b043860cfe1df3b861504acfde199 100644 (file)
--- a/makefile
+++ b/makefile
@@ -61,9 +61,9 @@ ifeq ($(DP_MAKE_TARGET), linux)
        LDFLAGS_SV=$(LDFLAGS_LINUXSV)
        LDFLAGS_SDL=$(LDFLAGS_LINUXSDL)
 
-       SDLCONFIG_CFLAGS=$(SDLCONFIG_UNIXCFLAGS)
-       SDLCONFIG_LIBS=$(SDLCONFIG_UNIXLIBS)
-       SDLCONFIG_STATICLIBS=$(SDLCONFIG_UNIXSTATICLIBS)
+       SDLCONFIG_CFLAGS=$(SDLCONFIG_UNIXCFLAGS) $(SDLCONFIG_UNIXCFLAGS_X11)
+       SDLCONFIG_LIBS=$(SDLCONFIG_UNIXLIBS) $(SDLCONFIG_UNIXLIBS_X11)
+       SDLCONFIG_STATICLIBS=$(SDLCONFIG_UNIXSTATICLIBS) $(SDLCONFIG_UNIXSTATICLIBS_X11)
 
        EXE_CL=$(EXE_UNIXCL)
        EXE_SV=$(EXE_UNIXSV)
@@ -126,9 +126,9 @@ ifeq ($(DP_MAKE_TARGET), sunos)
        LDFLAGS_SV=$(LDFLAGS_SUNOSSV)
        LDFLAGS_SDL=$(LDFLAGS_SUNOSSDL)
 
-       SDLCONFIG_CFLAGS=$(SDLCONFIG_UNIXCFLAGS)
-       SDLCONFIG_LIBS=$(SDLCONFIG_UNIXLIBS)
-       SDLCONFIG_STATICLIBS=$(SDLCONFIG_UNIXSTATICLIBS)
+       SDLCONFIG_CFLAGS=$(SDLCONFIG_UNIXCFLAGS) $(SDLCONFIG_UNIXCFLAGS_X11)
+       SDLCONFIG_LIBS=$(SDLCONFIG_UNIXLIBS) $(SDLCONFIG_UNIXLIBS_X11)
+       SDLCONFIG_STATICLIBS=$(SDLCONFIG_UNIXSTATICLIBS) $(SDLCONFIG_UNIXSTATICLIBS_X11)
 
        EXE_CL=$(EXE_UNIXCL)
        EXE_SV=$(EXE_UNIXSV)
@@ -159,9 +159,9 @@ endif
        LDFLAGS_SV=$(LDFLAGS_BSDSV)
        LDFLAGS_SDL=$(LDFLAGS_BSDSDL)
 
-       SDLCONFIG_CFLAGS=$(SDLCONFIG_UNIXCFLAGS)
-       SDLCONFIG_LIBS=$(SDLCONFIG_UNIXLIBS)
-       SDLCONFIG_STATICLIBS=$(SDLCONFIG_UNIXSTATICLIBS)
+       SDLCONFIG_CFLAGS=$(SDLCONFIG_UNIXCFLAGS) $(SDLCONFIG_UNIXCFLAGS_X11)
+       SDLCONFIG_LIBS=$(SDLCONFIG_UNIXLIBS) $(SDLCONFIG_UNIXLIBS_X11)
+       SDLCONFIG_STATICLIBS=$(SDLCONFIG_UNIXSTATICLIBS) $(SDLCONFIG_UNIXSTATICLIBS_X11)
 
        EXE_CL=$(EXE_UNIXCL)
        EXE_SV=$(EXE_UNIXSV)
index 4dead01dea1b03dc1f4f35146c038e2b757aec8a..a455c3fd37bea7b0d1f93be549926cafe3e2fa11 100644 (file)
@@ -36,8 +36,11 @@ CFLAGS_CG= `[ -n "$(DP_CG_LIBDIR)" ] && echo \ -DSUPPORTCG`
 
 SDL_CONFIG?=sdl-config
 SDLCONFIG_UNIXCFLAGS?=`$(SDL_CONFIG) --cflags`
-SDLCONFIG_UNIXLIBS?=`$(SDL_CONFIG) --libs`
+SDLCONFIG_UNIXLIBS?=`$(SDL_CONFIG) --libs` -lX11
+SDLCONFIG_UNIXLIBS_X11?=-lX11
+SDLCONFIG_UNIXCFLAGS_X11?=
 SDLCONFIG_UNIXSTATICLIBS?=`$(SDL_CONFIG) --static-libs`
+SDLCONFIG_UNIXSTATICLIBS_X11?=-lX11
 SDLCONFIG_MACOSXCFLAGS=-I/Library/Frameworks/SDL.framework/Headers -I$(HOME)/Library/Frameworks/SDL.framework/Headers
 SDLCONFIG_MACOSXLIBS=-F$(HOME)/Library/Frameworks/ -framework SDL -framework Cocoa $(SDLCONFIG_MACOSXCFLAGS)
 SDLCONFIG_MACOSXSTATICLIBS=-F$(HOME)/Library/Frameworks/ -framework SDL -framework Cocoa $(SDLCONFIG_MACOSXCFLAGS)
index 2c666495c5b1205e328f9a3c0b1ac12a03116b06..9618cb611d2ebcd80884afe8fa10bc9e785c96d5 100644 (file)
--- a/vid_sdl.c
+++ b/vid_sdl.c
@@ -532,7 +532,10 @@ static void VID_SetCaption(void)
 #endif
        SetClassLongPtr( info.window, GCLP_HICON, (LONG_PTR)icon );
 }
-static void VID_SetIcon(void)
+static void VID_SetIcon_Pre(void)
+{
+}
+static void VID_SetIcon_Post(void)
 {
 }
 #else
@@ -540,7 +543,7 @@ static void VID_SetIcon(void)
 #include "darkplaces.xpm"
 #include "nexuiz.xpm"
 static SDL_Surface *icon = NULL;
-static void VID_SetIcon(void)
+static void VID_SetIcon_Pre(void)
 {
        /*
         * Somewhat restricted XPM reader. Only supports XPMs saved by GIMP 2.4 at
@@ -590,51 +593,6 @@ static void VID_SetIcon(void)
                        icon->pixels = data;
                }
        }
-#if SDL_VIDEO_DRIVER_X11 && !SDL_VIDEO_DRIVER_QUARTZ
-       // ugly hack to upload a good icon on X11 too
-       else
-       {
-               SDL_SysWMinfo info;
-               SDL_VERSION(&info.version);
-               if(SDL_GetWMInfo(&info) == 1 && info.subsystem == SDL_SYSWM_X11)
-               {
-                       data = (char *) loadimagepixelsbgra("darkplaces-icon", false, false, false, NULL);
-                       if(data)
-                       {
-                               // use _NET_WM_ICON too
-                               static long netwm_icon[MAX_NETWM_ICON];
-                               int pos = 0;
-                               int i = 1;
-
-                               while(data)
-                               {
-                                       if(pos + 2 * image_width * image_height < MAX_NETWM_ICON)
-                                       {
-                                               netwm_icon[pos++] = image_width;
-                                               netwm_icon[pos++] = image_height;
-                                               for(i = 0; i < image_height; ++i)
-                                                       for(j = 0; j < image_width; ++j)
-                                                               netwm_icon[pos++] = BuffLittleLong((unsigned char *) &data[(i*image_width+j)*4]);
-                                       }
-                                       else
-                                       {
-                                               Con_Printf("Skipping NETWM icon #%d because there is no space left\n", i);
-                                       }
-                                       ++i;
-                                       Mem_Free(data);
-                                       data = (char *) loadimagepixelsbgra(va("darkplaces-icon%d", i), false, false, false, NULL);
-                               }
-
-                               info.info.x11.lock_func();
-                               {
-                                       Atom net_wm_icon = XInternAtom(info.info.x11.display, "_NET_WM_ICON", false);
-                                       XChangeProperty(info.info.x11.display, info.info.x11.wmwindow, net_wm_icon, XA_CARDINAL, 32, PropModeReplace, (const unsigned char *) netwm_icon, pos);
-                               }
-                               info.info.x11.unlock_func();
-                       }
-               }
-       }
-#endif
 
        // we only get here if non-XPM icon was missing, or SDL version is not
        // sufficient for transparent non-XPM icons
@@ -738,6 +696,62 @@ static void VID_SetIcon(void)
 
        SDL_WM_SetIcon(icon, NULL);
 }
+static void VID_SetIcon_Post(void)
+{
+#if SDL_VIDEO_DRIVER_X11 && !SDL_VIDEO_DRIVER_QUARTZ
+       int j;
+       char *data;
+       const SDL_version *version;
+
+       version = SDL_Linked_Version();
+       // only use non-XPM icon support in SDL v1.3 and higher
+       // SDL v1.2 does not support "smooth" transparency, and thus is better
+       // off the xpm way
+       if(!(version->major >= 2 || (version->major == 1 && version->minor >= 3)))
+       {
+               // in this case, we did not set the good icon yet
+               SDL_SysWMinfo info;
+               SDL_VERSION(&info.version);
+               if(SDL_GetWMInfo(&info) == 1 && info.subsystem == SDL_SYSWM_X11)
+               {
+                       data = (char *) loadimagepixelsbgra("darkplaces-icon", false, false, false, NULL);
+                       if(data)
+                       {
+                               // use _NET_WM_ICON too
+                               static long netwm_icon[MAX_NETWM_ICON];
+                               int pos = 0;
+                               int i = 1;
+
+                               while(data)
+                               {
+                                       if(pos + 2 * image_width * image_height < MAX_NETWM_ICON)
+                                       {
+                                               netwm_icon[pos++] = image_width;
+                                               netwm_icon[pos++] = image_height;
+                                               for(i = 0; i < image_height; ++i)
+                                                       for(j = 0; j < image_width; ++j)
+                                                               netwm_icon[pos++] = BuffLittleLong((unsigned char *) &data[(i*image_width+j)*4]);
+                                       }
+                                       else
+                                       {
+                                               Con_Printf("Skipping NETWM icon #%d because there is no space left\n", i);
+                                       }
+                                       ++i;
+                                       Mem_Free(data);
+                                       data = (char *) loadimagepixelsbgra(va("darkplaces-icon%d", i), false, false, false, NULL);
+                               }
+
+                               info.info.x11.lock_func();
+                               {
+                                       Atom net_wm_icon = XInternAtom(info.info.x11.display, "_NET_WM_ICON", false);
+                                       XChangeProperty(info.info.x11.display, info.info.x11.wmwindow, net_wm_icon, XA_CARDINAL, 32, PropModeReplace, (const unsigned char *) netwm_icon, pos);
+                               }
+                               info.info.x11.unlock_func();
+                       }
+               }
+       }
+#endif
+}
 
 
 static void VID_SetCaption(void)
@@ -840,8 +854,9 @@ qboolean VID_InitMode(viddef_mode_t *mode)
 
        video_bpp = mode->bitsperpixel;
        video_flags = flags;
-       VID_SetIcon();
+       VID_SetIcon_Pre();
        screen = SDL_SetVideoMode(mode->width, mode->height, mode->bitsperpixel, flags);
+       VID_SetIcon_Post();
 
        if (screen == NULL)
        {