1 #include "cwmcc_internal.h"
9 /* this just isn't used...
10 static gboolean get(Window win, Atom prop, Atom type, int size,
11 guchar **data, gulong num)
18 gulong ret_items, bytes_left;
19 long num32 = 32 / size * num; /\* num in 32-bit elements *\/
21 res = XGetWindowProperty(cwmcc_display, win, prop, 0l, num32,
22 FALSE, type, &ret_type, &ret_size,
23 &ret_items, &bytes_left, &xdata);
24 if (res == Success && ret_items && xdata) {
25 if (ret_size == size && ret_items >= num) {
26 *data = g_memdup(xdata, num * (size / 8));
35 static gboolean get_prealloc(Window win, Atom prop, Atom type, int size,
36 guchar *data, gulong num)
43 gulong ret_items, bytes_left;
44 long num32 = 32 / size * num; /* num in 32-bit elements */
46 res = XGetWindowProperty(cwmcc_display, win, prop, 0l, num32,
47 FALSE, type, &ret_type, &ret_size,
48 &ret_items, &bytes_left, &xdata);
49 if (res == Success && ret_items && xdata) {
50 if (ret_size == size && ret_items >= num) {
52 for (i = 0; i < num; ++i)
58 ((guint16*)data)[i] = ((guint16*)xdata)[i];
61 ((guint32*)data)[i] = ((guint32*)xdata)[i];
64 g_assert_not_reached(); /* unhandled size */
73 static gboolean get_all(Window win, Atom prop, Atom type, int size,
74 guchar **data, gulong *num)
81 gulong ret_items, bytes_left;
83 res = XGetWindowProperty(cwmcc_display, win, prop, 0l, G_MAXLONG,
84 FALSE, type, &ret_type, &ret_size,
85 &ret_items, &bytes_left, &xdata);
87 if (ret_size == size && ret_items > 0) {
88 *data = g_memdup(xdata, ret_items * (size / 8));
97 static gboolean get_stringlist(Window win, Atom prop, char ***list, int *nstr)
100 gboolean ret = FALSE;
102 if (XGetTextProperty(cwmcc_display, win, &tprop, prop) && tprop.nitems) {
103 if (XTextPropertyToStringList(&tprop, list, nstr))
110 gboolean prop_get32(Window win, Atom prop, Atom type, gulong *ret)
112 return get_prealloc(win, prop, type, 32, (guchar*)ret, 1);
115 gboolean prop_get_array32(Window win, Atom prop, Atom type, gulong **ret,
118 return get_all(win, prop, type, 32, (guchar**)ret, nret);
121 gboolean prop_get_string_locale(Window win, Atom prop, char **data)
126 if (get_stringlist(win, prop, &list, &nstr) && nstr) {
127 *data = g_locale_to_utf8(list[0], -1, NULL, NULL, NULL);
128 XFreeStringList(list);
129 if (data) return TRUE;
134 gboolean prop_get_string_utf(Window win, Atom prop, Atom type, char **ret)
139 if (get_all(win, prop, type, 8, (guchar**)&raw, &num)) {
140 *ret = g_strdup(raw); /* grab the first string from the list */
147 gboolean prop_get_strings_utf(Window win, Atom prop, Atom type, char ***ret)
152 if (get_all(win, prop, type, 8, (guchar**)&raw, &num)) {
153 *ret = g_new(char*, num + 1);
154 (*ret)[num] = NULL; /* null terminated list */
157 for (i = 0; i < num; ++i) {
158 (*ret)[i] = g_strdup(p);
167 gboolean prop_get_strings_locale(Window win, Atom prop, Atom type,char ***ret){
171 if (get_all(win, prop, type, 8, (guchar**)&raw, &num)) {
172 *ret = g_new(char*, num + 1);
173 (*ret)[num] = NULL; /* null terminated list */
176 for (i = 0; i < num; ++i) {
177 (*ret)[i] = g_locale_to_utf8(p, -1, NULL, NULL, NULL);
178 /* make sure translation did not fail */
180 g_strfreev(*ret); /* free what we did so far */
181 break; /* the force is not strong with us */
192 void prop_set_strings_utf(Window win, Atom prop, Atom type, char **strs)
197 str = g_string_sized_new(0);
198 for (i = 0; strs[i]; ++i) {
199 str = g_string_append(str, strs[i]);
200 str = g_string_append_c(str, '\0');
202 XChangeProperty(cwmcc_display, win, prop, type, 8,
203 PropModeReplace, (guchar*)str->str, str->len);
206 void prop_erase(Window win, Atom prop)
208 XDeleteProperty(cwmcc_display, win, prop);