From a73510026f17713e6929f32723b8d23e88bf6998 Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Tue, 3 Sep 2019 10:43:36 +0300 Subject: [PATCH] Remove packed attribute from Rect Fixes #3785 -- the issue where the Travis build failed because of gcc's -Werror=address-of-packed-member. Adds an equality function to avoid relying on memcmp(). --- include/data.h | 2 +- include/util.h | 1 + src/commands.c | 2 +- src/floating.c | 3 +-- src/load_layout.c | 3 +-- src/scratchpad.c | 2 +- src/util.c | 4 ++++ src/x.c | 7 +++---- 8 files changed, 13 insertions(+), 11 deletions(-) diff --git a/include/data.h b/include/data.h index 4c6ecb8c..82027f75 100644 --- a/include/data.h +++ b/include/data.h @@ -159,7 +159,7 @@ struct Rect { uint32_t y; uint32_t width; uint32_t height; -} __attribute__((packed)); +}; /** * Stores the reserved pixels on each screen edge read from a diff --git a/include/util.h b/include/util.h index d08ac69d..7a2b3083 100644 --- a/include/util.h +++ b/include/util.h @@ -64,6 +64,7 @@ int max(int a, int b); bool rect_contains(Rect rect, uint32_t x, uint32_t y); Rect rect_add(Rect a, Rect b); Rect rect_sub(Rect a, Rect b); +bool rect_equals(Rect a, Rect b); /** * Returns true if the name consists of only digits. diff --git a/src/commands.c b/src/commands.c index aadf204f..5b11fce1 100644 --- a/src/commands.c +++ b/src/commands.c @@ -469,7 +469,7 @@ static void cmd_resize_floating(I3_CMD, const char *way, const char *direction_s /* Did we actually resize anything or did the size constraints prevent us? * If we could not resize, exit now to not move the window. */ - if (memcmp(&old_rect, &(floating_con->rect), sizeof(Rect)) == 0) { + if (rect_equals(old_rect, floating_con->rect)) { return; } diff --git a/src/floating.c b/src/floating.c index 79f1d3d3..9a721301 100644 --- a/src/floating.c +++ b/src/floating.c @@ -322,11 +322,10 @@ void floating_enable(Con *con, bool automatic) { DLOG("Original rect: (%d, %d) with %d x %d\n", con->rect.x, con->rect.y, con->rect.width, con->rect.height); DLOG("Geometry = (%d, %d) with %d x %d\n", con->geometry.x, con->geometry.y, con->geometry.width, con->geometry.height); - Rect zero = {0, 0, 0, 0}; nc->rect = con->geometry; /* If the geometry was not set (split containers), we need to determine a * sensible one by combining the geometry of all children */ - if (memcmp(&(nc->rect), &zero, sizeof(Rect)) == 0) { + if (rect_equals(nc->rect, (Rect){0, 0, 0, 0})) { DLOG("Geometry not set, combining children\n"); Con *child; TAILQ_FOREACH(child, &(con->nodes_head), nodes) { diff --git a/src/load_layout.c b/src/load_layout.c index 47daada1..4f107cd6 100644 --- a/src/load_layout.c +++ b/src/load_layout.c @@ -141,8 +141,7 @@ static int json_end_map(void *ctx) { // Also set a size if none was supplied, otherwise the placeholder // window cannot be created as X11 requests with width=0 or // height=0 are invalid. - const Rect zero = {0, 0, 0, 0}; - if (memcmp(&(json_node->rect), &zero, sizeof(Rect)) == 0) { + if (rect_equals(json_node->rect, (Rect){0, 0, 0, 0})) { DLOG("Geometry not set, combining children\n"); Con *child; TAILQ_FOREACH(child, &(json_node->nodes_head), nodes) { diff --git a/src/scratchpad.c b/src/scratchpad.c index b7fbcc92..b74e4a6f 100644 --- a/src/scratchpad.c +++ b/src/scratchpad.c @@ -279,7 +279,7 @@ void scratchpad_fix_resolution(void) { Rect new_rect = __i3_output->rect; - if (memcmp(&old_rect, &new_rect, sizeof(Rect)) == 0) { + if (rect_equals(new_rect, old_rect)) { DLOG("Scratchpad size unchanged.\n"); return; } diff --git a/src/util.c b/src/util.c index 9fe3fa44..812aad37 100644 --- a/src/util.c +++ b/src/util.c @@ -53,6 +53,10 @@ Rect rect_sub(Rect a, Rect b) { a.height - b.height}; } +bool rect_equals(Rect a, Rect b) { + return a.x == b.x && a.y == b.y && a.width == b.width && a.height == b.height; +} + /* * Returns true if the name consists of only digits. * diff --git a/src/x.c b/src/x.c index e6d875e5..43824bbc 100644 --- a/src/x.c +++ b/src/x.c @@ -251,8 +251,7 @@ void x_move_win(Con *src, Con *dest) { state_dest->con = state_src->con; state_src->con = NULL; - Rect zero = {0, 0, 0, 0}; - if (memcmp(&(state_dest->window_rect), &(zero), sizeof(Rect)) == 0) { + if (rect_equals(state_dest->window_rect, (Rect){0, 0, 0, 0})) { memcpy(&(state_dest->window_rect), &(state_src->window_rect), sizeof(Rect)); DLOG("COPYING RECT\n"); } @@ -929,7 +928,7 @@ void x_push_node(Con *con) { bool fake_notify = false; /* Set new position if rect changed (and if height > 0) or if the pixmap * needs to be recreated */ - if ((is_pixmap_needed && con->frame_buffer.id == XCB_NONE) || (memcmp(&(state->rect), &rect, sizeof(Rect)) != 0 && + if ((is_pixmap_needed && con->frame_buffer.id == XCB_NONE) || (!rect_equals(state->rect, rect) && rect.height > 0)) { /* We first create the new pixmap, then render to it, set it as the * background and only afterwards change the window size. This reduces @@ -1008,7 +1007,7 @@ void x_push_node(Con *con) { /* dito, but for child windows */ if (con->window != NULL && - memcmp(&(state->window_rect), &(con->window_rect), sizeof(Rect)) != 0) { + !rect_equals(state->window_rect, con->window_rect)) { DLOG("setting window rect (%d, %d, %d, %d)\n", con->window_rect.x, con->window_rect.y, con->window_rect.width, con->window_rect.height); xcb_set_window_rect(conn, con->window->id, con->window_rect);