]> git.sur5r.net Git - i3/i3/commitdiff
General small cleanups
authorMichael Stapelberg <michael+x200@stapelberg.de>
Sat, 11 Apr 2009 12:08:19 +0000 (14:08 +0200)
committerMichael Stapelberg <michael+x200@stapelberg.de>
Sat, 11 Apr 2009 12:08:19 +0000 (14:08 +0200)
include/util.h
src/commands.c
src/handlers.c
src/layout.c
src/mainx.c
src/util.c
src/xcb.c

index b575e3fc68ce631ff3320352cb7724a0a3fb72be..01d7af698fdc8d3bbdc3a92d12cb350eb07311eb 100644 (file)
@@ -109,6 +109,13 @@ char *convert_utf8_to_ucs2(char *input, int *real_strlen);
  */
 void remove_client_from_container(xcb_connection_t *conn, Client *client, Container *container);
 
+/**
+ * Returns the client which comes next in focus stack (= was selected before) for
+ * the given container, optionally excluding the given client.
+ *
+ */
+Client *get_last_focused_client(xcb_connection_t *conn, Container *container, Client *exclude);
+
 /**
  * Sets the given client as focused by updating the data structures correctly,
  * updating the X input focus and finally re-decorating both windows (to signalize
index 7926c03f5572a2e13844544608cf078a89bbc356..bd3e9f1c16aefdd036497958be717a97a7233ce2 100644 (file)
@@ -174,13 +174,7 @@ static void move_current_window(xcb_connection_t *conn, direction_t direction) {
         /* As soon as the client is moved away, the last focused client in the old
          * container needs to get focus, if any. Therefore, we save it here. */
         Client *current_client = container->currently_focused;
