Re: [AD] Allegro window icon under X |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
Revised patch attached.
This will try to use a weak symbol on gcc, and failing that, try to use
Allegro's constructor function defines as an alternative (I think these
too are gcc specific, but I'm not sure. May be more robuste anyway).
I moved the -lXpm library flag in the configure machinery to aclocal.m4,
where it is added to the flags along with the other X11 libraries (as it
should be).
I also replaced the inlined alex icon with an #included version (I just
copied alex.xpm from the misc/ directory).
Also included is a misc/x11/xfixicon.sh script. It accepts an image file
and uses the convert program to change it to a .xpm file. It then
generates allegro_icon.c, which can be linked to the user program to
generate the icon. The .xpm file is inlined in it, so no other files are
needed.
I'm reasonably statisfied with the functionality of this patch (I may want
to add a xwin_set_window_icon() function to the API, so that there is an
alternative way to set the icon if this method does not work, but it's
more or less optional), so I'd like someone to look at it and comment on
what needs to be added (apart from documentation) before it can be
applied.
Evert
--- 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,
diff -N -U3 --recursive 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 -N -U3 --recursive 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-04 13:08:11.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;
@@ -2045,6 +2052,7 @@
{
XClassHint hint;
XWMHints wm_hints;
+ XpmAttributes attributes;
if (_xwin.window == None)
return;
@@ -2060,6 +2068,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 -N -U3 --recursive 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 -N -U3 --recursive 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-04 13:54:19.000000000 +0200
@@ -0,0 +1,39 @@
+#! /bin/sh
+
+# Generate X11 icon
+# Usage: xfixicon iconfile
+
+if test -z "$1"; then
+ echo "Usage:"
+ echo " xfixicon iconfile"
+ echo "this will generate allegro_icon.c."
+ echo "Link your allegro_icon.c to set the X11 icon."
+ exit
+fi
+
+file=$1
+
+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>" > allegro_icon.c
+cat /tmp/allegico_xpm.xpm >> allegro_icon.c
+echo "#ifdef ALLEGRO_GCC" >> allegro_icon.c
+echo "void *allegro_icon = allegico_xpm;" >> allegro_icon.c
+echo "#elif defined ALLEGRO_USE_CONSTRUCTOR" >> allegro_icon.c
+echo "extern void *allegro_icon;" >> allegro_icon.c
+echo "CONSTRUCTOR_FUNCTION(static void _set_allegro_icon(void));" >> allegro_icon.c
+echo "static void _set_allegro_icon(void)" >> allegro_icon.c
+echo "{" >> allegro_icon.c
+echo " allegro_icon = allegico_xpm;" >> allegro_icon.c
+echo "}" >> allegro_icon.c
+echo "#endif" >> allegro_icon.c
+
+rm /tmp/allegico_xpm.xpm