Re: [AD] Allegro window icon under X

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Revised patch attached.

> Personally, I'd prefer if the name would be <icon>.c, where <icon> is
> the bitmap name, or if there would be a -o switch for the output file
> name.

I have added a -o flag to the xfixicon.sh script that makes it possible to 
change the name of the output file (the default is still allegro_icon.c 
though).

> And the xpm files also are very evil:
> 
> static char *allegico_xpm[] = {
> "48 48 6 1",
> 
> Apparently a "const" is missing.. so I get lots of warnings - maybe a
> sed could be used on the generated file to add the const.

Done.

> >>- play nice with WindowMaker (there's no appicon, for one)
> >>    
> >>
> 
> I'm pretty sure I was also thinking of FAQ 9.1 from
> http://www.windowmaker.org/faq-chapter9.html

The attached patch makes appicons appear for Allegro programs, but with a 
hickup: it only works on odd calls to set_gfx_mode(). This is most 
noticable in the test program, where an app icon appears when the program 
is started, disappears when the graphics mode is selected, then reappears 
if it is changed again from the menu, disappears if set again, etc.
I'm clueless as to what is causing this behavior though. If anyone else can 
reproduce this and figure it out, I'd be glad to hear it.

On a different note, has anyone had any luck connecting to SourceForge's 
CVS server today? I haven't been able to read from, much less write to, 
the CVS tree.

Evert
diff -r -N -U3 allegro/src/x/alex.xpm alleg_icon/src/x/alex.xpm
--- allegro/src/x/alex.xpm	1970-01-01 01:00:00.000000000 +0100
+++ alleg_icon/src/x/alex.xpm	2004-07-04 13:05:43.000000000 +0200
@@ -0,0 +1,57 @@
+/* XPM */
+static char * alex_xpm[] = {
+"48 48 6 1",
+" 	c None",
+".	c #080808",
+"+	c #FCFCFC",
+"@	c #486028",
+"#	c #587834",
+"$	c #A4C47C",
+"                ....     ....                   ",
+"                ....     ....                   ",
+"               .++++..  .++++..                 ",
+"               .++++..  .++++..                 ",
+"  ......       ...++.......++...                ",
+"  ......       ...++.......++...                ",
+"..@@####............@@###....##@..              ",
+"..@@####............@@###....##@..              ",
+"..###########################..#@@..            ",
+"..###########################..#@@..            ",
+".............................#####..            ",
+".............................#####..            ",
+"                      ...#########@@..          ",
+"                ......#####..#######..          ",
+"                ......#####..#######..          ",
+"           .....######.....$$#######..          ",
+"           .....######.....$$#######..          ",
+"      .....#####......   ..$$#######..          ",
+"      .....#####......   ..$$#######..          ",
+"    ..#####.....        .$$##..###@@..          ",
+"    ..#####.....        .$$##..###@@..          ",
+"      .....           .......###@@..            ",
+"      .....           .......###@@..            ",
+"                    ..#########.@@..            ",
+"                    ..##.......@##..            ",
+"                    ..##.......@##..            ",
+"                      ...$$$$#####..            ",
+"                      ...$$$$#####..            ",
+"                        .$$$$#####..         .. ",
+"                        .$$$$#####..         .. ",
+"                        .$$$$#####..       ..@@.",
+"                        .$$$$#####..       ..@@.",
+"                        .$$..#####@@..     ..@@.",
+"                        .$$..#####@@..     ..@@.",
+"                         ..####@..##..   ..##@@.",
+"                         ..####@..##..   ..##@@.",
+"                         ..####@..####...##@@$$.",
+"                        .####@@.$$#######@@$$.. ",
+"                        .####@@.$$#######@@$$.. ",
+"                        .##@@.....$$$$$$$$$..   ",
+"                        .##@@.....$$$$$$$$$..   ",
+"                         ..##@@............     ",
+"                         ..##@@............     ",
+"                      ...######.@@..            ",
+"                      ...######.@@..            ",
+"                    ..#####@@###..@@..          ",
+"                    ..#####@@###..@@..          ",
+"                    ..................          "};
diff -r -N -U3 allegro/src/x/xwin.c alleg_icon/src/x/xwin.c
--- allegro/src/x/xwin.c	2004-07-08 00:43:05.000000000 +0200
+++ alleg_icon/src/x/xwin.c	2004-07-09 23:10:32.000000000 +0200
@@ -13,6 +13,7 @@
  *      By Michael Bukin.
  *
  *      Video mode switching by Peter Wang and Benjamin Stover.
+ *      X icon selection by Evert Glebbeek
  *
  *      See readme.txt for copyright information.
  */
@@ -47,6 +48,10 @@
 #endif
 
 
+#include <X11/xpm.h>
+#include "alex.xpm"
+
+
 #define XWIN_DEFAULT_WINDOW_TITLE "Allegro application"
 #define XWIN_DEFAULT_APPLICATION_NAME "allegro"
 #define XWIN_DEFAULT_APPLICATION_CLASS "Allegro"
@@ -134,6 +139,8 @@
    NULL         /* window close hook */
 };
 
+void *allegro_icon = alex_xpm;
+
 int _xwin_last_line = -1;
 int _xwin_in_gfx_call = 0;
 
@@ -367,6 +374,7 @@
 				CopyFromParent, InputOutput, CopyFromParent,
 				CWBorderPixel | CWEventMask, &setattr);
 