-        Client *to_focus = NULL, *client_loop;
-
-        SLIST_FOREACH(client_loop, &(container->workspace->focus_stack), focus_clients)
-                if ((client_loop->container == container) && (client_loop != current_client)) {
-                        to_focus = client_loop;
-                        break;
-                }
+        Client *to_focus = get_last_focused_client(conn, container, current_client);
 
         if (to_focus == NULL) {
                 to_focus = CIRCLEQ_NEXT_OR_NULL(&(container->clients), current_client, clients);
index caf08bf0c9e728bdde1fa863a462f33e0cc04295..19ceebd25b414704e0014f56d2223224a86e5796 100644 (file)
@@ -614,16 +614,11 @@ int handle_unmap_notify_event(void *data, xcb_connection_t *conn, xcb_unmap_noti
                 remove_client_from_container(conn, client, con);
 
                 /* Set focus to the last focused client in this container */
-                con->currently_focused = NULL;
-                Client *focus_client;
-                SLIST_FOREACH(focus_client, &(con->workspace->focus_stack), focus_clients)
-                        if (focus_client->container == con) {
-                                con->currently_focused = focus_client;
-                                /* Only if this is the active container, we need to really change focus */
-                                if (con == CUR_CELL)
-                                        set_focus(conn, focus_client, false);
-                                break;
-                        }
+                con->currently_focused = get_last_focused_client(conn, con, NULL);
+
+                /* Only if this is the active container, we need to really change focus */
+                if ((con->currently_focused != NULL) && (con == CUR_CELL))
+                        set_focus(conn, con->currently_focused, false);
         }
 
         if (client->dock) {
index 153d045450a7a8810e1b90d43c946f94913078c8..dcb48340d3c7cd760fd6763624e84f39b5c17fc6 100644 (file)
@@ -402,6 +402,7 @@ static void render_bars(xcb_connection_t *conn, Workspace *r_ws, int width, int
                         resize_client(conn, client);
 
                 client->force_reconfigure = false;
+                LOG("desired_height = %d\n", client->desired_height);
                 *height += client->desired_height;
         }
 }
@@ -437,21 +438,22 @@ static void render_internal_bar(xcb_connection_t *conn, Workspace *r_ws, int wid
 
         int drawn = 0;
         for (int c = 0; c < 10; c++) {
-                if (workspaces[c].screen == screen) {
-                        int set = (screen->current_workspace == c ? SET_FOCUSED : SET_NORMAL);
-
-                        xcb_draw_rect(conn, screen->bar, screen->bargc, border_color[set],
-                                      drawn * height, 1, height - 2, height - 2);
-                        xcb_draw_rect(conn, screen->bar, screen->bargc, background_color[set],
-                                      drawn * height + 1, 2, height - 4, height - 4);
-
-                        snprintf(label, sizeof(label), "%d", c+1);
-                        xcb_change_gc_single(conn, screen->bargc, XCB_GC_FOREGROUND, text_color[set]);
-                        xcb_change_gc_single(conn, screen->bargc, XCB_GC_BACKGROUND, background_color[set]);
-                        xcb_image_text_8(conn, strlen(label), screen->bar, screen->bargc, drawn * height + 5 /* X */,
-                                                        font->height + 1 /* Y = baseline of font */, label);
-                        drawn++;
-                }
+                if (workspaces[c].screen != screen)
+                        continue;
+
+                int set = (screen->current_workspace == c ? SET_FOCUSED : SET_NORMAL);
+
+                xcb_draw_rect(conn, screen->bar, screen->bargc, border_color[set],
+                              drawn * height, 1, height - 2, height - 2);
+                xcb_draw_rect(conn, screen->bar, screen->bargc, background_color[set],
+                              drawn * height + 1, 2, height - 4, height - 4);
+
+                snprintf(label, sizeof(label), "%d", c+1);
+                xcb_change_gc_single(conn, screen->bargc, XCB_GC_FOREGROUND, text_color[set]);
+                xcb_change_gc_single(conn, screen->bargc, XCB_GC_BACKGROUND, background_color[set]);
+                xcb_image_text_8(conn, strlen(label), screen->bar, screen->bargc, drawn * height + 5 /* X */,
+                                                font->height + 1 /* Y = baseline of font */, label);
+                drawn++;
         }
 
         LOG("done rendering internal\n");
index ef71b0fa18954efc1077fc3375ca84165f7378f0..9f93888a7b543f89deaebe79810eaf92228528a5 100644 (file)
@@ -467,7 +467,7 @@ int main(int argc, char *argv[], char *env[]) {
         #define GET_ATOM(name) { \
                 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(conn, atom_cookies[name], NULL); \
                 if (!reply) { \
-                        printf("Could not get atom " #name "\n"); \
+                        LOG("Could not get atom " #name "\n"); \
                         exit(-1); \
                 } \
                 atoms[name] = reply->atom; \
@@ -538,7 +538,7 @@ int main(int argc, char *argv[], char *env[]) {
 
         i3Screen *screen = get_screen_containing(reply->root_x, reply->root_y);
         if (screen == NULL) {
-                printf("ERROR: No screen at %d x %d\n", reply->root_x, reply->root_y);
+                LOG("ERROR: No screen at %d x %d\n", reply->root_x, reply->root_y);
                 return 0;
         }
         if (screen->current_workspace != 0) {
index a926bda5b298448cca06f92b59351ab51cddc497..1ac3357d048e28daa75c14cbd7e6759cee6433f9 100644 (file)
@@ -151,7 +151,6 @@ char *convert_utf8_to_ucs2(char *input, int *real_strlen) {
        size_t input_size = strlen(input) + 1;
        /* UCS-2 consumes exactly two bytes for each glyph */
        int buffer_size = input_size * 2;
-       printf("reserving %d bytes\n", buffer_size);
 
        char *buffer = smalloc(buffer_size);
        size_t output_size = buffer_size;
@@ -202,6 +201,19 @@ void remove_client_from_container(xcb_connection_t *conn, Client *client, Contai
         }
 }
 
+/*
+ * Returns the client which comes next in focus stack (= was selected before) for
+ * the given container, optionally excluding the given client.
+ *
+ */
+Client *get_last_focused_client(xcb_connection_t *conn, Container *container, Client *exclude) {
+        Client *current;
+        SLIST_FOREACH(current, &(container->workspace->focus_stack), focus_clients)
+                if ((current->container == container) && ((exclude == NULL) || (current != exclude)))
+                        return current;
+        return NULL;
+}
+
 /*
  * Sets the given client as focused by updating the data structures correctly,
  * updating the X input focus and finally re-decorating both windows (to signalize
@@ -240,14 +252,11 @@ void set_focus(xcb_connection_t *conn, Client *client, bool set_anyways) {
 
         /* Get the client which was last focused in this particular container, it may be a different
            one than old_client */
-        Client *last_container_client;
-        SLIST_FOREACH(last_container_client, &(c_ws->focus_stack), focus_clients)
-                if (last_container_client->container == client->container) {
-                        /* But if it is the same one as old_client, we save us the unnecessary redecorate */
-                        if (last_container_client != old_client)
-                                redecorate_window(conn, last_container_client);
-                        break;
-                }
+        Client *last_focused = get_last_focused_client(conn, client->container, NULL);
+
+        /* If it is the same one as old_client, we save us the unnecessary redecorate */
+        if ((last_focused != NULL) && (last_focused != old_client))
+                redecorate_window(conn, last_focused);
 
         /* If we’re in stacking mode, this renders the container to update changes in the title
            bars and to raise the focused client */
index dc83efa5a86234f481278e9d6a173f54d3bcc1a5..383500c71de0fa2d41ab5deb6abde3777a8ae86a 100644 (file)
--- a/src/xcb.c
+++ b/src/xcb.c
@@ -95,7 +95,7 @@ uint32_t get_colorpixel(xcb_connection_t *conn, char *hex) {
                                                             rgb16[0], rgb16[1], rgb16[2]), NULL);
 
         if (!reply) {
-                printf("Could not allocate color\n");
+                LOG("Could not allocate color\n");
                 exit(1);
         }