General small cleanups

This commit is contained in:
Michael Stapelberg 2009-04-11 14:08:19 +02:00
parent e3516d72f5
commit 8cc1fcf536
7 changed files with 49 additions and 42 deletions

View 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

View 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);

View 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;
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 == CUR_CELL)
set_focus(conn, focus_client, false);
break;
}
if ((con->currently_focused != NULL) && (con == CUR_CELL))
set_focus(conn, con->currently_focused, false);
}
if (client->dock) {

View 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,7 +438,9 @@ 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) {
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],
@ -452,7 +455,6 @@ static void render_internal_bar(xcb_connection_t *conn, Workspace *r_ws, int wid
font->height + 1 /* Y = baseline of font */, label);
drawn++;
}
}
LOG("done rendering internal\n");
}

View 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) {

View 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 were in stacking mode, this renders the container to update changes in the title
bars and to raise the focused client */

View File

@ -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);
}