proper cwmcc_ prefixing.

add gulong *num and gulong num to funciton params where needed. cant use 0 to terminate an array of numbers
This commit is contained in:
Dana Jansens 2003-04-12 21:02:41 +00:00
parent 4d510a8a92
commit fd5784c082
5 changed files with 159 additions and 142 deletions

View file

@ -6,32 +6,26 @@
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <string.h> #include <string.h>
void cwmcc_client_get_protocols(Window win, Atom **protocols) void cwmcc_client_get_protocols(Window win, Atom **protocols, gulong *num)
{ {
gulong num; if (!cwmcc_prop_get_array32(win, CWMCC_ATOM(client, wm_protocols),
CWMCC_ATOM(type, atom), protocols, num)) {
if (!prop_get_array32(win, CWMCC_ATOM(client, wm_protocols),
CWMCC_ATOM(type, atom), protocols, &num)) {
g_warning("Failed to read WM_PROTOCOLS from 0x%lx", win); g_warning("Failed to read WM_PROTOCOLS from 0x%lx", win);
*protocols = NULL; *protocols = NULL;
*num = 0;
} }
} }
void cwmcc_client_set_protocols(Window win, Atom *protocols) void cwmcc_client_set_protocols(Window win, Atom *protocols, gulong num)
{ {
gulong n; cwmcc_prop_set_array32(win, CWMCC_ATOM(client, wm_state),
Atom *a; CWMCC_ATOM(type, atom), protocols, num);
for (a = protocols, n = 0; *a; ++a, ++n);
XChangeProperty(cwmcc_display, win, CWMCC_ATOM(client, wm_state),
CWMCC_ATOM(type, atom), 32, PropModeReplace,
(guchar*)protocols, n);
} }
void cwmcc_client_get_wm_state(Window win, gulong *state) void cwmcc_client_get_wm_state(Window win, gulong *state)
{ {
if (!prop_get32(win, CWMCC_ATOM(client, wm_state), if (!cwmcc_prop_get32(win, CWMCC_ATOM(client, wm_state),
CWMCC_ATOM(client, wm_state), state)) { CWMCC_ATOM(client, wm_state), state)) {
g_warning("Failed to read WM_STATE from 0x%lx", win); g_warning("Failed to read WM_STATE from 0x%lx", win);
*state = NormalState; *state = NormalState;
} }
@ -39,15 +33,16 @@ void cwmcc_client_get_wm_state(Window win, gulong *state)
void cwmcc_client_set_wm_state(Window win, gulong state) void cwmcc_client_set_wm_state(Window win, gulong state)
{ {
XChangeProperty(cwmcc_display, win, CWMCC_ATOM(client, wm_state), cwmcc_prop_set32(win, CWMCC_ATOM(client, wm_state),
CWMCC_ATOM(client, wm_state), 32, PropModeReplace, CWMCC_ATOM(client, wm_state), state);
(guchar*)&state, 1);
} }
void cwmcc_client_get_name(Window win, char **name) void cwmcc_client_get_name(Window win, char **name)
{ {
if (!prop_get_string_utf8(win, CWMCC_ATOM(client, net_wm_name), name)) if (!cwmcc_prop_get_string_utf8(win, CWMCC_ATOM(client, net_wm_name),
if (!prop_get_string_locale(win, CWMCC_ATOM(client, wm_name), name)) { name))
if (!cwmcc_prop_get_string_locale(win, CWMCC_ATOM(client, wm_name),
name)) {
g_warning("Failed to read a name from 0x%lx", win); g_warning("Failed to read a name from 0x%lx", win);
*name = g_strdup("Unnamed Window"); *name = g_strdup("Unnamed Window");
} }
@ -55,16 +50,15 @@ void cwmcc_client_get_name(Window win, char **name)
void cwmcc_client_set_name(Window win, char *name) void cwmcc_client_set_name(Window win, char *name)
{ {
XChangeProperty(cwmcc_display, win, CWMCC_ATOM(client, net_wm_name), cwmcc_prop_set_string_utf8(win, CWMCC_ATOM(client, net_wm_name), name);
CWMCC_ATOM(type, utf8), 32, PropModeReplace,
(guchar*)name, strlen(name));
} }
void cwmcc_client_get_icon_name(Window win, char **name) void cwmcc_client_get_icon_name(Window win, char **name)
{ {
if (!prop_get_string_utf8(win, CWMCC_ATOM(client, net_wm_icon_name), name)) if (!cwmcc_prop_get_string_utf8(win, CWMCC_ATOM(client, net_wm_icon_name),
if (!prop_get_string_locale(win, name))
CWMCC_ATOM(client, wm_icon_name), name)) { if (!cwmcc_prop_get_string_locale(win,CWMCC_ATOM(client, wm_icon_name),
name)) {
g_warning("Failed to read an icon name from 0x%lx", win); g_warning("Failed to read an icon name from 0x%lx", win);
*name = g_strdup("Unnamed Window"); *name = g_strdup("Unnamed Window");
} }
@ -72,16 +66,14 @@ void cwmcc_client_get_icon_name(Window win, char **name)
void cwmcc_client_set_icon_name(Window win, char *name) void cwmcc_client_set_icon_name(Window win, char *name)
{ {
XChangeProperty(cwmcc_display, win, CWMCC_ATOM(client, net_wm_icon_name), cwmcc_prop_set_string_utf8(win, CWMCC_ATOM(client, net_wm_icon_name),name);
CWMCC_ATOM(type, utf8), 32, PropModeReplace,
(guchar*)name, strlen(name));
} }
void cwmcc_client_get_class(Window win, char **class, char **name) void cwmcc_client_get_class(Window win, char **class, char **name)
{ {
char **s; char **s;
if (!prop_get_strings_locale(win, CWMCC_ATOM(client, wm_class), &s)) { if (!cwmcc_prop_get_strings_locale(win, CWMCC_ATOM(client, wm_class), &s)){
g_warning("Failed to read WM_CLASS from 0x%lx", win); g_warning("Failed to read WM_CLASS from 0x%lx", win);
*class = g_strdup(""); *class = g_strdup("");
*name = g_strdup(""); *name = g_strdup("");
@ -104,8 +96,8 @@ void cwmcc_client_get_class(Window win, char **class, char **name)
void cwmcc_client_get_role(Window win, char **role) void cwmcc_client_get_role(Window win, char **role)
{ {
if (!prop_get_string_locale(win, if (!cwmcc_prop_get_string_locale(win, CWMCC_ATOM(client, wm_window_role),
CWMCC_ATOM(client, wm_window_role), role)) { role)) {
g_warning("Failed to read WM_WINDOW_ROLE from 0x%lx", win); g_warning("Failed to read WM_WINDOW_ROLE from 0x%lx", win);
*role = g_strdup(""); *role = g_strdup("");
} }
@ -115,8 +107,8 @@ void cwmcc_client_get_mwmhints(Window win, struct Cwmcc_MwmHints *hints)
{ {
gulong *l = NULL, num; gulong *l = NULL, num;
if (!prop_get_array32(win, CWMCC_ATOM(client, motif_wm_hints), if (!cwmcc_prop_get_array32(win, CWMCC_ATOM(client, motif_wm_hints),
CWMCC_ATOM(client, motif_wm_hints), &l, &num)) { CWMCC_ATOM(client, motif_wm_hints), &l, &num)){
g_warning("Failed to read Motif WM Hints from 0x%lx", win); g_warning("Failed to read Motif WM Hints from 0x%lx", win);
hints->flags = 0; hints->flags = 0;
} else if (num < 3) { } else if (num < 3) {
@ -132,8 +124,8 @@ void cwmcc_client_get_mwmhints(Window win, struct Cwmcc_MwmHints *hints)
void cwmcc_client_get_desktop(Window win, gulong *desk) void cwmcc_client_get_desktop(Window win, gulong *desk)
{ {
if (!prop_get32(win, CWMCC_ATOM(client, net_wm_desktop), if (!cwmcc_prop_get32(win, CWMCC_ATOM(client, net_wm_desktop),
CWMCC_ATOM(type, cardinal), desk)) { CWMCC_ATOM(type, cardinal), desk)) {
g_warning("Failed to read NET_WM_DESKTOP from 0x%lx", win); g_warning("Failed to read NET_WM_DESKTOP from 0x%lx", win);
*desk = 0; *desk = 0;
} }
@ -141,64 +133,49 @@ void cwmcc_client_get_desktop(Window win, gulong *desk)
void cwmcc_client_set_desktop(Window win, gulong desk) void cwmcc_client_set_desktop(Window win, gulong desk)
{ {
XChangeProperty(cwmcc_display, win, CWMCC_ATOM(client, net_wm_desktop), cwmcc_prop_set32(win, CWMCC_ATOM(client, net_wm_desktop),
CWMCC_ATOM(type, cardinal), 32, PropModeReplace, CWMCC_ATOM(type, cardinal), desk);
(guchar*)&desk, 1);
} }
void cwmcc_client_get_type(Window win, gulong **types) void cwmcc_client_get_type(Window win, gulong **types, gulong *num)
{ {
gulong num; if (!cwmcc_prop_get_array32(win, CWMCC_ATOM(client, net_wm_window_type),
CWMCC_ATOM(type, atom), types, num)) {
if (!prop_get_array32(win, CWMCC_ATOM(client, net_wm_window_type),
CWMCC_ATOM(type, atom), types, &num)) {
g_warning("Failed to read NET_WM_WINDOW_TYPE from 0x%lx", win); g_warning("Failed to read NET_WM_WINDOW_TYPE from 0x%lx", win);
*types = g_new(Atom, 2); *types = g_new(Atom, 1);
(*types)[0] = CWMCC_ATOM(data, net_wm_window_type_normal); (*types)[0] = CWMCC_ATOM(data, net_wm_window_type_normal);
(*types)[1] = 0; *num = 1;
} }
} }
void cwmcc_client_set_type(Window win, gulong *types) void cwmcc_client_set_type(Window win, gulong *types, gulong num)
{ {
gulong n; cwmcc_prop_set_array32(win, CWMCC_ATOM(client, net_wm_window_type),
gulong *t; CWMCC_ATOM(type, atom), types, num);
for (t = types, n = 0; *t; ++t, ++n);
XChangeProperty(cwmcc_display, win, CWMCC_ATOM(client, wm_state),
CWMCC_ATOM(type, atom), 32, PropModeReplace,
(guchar*)types, n);
} }
void cwmcc_client_get_state(Window win, gulong **states) void cwmcc_client_get_state(Window win, gulong **states, gulong *num)
{ {
gulong num; if (!cwmcc_prop_get_array32(win, CWMCC_ATOM(client, net_wm_state),
CWMCC_ATOM(type, atom), states, num)) {
if (!prop_get_array32(win, CWMCC_ATOM(client, net_wm_state),
CWMCC_ATOM(type, atom), states, &num)) {
g_warning("Failed to read NET_WM_STATE from 0x%lx", win); g_warning("Failed to read NET_WM_STATE from 0x%lx", win);
*states = g_new(Atom, 1); *states = NULL;
(*states)[0] = 0; *num = 0;
} }
} }
void cwmcc_client_set_state(Window win, gulong *states) void cwmcc_client_set_state(Window win, gulong *states, gulong num)
{ {
gulong n; cwmcc_prop_set_array32(win, CWMCC_ATOM(client, net_wm_state),
gulong *s; CWMCC_ATOM(type, atom), states, num);
for (s = states, n = 0; *s; ++s, ++n);
XChangeProperty(cwmcc_display, win, CWMCC_ATOM(client, wm_state),
CWMCC_ATOM(type, atom), 32, PropModeReplace,
(guchar*)states, n);
} }
void cwmcc_client_get_strut(Window win, int *l, int *t, int *r, int *b) void cwmcc_client_get_strut(Window win, int *l, int *t, int *r, int *b)
{ {
gulong *data = NULL, num; gulong *data = NULL, num;
if (!prop_get_array32(win, CWMCC_ATOM(client, net_wm_strut), if (!cwmcc_prop_get_array32(win, CWMCC_ATOM(client, net_wm_strut),
CWMCC_ATOM(type, cardinal), &data, &num)) { CWMCC_ATOM(type, cardinal), &data, &num)) {
g_warning("Failed to read NET_WM_STRUT from 0x%lx", win); g_warning("Failed to read NET_WM_STRUT from 0x%lx", win);
*l = *t = *r = *b = 0; *l = *t = *r = *b = 0;
} else if (num != 4) { } else if (num != 4) {
@ -213,6 +190,18 @@ void cwmcc_client_get_strut(Window win, int *l, int *t, int *r, int *b)
g_free(data); g_free(data);
} }
void cwmcc_client_set_strut(Window win, int l, int t, int r, int b)
{
gulong data[4];
data[0] = l;
data[1] = r;
data[2] = t;
data[3] = b;
cwmcc_prop_set_array32(win, CWMCC_ATOM(client, net_wm_strut),
CWMCC_ATOM(type, cardinal), data, 4);
}
static void convert_pixmap_to_icon(Pixmap pix, Pixmap mask, static void convert_pixmap_to_icon(Pixmap pix, Pixmap mask,
struct Cwmcc_Icon *icon) struct Cwmcc_Icon *icon)
{ {
@ -252,15 +241,15 @@ static void convert_pixmap_to_icon(Pixmap pix, Pixmap mask,
icon->data = NULL; icon->data = NULL;
} }
void cwmcc_client_get_icon(Window win, struct Cwmcc_Icon **icons) void cwmcc_client_get_icon(Window win, struct Cwmcc_Icon **icons, gulong *num)
{ {
gulong *data = NULL, num; gulong *data = NULL;
gulong w, h, i; gulong w, h, i;
int j; int j;
int nicons; int nicons;
if (!prop_get_array32(win, CWMCC_ATOM(client, net_wm_icon), if (!cwmcc_prop_get_array32(win, CWMCC_ATOM(client, net_wm_icon),
CWMCC_ATOM(type, cardinal), &data, &num)) { CWMCC_ATOM(type, cardinal), &data, num)) {
g_warning("Failed to read NET_WM_ICON from 0x%lx", win); g_warning("Failed to read NET_WM_ICON from 0x%lx", win);
*icons = NULL; *icons = NULL;
nicons = 0; nicons = 0;
@ -268,16 +257,15 @@ void cwmcc_client_get_icon(Window win, struct Cwmcc_Icon **icons)
/* figure out how many valid icons are in here */ /* figure out how many valid icons are in here */
i = 0; i = 0;
nicons = 0; nicons = 0;
while (num - i > 2) { while (*num - i > 2) {
w = data[i++]; w = data[i++];
h = data[i++]; h = data[i++];
i += w * h; i += w * h;
if (i > num) break; if (i > *num) break;
++nicons; ++nicons;
} }
*icons = g_new(struct Cwmcc_Icon, nicons + 1); *icons = g_new(struct Cwmcc_Icon, nicons);
(*icons)[nicons].data = NULL;
/* store the icons */ /* store the icons */
i = 0; i = 0;
@ -287,16 +275,16 @@ void cwmcc_client_get_icon(Window win, struct Cwmcc_Icon **icons)
(*icons)[j].data = (*icons)[j].data =
g_memdup(&data[i], w * h * sizeof(gulong)); g_memdup(&data[i], w * h * sizeof(gulong));
i += w * h; i += w * h;
g_assert(i <= num); g_assert(i <= *num);
} }
} }
g_free(data); g_free(data);
data = NULL; data = NULL;
if (!prop_get_array32(win, CWMCC_ATOM(client, kwm_win_icon), if (!cwmcc_prop_get_array32(win, CWMCC_ATOM(client, kwm_win_icon),
CWMCC_ATOM(client, kwm_win_icon), &data, &num)) { CWMCC_ATOM(client, kwm_win_icon), &data, num)){
g_warning("Failed to read KWM_WIN_ICON from 0x%lx", win); g_warning("Failed to read KWM_WIN_ICON from 0x%lx", win);
} else if (num != 2) { } else if (*num != 2) {
g_warning("Read invalid KWM_WIN_ICON from 0x%lx", win); g_warning("Read invalid KWM_WIN_ICON from 0x%lx", win);
} else { } else {
Pixmap p, m; Pixmap p, m;
@ -308,21 +296,23 @@ void cwmcc_client_get_icon(Window win, struct Cwmcc_Icon **icons)
convert_pixmap_to_icon(p, m, &icon); convert_pixmap_to_icon(p, m, &icon);
if (icon.data) { if (icon.data) {
*icons = g_renew(struct Cwmcc_Icon, *icons, nicons + 2); ++nicons;
(*icons[nicons + 1]).data = NULL; *icons = g_renew(struct Cwmcc_Icon, *icons, nicons);
g_memmove(&(*icons)[nicons], &icon, sizeof(struct Cwmcc_Icon)); (*icons[nicons]).data = NULL;
g_memmove(&(*icons)[nicons-1], &icon, sizeof(struct Cwmcc_Icon));
} }
} }
g_free(data); g_free(data);
*num = nicons;
} }
void cwmcc_client_get_premax(Window win, int *x, int *y, int *w, int *h) void cwmcc_client_get_premax(Window win, int *x, int *y, int *w, int *h)
{ {
gulong *l = NULL, num; gulong *l = NULL, num;
if (!prop_get_array32(win, CWMCC_ATOM(client, openbox_premax), if (!cwmcc_prop_get_array32(win, CWMCC_ATOM(client, openbox_premax),
CWMCC_ATOM(type, cardinal), &l, &num)) { CWMCC_ATOM(type, cardinal), &l, &num)) {
g_warning("Failed to read OPENBOX_PREMAX from 0x%lx", win); g_warning("Failed to read OPENBOX_PREMAX from 0x%lx", win);
*x = *y = *w = *h = 0; *x = *y = *w = *h = 0;
} else if (num != 4) { } else if (num != 4) {
@ -345,7 +335,6 @@ void cwmcc_client_set_premax(Window win, int x, int y, int w, int h)
l[1] = y; l[1] = y;
l[2] = w; l[2] = w;
l[3] = h; l[3] = h;
XChangeProperty(cwmcc_display, win, CWMCC_ATOM(client, openbox_premax), cwmcc_prop_set_array32(win, CWMCC_ATOM(client, openbox_premax),
CWMCC_ATOM(type, cardinal), 32, PropModeReplace, CWMCC_ATOM(type, cardinal), l, 4);
(guchar*)l, 4);
} }

View file

@ -1,7 +1,8 @@
#ifndef __cwmcc_client_get_props_h #ifndef __cwmcc_client_get_props_h
#define __cwmcc_client_get_props_h #define __cwmcc_client_get_props_h
void cwmcc_client_get_protocols(Window win, Atom **protocols); void cwmcc_client_get_protocols(Window win, Atom **protocols, gulong *num);
void cwmcc_client_set_protocols(Window win, Atom *protocols, gulong num);
void cwmcc_client_get_wm_state(Window win, gulong *state); void cwmcc_client_get_wm_state(Window win, gulong *state);
void cwmcc_client_set_wm_state(Window win, gulong state); void cwmcc_client_set_wm_state(Window win, gulong state);
@ -60,13 +61,14 @@ void cwmcc_client_get_mwmhints(Window win, struct Cwmcc_MwmHints *hints);
void cwmcc_client_get_desktop(Window win, gulong *desk); void cwmcc_client_get_desktop(Window win, gulong *desk);
void cwmcc_client_set_desktop(Window win, gulong desk); void cwmcc_client_set_desktop(Window win, gulong desk);
void cwmcc_client_get_type(Window win, gulong **types); void cwmcc_client_get_type(Window win, gulong **types, gulong *num);
void cwmcc_client_set_type(Window win, gulong *types); void cwmcc_client_set_type(Window win, gulong *types, gulong num);
void cwmcc_client_get_state(Window win, gulong **states); void cwmcc_client_get_state(Window win, gulong **states, gulong *num);
void cwmcc_client_set_state(Window win, gulong *states); void cwmcc_client_set_state(Window win, gulong *states, gulong num);
void cwmcc_client_get_strut(Window win, int *l, int *t, int *r, int *b); void cwmcc_client_get_strut(Window win, int *l, int *t, int *r, int *b);
void cwmcc_client_set_strut(Window win, int l, int t, int r, int b);
/*! Holds an icon in ARGB format */ /*! Holds an icon in ARGB format */
struct Cwmcc_Icon { struct Cwmcc_Icon {
@ -76,7 +78,7 @@ struct Cwmcc_Icon {
/* Returns an array of Cwms_Icons. The array is terminated by a Cwmcc_Icon with /* Returns an array of Cwms_Icons. The array is terminated by a Cwmcc_Icon with
its data member set to NULL */ its data member set to NULL */
void cwmcc_client_get_icon(Window win, struct Cwmcc_Icon **icons); void cwmcc_client_get_icon(Window win, struct Cwmcc_Icon **icons, gulong *num);
void cwmcc_client_get_premax(Window win, int *x, int *y, int *w, int *h); void cwmcc_client_get_premax(Window win, int *x, int *y, int *w, int *h);
void cwmcc_client_set_premax(Window win, int x, int y, int w, int h); void cwmcc_client_set_premax(Window win, int x, int y, int w, int h);

View file

@ -108,18 +108,18 @@ static gboolean get_stringlist(Window win, Atom prop, char ***list, int *nstr)
return ret; return ret;
} }
gboolean prop_get32(Window win, Atom prop, Atom type, gulong *ret) gboolean cwmcc_prop_get32(Window win, Atom prop, Atom type, gulong *ret)
{ {
return get_prealloc(win, prop, type, 32, (guchar*)ret, 1); return get_prealloc(win, prop, type, 32, (guchar*)ret, 1);
} }
gboolean prop_get_array32(Window win, Atom prop, Atom type, gulong **ret, gboolean cwmcc_prop_get_array32(Window win, Atom prop, Atom type, gulong **ret,
gulong *nret) gulong *nret)
{ {
return get_all(win, prop, type, 32, (guchar**)ret, nret); return get_all(win, prop, type, 32, (guchar**)ret, nret);
} }
gboolean prop_get_string_locale(Window win, Atom prop, char **data) gboolean cwmcc_prop_get_string_locale(Window win, Atom prop, char **data)
{ {
char **list; char **list;
int nstr; int nstr;
@ -132,7 +132,7 @@ gboolean prop_get_string_locale(Window win, Atom prop, char **data)
return FALSE; return FALSE;
} }
gboolean prop_get_string_utf8(Window win, Atom prop, char **ret) gboolean cwmcc_prop_get_string_utf8(Window win, Atom prop, char **ret)
{ {
char *raw; char *raw;
gulong num; gulong num;
@ -145,7 +145,7 @@ gboolean prop_get_string_utf8(Window win, Atom prop, char **ret)
return FALSE; return FALSE;
} }
gboolean prop_get_strings_utf8(Window win, Atom prop, char ***ret) gboolean cwmcc_prop_get_strings_utf8(Window win, Atom prop, char ***ret)
{ {
char *raw, *p; char *raw, *p;
gulong num, i; gulong num, i;
@ -165,7 +165,7 @@ gboolean prop_get_strings_utf8(Window win, Atom prop, char ***ret)
return FALSE; return FALSE;
} }
gboolean prop_get_strings_locale(Window win, Atom prop, char ***ret) gboolean cwmcc_prop_get_strings_locale(Window win, Atom prop, char ***ret)
{ {
char *raw, *p; char *raw, *p;
gulong num, i; gulong num, i;
@ -191,7 +191,26 @@ gboolean prop_get_strings_locale(Window win, Atom prop, char ***ret)
return FALSE; return FALSE;
} }
void prop_set_strings_utf8(Window win, Atom prop, char **strs) void cwmcc_prop_set32(Window win, Atom prop, Atom type, gulong val)
{
XChangeProperty(cwmcc_display, win, prop, type, 32, PropModeReplace,
(guchar*)&val, 1);
}
void cwmcc_prop_set_array32(Window win, Atom prop, Atom type,
gulong *val, gulong num)
{
XChangeProperty(cwmcc_display, win, prop, type, 32, PropModeReplace,
(guchar*)val, num);
}
void cwmcc_prop_set_string_utf8(Window win, Atom prop, char *val)
{
XChangeProperty(cwmcc_display, win, prop, CWMCC_ATOM(type, utf8), 8,
PropModeReplace, (guchar*)val, strlen(val));
}
void cwmcc_prop_set_strings_utf8(Window win, Atom prop, char **strs)
{ {
GString *str; GString *str;
guint i; guint i;
@ -205,7 +224,7 @@ void prop_set_strings_utf8(Window win, Atom prop, char **strs)
PropModeReplace, (guchar*)str->str, str->len); PropModeReplace, (guchar*)str->str, str->len);
} }
void prop_erase(Window win, Atom prop) void cwmcc_prop_erase(Window win, Atom prop)
{ {
XDeleteProperty(cwmcc_display, win, prop); XDeleteProperty(cwmcc_display, win, prop);
} }

View file

@ -8,31 +8,38 @@
you to free the returned value with g_free or g_strfreev (for the char**s) you to free the returned value with g_free or g_strfreev (for the char**s)
*/ */
gboolean prop_get32(Window win, Atom prop, Atom type, gulong *ret); gboolean cwmcc_prop_get32(Window win, Atom prop, Atom type, gulong *ret);
gboolean prop_get_array32(Window win, Atom prop, Atom type, gulong **ret, gboolean cwmcc_prop_get_array32(Window win, Atom prop, Atom type, gulong **ret,
gulong *nret); gulong *nret);
gboolean prop_get_string(Window win, Atom prop, Atom type, char **ret); gboolean cwmcc_prop_get_string(Window win, Atom prop, Atom type, char **ret);
/*! Gets a string from a property which is stored in UTF-8 encoding. */ /*! Gets a string from a property which is stored in UTF-8 encoding. */
gboolean prop_get_string_utf8(Window win, Atom prop, char **ret); gboolean cwmcc_prop_get_string_utf8(Window win, Atom prop, char **ret);
/*! Gets a string from a property which is stored in the current local /*! Gets a string from a property which is stored in the current local
encoding. The returned string is in UTF-8 encoding. */ encoding. The returned string is in UTF-8 encoding. */
gboolean prop_get_string_locale(Window win, Atom prop, char **ret); gboolean cwmcc_prop_get_string_locale(Window win, Atom prop, char **ret);
/*! Gets a null terminated array of strings from a property which is stored in /*! Gets a null terminated array of strings from a property which is stored in
UTF-8 encoding. */ UTF-8 encoding. */
gboolean prop_get_strings_utf8(Window win, Atom prop, char ***ret); gboolean cwmcc_prop_get_strings_utf8(Window win, Atom prop, char ***ret);
/*! Gets a null terminated array of strings from a property which is stored in /*! Gets a null terminated array of strings from a property which is stored in
the current locale encoding. The returned string is in UTF-8 encoding. */ the current locale encoding. The returned string is in UTF-8 encoding. */
gboolean prop_get_strings_locale(Window win, Atom prop, char ***ret); gboolean cwmcc_prop_get_strings_locale(Window win, Atom prop, char ***ret);
void cwmcc_prop_set32(Window win, Atom prop, Atom type, gulong val);
void cwmcc_prop_set_array32(Window win, Atom prop, Atom type,
gulong *val, gulong num);
void cwmcc_prop_set_string_utf8(Window win, Atom prop, char *val);
/*! Sets a null terminated array of strings in a property encoded as UTF-8. */ /*! Sets a null terminated array of strings in a property encoded as UTF-8. */
void prop_set_strings_utf8(Window win, Atom prop, char **strs); void cwmcc_prop_set_strings_utf8(Window win, Atom prop, char **strs);
void prop_erase(Window win, Atom prop); void cwmcc_prop_erase(Window win, Atom prop);
#endif #endif

View file

@ -9,8 +9,8 @@ void cwmcc_root_get_supported(Window win, Atom **atoms)
{ {
gulong num; gulong num;
if (!prop_get_array32(win, CWMCC_ATOM(root, net_supported), if (!cwmcc_prop_get_array32(win, CWMCC_ATOM(root, net_supported),
CWMCC_ATOM(type, atom), atoms, &num)) { CWMCC_ATOM(type, atom), atoms, &num)) {
g_warning("Failed to read NET_SUPPORTED from 0x%lx", win); g_warning("Failed to read NET_SUPPORTED from 0x%lx", win);
*atoms = NULL; *atoms = NULL;
} }
@ -20,8 +20,8 @@ void cwmcc_root_get_client_list(Window win, Window **windows)
{ {
gulong num; gulong num;
if (!prop_get_array32(win, CWMCC_ATOM(root, net_client_list), if (!cwmcc_prop_get_array32(win, CWMCC_ATOM(root, net_client_list),
CWMCC_ATOM(type, window), windows, &num)) { CWMCC_ATOM(type, window), windows, &num)) {
g_warning("Failed to read NET_CLIENT_LIST from 0x%lx", win); g_warning("Failed to read NET_CLIENT_LIST from 0x%lx", win);
*windows = NULL; *windows = NULL;
} }
@ -31,8 +31,8 @@ void cwmcc_root_get_client_list_stacking(Window win, Window **windows)
{ {
gulong num; gulong num;
if (!prop_get_array32(win, CWMCC_ATOM(root, net_client_list_stacking), if (!cwmcc_prop_get_array32(win,CWMCC_ATOM(root, net_client_list_stacking),
CWMCC_ATOM(type, window), windows, &num)) { CWMCC_ATOM(type, window), windows, &num)) {
g_warning("Failed to read NET_CLIENT_LIST_STACKING from 0x%lx", win); g_warning("Failed to read NET_CLIENT_LIST_STACKING from 0x%lx", win);
*windows = NULL; *windows = NULL;
} }
@ -40,8 +40,8 @@ void cwmcc_root_get_client_list_stacking(Window win, Window **windows)
void cwmcc_root_get_number_of_desktops(Window win, gulong *desktops) void cwmcc_root_get_number_of_desktops(Window win, gulong *desktops)
{ {
if (!prop_get32(win, CWMCC_ATOM(root, net_number_of_desktops), if (!cwmcc_prop_get32(win, CWMCC_ATOM(root, net_number_of_desktops),
CWMCC_ATOM(type, cardinal), desktops)) { CWMCC_ATOM(type, cardinal), desktops)) {
g_warning("Failed to read NET_NUMBER_OF_DESKTOPS from 0x%lx", win); g_warning("Failed to read NET_NUMBER_OF_DESKTOPS from 0x%lx", win);
*desktops = 1; *desktops = 1;
} }
@ -51,8 +51,8 @@ void cwmcc_root_get_desktop_geometry(Window win, gulong *w, gulong *h)
{ {
gulong *data = NULL, num; gulong *data = NULL, num;
if (!prop_get_array32(win, CWMCC_ATOM(root, net_desktop_geometry), if (!cwmcc_prop_get_array32(win, CWMCC_ATOM(root, net_desktop_geometry),
CWMCC_ATOM(type, cardinal), &data, &num)) { CWMCC_ATOM(type, cardinal), &data, &num)) {
g_warning("Failed to read NET_DESKTOP_GEOMETRY from 0x%lx", win); g_warning("Failed to read NET_DESKTOP_GEOMETRY from 0x%lx", win);
*w = *h = 0; *w = *h = 0;
} else if (num != 2) { } else if (num != 2) {
@ -69,8 +69,8 @@ void cwmcc_root_get_desktop_viewport(Window win, gulong *x, gulong *y)
{ {
gulong *data = NULL, num; gulong *data = NULL, num;
if (!prop_get_array32(win, CWMCC_ATOM(root, net_desktop_viewport), if (!cwmcc_prop_get_array32(win, CWMCC_ATOM(root, net_desktop_viewport),
CWMCC_ATOM(type, cardinal), &data, &num)) { CWMCC_ATOM(type, cardinal), &data, &num)) {
g_warning("Failed to read NET_DESKTOP_VIEWPORT from 0x%lx", win); g_warning("Failed to read NET_DESKTOP_VIEWPORT from 0x%lx", win);
*x = *y = 0; *x = *y = 0;
} else if (num != 2) { } else if (num != 2) {
@ -85,8 +85,8 @@ void cwmcc_root_get_desktop_viewport(Window win, gulong *x, gulong *y)
void cwmcc_root_get_current_desktop(Window win, gulong *desktop) void cwmcc_root_get_current_desktop(Window win, gulong *desktop)
{ {
if (!prop_get32(win, CWMCC_ATOM(root, net_current_desktop), if (!cwmcc_prop_get32(win, CWMCC_ATOM(root, net_current_desktop),
CWMCC_ATOM(type, cardinal), desktop)) { CWMCC_ATOM(type, cardinal), desktop)) {
g_warning("Failed to read NET_CURRENT_DESKTOP from 0x%lx", win); g_warning("Failed to read NET_CURRENT_DESKTOP from 0x%lx", win);
*desktop = 0; *desktop = 0;
} }
@ -94,8 +94,8 @@ void cwmcc_root_get_current_desktop(Window win, gulong *desktop)
void cwmcc_root_get_desktop_names(Window win, char ***names) void cwmcc_root_get_desktop_names(Window win, char ***names)
{ {
if (!prop_get_strings_utf8(win, if (!cwmcc_prop_get_strings_utf8(win, CWMCC_ATOM(root, net_desktop_names),
CWMCC_ATOM(root, net_desktop_names), names)) { names)) {
g_warning("Failed to read NET_DESKTOP_NAMES from 0x%lx", win); g_warning("Failed to read NET_DESKTOP_NAMES from 0x%lx", win);
*names = NULL; *names = NULL;
} }
@ -103,8 +103,8 @@ void cwmcc_root_get_desktop_names(Window win, char ***names)
void cwmcc_root_get_active_window(Window win, Window *window) void cwmcc_root_get_active_window(Window win, Window *window)
{ {
if (!prop_get32(win, CWMCC_ATOM(root, net_active_window), if (!cwmcc_prop_get32(win, CWMCC_ATOM(root, net_active_window),
CWMCC_ATOM(type, window), window)) { CWMCC_ATOM(type, window), window)) {
g_warning("Failed to read NET_ACTIVE_WINDOW from 0x%lx", win); g_warning("Failed to read NET_ACTIVE_WINDOW from 0x%lx", win);
*window = None; *window = None;
} }
@ -118,8 +118,8 @@ void cwmcc_root_get_workarea(Window win, int **x, int **y, int **w, int **h)
/* need the number of desktops */ /* need the number of desktops */
cwmcc_root_get_number_of_desktops(win, &desks); cwmcc_root_get_number_of_desktops(win, &desks);
if (!prop_get_array32(win, CWMCC_ATOM(root, net_workarea), if (!cwmcc_prop_get_array32(win, CWMCC_ATOM(root, net_workarea),
CWMCC_ATOM(type, cardinal), &data, &num)) { CWMCC_ATOM(type, cardinal), &data, &num)) {
g_warning("Failed to read NET_DESKTOP_LAYOUT from 0x%lx", win); g_warning("Failed to read NET_DESKTOP_LAYOUT from 0x%lx", win);
} else if (num != 4 * desks) { } else if (num != 4 * desks) {
g_warning("Read invalid NET_DESKTOP_LAYOUT from 0x%lx", win); g_warning("Read invalid NET_DESKTOP_LAYOUT from 0x%lx", win);
@ -139,8 +139,8 @@ void cwmcc_root_get_workarea(Window win, int **x, int **y, int **w, int **h)
void cwmcc_root_get_supporting_wm_check(Window win, Window *window) void cwmcc_root_get_supporting_wm_check(Window win, Window *window)
{ {
if (!prop_get32(win, CWMCC_ATOM(root, net_supporting_wm_check), if (!cwmcc_prop_get32(win, CWMCC_ATOM(root, net_supporting_wm_check),
CWMCC_ATOM(type, window), window)) { CWMCC_ATOM(type, window), window)) {
g_warning("Failed to read NET_SUPPORTING_WM_CHECK from 0x%lx", win); g_warning("Failed to read NET_SUPPORTING_WM_CHECK from 0x%lx", win);
*window = None; *window = None;
} }
@ -160,8 +160,8 @@ void cwmcc_root_get_desktop_layout(Window win,
layout->rows = 1; layout->rows = 1;
layout->columns = desks; layout->columns = desks;
if (!prop_get_array32(win, CWMCC_ATOM(root, net_desktop_layout), if (!cwmcc_prop_get_array32(win, CWMCC_ATOM(root, net_desktop_layout),
CWMCC_ATOM(type, cardinal), &data, &num)) { CWMCC_ATOM(type, cardinal), &data, &num)) {
g_warning("Failed to read NET_DESKTOP_LAYOUT from 0x%lx", win); g_warning("Failed to read NET_DESKTOP_LAYOUT from 0x%lx", win);
} else if (num != 4) { } else if (num != 4) {
g_warning("Read invalid NET_DESKTOP_LAYOUT from 0x%lx", win); g_warning("Read invalid NET_DESKTOP_LAYOUT from 0x%lx", win);
@ -201,8 +201,8 @@ void cwmcc_root_get_showing_desktop(Window win, gboolean *showing)
{ {
gulong a; gulong a;
if (!prop_get32(win, CWMCC_ATOM(root, net_showing_desktop), if (!cwmcc_prop_get32(win, CWMCC_ATOM(root, net_showing_desktop),
CWMCC_ATOM(type, cardinal), &a)) { CWMCC_ATOM(type, cardinal), &a)) {
g_warning("Failed to read NET_SHOWING_DESKTOP from 0x%lx", win); g_warning("Failed to read NET_SHOWING_DESKTOP from 0x%lx", win);
a = FALSE; a = FALSE;
} }
@ -211,8 +211,8 @@ void cwmcc_root_get_showing_desktop(Window win, gboolean *showing)
void cwmcc_root_get_openbox_pid(Window win, gulong *pid) void cwmcc_root_get_openbox_pid(Window win, gulong *pid)
{ {
if (!prop_get32(win, CWMCC_ATOM(root, openbox_pid), if (!cwmcc_prop_get32(win, CWMCC_ATOM(root, openbox_pid),
CWMCC_ATOM(type, cardinal), pid)) { CWMCC_ATOM(type, cardinal), pid)) {
g_warning("Failed to read OPENBOX_PID from 0x%lx", win); g_warning("Failed to read OPENBOX_PID from 0x%lx", win);
*pid = 0; *pid = 0;
} }