Skip to content
Snippets Groups Projects
pixmap.c 1.95 KiB
Newer Older
Olivier Fourdan's avatar
Olivier Fourdan committed
/*
	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; You may only use version 2 of the License,
	you have no option to use any other version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

        oroborus - (c) 2001 Ken Lynch
        xfwm4    - (c) 2002 Olivier Fourdan

 */

#ifdef HAVE_CONFIG_H
#  include "config.h"
#endif

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
Olivier Fourdan's avatar
Olivier Fourdan committed
#include "pixmap.h"
Olivier Fourdan's avatar
Olivier Fourdan committed
#include "debug.h"

gboolean loadPixmap(Display * dpy, MyPixmap * pm, gchar *dir, gchar *file, XpmColorSymbol * cs, gint n)
Olivier Fourdan's avatar
Olivier Fourdan committed
{
    gchar filename[512];
    XpmAttributes attr;

    DBG("entering loadPixmap\n");

    pm->pixmap = None;
    pm->mask = None;
    pm->width = 1;
    pm->height = 1;
    g_snprintf(filename, sizeof(filename), "%s/%s", dir, file);
    attr.colorsymbols = cs;
    attr.numsymbols = n;
    attr.valuemask = XpmSize;
    if(n > 0 && cs)
Olivier Fourdan's avatar
Olivier Fourdan committed
        attr.valuemask = attr.valuemask | XpmColorSymbols;
    }
    if(XpmReadFileToPixmap (dpy, XDefaultRootWindow(dpy), filename, &pm->pixmap, &pm->mask, &attr))
    {
Olivier Fourdan's avatar
Olivier Fourdan committed
        return FALSE;
Olivier Fourdan's avatar
Olivier Fourdan committed
    pm->width = attr.width;
    pm->height = attr.height;
    XpmFreeAttributes(&attr);
    return TRUE;
}

void freePixmap(Display * dpy, MyPixmap * pm)
{
    DBG("entering freePixmap\n");

    if(pm->pixmap != None)
Olivier Fourdan's avatar
Olivier Fourdan committed
        XFreePixmap(dpy, pm->pixmap);
Olivier Fourdan's avatar
Olivier Fourdan committed
    if(pm->mask != None)
    {
Olivier Fourdan's avatar
Olivier Fourdan committed
    }
}