From: Michael Stapelberg Date: Sat, 11 Apr 2009 12:08:19 +0000 (+0200) Subject: General small cleanups X-Git-Tag: 3.a-bf1~46 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=8cc1fcf536486a7229db906d432094afa0066002;p=i3%2Fi3 General small cleanups --- diff --git a/include/util.h b/include/util.h index b575e3fc..01d7af69 100644 --- a/include/util.h +++ b/include/util.h @@ -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 diff --git a/src/commands.c b/src/commands.c index 7926c03f..bd3e9f1c 100644 --- a/src/commands.c +++ b/src/commands.c @@ -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); diff --git a/src/handlers.c b/src/handlers.c index caf08bf0..19ceebd2 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -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) { diff --git a/src/layout.c b/src/layout.c index 153d0454..dcb48340 100644 --- a/src/layout.c +++ b/src/layout.c @@ -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"); diff --git a/src/mainx.c b/src/mainx.c index ef71b0fa..9f93888a 100644 --- a/src/mainx.c +++ b/src/mainx.c @@ -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) { diff --git a/src/util.c b/src/util.c index a926bda5..1ac3357d 100644 --- a/src/util.c +++ b/src/util.c @@ -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 */ diff --git a/src/xcb.c b/src/xcb.c index dc83efa5..383500c7 100644 --- 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); }