*/
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
/* 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);
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) {
resize_client(conn, client);
client->force_reconfigure = false;
+ LOG("desired_height = %d\n", client->desired_height);
*height += client->desired_height;
}
}
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");
#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; \
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) {
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;
}
}
+/*
+ * 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
/* 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 */
rgb16[0], rgb16[1], rgb16[2]), NULL);
if (!reply) {
- printf("Could not allocate color\n");
+ LOG("Could not allocate color\n");
exit(1);
}