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:
Yuxuan Shui 2018-12-09 20:54:16 +00:00
parent 8805cfa986
commit 345bacf3b3
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
4 changed files with 44 additions and 43 deletions

View File

@ -1595,21 +1595,6 @@ bool
wid_get_text_prop(session_t *ps, Window wid, Atom prop, wid_get_text_prop(session_t *ps, Window wid, Atom prop,
char ***pstrlst, int *pnstr); 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 void
force_repaint(session_t *ps); force_repaint(session_t *ps);

View File

@ -1231,7 +1231,7 @@ win_update_frame_extents(session_t *ps, win *w, Window client) {
4L, XCB_ATOM_CARDINAL, 32); 4L, XCB_ATOM_CARDINAL, 32);
if (prop.nitems == 4) { 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] || const bool changed = w->frame_extents.left != extents[0] ||
w->frame_extents.right != extents[1] || w->frame_extents.right != extents[1] ||
w->frame_extents.top != extents[2] || w->frame_extents.top != extents[2] ||

37
src/x.c
View File

@ -27,28 +27,27 @@
* and number of items. A blank one on failure. * and number of items. A blank one on failure.
*/ */
winprop_t winprop_t
wid_get_prop_adv(const session_t *ps, Window w, Atom atom, long offset, wid_get_prop_adv(const session_t *ps, xcb_window_t w, xcb_atom_t atom, long offset,
long length, Atom rtype, int rformat) { long length, xcb_atom_t rtype, int rformat) {
Atom type = None; xcb_get_property_reply_t *r = xcb_get_property_reply(ps->c,
int format = 0; xcb_get_property(ps->c, 0, w, atom, rtype, offset, length), NULL);
unsigned long nitems = 0, after = 0;
unsigned char *data = NULL;
if (Success == XGetWindowProperty(ps->dpy, w, atom, offset, length, if (r && xcb_get_property_value_length(r) &&
False, rtype, &type, &format, &nitems, &after, &data) (rtype == XCB_ATOM_ANY || r->type == rtype) &&
&& nitems && (AnyPropertyType == type || type == rtype) (!rformat || r->format == rformat) &&
&& (!rformat || format == rformat) (r->format == 8 || r->format == 16 || r->format == 32))
&& (8 == format || 16 == format || 32 == format)) { {
return (winprop_t) { int len = xcb_get_property_value_length(r);
.ptr = data, return (winprop_t) {
.nitems = nitems, .ptr = xcb_get_property_value(r),
.type = type, .nitems = len/(r->format/8),
.format = format, .type = r->type,
}; .format = r->format,
.r = r,
};
} }
cxfree(data); free(r);
return (winprop_t) { return (winprop_t) {
.ptr = NULL, .ptr = NULL,
.nitems = 0, .nitems = 0,

33
src/x.h
View File

@ -15,14 +15,16 @@ typedef struct session session_t;
typedef struct winprop { typedef struct winprop {
union { union {
void *ptr; void *ptr;
char *p8; int8_t *p8;
short *p16; int16_t *p16;
long *p32; int32_t *p32;
unsigned long *c32; // 32bit cardinal uint32_t *c32; // 32bit cardinal
}; };
unsigned long nitems; unsigned long nitems;
xcb_atom_t type; xcb_atom_t type;
int format; int format;
xcb_get_property_reply_t *r;
} winprop_t; } winprop_t;
#define XCB_SYNCED_VOID(func, c, ...) xcb_request_check(c, func##_checked(c, __VA_ARGS__)); #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. * and number of items. A blank one on failure.
*/ */
winprop_t winprop_t
wid_get_prop_adv(const session_t *ps, Window w, Atom atom, long offset, wid_get_prop_adv(const session_t *ps, xcb_window_t w, xcb_atom_t atom, long offset,
long length, Atom rtype, int rformat); long length, xcb_atom_t rtype, int rformat);
/** /**
* Wrapper of wid_get_prop_adv(). * Wrapper of wid_get_prop_adv().
*/ */
static inline winprop_t static inline winprop_t
wid_get_prop(const session_t *ps, Window wid, Atom atom, long length, wid_get_prop(const session_t *ps, xcb_window_t wid, xcb_atom_t atom, long length,
Atom rtype, int rformat) { xcb_atom_t rtype, int rformat) {
return wid_get_prop_adv(ps, wid, atom, 0L, length, rtype, 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 xcb_pixmap_t
x_create_pixmap(session_t *ps, uint8_t depth, xcb_drawable_t drawable, uint16_t width, uint16_t height); 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;
}