Convert wid_get_prop to xcb
This should give us sane item size, i.e. the item has the same number of bits their format says they have. Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
parent
8805cfa986
commit
345bacf3b3
15
src/common.h
15
src/common.h
|
@ -1595,21 +1595,6 @@ bool
|
|||
wid_get_text_prop(session_t *ps, Window wid, Atom prop,
|
||||
char ***pstrlst, int *pnstr);
|
||||
|
||||
/**
|
||||
* Free a <code>winprop_t</code>.
|
||||
*
|
||||
* @param pprop pointer to the <code>winprop_t</code> to free.
|
||||
*/
|
||||
static inline void
|
||||
free_winprop(winprop_t *pprop) {
|
||||
// Empty the whole structure to avoid possible issues
|
||||
if (pprop->ptr) {
|
||||
cxfree(pprop->ptr);
|
||||
pprop->ptr = NULL;
|
||||
}
|
||||
pprop->nitems = 0;
|
||||
}
|
||||
|
||||
void
|
||||
force_repaint(session_t *ps);
|
||||
|
||||
|
|
|
@ -1231,7 +1231,7 @@ win_update_frame_extents(session_t *ps, win *w, Window client) {
|
|||
4L, XCB_ATOM_CARDINAL, 32);
|
||||
|
||||
if (prop.nitems == 4) {
|
||||
const unsigned long * const extents = prop.c32;
|
||||
const uint32_t * const extents = prop.c32;
|
||||
const bool changed = w->frame_extents.left != extents[0] ||
|
||||
w->frame_extents.right != extents[1] ||
|
||||
w->frame_extents.top != extents[2] ||
|
||||
|
|
37
src/x.c
37
src/x.c
|
@ -27,28 +27,27 @@
|
|||
* and number of items. A blank one on failure.
|
||||
*/
|
||||
winprop_t
|
||||
wid_get_prop_adv(const session_t *ps, Window w, Atom atom, long offset,
|
||||
long length, Atom rtype, int rformat) {
|
||||
Atom type = None;
|
||||
int format = 0;
|
||||
unsigned long nitems = 0, after = 0;
|
||||
unsigned char *data = NULL;
|
||||
wid_get_prop_adv(const session_t *ps, xcb_window_t w, xcb_atom_t atom, long offset,
|
||||
long length, xcb_atom_t rtype, int rformat) {
|
||||
xcb_get_property_reply_t *r = xcb_get_property_reply(ps->c,
|
||||
xcb_get_property(ps->c, 0, w, atom, rtype, offset, length), NULL);
|
||||
|
||||
if (Success == XGetWindowProperty(ps->dpy, w, atom, offset, length,
|
||||
False, rtype, &type, &format, &nitems, &after, &data)
|
||||
&& nitems && (AnyPropertyType == type || type == rtype)
|
||||
&& (!rformat || format == rformat)
|
||||
&& (8 == format || 16 == format || 32 == format)) {
|
||||
return (winprop_t) {
|
||||
.ptr = data,
|
||||
.nitems = nitems,
|
||||
.type = type,
|
||||
.format = format,
|
||||
};
|
||||
if (r && xcb_get_property_value_length(r) &&
|
||||
(rtype == XCB_ATOM_ANY || r->type == rtype) &&
|
||||
(!rformat || r->format == rformat) &&
|
||||
(r->format == 8 || r->format == 16 || r->format == 32))
|
||||
{
|
||||
int len = xcb_get_property_value_length(r);
|
||||
return (winprop_t) {
|
||||
.ptr = xcb_get_property_value(r),
|
||||
.nitems = len/(r->format/8),
|
||||
.type = r->type,
|
||||
.format = r->format,
|
||||
.r = r,
|
||||
};
|
||||
}
|
||||
|
||||
cxfree(data);
|
||||
|
||||
free(r);
|
||||
return (winprop_t) {
|
||||
.ptr = NULL,
|
||||
.nitems = 0,
|
||||
|
|
33
src/x.h
33
src/x.h
|
@ -15,14 +15,16 @@ typedef struct session session_t;
|
|||
typedef struct winprop {
|
||||
union {
|
||||
void *ptr;
|
||||
char *p8;
|
||||
short *p16;
|
||||
long *p32;
|
||||
unsigned long *c32; // 32bit cardinal
|
||||
int8_t *p8;
|
||||
int16_t *p16;
|
||||
int32_t *p32;
|
||||
uint32_t *c32; // 32bit cardinal
|
||||
};
|
||||
unsigned long nitems;
|
||||
xcb_atom_t type;
|
||||
int format;
|
||||
|
||||
xcb_get_property_reply_t *r;
|
||||
} winprop_t;
|
||||
|
||||
#define XCB_SYNCED_VOID(func, c, ...) xcb_request_check(c, func##_checked(c, __VA_ARGS__));
|
||||
|
@ -64,15 +66,15 @@ x_sync(xcb_connection_t *c) {
|
|||
* and number of items. A blank one on failure.
|
||||
*/
|
||||
winprop_t
|
||||
wid_get_prop_adv(const session_t *ps, Window w, Atom atom, long offset,
|
||||
long length, Atom rtype, int rformat);
|
||||
wid_get_prop_adv(const session_t *ps, xcb_window_t w, xcb_atom_t atom, long offset,
|
||||
long length, xcb_atom_t rtype, int rformat);
|
||||
|
||||
/**
|
||||
* Wrapper of wid_get_prop_adv().
|
||||
*/
|
||||
static inline winprop_t
|
||||
wid_get_prop(const session_t *ps, Window wid, Atom atom, long length,
|
||||
Atom rtype, int rformat) {
|
||||
wid_get_prop(const session_t *ps, xcb_window_t wid, xcb_atom_t atom, long length,
|
||||
xcb_atom_t rtype, int rformat) {
|
||||
return wid_get_prop_adv(ps, wid, atom, 0L, length, rtype, rformat);
|
||||
}
|
||||
|
||||
|
@ -134,3 +136,18 @@ x_print_error(unsigned long serial, uint8_t major, uint8_t minor, uint8_t error_
|
|||
|
||||
xcb_pixmap_t
|
||||
x_create_pixmap(session_t *ps, uint8_t depth, xcb_drawable_t drawable, uint16_t width, uint16_t height);
|
||||
|
||||
/**
|
||||
* Free a <code>winprop_t</code>.
|
||||
*
|
||||
* @param pprop pointer to the <code>winprop_t</code> to free.
|
||||
*/
|
||||
static inline void
|
||||
free_winprop(winprop_t *pprop) {
|
||||
// Empty the whole structure to avoid possible issues
|
||||
if (pprop->r)
|
||||
free(pprop->r);
|
||||
pprop->ptr = NULL;
|
||||
pprop->r = NULL;
|
||||
pprop->nitems = 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue