From: mdw Date: Fri, 20 Aug 1999 07:28:44 +0000 (+0000) Subject: New source file for manipulating atom-valued window properties. X-Git-Tag: 1.2.6~6 X-Git-Url: https://git.distorted.org.uk/~mdw/xtoys/commitdiff_plain/5ac66f5c6c2a9f1ebf035e9deb4a718d117fe3f8 New source file for manipulating atom-valued window properties. --- diff --git a/xatom.c b/xatom.c new file mode 100644 index 0000000..572778c --- /dev/null +++ b/xatom.c @@ -0,0 +1,113 @@ +/* -*-c-*- + * + * $Id: xatom.c,v 1.1 1999/08/20 07:28:44 mdw Exp $ + * + * Set and fetch X atom properties + * + * (c) 1999 Straylight/Edgeware + */ + +/*----- Licensing notice --------------------------------------------------* + * + * This file is part of the Edgeware X tools collection. + * + * X tools 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; either version 2 of the License, or + * (at your option) any later version. + * + * X tools 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 X tools; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +/*----- Revision history --------------------------------------------------* + * + * $Log: xatom.c,v $ + * Revision 1.1 1999/08/20 07:28:44 mdw + * New source file for manipulating atom-valued window properties. + * + */ + +/*----- Header files ------------------------------------------------------*/ + +#include +#include +#include + +#include +#include +#include + +/*----- Main code ---------------------------------------------------------*/ + +/* --- @xatom_set@ --- * + * + * Arguments: @Display *d@ = pointer to display + * @Window w@ = window to set + * @Atom p@ = property to set + * @Atom a@ = atom property value + * + * Returns: --- + * + * Use: Sets an atom property on a particular window. + */ + +void xatom_set(Display *d, Window w, Atom p, Atom a) +{ + XChangeProperty(d, w, p, XA_ATOM, 32, PropModeReplace, + (unsigned char *)&a, 1); +} + +/* --- @xatom_get@ --- * + * + * Arguments: @Display *d@ = pointer to display + * @Window w@ = window to set + * @Atom p@ = property to read + * + * Returns: Atom which is the value of the property. + * + * Use: Reads an atom property from a particular window. The value + * @None@ is returned if there is no atom value. + */ + +Atom xatom_get(Display *d, Window w, Atom p) +{ + Atom type, v; + unsigned long n, left; + int fmt; + unsigned char *buf; + + /* --- Fetch the property value --- */ + + if (XGetWindowProperty(d, w, p, /* Display, window, property */ + 0, 64, /* Offset, length (both in words) */ + False, /* Delete after return? */ + XA_ATOM, /* Data format type */ + &type, &fmt, /* Actual type and format */ + &n, &left, /* Amount read, and bytes left */ + &buf) /* Where to put the buffer */ + != Success || + type != XA_ATOM || + n < 1 || fmt < 32) + return (None); + + /* --- OK, get the atom and return --- * + * + * This assumes that atoms are 32-bit things. This may not be the case. + * That's a right pain, actually. It looks as if Xlib is trying to do the + * right thing, so I'll go with that rather than trying to do anything + * clever. This is actually a bit of a poor interface. + */ + + v = *(Atom *)buf; + XFree(buf); + return (v); +} + +/*----- That's all, folks -------------------------------------------------*/ diff --git a/xatom.h b/xatom.h new file mode 100644 index 0000000..317842a --- /dev/null +++ b/xatom.h @@ -0,0 +1,85 @@ +/* -*-c-*- + * + * $Id: xatom.h,v 1.1 1999/08/20 07:28:44 mdw Exp $ + * + * Set and fetch X atom properties + * + * (c) 1999 Straylight/Edgeware + */ + +/*----- Licensing notice --------------------------------------------------* + * + * This file is part of the Edgeware X tools collection. + * + * X tools 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; either version 2 of the License, or + * (at your option) any later version. + * + * X tools 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 X tools; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +/*----- Revision history --------------------------------------------------* + * + * $Log: xatom.h,v $ + * Revision 1.1 1999/08/20 07:28:44 mdw + * New source file for manipulating atom-valued window properties. + * + */ + +#ifndef XATOM_H +#define XATOM_H + +#ifdef __cplusplus + extern "C" { +#endif + +/*----- Header files ------------------------------------------------------*/ + +#include +#include + +/*----- Functions provided ------------------------------------------------*/ + +/* --- @xatom_set@ --- * + * + * Arguments: @Display *d@ = pointer to display + * @Window w@ = window to set + * @Atom p@ = property to set + * @Atom a@ = atom property value + * + * Returns: --- + * + * Use: Sets an atom property on a particular window. + */ + +extern void xatom_set(Display */*d*/, Window /*w*/, Atom /*p*/, Atom /*a*/); + +/* --- @xatom_get@ --- * + * + * Arguments: @Display *d@ = pointer to display + * @Window w@ = window to set + * @Atom p@ = property to read + * + * Returns: Atom which is the value of the property. + * + * Use: Reads an atom property from a particular window. The value + * @None@ is returned if there is no atom value. + */ + +extern Atom xatom_get(Display */*d*/, Window /*w*/, Atom /*p*/); + +/*----- That's all, folks -------------------------------------------------*/ + +#ifdef __cplusplus + } +#endif + +#endif