xwait, xtell: Add short help options!
[xtoys] / xatom.c
CommitLineData
5ac66f5c 1/* -*-c-*-
2 *
47747dbe 3 * $Id: xatom.c,v 1.2 2004/04/08 01:36:29 mdw Exp $
5ac66f5c 4 *
5 * Set and fetch X atom properties
6 *
7 * (c) 1999 Straylight/Edgeware
8 */
9
10/*----- Licensing notice --------------------------------------------------*
11 *
12 * This file is part of the Edgeware X tools collection.
13 *
14 * X tools is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * X tools is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with X tools; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 */
28
5ac66f5c 29/*----- Header files ------------------------------------------------------*/
30
31#include <stdio.h>
32#include <stdlib.h>
33#include <string.h>
34
35#include <X11/Xatom.h>
36#include <X11/Xlib.h>
37#include <X11/Xutil.h>
38
39/*----- Main code ---------------------------------------------------------*/
40
41/* --- @xatom_set@ --- *
42 *
43 * Arguments: @Display *d@ = pointer to display
44 * @Window w@ = window to set
45 * @Atom p@ = property to set
46 * @Atom a@ = atom property value
47 *
48 * Returns: ---
49 *
50 * Use: Sets an atom property on a particular window.
51 */
52
53void xatom_set(Display *d, Window w, Atom p, Atom a)
54{
55 XChangeProperty(d, w, p, XA_ATOM, 32, PropModeReplace,
56 (unsigned char *)&a, 1);
57}
58
59/* --- @xatom_get@ --- *
60 *
61 * Arguments: @Display *d@ = pointer to display
62 * @Window w@ = window to set
63 * @Atom p@ = property to read
64 *
65 * Returns: Atom which is the value of the property.
66 *
67 * Use: Reads an atom property from a particular window. The value
68 * @None@ is returned if there is no atom value.
69 */
70
71Atom xatom_get(Display *d, Window w, Atom p)
72{
73 Atom type, v;
74 unsigned long n, left;
75 int fmt;
76 unsigned char *buf;
77
78 /* --- Fetch the property value --- */
79
80 if (XGetWindowProperty(d, w, p, /* Display, window, property */
81 0, 64, /* Offset, length (both in words) */
82 False, /* Delete after return? */
83 XA_ATOM, /* Data format type */
84 &type, &fmt, /* Actual type and format */
85 &n, &left, /* Amount read, and bytes left */
86 &buf) /* Where to put the buffer */
87 != Success ||
88 type != XA_ATOM ||
89 n < 1 || fmt < 32)
90 return (None);
91
92 /* --- OK, get the atom and return --- *
93 *
94 * This assumes that atoms are 32-bit things. This may not be the case.
95 * That's a right pain, actually. It looks as if Xlib is trying to do the
96 * right thing, so I'll go with that rather than trying to do anything
97 * clever. This is actually a bit of a poor interface.
98 */
99
100 v = *(Atom *)buf;
101 XFree(buf);
102 return (v);
103}
104
105/*----- That's all, folks -------------------------------------------------*/