3 * Messing with X atom properties
5 * (c) 2007 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of the Edgeware X tools collection.
12 * X tools is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * X tools is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with X tools; if not, write to the Free Software Foundation,
24 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 /*----- Header files ------------------------------------------------------*/
32 #include <X11/Xatom.h>
36 /*----- Main code ---------------------------------------------------------*/
38 /* --- @xatom_set@ --- *
40 * Arguments: @Display *d@ = pointer to display
41 * @Window w@ = window to set
42 * @Atom p@ = property to set
43 * @Atom a@ = atom property value
47 * Use: Sets an atom property on a particular window.
50 void xatom_set(Display
*d
, Window w
, Atom p
, Atom a
)
52 XChangeProperty(d
, w
, p
, XA_ATOM
, 32, PropModeReplace
,
53 (unsigned char *)&a
, 1);
57 /* --- @xatom_get@ --- *
59 * Arguments: @Display *d@ = pointer to display
60 * @Window w@ = window to set
61 * @Atom p@ = property to read
63 * Returns: Atom which is the value of the property.
65 * Use: Reads an atom property from a particular window. The value
66 * @None@ is returned if there is no atom value.
69 Atom
xatom_get(Display
*d
, Window w
, Atom p
)
72 unsigned long n
, left
;
76 /* --- Fetch the property value --- */
78 if (XGetWindowProperty(d
, w
, p
, /* Display, window, property */
79 0, 64, /* Offset, length (both in words) */
80 False
, /* Delete after return? */
81 XA_ATOM
, /* Data format type */
82 &type
, &fmt
, /* Actual type and format */
83 &n
, &left
, /* Amount read, and bytes left */
84 &buf
) /* Where to put the buffer */
90 /* --- OK, get the atom and return --- *
92 * This assumes that atoms are 32-bit things. This may not be the case.
93 * That's a right pain, actually. It looks as if Xlib is trying to do the
94 * right thing, so I'll go with that rather than trying to do anything
95 * clever. This is actually a bit of a poor interface.
103 /* --- @xatom_delete@ --- *
105 * Arguments: @Display *d@ = pointer to display
106 * @Window w@ = window containing atom
107 * @Atom p@ = property to delete
111 * Use: Removes a property from a window.
114 void xatom_delete(Display
*d
, Window w
, Atom p
)
116 XDeleteProperty(d
, w
, p
);
120 /* --- @xatom_wait@ --- *
122 * Arguments: @Display *d@ = pointer to display
123 * @Window w@ = window to watch
124 * @Atom p@ = property to fetch
125 * @const Atom *aa@ = pointer to vector of atoms
126 * @size_t n@ = numer of atoms in vector
128 * Returns: The matching atom.
130 * Use: Waits for the given property on the window to match one of
134 Atom
xatom_wait(Display
*d
, Window w
, Atom p
, const Atom
*aa
, size_t n
)
140 XSelectInput(d
, w
, PropertyChangeMask
);
142 a
= xatom_get(d
, w
, p
);
145 for (i
= 0; i
< n
; i
++)
146 if (a
== aa
[i
]) return (a
);
148 do XNextEvent(d
, &event
); while (event
.type
!= PropertyNotify
);
152 /*----- That's all, folks -------------------------------------------------*/