]>
Dogcows Code - chaz/openbox/blob - prop.c
1c6ab8cc930c06152c592311d0b9704473032774
1 #include "cwmcc_internal.h"
10 /* this just isn't used...
11 static gboolean get(Window win, Atom prop, Atom type, int size,
12 guchar **data, gulong num)
19 gulong ret_items, bytes_left;
20 long num32 = 32 / size * num; /\* num in 32-bit elements *\/
22 res = XGetWindowProperty(cwmcc_display, win, prop, 0l, num32,
23 FALSE, type, &ret_type, &ret_size,
24 &ret_items, &bytes_left, &xdata);
25 if (res == Success && ret_items && xdata) {
26 if (ret_size == size && ret_items >= num) {
27 *data = g_memdup(xdata, num * (size / 8));
36 static gboolean
get_prealloc(Window win
, Atom prop
, Atom type
, int size
,
37 guchar
*data
, gulong num
)
44 gulong ret_items
, bytes_left
;
45 long num32
= 32 / size
* num
; /* num in 32-bit elements */
47 res
= XGetWindowProperty(cwmcc_display
, win
, prop
, 0l, num32
,
48 FALSE
, type
, &ret_type
, &ret_size
,
49 &ret_items
, &bytes_left
, &xdata
);
50 if (res
== Success
&& ret_items
&& xdata
) {
51 if (ret_size
== size
&& ret_items
>= num
) {
53 for (i
= 0; i
< num
; ++i
)
59 ((guint16
*)data
)[i
] = ((guint16
*)xdata
)[i
];
62 ((guint32
*)data
)[i
] = ((guint32
*)xdata
)[i
];
65 g_assert_not_reached(); /* unhandled size */
74 static gboolean
get_all(Window win
, Atom prop
, Atom type
, int size
,
75 guchar
**data
, gulong
*num
)
82 gulong ret_items
, bytes_left
;
84 res
= XGetWindowProperty(cwmcc_display
, win
, prop
, 0l, G_MAXLONG
,
85 FALSE
, type
, &ret_type
, &ret_size
,
86 &ret_items
, &bytes_left
, &xdata
);
88 if (ret_size
== size
&& ret_items
> 0) {
89 *data
= g_malloc(ret_items
* (size
/ 8) + sizeof(guchar
*));
90 g_memmove(*data
, xdata
, ret_items
* (size
/ 8));
91 data
[ret_items
* (size
/ 8)] = NULL
;
100 static gboolean
get_stringlist(Window win
, Atom prop
, char ***list
, int *nstr
)
103 gboolean ret
= FALSE
;
105 if (XGetTextProperty(cwmcc_display
, win
, &tprop
, prop
) && tprop
.nitems
) {
106 if (XTextPropertyToStringList(&tprop
, list
, nstr
))
113 gboolean
prop_get32(Window win
, Atom prop
, Atom type
, gulong
*ret
)
115 return get_prealloc(win
, prop
, type
, 32, (guchar
*)ret
, 1);
118 gboolean
prop_get_array32(Window win
, Atom prop
, Atom type
, gulong
**ret
,
121 return get_all(win
, prop
, type
, 32, (guchar
**)ret
, nret
);
124 gboolean
prop_get_string_locale(Window win
, Atom prop
, char **data
)
129 if (get_stringlist(win
, prop
, &list
, &nstr
) && nstr
) {
130 *data
= g_locale_to_utf8(list
[0], -1, NULL
, NULL
, NULL
);
131 XFreeStringList(list
);
132 if (data
) return TRUE
;
137 gboolean
prop_get_string_utf8(Window win
, Atom prop
, char **ret
)
142 if (get_all(win
, prop
, CWMCC_ATOM(type
, utf8
), 8, (guchar
**)&raw
, &num
)) {
143 *ret
= g_strdup(raw
); /* grab the first string from the list */
150 gboolean
prop_get_strings_utf8(Window win
, Atom prop
, char ***ret
)
155 if (get_all(win
, prop
, CWMCC_ATOM(type
, utf8
), 8, (guchar
**)&raw
, &num
)) {
156 *ret
= g_new(char*, num
+ 1);
157 (*ret
)[num
] = NULL
; /* null terminated list */
160 for (i
= 0; i
< num
; ++i
) {
161 (*ret
)[i
] = g_strdup(p
);
170 gboolean
prop_get_strings_locale(Window win
, Atom prop
, char ***ret
)
175 if (get_all(win
, prop
, CWMCC_ATOM(type
, string
), 8, (guchar
**)&raw
, &num
)){
176 *ret
= g_new(char*, num
+ 1);
177 (*ret
)[num
] = NULL
; /* null terminated list */
180 for (i
= 0; i
< num
; ++i
) {
181 (*ret
)[i
] = g_locale_to_utf8(p
, -1, NULL
, NULL
, NULL
);
182 /* make sure translation did not fail */
184 g_strfreev(*ret
); /* free what we did so far */
185 break; /* the force is not strong with us */
196 void prop_set_strings_utf8(Window win
, Atom prop
, char **strs
)
201 str
= g_string_sized_new(0);
202 for (i
= 0; strs
[i
]; ++i
) {
203 str
= g_string_append(str
, strs
[i
]);
204 str
= g_string_append_c(str
, '\0');
206 XChangeProperty(cwmcc_display
, win
, prop
, CWMCC_ATOM(type
, utf8
), 8,
207 PropModeReplace
, (guchar
*)str
->str
, str
->len
);
210 void prop_erase(Window win
, Atom prop
)
212 XDeleteProperty(cwmcc_display
, win
, prop
);
This page took 0.039275 seconds and 3 git commands to generate.