[AD] Allegro window icon under X

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


Attached is a preliminary patch that adds support for setting a window icon 
for X. Note that it would have to be cleaned up somewhat before it can be 
applied. For now, however, it works!
It adds the symbol 
char *allegro_icon[] to xwin.c and xwin.h, which contains a standard .xpm 
pixmap. I have taken the alex.xpm logo for this, actually.
The allegro_icon is used by _xwin_private_set_window_defaults in xwin.c to 
set the window icon.
The allegro_icon is declared as a weak symbol, meaning it can be overridden  
by the user by simply defining his own allegro_icon. This is convenient, 
because it is rather close to the way icons are added in the Windows port 
of Allegro (by defining an allegro_icon resource).

Two drawbacks: it relies on the compiler providing weak symbols, which 
works for gcc but may not be supported by other compilers or other 
platforms. One work around for this one is to provide a platfom-specific 
xwin_set_window_icon function that the user has to call explicitly. I 
would prefer the usage of weak symbols if at all possible.
Secondly, it adds a dependency on libXpm.a. I don't think this is not much 
of an issue, but it should probably be placed under a configure check, 
which I haven't done yet.

Comments please.

Evert
--- allegro/configure.in	2004-05-15 11:05:10.000000000 +0200
+++ alleg_icon/configure.in	2004-07-02 21:51:35.000000000 +0200
@@ -628,6 +628,7 @@
 
 dnl Additional libraries.
 LIBS="-lm $LIBS"
+LIBS="-lXpm $LIBS"
 
 case "$allegro_system" in
 
diff --recursive -U3 allegro/src/linux/CVS/Entries alleg_icon/src/linux/CVS/Entries
--- allegro/src/linux/CVS/Entries	2004-07-02 21:44:35.000000000 +0200
+++ alleg_icon/src/linux/CVS/Entries	2004-07-02 21:42:39.000000000 +0200
@@ -1,6 +1,7 @@
 /lasyncio.c/1.5/Fri Mar 14 13:44:18 2003//
 /lconsole.c/1.10/Fri Feb  7 12:38:34 2003//
 /lgfxdrv.c/1.5/Mon Dec  3 13:34:27 2001//
+/ljoy.c/1.21/Fri Apr  9 04:21:17 2004//
 /lkeybd.c/1.9/Sat Oct 11 07:53:27 2003//
 /lmemory.c/1.5/Thu Sep 18 09:04:29 2003//
 /lmouse.c/1.6/Sat Oct 11 07:53:27 2003//
@@ -18,5 +19,4 @@
 /svgalibs.s/1.5/Tue Jul  9 17:45:20 2002//
 /vtswitch.c/1.14/Sat Oct 11 07:53:28 2003//
 /fbcon.c/1.30/Fri Jul  2 16:18:24 2004//
-/ljoy.c/1.21/Fri Jul  2 19:44:35 2004//
 D
diff --recursive -U3 allegro/src/x/xwin.c alleg_icon/src/x/xwin.c
--- allegro/src/x/xwin.c	2004-07-02 18:18:24.000000000 +0200
+++ alleg_icon/src/x/xwin.c	2004-07-02 22:13:17.000000000 +0200
@@ -47,6 +47,9 @@
 #endif
 
 
+#include <X11/xpm.h>
+
+
 #define XWIN_DEFAULT_WINDOW_TITLE "Allegro application"
 #define XWIN_DEFAULT_APPLICATION_NAME "allegro"
 #define XWIN_DEFAULT_APPLICATION_CLASS "Allegro"
@@ -134,6 +137,63 @@
    NULL         /* window close hook */
 };
 
+char * allegro_icon[] = {
+"48 48 6 1",
+" 	c None",
+".	c #080808",
+"+	c #FCFCFC",
+"@	c #486028",
+"#	c #587834",
+"$	c #A4C47C",
+"                ....     ....                   ",
+"                ....     ....                   ",
+"               .++++..  .++++..                 ",
+"               .++++..  .++++..                 ",
+"  ......       ...++.......++...                ",
+"  ......       ...++.......++...                ",
+"..@@####............@@###....##@..              ",
+"..@@####............@@###....##@..              ",
+"..###########################..#@@..            ",
+"..###########################..#@@..            ",
+".............................#####..            ",
+".............................#####..            ",
+"                      ...#########@@..          ",
+"                ......#####..#######..          ",
+"                ......#####..#######..          ",
+"           .....######.....$$#######..          ",
+"           .....######.....$$#######..          ",
+"      .....#####......   ..$$#######..          ",
+"      .....#####......   ..$$#######..          ",
+"    ..#####.....        .$$##..###@@..          ",
+"    ..#####.....        .$$##..###@@..          ",
+"      .....           .......###@@..            ",
+"      .....           .......###@@..            ",
+"                    ..#########.@@..            ",
+"                    ..##.......@##..            ",
+"                    ..##.......@##..            ",
+"                      ...$$$$#####..            ",
+"                      ...$$$$#####..            ",
+"                        .$$$$#####..         .. ",
+"                        .$$$$#####..         .. ",
+"                        .$$$$#####..       ..@@.",
+"                        .$$$$#####..       ..@@.",
+"                        .$$..#####@@..     ..@@.",
+"                        .$$..#####@@..     ..@@.",
+"                         ..####@..##..   ..##@@.",
+"                         ..####@..##..   ..##@@.",
+"                         ..####@..####...##@@$$.",
+"                        .####@@.$$#######@@$$.. ",
+"                        .####@@.$$#######@@$$.. ",
+"                        .##@@.....$$$$$$$$$..   ",
+"                        .##@@.....$$$$$$$$$..   ",
+"                         ..##@@............     ",
+"                         ..##@@............     ",
+"                      ...######.@@..            ",
+"                      ...######.@@..            ",
+"                    ..#####@@###..@@..          ",
+"                    ..#####@@###..@@..          ",
+"                    ..................          "};
+
 int _xwin_last_line = -1;
 int _xwin_in_gfx_call = 0;
 
@@ -2045,6 +2105,7 @@
 {
    XClassHint hint;
    XWMHints wm_hints;
+   XpmAttributes attributes;
 
    if (_xwin.window == None)
       return;
@@ -2060,6 +2121,13 @@
    wm_hints.flags = InputHint | StateHint;
    wm_hints.input = True;
    wm_hints.initial_state = NormalState;
+
+   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 --recursive -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-02 22:07:22.000000000 +0200
@@ -26,6 +26,7 @@
 /* Defined in xwin.c.  */
 AL_VAR(int, _xwin_last_line);
 AL_VAR(int, _xwin_in_gfx_call);
+AL_VAR(char *, allegro_icon[] __attribute__((weak)));
 
 AL_FUNC(int, _xwin_open_display, (char *name));
 AL_FUNC(void, _xwin_close_display, (void));


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