+
    /* Get associated visual and window depth (bits per pixel).  */
    XGetWindowAttributes(_xwin.display, _xwin.window, &getattr);
    _xwin.visual = getattr.visual;
@@ -2045,6 +2053,7 @@
 {
    XClassHint hint;
    XWMHints wm_hints;
+   XpmAttributes attributes;
 
    if (_xwin.window == None)
       return;
@@ -2056,10 +2065,18 @@
    hint.res_name = _xwin.application_name;
    hint.res_class = _xwin.application_class;
    XSetClassHint(_xwin.display, _xwin.window, &hint);
-   
-   wm_hints.flags = InputHint | StateHint;
+
+   wm_hints.flags = InputHint | StateHint | WindowGroupHint;
    wm_hints.input = True;
    wm_hints.initial_state = NormalState;
+   wm_hints.window_group = _xwin.window;
+   
+   if (allegro_icon) {
+      wm_hints.flags |= IconPixmapHint | IconMaskHint;
+      attributes.valuemask = XpmReturnAllocPixels | XpmReturnExtensions;
+      XpmCreatePixmapFromData(_xwin.display,_xwin.window,allegro_icon,&wm_hints.icon_pixmap,&wm_hints.icon_mask, &attributes);
+   }
+
    XSetWMHints(_xwin.display, _xwin.window, &wm_hints);
 }
 
diff -r -N -U3 allegro/src/x/xwin.h alleg_icon/src/x/xwin.h
--- allegro/src/x/xwin.h	2003-07-07 16:57:14.000000000 +0200
+++ alleg_icon/src/x/xwin.h	2004-07-04 13:29:01.000000000 +0200
@@ -27,6 +27,13 @@
 AL_VAR(int, _xwin_last_line);
 AL_VAR(int, _xwin_in_gfx_call);
 
+/* Weak symbol declaration for the allegro_icon - only supported in gcc */
+#ifdef ALLEGRO_GCC
+AL_VAR(void *, allegro_icon __attribute__((weak)));
+#else
+AL_VAR(void *, allegro_icon);
+#endif
+
 AL_FUNC(int, _xwin_open_display, (char *name));
 AL_FUNC(void, _xwin_close_display, (void));
 AL_FUNC(int, _xwin_create_window, (void));
diff -r -N -U3 allegro/tools/x11/xfixicon.sh alleg_icon/tools/x11/xfixicon.sh
--- allegro/tools/x11/xfixicon.sh	1970-01-01 01:00:00.000000000 +0100
+++ alleg_icon/tools/x11/xfixicon.sh	2004-07-06 10:34:47.000000000 +0200
@@ -0,0 +1,57 @@
+#! /bin/sh
+
+# Generate X11 icon
+# Usage: xfixicon iconfile
+
+if test -z "$1"; then
+   echo "Usage:"
+   echo "   xfixicon iconfile [-o outputfile]"
+   echo "this will generate a C file that can be linked with your application"
+   echo "to set the X11 icon automatically."
+   echo ""
+   echo "Options:"
+   echo "  -o  Set the name of the output file. Default name is allegro_icon.c"
+   exit
+fi
+
+outfile="allegro_icon.c"
+
+while !(test -z "$1"); do
+   if (test "$1" = "-o"); then
+      outfile=$2
+      shift
+   else
+      file=$1
+   fi
+   shift
+done
+
+if !(test -e "$file"); then
+   echo "File not found: $file"
+   exit 1
+fi
+
+if !(convert "$file" "/tmp/allegico_xpm.xpm"); then
+   echo "Conversion failed"
+   exit 1
+fi
+
+echo "#include <allegro.h>" > $outfile
+cat /tmp/allegico_xpm.xpm | sed -e 's,static char,static const char,' >> $outfile
+echo "#ifdef ALLEGRO_GCC" >> $outfile
+echo "void *allegro_icon = allegico_xpm;" >> $outfile
+echo "#elif defined ALLEGRO_USE_CONSTRUCTOR" >> $outfile
+echo "extern void *allegro_icon;" >>  $outfile
+echo "CONSTRUCTOR_FUNCTION(static void _set_allegro_icon(void));" >> $outfile
+echo "static void _set_allegro_icon(void)" >> $outfile
+echo "{" >> $outfile
+echo "    allegro_icon = allegico_xpm;" >> $outfile
+echo "}" >> $outfile
+echo "#endif" >> $outfile
+
+rm /tmp/allegico_xpm.xpm
diff -U3 allegro/aclocal.m4 alleg_icon/aclocal.m4
--- allegro/aclocal.m4	2004-05-11 18:51:27.000000000 +0200
+++ alleg_icon/aclocal.m4	2004-07-04 12:35:18.000000000 +0200
@@ -226,6 +226,10 @@
   AC_CHECK_LIB(Xext, XMissingExtension,
     [LIBS="-lXext $LIBS"])
 
+  dnl Test for Xpm library.
+  AC_CHECK_LIB(Xpm, XMissingExtension,
+    [LIBS="-lXpm $LIBS"])
+
   dnl Test for SHM extension.
   if test -n "$allegro_enable_xwin_shm"; then
     AC_CHECK_LIB(Xext, XShmQueryExtension,


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/