summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Fourdan <fourdan.olivier@wanadoo.fr>2006-05-08 21:38:47 +0000
committerOlivier Fourdan <fourdan.olivier@wanadoo.fr>2006-05-08 21:38:47 +0000
commit529765c468e6a82ceb27c3125302a34b007a2269 (patch)
tree343c611ceb6d040700d2a2a44f32f06ffd43ad41
parentadf20f1ccf9fa6dc9f7f7d186fc9f19c0fcbab02 (diff)
downloadxfwm4-529765c468e6a82ceb27c3125302a34b007a2269.tar.gz
Get rid on libXpm dependency by reimplementing the XPM loader with color symbol substitution (beware, it's a pretty huge change, handle with care).
(Old svn revision: 21595)
-rw-r--r--configure.ac.in1
-rw-r--r--src/Makefile.am8
-rw-r--r--src/mypixmap.c789
-rw-r--r--src/mypixmap.h11
-rw-r--r--src/settings.c106
-rw-r--r--themes/moheli/title-1-inactive.xpm2
-rw-r--r--themes/moheli/title-3-inactive.xpm2
7 files changed, 828 insertions, 91 deletions
diff --git a/configure.ac.in b/configure.ac.in
index 153d63629..234cb116f 100644
--- a/configure.ac.in
+++ b/configure.ac.in
@@ -46,7 +46,6 @@ XDT_I18N([ar az be bg bn_IN ca cs de el en_GB eo es es_MX et eu fa fi fr gu
dnl Check for X11 window system
XDT_CHECK_LIBX11_REQUIRE
-XDT_CHECK_LIBXPM_REQUIRE
XDT_CHECK_LIBSM
dnl Check for Xext library
diff --git a/src/Makefile.am b/src/Makefile.am
index cdc8c7e9c..7c2dbed94 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -67,7 +67,6 @@ xfwm4_CFLAGS = \
@LIBX11_CFLAGS@ \
@LIBXFCE4MCS_CLIENT_CFLAGS@ \
@LIBXFCEGUI4_CFLAGS@ \
- @LIBXPM_CFLAGS@ \
@RENDER_CFLAGS@ \
@LIBSTARTUP_NOTIFICATION_CFLAGS@ \
@COMPOSITOR_CFLAGS@ \
@@ -80,17 +79,14 @@ xfwm4_LDADD = \
@LIBX11_LIBS@ \
@LIBXFCE4MCS_CLIENT_LIBS@ \
@LIBXFCEGUI4_LIBS@ \
- @LIBXPM_LIBS@ \
@LIBSTARTUP_NOTIFICATION_LIBS@ \
@RENDER_LIBS@ \
@COMPOSITOR_LIBS@ \
@RANDR_LIBS@
-xfwm4_LDFLAGS = \
- @LIBXPM_LDFLAGS@
-
EXTRA_DIST = inline-tabwin-icon.h tabwin-icon.png \
- inline-default-icon.h default_icon.png
+ inline-default-icon.h default_icon.png \
+ gen-color-table.pl
noinst_DATA = inline-tabwin-icon.h tabwin-icon.png
diff --git a/src/mypixmap.c b/src/mypixmap.c
index 711efbdbf..532f3179b 100644
--- a/src/mypixmap.c
+++ b/src/mypixmap.c
@@ -14,6 +14,14 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ XPM load routines taken from GdkPixbuf:
+
+ Copyright (C) 1999 Mark Crichton
+ Copyright (C) 1999 The Free Software Foundation
+
+ Authors: Mark Crichton <crichton@gimp.org>
+ Federico Mena-Quintero <federico@gimp.org>
+
oroborus - (c) 2001 Ken Lynch
xfwm4 - (c) 2002-2006 Olivier Fourdan
@@ -26,6 +34,7 @@
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <glib.h>
+#include <glib/gstdio.h>
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#include <libxfce4util/libxfce4util.h>
@@ -33,6 +42,657 @@
#include <stdio.h>
#include "mypixmap.h"
+#include "xpm-color-table.h"
+
+enum buf_op
+{
+ op_header,
+ op_cmap,
+ op_body
+};
+
+typedef struct
+{
+ gchar *color_string;
+ guint16 red;
+ guint16 green;
+ guint16 blue;
+ gint transparent;
+}
+XPMColor;
+
+struct file_handle
+{
+ FILE *infile;
+ gchar *buffer;
+ guint buffer_size;
+};
+
+/* The following 2 routines (parse_color, find_color) come from Tk, via the Win32
+ * port of GDK. The licensing terms on these (longer than the functions) is:
+ *
+ * This software is copyrighted by the Regents of the University of
+ * California, Sun Microsystems, Inc., and other parties. The following
+ * terms apply to all files associated with the software unless explicitly
+ * disclaimed in individual files.
+ *
+ * The authors hereby grant permission to use, copy, modify, distribute,
+ * and license this software and its documentation for any purpose, provided
+ * that existing copyright notices are retained in all copies and that this
+ * notice is included verbatim in any distributions. No written agreement,
+ * license, or royalty fee is required for any of the authorized uses.
+ * Modifications to this software may be copyrighted by their authors
+ * and need not follow the licensing terms described here, provided that
+ * the new terms are clearly indicated on the first page of each file where
+ * they apply.
+ *
+ * IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY
+ * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
+ * ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
+ * DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE
+ * IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE
+ * NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
+ * MODIFICATIONS.
+ *
+ * GOVERNMENT USE: If you are acquiring this software on behalf of the
+ * U.S. government, the Government shall have only "Restricted Rights"
+ * in the software and related documentation as defined in the Federal
+ * Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you
+ * are acquiring the software on behalf of the Department of Defense, the
+ * software shall be classified as "Commercial Computer Software" and the
+ * Government shall have only "Restricted Rights" as defined in Clause
+ * 252.227-7013 (c) (1) of DFARs. Notwithstanding the foregoing, the
+ * authors grant the U.S. Government and others acting in its behalf
+ * permission to use and distribute the software in accordance with the
+ * terms specified in this license.
+ */
+
+static int
+compare_xcolor_entries (const void *a, const void *b)
+{
+ return g_ascii_strcasecmp ((const char *) a,
+ color_names + ((const XPMColorEntry *) b)->name_offset);
+}
+
+static gboolean
+find_color(const char *name, XPMColor *colorPtr)
+{
+ XPMColorEntry *found;
+
+ found = bsearch (name, xColors, G_N_ELEMENTS (xColors), sizeof (XPMColorEntry),
+ compare_xcolor_entries);
+ if (found == NULL)
+ {
+ return FALSE;
+ }
+
+ colorPtr->red = (found->red * 65535) / 255;
+ colorPtr->green = (found->green * 65535) / 255;
+ colorPtr->blue = (found->blue * 65535) / 255;
+
+ return TRUE;
+}
+
+static gboolean
+parse_color (const char *spec, XPMColor *colorPtr)
+{
+ if (spec[0] == '#')
+ {
+ char fmt[16];
+ int i, red, green, blue;
+
+ if ((i = strlen (spec + 1)) % 3)
+ {
+ return FALSE;
+ }
+ i /= 3;
+
+ g_snprintf (fmt, 16, "%%%dx%%%dx%%%dx", i, i, i);
+
+ if (sscanf (spec + 1, fmt, &red, &green, &blue) != 3)
+ {
+ return FALSE;
+ }
+ if (i == 4)
+ {
+ colorPtr->red = red;
+ colorPtr->green = green;
+ colorPtr->blue = blue;
+ }
+ else if (i == 1)
+ {
+ colorPtr->red = (red * 65535) / 15;
+ colorPtr->green = (green * 65535) / 15;
+ colorPtr->blue = (blue * 65535) / 15;
+ }
+ else if (i == 2)
+ {
+ colorPtr->red = (red * 65535) / 255;
+ colorPtr->green = (green * 65535) / 255;
+ colorPtr->blue = (blue * 65535) / 255;
+ }
+ else /* if (i == 3) */
+ {
+ colorPtr->red = (red * 65535) / 4095;
+ colorPtr->green = (green * 65535) / 4095;
+ colorPtr->blue = (blue * 65535) / 4095;
+ }
+ }
+ else
+ {
+ if (!find_color(spec, colorPtr))
+ {
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+
+static gint
+xpm_seek_string (FILE *infile, const gchar *str)
+{
+ char instr[1024];
+
+ while (!feof (infile))
+ {
+ if (fscanf (infile, "%1023s", instr) < 0)
+ {
+ return FALSE;
+ }
+ if (strcmp (instr, str) == 0)
+ {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+static gint
+xpm_seek_char (FILE *infile, gchar c)
+{
+ gint b, oldb;
+
+ while ((b = getc (infile)) != EOF)
+ {
+ if (c != b && b == '/')
+ {
+ b = getc (infile);
+ if (b == EOF)
+ {
+ return FALSE;
+ }
+ else if (b == '*')
+ { /* we have a comment */
+ b = -1;
+ do
+ {
+ oldb = b;
+ b = getc (infile);
+ if (b == EOF)
+ {
+ return FALSE;
+ }
+ }
+ while (!(oldb == '*' && b == '/'));
+ }
+ }
+ else if (c == b)
+ {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+static gint
+xpm_read_string (FILE *infile, gchar **buffer, guint *buffer_size)
+{
+ gint c;
+ guint cnt = 0, bufsiz, ret = FALSE;
+ gchar *buf;
+
+ buf = *buffer;
+ bufsiz = *buffer_size;
+ if (buf == NULL)
+ {
+ bufsiz = 10 * sizeof (gchar);
+ buf = g_new (gchar, bufsiz);
+ }
+
+ do
+ {
+ c = getc (infile);
+ }
+ while (c != EOF && c != '"');
+
+ if (c != '"')
+ {
+ goto out;
+ }
+ while ((c = getc (infile)) != EOF)
+ {
+ if (cnt == bufsiz)
+ {
+ guint new_size = bufsiz * 2;
+
+ if (new_size > bufsiz)
+ {
+ bufsiz = new_size;
+ }
+ else
+ {
+ goto out;
+ }
+ buf = g_realloc (buf, bufsiz);
+ buf[bufsiz - 1] = '\0';
+ }
+
+ if (c != '"')
+ {
+ buf[cnt++] = c;
+ }
+ else
+ {
+ buf[cnt] = 0;
+ ret = TRUE;
+ break;
+ }
+ }
+
+out:
+ buf[bufsiz - 1] = '\0'; /* ensure null termination for errors */
+ *buffer = buf;
+ *buffer_size = bufsiz;
+ return ret;
+}
+
+static gchar *
+search_color_symbol (gchar *symbol, xfwmColorSymbol *color_sym)
+{
+ xfwmColorSymbol *i;
+
+ i = color_sym;
+ while (i && i->name)
+ {
+ if (!g_ascii_strcasecmp (i->name, symbol))
+ {
+ return i->value;
+ }
+ ++i;
+ }
+ return NULL;
+}
+
+static gchar *
+xpm_extract_color (const gchar *buffer, xfwmColorSymbol *color_sym)
+{
+ const gchar *p = &buffer[0];
+ gint new_key = 0;
+ gint key = 0;
+ gint current_key = 1;
+ gint space = 128;
+ gchar word[129], color[129], current_color[129];
+ gchar *r;
+
+ word[0] = '\0';
+ color[0] = '\0';
+ current_color[0] = '\0';
+ while (1)
+ {
+ /* skip whitespace */
+ for (; *p != '\0' && g_ascii_isspace (*p); p++)
+ {
+ }
+ /* copy word */
+ for (r = word;
+ (*p != '\0') &&
+ (!g_ascii_isspace (*p)) &&
+ (r - word < sizeof (word) - 1);
+ p++, r++)
+ {
+ *r = *p;
+ }
+ *r = '\0';
+ if (*word == '\0')
+ {
+ if (color[0] == '\0') /* incomplete colormap entry */
+ {
+ return NULL;
+ }
+ else /* end of entry, still store the last color */
+ {
+ new_key = 1;
+ }
+ }
+ else if (key > 0 && color[0] == '\0') /* next word must be a color name part */
+ {
+ new_key = 0;
+ }
+ else
+ {
+ if (strcmp (word, "s") == 0)
+ {
+ new_key = 5;
+ }
+ else if (strcmp (word, "c") == 0)
+ {
+ new_key = 4;
+ }
+ else if (strcmp (word, "g") == 0)
+ {
+ new_key = 3;
+ }
+ else if (strcmp (word, "g4") == 0)
+ {
+ new_key = 2;
+ }
+ else if (strcmp (word, "m") == 0)
+ {
+ new_key = 1;
+ }
+ else
+ {
+ new_key = 0;
+ }
+ }
+ if (new_key == 0)
+ { /* word is a color name part */
+ if (key == 0) /* key expected */
+ {
+ return NULL;
+ }
+ /* accumulate color name */
+ if (color[0] != '\0')
+ {
+ strncat (color, " ", space);
+ space -= MIN (space, 1);
+ }
+ strncat (color, word, space);
+ space -= MIN (space, strlen (word));
+ }
+ else if (key == 5)
+ {
+ gchar *new_color = NULL;
+ new_color = search_color_symbol (color, color_sym);
+ if (new_color)
+ {
+ current_key = key;
+ strcpy (current_color, new_color);
+ }
+ space = 128;
+ color[0] = '\0';
+ key = new_key;
+ if (*p == '\0')
+ {
+ break;
+ }
+ }
+ else
+ { /* word is a key */
+ if (key > current_key)
+ {
+ current_key = key;
+ strcpy (current_color, color);
+ }
+ space = 128;
+ color[0] = '\0';
+ key = new_key;
+ if (*p == '\0')
+ {
+ break;
+ }
+ }
+ }
+ if (current_key > 1)
+ {
+ return g_strdup (current_color);
+ }
+ else
+ {
+ return NULL;
+ }
+}
+
+static const gchar *
+file_buffer (enum buf_op op, gpointer handle)
+{
+ struct file_handle *h = handle;
+
+ switch (op)
+ {
+ case op_header:
+ if (xpm_seek_string (h->infile, "XPM") != TRUE)
+ {
+ break;
+ }
+ if (xpm_seek_char (h->infile, '{') != TRUE)
+ {
+ break;
+ }
+ /* Fall through to the next xpm_seek_char. */
+
+ case op_cmap:
+ xpm_seek_char (h->infile, '"');
+ fseek (h->infile, -1, SEEK_CUR);
+ /* Fall through to the xpm_read_string. */
+
+ case op_body:
+ if(!xpm_read_string (h->infile, &h->buffer, &h->buffer_size))
+ {
+ return NULL;
+ }
+ return h->buffer;
+
+ default:
+ g_assert_not_reached ();
+ }
+
+ return NULL;
+}
+
+/* This function does all the work. */
+static GdkPixbuf *
+pixbuf_create_from_xpm (const gchar * (*get_buf) (enum buf_op op, gpointer handle), gpointer handle, xfwmColorSymbol *color_sym)
+{
+ gint w, h, n_col, cpp, x_hot, y_hot, items;
+ gint cnt, xcnt, ycnt, wbytes, n;
+ gint is_trans = FALSE;
+ const gchar *buffer;
+ gchar *name_buf;
+ gchar pixel_str[32];
+ GHashTable *color_hash;
+ XPMColor *colors, *color, *fallbackcolor;
+ guchar *pixtmp;
+ GdkPixbuf *pixbuf;
+
+ fallbackcolor = NULL;
+
+ buffer = (*get_buf) (op_header, handle);
+ if (!buffer)
+ {
+ return NULL;
+ }
+ items = sscanf (buffer, "%d %d %d %d %d %d", &w, &h, &n_col, &cpp, &x_hot, &y_hot);
+
+ if (items != 4 && items != 6)
+ {
+ return NULL;
+ }
+
+ if ((w <= 0) ||
+ (h <= 0) ||
+ (cpp <= 0) ||
+ (cpp >= 32) ||
+ (n_col <= 0) ||
+ (n_col >= G_MAXINT / (cpp + 1)) ||
+ (n_col >= G_MAXINT / sizeof (XPMColor)))
+ {
+ return NULL;
+ }
+
+ /* The hash is used for fast lookups of color from chars */
+ color_hash = g_hash_table_new (g_str_hash, g_str_equal);
+
+ name_buf = g_try_malloc (n_col * (cpp + 1));
+ if (!name_buf) {
+ g_hash_table_destroy (color_hash);
+ return NULL;
+ }
+
+ colors = (XPMColor *) g_try_malloc (sizeof (XPMColor) * n_col);
+ if (!colors) {
+ g_hash_table_destroy (color_hash);
+ g_free (name_buf);
+ return NULL;
+ }
+
+ for (cnt = 0; cnt < n_col; cnt++)
+ {
+ gchar *color_name;
+
+ buffer = (*get_buf) (op_cmap, handle);
+ if (!buffer)
+ {
+ g_hash_table_destroy (color_hash);
+ g_free (name_buf);
+ g_free (colors);
+ return NULL;
+ }
+
+ color = &colors[cnt];
+ color->color_string = &name_buf[cnt * (cpp + 1)];
+ strncpy (color->color_string, buffer, cpp);
+ color->color_string[cpp] = 0;
+ buffer += strlen (color->color_string);
+ color->transparent = FALSE;
+
+ color_name = xpm_extract_color (buffer, color_sym);
+
+ if ((color_name == NULL) ||
+ (g_ascii_strcasecmp (color_name, "None") == 0) ||
+ (parse_color (color_name, color) == FALSE))
+ {
+ color->transparent = TRUE;
+ color->red = 0;
+ color->green = 0;
+ color->blue = 0;
+ is_trans = TRUE;
+ }
+
+ g_free (color_name);
+ g_hash_table_insert (color_hash, color->color_string, color);
+
+ if (cnt == 0)
+ {
+ fallbackcolor = color;
+ }
+ }
+
+ pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, is_trans, 8, w, h);
+
+ if (!pixbuf)
+ {
+ g_hash_table_destroy (color_hash);
+ g_free (colors);
+ g_free (name_buf);
+ return NULL;
+ }
+
+ wbytes = w * cpp;
+
+ for (ycnt = 0; ycnt < h; ycnt++)
+ {
+ pixtmp = gdk_pixbuf_get_pixels (pixbuf) + ycnt * gdk_pixbuf_get_rowstride(pixbuf);
+
+ buffer = (*get_buf) (op_body, handle);
+ if ((!buffer) || (strlen (buffer) < wbytes))
+ {
+ continue;
+ }
+
+ for (n = 0, cnt = 0, xcnt = 0; n < wbytes; n += cpp, xcnt++)
+ {
+ strncpy (pixel_str, &buffer[n], cpp);
+ pixel_str[cpp] = 0;
+
+ color = g_hash_table_lookup (color_hash, pixel_str);
+
+ /* Bad XPM...punt */
+ if (!color)
+ {
+ color = fallbackcolor;
+ }
+
+ *pixtmp++ = color->red >> 8;
+ *pixtmp++ = color->green >> 8;
+ *pixtmp++ = color->blue >> 8;
+
+ if (is_trans && color->transparent)
+ {
+ *pixtmp++ = 0;
+ }
+ else if (is_trans)
+ {
+ *pixtmp++ = 0xFF;
+ }
+ }
+ }
+
+ g_hash_table_destroy (color_hash);
+ g_free (colors);
+ g_free (name_buf);
+
+ if (items == 6)
+ {
+ gchar hot[10];
+ g_snprintf (hot, 10, "%d", x_hot);
+ gdk_pixbuf_set_option (pixbuf, "x_hot", hot);
+ g_snprintf (hot, 10, "%d", y_hot);
+ gdk_pixbuf_set_option (pixbuf, "y_hot", hot);
+ }
+
+ return pixbuf;
+}
+
+
+static GdkPixbuf *
+xpm_image_load (const char *filename, xfwmColorSymbol *color_sym)
+{
+ guchar buffer[1024];
+ GdkPixbuf *pixbuf;
+ struct file_handle h;
+ int size;
+ FILE *f;
+
+ f = g_fopen (filename, "rb");
+ if (!f)
+ {
+ return NULL;
+ }
+
+ size = fread (&buffer, 1, sizeof (buffer), f);
+ if (size == 0)
+ {
+ fclose (f);
+ return NULL;
+ }
+
+ fseek (f, 0, SEEK_SET);
+ memset (&h, 0, sizeof (h));
+ h.infile = f;
+ pixbuf = pixbuf_create_from_xpm (file_buffer, &h, color_sym);
+ g_free (h.buffer);
+ fclose (f);
+
+ return pixbuf;
+}
static void
xfwmPixmapRefreshPict (xfwmPixmap * pm)
@@ -61,23 +721,25 @@ xfwmPixmapRefreshPict (xfwmPixmap * pm)
}
static gboolean
-xfwmPixmapCompose (xfwmPixmap * pm, gchar * dir, gchar * file)
+xfwmPixmapCompose (GdkPixbuf *pixbuf, gchar * dir, gchar * file)
{
gchar *filepng;
gchar *filename;
GdkPixbuf *alpha;
GError *error = NULL;
+ gint width, height;
gboolean status;
filepng = g_strdup_printf ("%s.%s", file, "png");
filename = g_build_filename (dir, filepng, NULL);
g_free (filepng);
-
+
if (!g_file_test (filename, G_FILE_TEST_IS_REGULAR))
{
g_free (filename);
return FALSE;
}
+
alpha = gdk_pixbuf_new_from_file (filename, &error);
g_free (filename);
if (error)
@@ -86,15 +748,98 @@ xfwmPixmapCompose (xfwmPixmap * pm, gchar * dir, gchar * file)
g_error_free (error);
return FALSE;
}
+
if (!gdk_pixbuf_get_has_alpha (alpha))
{
g_object_unref (alpha);
return FALSE;
}
- status = xfwmPixmapRenderGdkPixbuf (pm, alpha);
+
+ width = MIN (gdk_pixbuf_get_width (pixbuf),
+ gdk_pixbuf_get_width (alpha));
+ height = MIN (gdk_pixbuf_get_height (pixbuf),
+ gdk_pixbuf_get_height (alpha));
+
+ gdk_pixbuf_composite (alpha, pixbuf, 0, 0, width, height,
+ 0, 0, 1.0, 1.0, GDK_INTERP_NEAREST, 255);
+
g_object_unref (alpha);
- return status;
+ return TRUE;
+}
+
+static gboolean
+xfwmPixmapDrawFromGdkPixbuf (xfwmPixmap * pm, GdkPixbuf *pixbuf)
+{
+ GdkPixmap *dest_pixmap;
+ GdkPixmap *dest_bitmap;
+ GdkVisual *gvisual;
+ GdkColormap *cmap;
+ gint width, height;
+ gint dest_x, dest_y;
+
+ dest_pixmap = gdk_xid_table_lookup (pm->pixmap);
+ if (dest_pixmap)
+ {
+ g_object_ref (G_OBJECT (dest_pixmap));
+ }
+ else
+ {
+ dest_pixmap = gdk_pixmap_foreign_new (pm->pixmap);
+ }
+
+ if (!dest_pixmap)
+ {
+ g_warning ("Cannot get pixmap");
+ return FALSE;
+ }
+
+ dest_bitmap = gdk_xid_table_lookup (pm->mask);
+ if (dest_bitmap)
+ {
+ g_object_ref (G_OBJECT (dest_bitmap));
+ }
+ else
+ {
+ dest_bitmap = gdk_pixmap_foreign_new (pm->mask);
+ }
+
+ if (!dest_bitmap)
+ {
+ g_warning ("Cannot get bitmap");
+ g_object_unref (dest_pixmap);
+ return FALSE;
+ }
+
+ gvisual = gdk_screen_get_system_visual (pm->screen_info->gscr);
+ cmap = gdk_x11_colormap_foreign_new (gvisual, pm->screen_info->cmap);
+
+ if (!cmap)
+ {
+ g_warning ("Cannot create colormap");
+ g_object_unref (dest_pixmap);
+ g_object_unref (dest_bitmap);
+ return FALSE;
+ }
+
+ width = MIN (gdk_pixbuf_get_width (pixbuf), pm->width);
+ height = MIN (gdk_pixbuf_get_height (pixbuf), pm->height);
+ dest_x = (pm->width - width) / 2;
+ dest_y = (pm->height - height) / 2;
+
+ gdk_drawable_set_colormap (GDK_DRAWABLE (dest_pixmap), cmap);
+ gdk_draw_pixbuf (GDK_DRAWABLE (dest_pixmap), NULL, pixbuf, 0, 0, dest_x, dest_y,
+ width, height, GDK_RGB_DITHER_NONE, 0, 0);
+
+ gdk_pixbuf_render_threshold_alpha (pixbuf, dest_bitmap,
+ 0, 0, dest_x, dest_y,
+ width, height, 255);
+
+ g_object_unref (cmap);
+ g_object_unref (dest_pixmap);
+ g_object_unref (dest_bitmap);
+
+ return TRUE;
}
gboolean
@@ -153,11 +898,11 @@ xfwmPixmapRenderGdkPixbuf (xfwmPixmap * pm, GdkPixbuf *pixbuf)
}
gboolean
-xfwmPixmapLoad (ScreenInfo * screen_info, xfwmPixmap * pm, gchar * dir, gchar * file, XpmColorSymbol * cs, gint n)
+xfwmPixmapLoad (ScreenInfo * screen_info, xfwmPixmap * pm, gchar * dir, gchar * file, xfwmColorSymbol * cs)
{
gchar *filename;
gchar *filexpm;
- XpmAttributes attr;
+ GdkPixbuf *pixbuf;
TRACE ("entering xfwmPixmapLoad");
@@ -172,32 +917,24 @@ xfwmPixmapLoad (ScreenInfo * screen_info, xfwmPixmap * pm, gchar * dir, gchar *
filexpm = g_strdup_printf ("%s.%s", file, "xpm");
filename = g_build_filename (dir, filexpm, NULL);
g_free (filexpm);
- attr.colorsymbols = cs;
- attr.numsymbols = n;
- attr.depth = screen_info->depth;
- attr.colormap = pm->screen_info->cmap;
- attr.closeness = 65535;
- attr.valuemask = XpmCloseness | XpmColormap | XpmSize | XpmDepth;
- if ((n > 0) && (cs != NULL))
- {
- attr.valuemask = attr.valuemask | XpmColorSymbols;
- }
- if (XpmReadFileToPixmap (myScreenGetXDisplay (screen_info),
- screen_info->xroot, filename,
- &pm->pixmap, &pm->mask, &attr))
+
+ pixbuf = xpm_image_load (filename, cs);
+ if (!pixbuf)
{
TRACE ("%s not found", filename);
g_free (filename);
return FALSE;
}
- pm->width = attr.width;
- pm->height = attr.height;
- XpmFreeAttributes (&attr);
g_free (filename);
- /* Apply the alpha channel if available */
- xfwmPixmapCompose (pm, dir, file);
-
+ /* Apply the alpha channel from PNG if available */
+ xfwmPixmapCompose (pixbuf, dir, file);
+
+ xfwmPixmapCreate (screen_info, pm,
+ gdk_pixbuf_get_width (pixbuf),
+ gdk_pixbuf_get_height (pixbuf));
+ xfwmPixmapDrawFromGdkPixbuf (pm, pixbuf);
+
#ifdef HAVE_RENDER
xfwmPixmapRefreshPict (pm);
#endif
@@ -337,5 +1074,3 @@ xfwmPixmapDuplicate (xfwmPixmap * src, xfwmPixmap * dst)
xfwmPixmapCreate (src->screen_info, dst, src->width, src->height);
xfwmPixmapFill (src, dst, 0, 0, src->width, src->height);
}
-
-
diff --git a/src/mypixmap.h b/src/mypixmap.h
index 04b7534c0..a5926916b 100644
--- a/src/mypixmap.h
+++ b/src/mypixmap.h
@@ -23,7 +23,6 @@
# include "config.h"
#endif
-#include <X11/xpm.h>
#include <glib.h>
#include "screen.h"
@@ -36,6 +35,13 @@
#define MYPIXMAP_XPIXMAP(p) (p.pixmap)
+typedef struct
+{
+ gchar *name;
+ gchar *value;
+}
+xfwmColorSymbol;
+
struct _xfwmPixmap
{
ScreenInfo *screen_info;
@@ -53,8 +59,7 @@ gboolean xfwmPixmapLoad (ScreenInfo *,
xfwmPixmap *,
gchar *,
gchar *,
- XpmColorSymbol *,
- gint);
+ xfwmColorSymbol *);
void xfwmPixmapCreate (ScreenInfo *,
xfwmPixmap *,
gint,
diff --git a/src/settings.c b/src/settings.c
index c87392ef2..ba304eafc 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -867,7 +867,7 @@ loadTheme (ScreenInfo *screen_info, Settings *rc)
DisplayInfo *display_info = NULL;
gchar *theme;
gchar *font;
- XpmColorSymbol colsym[XPM_COLOR_SYMBOL_SIZE];
+ xfwmColorSymbol colsym[ XPM_COLOR_SYMBOL_SIZE + 1 ];
PangoFontDescription *desc = NULL;
guint i;
GValue tmp_val = { 0, };
@@ -916,6 +916,8 @@ loadTheme (ScreenInfo *screen_info, Settings *rc)
colsym[i].name = rc[i].option;
colsym[i].value = rc[i].value;
}
+ colsym[XPM_COLOR_SYMBOL_SIZE].name = NULL;
+ colsym[XPM_COLOR_SYMBOL_SIZE].value = NULL;
display_info->dbl_click_time = abs (TOINT (getValue ("dbl_click_time", rc)));
g_value_init (&tmp_val, G_TYPE_INT);
@@ -955,107 +957,107 @@ loadTheme (ScreenInfo *screen_info, Settings *rc)
g_object_ref (G_OBJECT (widget->style->white_gc));
xfwmPixmapLoad (screen_info, &screen_info->sides[SIDE_LEFT][ACTIVE], theme,
- "left-active", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "left-active", colsym);
xfwmPixmapLoad (screen_info, &screen_info->sides[SIDE_LEFT][INACTIVE], theme,
- "left-inactive", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "left-inactive", colsym);
xfwmPixmapLoad (screen_info, &screen_info->sides[SIDE_RIGHT][ACTIVE], theme,
- "right-active", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "right-active", colsym);
xfwmPixmapLoad (screen_info, &screen_info->sides[SIDE_RIGHT][INACTIVE], theme,
- "right-inactive", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "right-inactive", colsym);
xfwmPixmapLoad (screen_info, &screen_info->sides[SIDE_BOTTOM][ACTIVE], theme,
- "bottom-active", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "bottom-active", colsym);
xfwmPixmapLoad (screen_info, &screen_info->sides[SIDE_BOTTOM][INACTIVE], theme,
- "bottom-inactive", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "bottom-inactive", colsym);
xfwmPixmapLoad (screen_info, &screen_info->corners[CORNER_TOP_LEFT][ACTIVE], theme,
- "top-left-active", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "top-left-active", colsym);
xfwmPixmapLoad (screen_info, &screen_info->corners[CORNER_TOP_LEFT][INACTIVE], theme,
- "top-left-inactive", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "top-left-inactive", colsym);
xfwmPixmapLoad (screen_info, &screen_info->corners[CORNER_TOP_RIGHT][ACTIVE], theme,
- "top-right-active", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "top-right-active", colsym);
xfwmPixmapLoad (screen_info, &screen_info->corners[CORNER_TOP_RIGHT][INACTIVE], theme,
- "top-right-inactive", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "top-right-inactive", colsym);
xfwmPixmapLoad (screen_info, &screen_info->corners[CORNER_BOTTOM_LEFT][ACTIVE], theme,
- "bottom-left-active", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "bottom-left-active", colsym);
xfwmPixmapLoad (screen_info, &screen_info->corners[CORNER_BOTTOM_LEFT][INACTIVE], theme,
- "bottom-left-inactive", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "bottom-left-inactive", colsym);
xfwmPixmapLoad (screen_info, &screen_info->corners[CORNER_BOTTOM_RIGHT][ACTIVE], theme,
- "bottom-right-active", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "bottom-right-active", colsym);
xfwmPixmapLoad (screen_info, &screen_info->corners[CORNER_BOTTOM_RIGHT][INACTIVE], theme,
- "bottom-right-inactive", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "bottom-right-inactive", colsym);
xfwmPixmapLoad (screen_info, &screen_info->buttons[HIDE_BUTTON][ACTIVE], theme,
- "hide-active", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "hide-active", colsym);
xfwmPixmapLoad (screen_info, &screen_info->buttons[HIDE_BUTTON][INACTIVE], theme,
- "hide-inactive", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "hide-inactive", colsym);
xfwmPixmapLoad (screen_info, &screen_info->buttons[HIDE_BUTTON][PRESSED], theme,
- "hide-pressed", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "hide-pressed", colsym);
xfwmPixmapLoad (screen_info, &screen_info->buttons[CLOSE_BUTTON][ACTIVE], theme,
- "close-active", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "close-active", colsym);
xfwmPixmapLoad (screen_info, &screen_info->buttons[CLOSE_BUTTON][INACTIVE], theme,
- "close-inactive", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "close-inactive", colsym);
xfwmPixmapLoad (screen_info, &screen_info->buttons[CLOSE_BUTTON][PRESSED], theme,
- "close-pressed", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "close-pressed", colsym);
xfwmPixmapLoad (screen_info, &screen_info->buttons[MAXIMIZE_BUTTON][ACTIVE], theme,
- "maximize-active", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "maximize-active", colsym);
xfwmPixmapLoad (screen_info, &screen_info->buttons[MAXIMIZE_BUTTON][INACTIVE], theme,
- "maximize-inactive", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "maximize-inactive", colsym);
xfwmPixmapLoad (screen_info, &screen_info->buttons[MAXIMIZE_BUTTON][PRESSED], theme,
- "maximize-pressed", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "maximize-pressed", colsym);
xfwmPixmapLoad (screen_info, &screen_info->buttons[SHADE_BUTTON][ACTIVE], theme,
- "shade-active", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "shade-active", colsym);
xfwmPixmapLoad (screen_info, &screen_info->buttons[SHADE_BUTTON][INACTIVE], theme,
- "shade-inactive", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "shade-inactive", colsym);
xfwmPixmapLoad (screen_info, &screen_info->buttons[SHADE_BUTTON][PRESSED], theme,
- "shade-pressed", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "shade-pressed", colsym);
xfwmPixmapLoad (screen_info, &screen_info->buttons[STICK_BUTTON][ACTIVE], theme,
- "stick-active", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "stick-active", colsym);
xfwmPixmapLoad (screen_info, &screen_info->buttons[STICK_BUTTON][INACTIVE], theme,
- "stick-inactive", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "stick-inactive", colsym);
xfwmPixmapLoad (screen_info, &screen_info->buttons[STICK_BUTTON][PRESSED], theme,
- "stick-pressed", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "stick-pressed", colsym);
xfwmPixmapLoad (screen_info, &screen_info->buttons[MENU_BUTTON][ACTIVE], theme,
- "menu-active", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "menu-active", colsym);
xfwmPixmapLoad (screen_info, &screen_info->buttons[MENU_BUTTON][INACTIVE], theme,
- "menu-inactive", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "menu-inactive", colsym);
xfwmPixmapLoad (screen_info, &screen_info->buttons[MENU_BUTTON][PRESSED], theme,
- "menu-pressed", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "menu-pressed", colsym);
xfwmPixmapLoad (screen_info, &screen_info->buttons[SHADE_BUTTON][T_ACTIVE], theme,
- "shade-toggled-active", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "shade-toggled-active", colsym);
xfwmPixmapLoad (screen_info, &screen_info->buttons[SHADE_BUTTON][T_INACTIVE], theme,
- "shade-toggled-inactive", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "shade-toggled-inactive", colsym);
xfwmPixmapLoad (screen_info, &screen_info->buttons[SHADE_BUTTON][T_PRESSED], theme,
- "shade-toggled-pressed", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "shade-toggled-pressed", colsym);
xfwmPixmapLoad (screen_info, &screen_info->buttons[STICK_BUTTON][T_ACTIVE], theme,
- "stick-toggled-active", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "stick-toggled-active", colsym);
xfwmPixmapLoad (screen_info, &screen_info->buttons[STICK_BUTTON][T_INACTIVE], theme,
- "stick-toggled-inactive", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "stick-toggled-inactive", colsym);
xfwmPixmapLoad (screen_info, &screen_info->buttons[STICK_BUTTON][T_PRESSED], theme,
- "stick-toggled-pressed", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "stick-toggled-pressed", colsym);
xfwmPixmapLoad (screen_info, &screen_info->buttons[MAXIMIZE_BUTTON][T_ACTIVE], theme,
- "maximize-toggled-active", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "maximize-toggled-active", colsym);
xfwmPixmapLoad (screen_info, &screen_info->buttons[MAXIMIZE_BUTTON][T_INACTIVE], theme,
- "maximize-toggled-inactive", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "maximize-toggled-inactive", colsym);
xfwmPixmapLoad (screen_info, &screen_info->buttons[MAXIMIZE_BUTTON][T_PRESSED], theme,
- "maximize-toggled-pressed", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "maximize-toggled-pressed", colsym);
xfwmPixmapLoad (screen_info, &screen_info->title[TITLE_1][ACTIVE], theme,
- "title-1-active", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "title-1-active", colsym);
xfwmPixmapLoad (screen_info, &screen_info->title[TITLE_1][INACTIVE], theme,
- "title-1-inactive", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "title-1-inactive", colsym);
xfwmPixmapLoad (screen_info, &screen_info->title[TITLE_2][ACTIVE], theme,
- "title-2-active", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "title-2-active", colsym);
xfwmPixmapLoad (screen_info, &screen_info->title[TITLE_2][INACTIVE], theme,
- "title-2-inactive", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "title-2-inactive", colsym);
xfwmPixmapLoad (screen_info, &screen_info->title[TITLE_3][ACTIVE], theme,
- "title-3-active", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "title-3-active", colsym);
xfwmPixmapLoad (screen_info, &screen_info->title[TITLE_3][INACTIVE], theme,
- "title-3-inactive", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "title-3-inactive", colsym);
xfwmPixmapLoad (screen_info, &screen_info->title[TITLE_4][ACTIVE], theme,
- "title-4-active", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "title-4-active", colsym);
xfwmPixmapLoad (screen_info, &screen_info->title[TITLE_4][INACTIVE], theme,
- "title-4-inactive", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "title-4-inactive", colsym);
xfwmPixmapLoad (screen_info, &screen_info->title[TITLE_5][ACTIVE], theme,
- "title-5-active", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "title-5-active", colsym);
xfwmPixmapLoad (screen_info, &screen_info->title[TITLE_5][INACTIVE], theme,
- "title-5-inactive", colsym, XPM_COLOR_SYMBOL_SIZE);
+ "title-5-inactive", colsym);
screen_info->box_gc = createGC (screen_info, "#FFFFFF", GXxor, NULL, 2, TRUE);
diff --git a/themes/moheli/title-1-inactive.xpm b/themes/moheli/title-1-inactive.xpm
index 5bd0d6788..bcbe6ffcc 100644
--- a/themes/moheli/title-1-inactive.xpm
+++ b/themes/moheli/title-1-inactive.xpm
@@ -29,4 +29,4 @@ static char * title_1_inactive_xpm[] = {
"@@@@",
"@@@@",
"@@@@",
-"@@@@};
+"@@@@"};
diff --git a/themes/moheli/title-3-inactive.xpm b/themes/moheli/title-3-inactive.xpm
index 72a31e68f..b250ff14e 100644
--- a/themes/moheli/title-3-inactive.xpm
+++ b/themes/moheli/title-3-inactive.xpm
@@ -29,4 +29,4 @@ static char * title_1_inactive_xpm[] = {
"@@@@",
"@@@@",
"@@@@",
-"@@@@};
+"@@@@"};