General small cleanups
This commit is contained in:
parent
e3516d72f5
commit
8cc1fcf536
|
@ -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);
|
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,
|
* 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
|
* updating the X input focus and finally re-decorating both windows (to signalize
|
||||||
|
|
|
@ -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
|
/* 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. */
|
* container needs to get focus, if any. Therefore, we save it here. */
|
||||||
Client *current_client = container->currently_focused;
|
Client *current_client = container->currently_focused;
|
||||||
Client *to_focus = NULL, *client_loop;
|
Client *to_focus = get_last_focused_client(conn, container, current_client);
|
||||||
|
|
||||||
SLIST_FOREACH(client_loop, &(container->workspace->focus_stack), focus_clients)
|
|
||||||
if ((client_loop->container == container) && (client_loop != current_client)) {
|
|
||||||
to_focus = client_loop;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (to_focus == NULL) {
|
if (to_focus == NULL) {
|
||||||
to_focus = CIRCLEQ_NEXT_OR_NULL(&(container->clients), current_client, clients);
|
to_focus = CIRCLEQ_NEXT_OR_NULL(&(container->clients), current_client, clients);
|
||||||
|
|
|
@ -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);
|
remove_client_from_container(conn, client, con);
|
||||||
|
|
||||||
/* Set focus to the last focused client in this container */
|
/* Set focus to the last focused client in this container */
|
||||||
con->currently_focused = NULL;
|
con->currently_focused = get_last_focused_client(conn, con, NULL);
|
||||||
Client *focus_client;
|
|
||||||
SLIST_FOREACH(focus_client, &(con->workspace->focus_stack), focus_clients)
|
/* Only if this is the active container, we need to really change focus */
|
||||||
if (focus_client->container == con) {
|
if ((con->currently_focused != NULL) && (con == CUR_CELL))
|
||||||
con->currently_focused = focus_client;
|
set_focus(conn, con->currently_focused, false);
|
||||||
/* 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 (client->dock) {
|
if (client->dock) {
|
||||||
|
|
28
src/layout.c
28
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);
|
resize_client(conn, client);
|
||||||
|
|
||||||
client->force_reconfigure = false;
|
client->force_reconfigure = false;
|
||||||
|
LOG("desired_height = %d\n", client->desired_height);
|
||||||
*height += 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;
|
int drawn = 0;
|
||||||
for (int c = 0; c < 10; c++) {
|
for (int c = 0; c < 10; c++) {
|
||||||
if (workspaces[c].screen == screen) {
|
if (workspaces[c].screen != screen)
|
||||||
int set = (screen->current_workspace == c ? SET_FOCUSED : SET_NORMAL);
|
continue;
|
||||||
|
|
||||||
xcb_draw_rect(conn, screen->bar, screen->bargc, border_color[set],
|
int set = (screen->current_workspace == c ? SET_FOCUSED : SET_NORMAL);
|
||||||
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_draw_rect(conn, screen->bar, screen->bargc, border_color[set],
|
||||||
xcb_change_gc_single(conn, screen->bargc, XCB_GC_FOREGROUND, text_color[set]);
|
drawn * height, 1, height - 2, height - 2);
|
||||||
xcb_change_gc_single(conn, screen->bargc, XCB_GC_BACKGROUND, background_color[set]);
|
xcb_draw_rect(conn, screen->bar, screen->bargc, background_color[set],
|
||||||
xcb_image_text_8(conn, strlen(label), screen->bar, screen->bargc, drawn * height + 5 /* X */,
|
drawn * height + 1, 2, height - 4, height - 4);
|
||||||
font->height + 1 /* Y = baseline of font */, label);
|
|
||||||
drawn++;
|
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");
|
LOG("done rendering internal\n");
|
||||||
|
|
|
@ -467,7 +467,7 @@ int main(int argc, char *argv[], char *env[]) {
|
||||||
#define GET_ATOM(name) { \
|
#define GET_ATOM(name) { \
|
||||||
xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(conn, atom_cookies[name], NULL); \
|
xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(conn, atom_cookies[name], NULL); \
|
||||||
if (!reply) { \
|
if (!reply) { \
|
||||||
printf("Could not get atom " #name "\n"); \
|
LOG("Could not get atom " #name "\n"); \
|
||||||
exit(-1); \
|
exit(-1); \
|
||||||
} \
|
} \
|
||||||
atoms[name] = reply->atom; \
|
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);
|
i3Screen *screen = get_screen_containing(reply->root_x, reply->root_y);
|
||||||
if (screen == NULL) {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
if (screen->current_workspace != 0) {
|
if (screen->current_workspace != 0) {
|
||||||
|
|
27
src/util.c
27
src/util.c
|
@ -151,7 +151,6 @@ char *convert_utf8_to_ucs2(char *input, int *real_strlen) {
|
||||||
size_t input_size = strlen(input) + 1;
|
size_t input_size = strlen(input) + 1;
|
||||||
/* UCS-2 consumes exactly two bytes for each glyph */
|
/* UCS-2 consumes exactly two bytes for each glyph */
|
||||||
int buffer_size = input_size * 2;
|
int buffer_size = input_size * 2;
|
||||||
printf("reserving %d bytes\n", buffer_size);
|
|
||||||
|
|
||||||
char *buffer = smalloc(buffer_size);
|
char *buffer = smalloc(buffer_size);
|
||||||
size_t output_size = 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,
|
* 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
|
* 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
|
/* Get the client which was last focused in this particular container, it may be a different
|
||||||
one than old_client */
|
one than old_client */
|
||||||
Client *last_container_client;
|
Client *last_focused = get_last_focused_client(conn, client->container, NULL);
|
||||||
SLIST_FOREACH(last_container_client, &(c_ws->focus_stack), focus_clients)
|
|
||||||
if (last_container_client->container == client->container) {
|
/* If it is the same one as old_client, we save us the unnecessary redecorate */
|
||||||
/* But if it is the same one as old_client, we save us the unnecessary redecorate */
|
if ((last_focused != NULL) && (last_focused != old_client))
|
||||||
if (last_container_client != old_client)
|
redecorate_window(conn, last_focused);
|
||||||
redecorate_window(conn, last_container_client);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If we’re in stacking mode, this renders the container to update changes in the title
|
/* If we’re in stacking mode, this renders the container to update changes in the title
|
||||||
bars and to raise the focused client */
|
bars and to raise the focused client */
|
||||||
|
|
Loading…
Reference in New Issue