]> git.sur5r.net Git - i3/i3/commitdiff
Move HAS_CHANGED into a function
authorMichael Stapelberg <michael+x200@stapelberg.de>
Thu, 5 Mar 2009 15:23:26 +0000 (16:23 +0100)
committerMichael Stapelberg <michael+x200@stapelberg.de>
Thu, 5 Mar 2009 15:23:26 +0000 (16:23 +0100)
src/layout.c

index 6a441e8c32542d05643bf0937d6c36981f31efd5..a6507f3a016af3d4d370d52e87440db625a8145d 100644 (file)
 #include "xinerama.h"
 #include "layout.h"
 
-/* This macro copies the old value of the given variable, changes the variable to contain
-   the new one and returns true if it changed.
-   Note that when combining multiple HAS_CHANGED statements, you need to use different variables.
-   If someone by chance knows why this is necessary (order of expressions in gcc?) and/or can
-   come up with a fix, please mail me. */
-#define HAS_CHANGED(temp, value, new) (temp = value, temp != (value = new))
-
-static int old_value_1;
-static int old_value_2;
-static int old_value_3;
-static int old_value_4;
+/*
+ * Updates *destination with new_value and returns true if it was changed or false
+ * if it was the same
+ *
+ */
+static bool update_if_necessary(uint32_t *destination, const uint32_t new_value) {
+        int old_value = *destination;
+
+        return ((*destination = new_value) != old_value);
+}
 
 /*
  * Gets the unoccupied space (= space which is available for windows which were resized by the user)
@@ -257,15 +256,15 @@ void render_container(xcb_connection_t *conn, Container *container) {
                         /* Check if we changed client->x or client->y by updating it.
                          * Note the bitwise OR instead of logical OR to force evaluation of both statements */
                         if (client->force_reconfigure |
-                            HAS_CHANGED(old_value_1, client->rect.x, container->x) |
-                            HAS_CHANGED(old_value_2, client->rect.y, container->y +
+                            update_if_necessary(&(client->rect.x), container->x) |
+                            update_if_necessary(&(client->rect.y), container->y +
                                         (container->height / num_clients) * current_client))
                                 reposition_client(conn, client);
 
                         /* TODO: vertical default layout */
                         if (client->force_reconfigure |
-                            HAS_CHANGED(old_value_1, client->rect.width, container->width) |
-                            HAS_CHANGED(old_value_2, client->rect.height, container->height / num_clients))
+                            update_if_necessary(&(client->rect.width), container->width) |
+                            update_if_necessary(&(client->rect.height), container->height / num_clients))
                                 resize_client(conn, client);
 
                         client->force_reconfigure = false;
@@ -283,10 +282,10 @@ void render_container(xcb_connection_t *conn, Container *container) {
                         xcb_map_window(conn, stack_win->window);
 
                 /* Check if we need to reconfigure our stack title window */
-                if (HAS_CHANGED(old_value_1, stack_win->rect.x, container->x) |
-                    HAS_CHANGED(old_value_2, stack_win->rect.y, container->y) |
-                    HAS_CHANGED(old_value_3, stack_win->rect.width, container->width) |
-                    HAS_CHANGED(old_value_4, stack_win->rect.height, decoration_height * num_clients)) {
+                if (update_if_necessary(&(stack_win->rect.x), container->x) |
+                    update_if_necessary(&(stack_win->rect.y), container->y) |
+                    update_if_necessary(&(stack_win->rect.width), container->width) |
+                    update_if_necessary(&(stack_win->rect.height), decoration_height * num_clients)) {
 
                         uint32_t values[] = { stack_win->rect.x, stack_win->rect.y,
                                               stack_win->rect.width, stack_win->rect.height,
@@ -312,13 +311,13 @@ void render_container(xcb_connection_t *conn, Container *container) {
                         /* Check if we changed client->x or client->y by updating it.
                          * Note the bitwise OR instead of logical OR to force evaluation of both statements */
                         if (client->force_reconfigure |
-                            HAS_CHANGED(old_value_1, client->rect.x, container->x) |
-                            HAS_CHANGED(old_value_2, client->rect.y, container->y + (decoration_height * num_clients)))
+                            update_if_necessary(&(client->rect.x), container->x) |
+                            update_if_necessary(&(client->rect.y), container->y + (decoration_height * num_clients)))
                                 reposition_client(conn, client);
 
                         if (client->force_reconfigure |
-                            HAS_CHANGED(old_value_1, client->rect.width, container->width) |
-                            HAS_CHANGED(old_value_2, client->rect.height, container->height - (decoration_height * num_clients)))
+                            update_if_necessary(&(client->rect.width), container->width) |
+                            update_if_necessary(&(client->rect.height), container->height - (decoration_height * num_clients)))
                                 resize_client(conn, client);
 
                         client->force_reconfigure = false;
@@ -333,13 +332,13 @@ static void render_bars(xcb_connection_t *conn, Workspace *r_ws, int width, int
         Client *client;
         SLIST_FOREACH(client, &(r_ws->dock_clients), dock_clients) {
                 if (client->force_reconfigure |
-                    HAS_CHANGED(old_value_1, client->rect.x, 0) |
-                    HAS_CHANGED(old_value_2, client->rect.y, *height))
+                    update_if_necessary(&(client->rect.x), 0) |
+                    update_if_necessary(&(client->rect.y), *height))
                         reposition_client(conn, client);
 
                 if (client->force_reconfigure |
-                    HAS_CHANGED(old_value_1, client->rect.width, width) |
-                    HAS_CHANGED(old_value_2, client->rect.height, client->desired_height))
+                    update_if_necessary(&(client->rect.width), width) |
+                    update_if_necessary(&(client->rect.height), client->desired_height))
                         resize_client(conn, client);
 
                 client->force_reconfigure = false;