From 63dd16ebac275a676792b4f9fdc898839884bffc Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Sat, 30 Mar 2019 10:19:31 +0000 Subject: [PATCH] Use int in margin_t Signed-off-by: Yuxuan Shui --- src/dbus.c | 8 ++++---- src/render.c | 8 ++++---- src/types.h | 8 ++++---- src/win.c | 23 ++++++++++++++--------- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/dbus.c b/src/dbus.c index dc54b3e..01f1d45 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -803,19 +803,19 @@ static bool cdbus_process_win_get(session_t *ps, DBusMessage *msg) { cdbus_m_win_get_do(frame_opacity, cdbus_reply_double); if (!strcmp("left_width", target)) { - cdbus_reply_uint32(ps, msg, w->frame_extents.left); + cdbus_reply_int32(ps, msg, w->frame_extents.left); return true; } if (!strcmp("right_width", target)) { - cdbus_reply_uint32(ps, msg, w->frame_extents.right); + cdbus_reply_int32(ps, msg, w->frame_extents.right); return true; } if (!strcmp("top_width", target)) { - cdbus_reply_uint32(ps, msg, w->frame_extents.top); + cdbus_reply_int32(ps, msg, w->frame_extents.top); return true; } if (!strcmp("bottom_width", target)) { - cdbus_reply_uint32(ps, msg, w->frame_extents.bottom); + cdbus_reply_int32(ps, msg, w->frame_extents.bottom); return true; } diff --git a/src/render.c b/src/render.c index 5ddbd68..074a258 100644 --- a/src/render.c +++ b/src/render.c @@ -321,10 +321,10 @@ void paint_one(session_t *ps, win *w, const region_t *reg_paint) { } else { // Painting parameters const margin_t extents = win_calc_frame_extents(w); - const auto t = (int)extents.top; - const auto l = (int)extents.left; - const auto b = (int)extents.bottom; - const auto r = (int)extents.right; + const auto t = extents.top; + const auto l = extents.left; + const auto b = extents.bottom; + const auto r = extents.right; #define COMP_BDR(cx, cy, cwid, chei) \ paint_region(ps, w, (cx), (cy), (cwid), (chei), w->frame_opacity * w->opacity, \ diff --git a/src/types.h b/src/types.h index f446833..99807d0 100644 --- a/src/types.h +++ b/src/types.h @@ -16,10 +16,10 @@ typedef enum { /// A structure representing margins around a rectangle. typedef struct { - unsigned int top; - unsigned int left; - unsigned int bottom; - unsigned int right; + int top; + int left; + int bottom; + int right; } margin_t; typedef uint32_t opacity_t; diff --git a/src/win.c b/src/win.c index c6eab85..de2fb18 100644 --- a/src/win.c +++ b/src/win.c @@ -121,10 +121,10 @@ static void win_get_region_local(const win *w, region_t *res) { void win_get_region_noframe_local(const win *w, region_t *res) { const margin_t extents = win_calc_frame_extents(w); - int x = (int)extents.left; - int y = (int)extents.top; - int width = max2(w->g.width - (int)(extents.left + extents.right), 0); - int height = max2(w->g.height - (int)(extents.top + extents.bottom), 0); + int x = extents.left; + int y = extents.top; + int width = max2(w->g.width - (extents.left + extents.right), 0); + int height = max2(w->g.height - (extents.top + extents.bottom), 0); pixman_region32_fini(res); if (width > 0 && height > 0) { @@ -141,13 +141,13 @@ void win_get_region_frame_local(const win *w, region_t *res) { res, (rect_t[]){ // top - {.x1 = 0, .y1 = 0, .x2 = w->g.width, .y2 = (int)extents.top}, + {.x1 = 0, .y1 = 0, .x2 = w->g.width, .y2 = extents.top}, // bottom - {.x1 = 0, .y1 = (int)(w->g.height - extents.bottom), .x2 = w->g.width, .y2 = w->g.height}, + {.x1 = 0, .y1 = w->g.height - extents.bottom, .x2 = w->g.width, .y2 = w->g.height}, // left - {.x1 = 0, .y1 = 0, .x2 = (int)extents.left, .y2 = w->g.height}, + {.x1 = 0, .y1 = 0, .x2 = extents.left, .y2 = w->g.height}, // right - {.x1 = (int)(w->g.width - extents.right), .y1 = 0, .x2 = w->g.width, .y2 = w->g.height}, + {.x1 = w->g.width - extents.right, .y1 = 0, .x2 = w->g.width, .y2 = w->g.height}, }, 4); @@ -1358,7 +1358,12 @@ void win_update_frame_extents(session_t *ps, win *w, xcb_window_t client) { wid_get_prop(ps, client, ps->atom_frame_extents, 4L, XCB_ATOM_CARDINAL, 32); if (prop.nitems == 4) { - const uint32_t *const extents = prop.c32; + const int32_t extents[4] = { + to_int_checked(prop.c32[0]), + to_int_checked(prop.c32[1]), + to_int_checked(prop.c32[2]), + to_int_checked(prop.c32[3]), + }; const bool changed = w->frame_extents.left != extents[0] || w->frame_extents.right != extents[1] || w->frame_extents.top != extents[2] ||