Fix signedness of x properties
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
parent
32e0b45255
commit
4f4201976d
24
src/common.h
24
src/common.h
|
@ -224,13 +224,13 @@ typedef struct {
|
|||
|
||||
/// Structure representing Window property value.
|
||||
typedef struct winprop {
|
||||
// All pointers have the same length, right?
|
||||
// I wanted to use anonymous union but it's a GNU extension...
|
||||
union {
|
||||
unsigned char *p8;
|
||||
short *p16;
|
||||
long *p32;
|
||||
} data;
|
||||
void *ptr;
|
||||
uint8_t *p8;
|
||||
int16_t *p16;
|
||||
int32_t *p32;
|
||||
uint32_t *c32; // 32bit cardinal
|
||||
};
|
||||
unsigned long nitems;
|
||||
Atom type;
|
||||
int format;
|
||||
|
@ -1570,9 +1570,9 @@ winprop_get_int(winprop_t prop) {
|
|||
return 0;
|
||||
|
||||
switch (prop.format) {
|
||||
case 8: tgt = *(prop.data.p8); break;
|
||||
case 16: tgt = *(prop.data.p16); break;
|
||||
case 32: tgt = *(prop.data.p32); break;
|
||||
case 8: tgt = *(prop.p8); break;
|
||||
case 16: tgt = *(prop.p16); break;
|
||||
case 32: tgt = *(prop.p32); break;
|
||||
default: assert(0);
|
||||
break;
|
||||
}
|
||||
|
@ -1592,9 +1592,9 @@ wid_get_text_prop(session_t *ps, Window wid, Atom prop,
|
|||
static inline void
|
||||
free_winprop(winprop_t *pprop) {
|
||||
// Empty the whole structure to avoid possible issues
|
||||
if (pprop->data.p8) {
|
||||
cxfree(pprop->data.p8);
|
||||
pprop->data.p8 = NULL;
|
||||
if (pprop->ptr) {
|
||||
cxfree(pprop->ptr);
|
||||
pprop->ptr = NULL;
|
||||
}
|
||||
pprop->nitems = 0;
|
||||
}
|
||||
|
|
|
@ -912,7 +912,7 @@ get_root_tile(session_t *ps) {
|
|||
get_atom(ps, background_props_str[p]),
|
||||
1L, XCB_ATOM_PIXMAP, 32);
|
||||
if (prop.nitems) {
|
||||
pixmap = *prop.data.p32;
|
||||
pixmap = *prop.p32;
|
||||
fill = false;
|
||||
free_winprop(&prop);
|
||||
break;
|
||||
|
|
|
@ -24,10 +24,10 @@ typedef struct {
|
|||
|
||||
/// A structure representing margins around a rectangle.
|
||||
typedef struct {
|
||||
int top;
|
||||
int left;
|
||||
int bottom;
|
||||
int right;
|
||||
unsigned int top;
|
||||
unsigned int left;
|
||||
unsigned int bottom;
|
||||
unsigned int right;
|
||||
} margin_t;
|
||||
|
||||
typedef uint32_t opacity_t;
|
||||
|
|
13
src/win.c
13
src/win.c
|
@ -251,7 +251,7 @@ wintype_t wid_get_prop_wintype(session_t *ps, Window wid) {
|
|||
|
||||
for (unsigned i = 0; i < prop.nitems; ++i) {
|
||||
for (wintype_t j = 1; j < NUM_WINTYPES; ++j) {
|
||||
if (ps->atoms_wintypes[j] == (Atom)prop.data.p32[i]) {
|
||||
if (ps->atoms_wintypes[j] == (xcb_atom_t)prop.p32[i]) {
|
||||
free_winprop(&prop);
|
||||
return j;
|
||||
}
|
||||
|
@ -271,12 +271,7 @@ bool wid_get_opacity_prop(session_t *ps, Window wid, opacity_t def,
|
|||
winprop_t prop = wid_get_prop(ps, wid, ps->atom_opacity, 1L, XCB_ATOM_CARDINAL, 32);
|
||||
|
||||
if (prop.nitems) {
|
||||
// sanitize the opacity data, if opacity is out of bounds,
|
||||
// assuming they are opaque
|
||||
if (*prop.data.p32 < 0 || *prop.data.p32 > OPAQUE)
|
||||
*out = OPAQUE;
|
||||
else
|
||||
*out = *prop.data.p32;
|
||||
*out = *prop.c32;
|
||||
ret = true;
|
||||
}
|
||||
|
||||
|
@ -405,7 +400,7 @@ void win_update_prop_shadow_raw(session_t *ps, win *w) {
|
|||
if (!prop.nitems) {
|
||||
w->prop_shadow = -1;
|
||||
} else {
|
||||
w->prop_shadow = *prop.data.p32;
|
||||
w->prop_shadow = *prop.c32;
|
||||
}
|
||||
|
||||
free_winprop(&prop);
|
||||
|
@ -1236,7 +1231,7 @@ win_update_frame_extents(session_t *ps, win *w, Window client) {
|
|||
4L, XCB_ATOM_CARDINAL, 32);
|
||||
|
||||
if (prop.nitems == 4) {
|
||||
const long * const extents = prop.data.p32;
|
||||
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] ||
|
||||
|
|
6
src/x.c
6
src/x.c
|
@ -40,7 +40,7 @@ wid_get_prop_adv(const session_t *ps, Window w, Atom atom, long offset,
|
|||
&& (!rformat || format == rformat)
|
||||
&& (8 == format || 16 == format || 32 == format)) {
|
||||
return (winprop_t) {
|
||||
.data.p8 = data,
|
||||
.ptr = data,
|
||||
.nitems = nitems,
|
||||
.type = type,
|
||||
.format = format,
|
||||
|
@ -50,7 +50,7 @@ wid_get_prop_adv(const session_t *ps, Window w, Atom atom, long offset,
|
|||
cxfree(data);
|
||||
|
||||
return (winprop_t) {
|
||||
.data.p8 = NULL,
|
||||
.ptr = NULL,
|
||||
.nitems = 0,
|
||||
.type = AnyPropertyType,
|
||||
.format = 0
|
||||
|
@ -70,7 +70,7 @@ wid_get_prop_window(session_t *ps, Window wid, Atom aprop) {
|
|||
|
||||
// Return it
|
||||
if (prop.nitems) {
|
||||
p = *prop.data.p32;
|
||||
p = *prop.p32;
|
||||
}
|
||||
|
||||
free_winprop(&prop);
|
||||
|
|
Loading…
Reference in New Issue