Renamed package to ion1, and made it conflict with package 'ion'.
[ion1.git] / src / property.c
blobe4724e30cd94132717f80ce184b549fa38c116b1
1 /*
2 * ion/property.c
4 * Copyright (c) Tuomo Valkonen 1999-2001.
5 * See the included file LICENSE for details.
6 */
8 #include <X11/Xmd.h>
9 #include <string.h>
11 #include "common.h"
12 #include "property.h"
13 #include "global.h"
16 int get_property(Display *dpy, Window win, Atom atom, Atom type,
17 long len, uchar **p)
19 Atom real_type;
20 int format;
21 ulong n, extra;
22 int status;
24 status=XGetWindowProperty(dpy, win, atom, 0L, len, False,
25 type, &real_type, &format, &n, &extra, p);
27 if(status!=Success || *p==NULL)
28 return -1;
30 if(n==0){
31 XFree((void*)*p);
32 return -1;
35 return n;
39 /* string
42 char *get_string_property(Window win, Atom a, int *nret)
44 char *p;
45 int n;
47 n=get_property(wglobal.dpy, win, a, XA_STRING, 100L, (uchar**)&p);
49 if(nret!=NULL)
50 *nret=n;
52 return (n<=0 ? NULL : p);
56 void set_string_property(Window win, Atom a, const char *value)
58 if(value==NULL){
59 XDeleteProperty(wglobal.dpy, win, a);
60 }else{
61 XChangeProperty(wglobal.dpy, win, a, XA_STRING,
62 8, PropModeReplace, (uchar*)value, strlen(value));
67 /* integer
70 bool get_integer_property(Window win, Atom a, int *vret)
72 CARD32 *p=NULL;
74 if(get_property(wglobal.dpy, win, a, XA_INTEGER, 1L, (uchar**)&p)<=0)
75 return FALSE;
77 *vret=(CARD32)*p;
79 XFree((void*)p);
81 return TRUE;
85 void set_integer_property(Window win, Atom a, int value)
87 CARD32 data[2];
89 data[0]=value;
91 XChangeProperty(wglobal.dpy, win, a, XA_INTEGER,
92 32, PropModeReplace, (uchar*)data, 1);
96 /* WM_STATE
99 bool get_win_state(Window win, int *state)
101 CARD32 *p=NULL;
103 if(get_property(wglobal.dpy, win, wglobal.atom_wm_state,
104 wglobal.atom_wm_state, 2L, (uchar**)&p)<=0)
105 return FALSE;
107 *state=(CARD32)*p;
109 XFree((void*)p);
111 return TRUE;
115 void set_win_state(Window win, int state)
117 CARD32 data[2];
119 data[0]=state;
120 data[1]=None;
122 XChangeProperty(wglobal.dpy, win,
123 wglobal.atom_wm_state, wglobal.atom_wm_state,
124 32, PropModeReplace, (uchar*)data, 2);