]>
Dogcows Code - chaz/openbox/blob - cwmcc/prop.c
1 #include "cwmcc_internal.h"
8 /* this just isn't used...
9 static gboolean get(Window win, Atom prop, Atom type, int size,
10 guchar **data, gulong num)
17 gulong ret_items, bytes_left;
18 long num32 = 32 / size * num; /\* num in 32-bit elements *\/
20 res = XGetWindowProperty(cwmcc_display, win, prop, 0l, num32,
21 FALSE, type, &ret_type, &ret_size,
22 &ret_items, &bytes_left, &xdata);
23 if (res == Success && ret_items && xdata) {
24 if (ret_size == size && ret_items >= num) {
25 *data = g_memdup(xdata, num * (size / 8));
34 static gboolean
get_prealloc(Window win
, Atom prop
, Atom type
, int size
,
35 guchar
*data
, gulong num
)
42 gulong ret_items
, bytes_left
;
43 long num32
= 32 / size
* num
; /* num in 32-bit elements */
45 res
= XGetWindowProperty(cwmcc_display
, win
, prop
, 0l, num32
,
46 FALSE
, type
, &ret_type
, &ret_size
,
47 &ret_items
, &bytes_left
, &xdata
);
48 if (res
== Success
&& ret_items
&& xdata
) {
49 if (ret_size
== size
&& ret_items
>= num
) {
51 for (i
= 0; i
< num
; ++i
)
57 ((guint16
*)data
)[i
] = ((guint16
*)xdata
)[i
];
60 ((guint32
*)data
)[i
] = ((guint32
*)xdata
)[i
];
63 g_assert_not_reached(); /* unhandled size */
72 static gboolean
get_all(Window win
, Atom prop
, Atom type
, int size
,
73 guchar
**data
, gulong
*num
)
80 gulong ret_items
, bytes_left
;
82 res
= XGetWindowProperty(cwmcc_display
, win
, prop
, 0l, G_MAXLONG
,
83 FALSE
, type
, &ret_type
, &ret_size
,
84 &ret_items
, &bytes_left
, &xdata
);
86 if (ret_size
== size
&& ret_items
> 0) {
87 *data
= g_memdup(xdata
, ret_items
* (size
/ 8));
96 static gboolean
get_stringlist(Window win
, Atom prop
, char ***list
, int *nstr
)
101 if (XGetTextProperty(cwmcc_display
, win
, &tprop
, prop
) && tprop
.nitems
) {
102 if (XTextPropertyToStringList(&tprop
, list
, nstr
))
109 gboolean
cwmcc_prop_get32(Window win
, Atom prop
, Atom type
, gulong
*ret
)
111 return get_prealloc(win
, prop
, type
, 32, (guchar
*)ret
, 1);
114 gboolean
cwmcc_prop_get_array32(Window win
, Atom prop
, Atom type
, gulong
**ret
,
117 return get_all(win
, prop
, type
, 32, (guchar
**)ret
, nret
);
120 gboolean
cwmcc_prop_get_string_locale(Window win
, Atom prop
, char **data
)
125 if (get_stringlist(win
, prop
, &list
, &nstr
) && nstr
) {
126 *data
= g_locale_to_utf8(list
[0], -1, NULL
, NULL
, NULL
);
127 XFreeStringList(list
);
128 if (data
) return TRUE
;
133 gboolean
cwmcc_prop_get_string_utf8(Window win
, Atom prop
, char **ret
)
138 if (get_all(win
, prop
, CWMCC_ATOM(type
, utf8
), 8, (guchar
**)&raw
, &num
)) {
139 *ret
= g_strdup(raw
); /* grab the first string from the list */
146 gboolean
cwmcc_prop_get_strings_utf8(Window win
, Atom prop
, char ***ret
)
151 if (get_all(win
, prop
, CWMCC_ATOM(type
, utf8
), 8, (guchar
**)&raw
, &num
)) {
152 *ret
= g_new(char*, num
+ 1);
153 (*ret
)[num
] = NULL
; /* null terminated list */
156 for (i
= 0; i
< num
; ++i
) {
157 (*ret
)[i
] = g_strdup(p
);
166 gboolean
cwmcc_prop_get_strings_locale(Window win
, Atom prop
, char ***ret
)
171 if (get_all(win
, prop
, CWMCC_ATOM(type
, string
), 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 cwmcc_prop_set32(Window win
, Atom prop
, Atom type
, gulong val
)
194 XChangeProperty(cwmcc_display
, win
, prop
, type
, 32, PropModeReplace
,
198 void cwmcc_prop_set_array32(Window win
, Atom prop
, Atom type
,
199 gulong
*val
, gulong num
)
201 XChangeProperty(cwmcc_display
, win
, prop
, type
, 32, PropModeReplace
,
205 void cwmcc_prop_set_string_utf8(Window win
, Atom prop
, char *val
)
207 XChangeProperty(cwmcc_display
, win
, prop
, CWMCC_ATOM(type
, utf8
), 8,
208 PropModeReplace
, (guchar
*)val
, strlen(val
));
211 void cwmcc_prop_set_strings_utf8(Window win
, Atom prop
, char **strs
)
216 str
= g_string_sized_new(0);
217 for (i
= 0; strs
[i
]; ++i
) {
218 str
= g_string_append(str
, strs
[i
]);
219 str
= g_string_append_c(str
, '\0');
221 XChangeProperty(cwmcc_display
, win
, prop
, CWMCC_ATOM(type
, utf8
), 8,
222 PropModeReplace
, (guchar
*)str
->str
, str
->len
);
225 void cwmcc_prop_erase(Window win
, Atom prop
)
227 XDeleteProperty(cwmcc_display
, win
, prop
);
This page took 0.041515 seconds and 4 git commands to generate.