Some cleanups, remove some unnecessary stuff, fix focus bugs

This commit is contained in:
Michael Stapelberg 2009-02-11 01:33:18 +01:00
parent 97d5887320
commit a8dd2d8388
2 changed files with 32 additions and 26 deletions

1
data.h
View File

@ -84,6 +84,7 @@ struct Client {
/* Backpointer. A client is inside a container */ /* Backpointer. A client is inside a container */
Container *container; Container *container;
int x, y;
int width, height; int width, height;
/* XCB contexts */ /* XCB contexts */

57
mainx.c
View File

@ -348,7 +348,6 @@ uint32_t get_colorpixel(xcb_connection_t *conn, xcb_window_t window, char *hex)
void decorate_window(xcb_connection_t *conn, Client *client) { void decorate_window(xcb_connection_t *conn, Client *client) {
uint32_t mask = 0; uint32_t mask = 0;
uint32_t values[3]; uint32_t values[3];
xcb_screen_t *root_screen = xcb_setup_roots_iterator(xcb_get_setup(conn)).data;
i3Font *font = load_font(conn, pattern); i3Font *font = load_font(conn, pattern);
uint32_t background_color, uint32_t background_color,
text_color, text_color,
@ -427,6 +426,7 @@ void render_container(xcb_connection_t *connection, Container *container) {
int current_client = 0; int current_client = 0;
CIRCLEQ_FOREACH(client, &(container->clients), clients) { CIRCLEQ_FOREACH(client, &(container->clients), clients) {
/* TODO: rewrite this block so that the need to puke vanishes :) */
/* TODO: at the moment, every column/row is 200px. This /* TODO: at the moment, every column/row is 200px. This
* needs to be changed to "percentage of the screen" by * needs to be changed to "percentage of the screen" by
* default and adjustable by the user if necessary. * default and adjustable by the user if necessary.
@ -434,18 +434,27 @@ void render_container(xcb_connection_t *connection, Container *container) {
values[0] = container->col * container->width; /* x */ values[0] = container->col * container->width; /* x */
values[1] = container->row * container->height + values[1] = container->row * container->height +
(container->height / num_clients) * current_client; /* y */ (container->height / num_clients) * current_client; /* y */
if (client->x != values[0] || client->y != values[1]) {
printf("frame needs to be pushed to %dx%d\n",
values[0], values[1]);
client->x = values[0];
client->y = values[1];
xcb_configure_window(connection, client->frame,
XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, values);
}
/* TODO: vertical default layout */ /* TODO: vertical default layout */
values[2] = container->width; /* width */ values[0] = container->width; /* width */
values[3] = container->height / num_clients; /* height */ values[1] = container->height / num_clients; /* height */
printf("frame will be at %dx%d with size %dx%d\n",
values[0], values[1], values[2], values[3]);
client->width = values[2]; if (client->width != values[0] || client->height != values[1]) {
client->height = values[3]; client->width = values[0];
client->height = values[1];
/* TODO: update only if necessary */ xcb_configure_window(connection, client->frame,
xcb_configure_window(connection, client->frame, mask, values); XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, values);
}
/* TODO: hmm, only do this for new wins */
/* The coordinates of the child are relative to its frame, we /* The coordinates of the child are relative to its frame, we
* add a border of 2 pixel to each value */ * add a border of 2 pixel to each value */
values[0] = 2; values[0] = 2;
@ -512,7 +521,6 @@ void reparent_window(xcb_connection_t *conn, xcb_window_t child,
} }
uint32_t mask = 0; uint32_t mask = 0;
uint32_t values[3]; uint32_t values[3];
xcb_screen_t *root_screen = xcb_setup_roots_iterator(xcb_get_setup(conn)).data;
/* Insert into the currently active container */ /* Insert into the currently active container */
CIRCLEQ_INSERT_TAIL(&(CUR_CELL->clients), new, clients); CIRCLEQ_INSERT_TAIL(&(CUR_CELL->clients), new, clients);
@ -526,16 +534,16 @@ void reparent_window(xcb_connection_t *conn, xcb_window_t child,
new->width = width; new->width = width;
new->height = height; new->height = height;
/* TODO: what do these mean? */ /* Dont generate events for our new window, it should *not* be managed */
mask |= XCB_CW_BACK_PIXEL;
values[0] = root_screen->white_pixel;
mask |= XCB_CW_OVERRIDE_REDIRECT; mask |= XCB_CW_OVERRIDE_REDIRECT;
values[1] = 1; values[0] = 1;
/* We want to know when… */
mask |= XCB_CW_EVENT_MASK; mask |= XCB_CW_EVENT_MASK;
values[2] = XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE values[1] = XCB_EVENT_MASK_BUTTON_PRESS | /* …mouse is pressed/released */
| XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_ENTER_WINDOW; XCB_EVENT_MASK_BUTTON_RELEASE |
XCB_EVENT_MASK_EXPOSURE | /* …our window needs to be redrawn */
XCB_EVENT_MASK_ENTER_WINDOW /* …user moves cursor inside our window */;
printf("Reparenting 0x%08x under 0x%08x.\n", child, new->frame); printf("Reparenting 0x%08x under 0x%08x.\n", child, new->frame);
@ -580,12 +588,10 @@ void reparent_window(xcb_connection_t *conn, xcb_window_t child,
XCB_EVENT_MASK_ENTER_WINDOW; XCB_EVENT_MASK_ENTER_WINDOW;
xcb_change_window_attributes(conn, child, mask, values); xcb_change_window_attributes(conn, child, mask, values);
/* TODO: At the moment, new windows just get focus */ /* Focus the new window */
xcb_set_input_focus(conn, XCB_INPUT_FOCUS_NONE, new->frame, XCB_CURRENT_TIME); xcb_set_input_focus(conn, XCB_INPUT_FOCUS_NONE, new->child, XCB_CURRENT_TIME);
render_layout(conn); render_layout(conn);
xcb_flush(conn);
} }
static bool focus_window_in_container(xcb_connection_t *connection, Container *container, static bool focus_window_in_container(xcb_connection_t *connection, Container *container,
@ -608,7 +614,6 @@ static bool focus_window_in_container(xcb_connection_t *connection, Container *c
container->currently_focused = candidad; container->currently_focused = candidad;
xcb_set_input_focus(connection, XCB_INPUT_FOCUS_NONE, candidad->child, XCB_CURRENT_TIME); xcb_set_input_focus(connection, XCB_INPUT_FOCUS_NONE, candidad->child, XCB_CURRENT_TIME);
render_layout(connection); render_layout(connection);
xcb_flush(connection);
return true; return true;
} }
@ -638,7 +643,6 @@ static void focus_window(xcb_connection_t *connection, direction_t direction) {
xcb_set_input_focus(connection, XCB_INPUT_FOCUS_NONE, xcb_set_input_focus(connection, XCB_INPUT_FOCUS_NONE,
CUR_CELL->currently_focused->child, XCB_CURRENT_TIME); CUR_CELL->currently_focused->child, XCB_CURRENT_TIME);
render_layout(connection); render_layout(connection);
xcb_flush(connection);
} }
} else { } else {
@ -1002,6 +1006,8 @@ static int handle_key_press(void *ignored, xcb_connection_t *conn, xcb_key_press
* *
*/ */
static int handle_enter_notify(void *ignored, xcb_connection_t *conn, xcb_enter_notify_event_t *event) { static int handle_enter_notify(void *ignored, xcb_connection_t *conn, xcb_enter_notify_event_t *event) {
printf("enter_notify\n");
/* This was either a focus for a clients parent (= titlebar)… */ /* This was either a focus for a clients parent (= titlebar)… */
Client *client = table_get(byParent, event->event), Client *client = table_get(byParent, event->event),
*old_client; *old_client;
@ -1023,7 +1029,7 @@ static int handle_enter_notify(void *ignored, xcb_connection_t *conn, xcb_enter_
current_row = client->container->row; current_row = client->container->row;
/* Set focus to the entered window, and flush xcb buffer immediately */ /* Set focus to the entered window, and flush xcb buffer immediately */
xcb_set_input_focus(conn, XCB_INPUT_FOCUS_POINTER_ROOT, client->child, XCB_CURRENT_TIME); xcb_set_input_focus(conn, XCB_INPUT_FOCUS_NONE, client->child, XCB_CURRENT_TIME);
/* Update last/current clients titlebar */ /* Update last/current clients titlebar */
if (old_client != NULL) if (old_client != NULL)
decorate_window(conn, old_client); decorate_window(conn, old_client);
@ -1033,7 +1039,6 @@ static int handle_enter_notify(void *ignored, xcb_connection_t *conn, xcb_enter_
return 1; return 1;
} }
int handle_map_notify_event(void *prophs, xcb_connection_t *c, xcb_map_notify_event_t *e) int handle_map_notify_event(void *prophs, xcb_connection_t *c, xcb_map_notify_event_t *e)
{ {
window_attributes_t wa = { TAG_VALUE }; window_attributes_t wa = { TAG_VALUE };