Use "conn" for xcb_connection and "event" for xcb_event_* variables everywhere

This commit is contained in:
Michael Stapelberg 2009-03-04 15:45:12 +01:00
parent 45827607dc
commit a02b861826
10 changed files with 153 additions and 154 deletions

View File

@ -16,7 +16,7 @@
Rect get_unoccupied_space(Workspace *workspace); Rect get_unoccupied_space(Workspace *workspace);
void decorate_window(xcb_connection_t *conn, Client *client, xcb_drawable_t drawable, xcb_gcontext_t gc, int offset); void decorate_window(xcb_connection_t *conn, Client *client, xcb_drawable_t drawable, xcb_gcontext_t gc, int offset);
void redecorate_window(xcb_connection_t *conn, Client *client); void redecorate_window(xcb_connection_t *conn, Client *client);
void render_container(xcb_connection_t *connection, Container *container); void render_container(xcb_connection_t *conn, Container *container);
void render_layout(xcb_connection_t *conn); void render_layout(xcb_connection_t *conn);
#endif #endif

View File

@ -29,10 +29,10 @@ void *smalloc(size_t size);
void *scalloc(size_t size); void *scalloc(size_t size);
char *sstrdup(const char *str); char *sstrdup(const char *str);
void start_application(const char *command); void start_application(const char *command);
void check_error(xcb_connection_t *connection, xcb_void_cookie_t cookie, char *err_message); void check_error(xcb_connection_t *conn, xcb_void_cookie_t cookie, char *err_message);
void set_focus(xcb_connection_t *conn, Client *client); void set_focus(xcb_connection_t *conn, Client *client);
void switch_layout_mode(xcb_connection_t *conn, Container *container, int mode); void switch_layout_mode(xcb_connection_t *conn, Container *container, int mode);
void warp_pointer_into(xcb_connection_t *connection, Client *client); void warp_pointer_into(xcb_connection_t *conn, Client *client);
void toggle_fullscreen(xcb_connection_t *conn, Client *client); void toggle_fullscreen(xcb_connection_t *conn, Client *client);
#endif #endif

View File

@ -34,14 +34,14 @@ enum { _NET_SUPPORTED = 0,
UTF8_STRING UTF8_STRING
}; };
i3Font *load_font(xcb_connection_t *connection, const char *pattern); i3Font *load_font(xcb_connection_t *conn, const char *pattern);
uint32_t get_colorpixel(xcb_connection_t *conn, Client *client, xcb_window_t window, char *hex); uint32_t get_colorpixel(xcb_connection_t *conn, Client *client, xcb_window_t window, char *hex);
xcb_window_t create_window(xcb_connection_t *conn, Rect r, uint16_t window_class, uint16_t cursor, xcb_window_t create_window(xcb_connection_t *conn, Rect r, uint16_t window_class, uint16_t cursor,
uint32_t mask, uint32_t *values); uint32_t mask, uint32_t *values);
void xcb_change_gc_single(xcb_connection_t *conn, xcb_gcontext_t gc, uint32_t mask, uint32_t value); void xcb_change_gc_single(xcb_connection_t *conn, xcb_gcontext_t gc, uint32_t mask, uint32_t value);
void xcb_draw_line(xcb_connection_t *conn, xcb_drawable_t drawable, xcb_gcontext_t gc, void xcb_draw_line(xcb_connection_t *conn, xcb_drawable_t drawable, xcb_gcontext_t gc,
uint32_t colorpixel, uint32_t x, uint32_t y, uint32_t to_x, uint32_t to_y); uint32_t colorpixel, uint32_t x, uint32_t y, uint32_t to_x, uint32_t to_y);
void xcb_draw_rect(xcb_connection_t *connection, xcb_drawable_t drawable, xcb_gcontext_t gc, void xcb_draw_rect(xcb_connection_t *conn, xcb_drawable_t drawable, xcb_gcontext_t gc,
uint32_t colorpixel, uint32_t x, uint32_t y, uint32_t width, uint32_t height); uint32_t colorpixel, uint32_t x, uint32_t y, uint32_t width, uint32_t height);
#endif #endif

View File

@ -24,7 +24,7 @@
#include "i3.h" #include "i3.h"
#include "xinerama.h" #include "xinerama.h"
static bool focus_window_in_container(xcb_connection_t *connection, Container *container, static bool focus_window_in_container(xcb_connection_t *conn, Container *container,
direction_t direction) { direction_t direction) {
/* If this container is empty, were done */ /* If this container is empty, were done */
if (container->currently_focused == NULL) if (container->currently_focused == NULL)
@ -42,12 +42,12 @@ static bool focus_window_in_container(xcb_connection_t *connection, Container *c
return false; return false;
/* Set focus if we could successfully move */ /* Set focus if we could successfully move */
set_focus(connection, candidate); set_focus(conn, candidate);
return true; return true;
} }
static void focus_window(xcb_connection_t *connection, direction_t direction) { static void focus_window(xcb_connection_t *conn, direction_t direction) {
printf("focusing direction %d\n", direction); printf("focusing direction %d\n", direction);
int new_row = current_row, int new_row = current_row,
@ -62,7 +62,7 @@ static void focus_window(xcb_connection_t *connection, direction_t direction) {
/* TODO: for horizontal default layout, this has to be expanded to LEFT/RIGHT */ /* TODO: for horizontal default layout, this has to be expanded to LEFT/RIGHT */
if (direction == D_UP || direction == D_DOWN) { if (direction == D_UP || direction == D_DOWN) {
/* Lets see if we can perform up/down focus in the current container */ /* Lets see if we can perform up/down focus in the current container */
if (focus_window_in_container(connection, container, direction)) if (focus_window_in_container(conn, container, direction))
return; return;
if (direction == D_DOWN && cell_exists(current_col, current_row+1)) if (direction == D_DOWN && cell_exists(current_col, current_row+1))
@ -114,7 +114,7 @@ static void focus_window(xcb_connection_t *connection, direction_t direction) {
} }
if (t_ws->table[new_col][new_row]->currently_focused != NULL) if (t_ws->table[new_col][new_row]->currently_focused != NULL)
set_focus(connection, t_ws->table[new_col][new_row]->currently_focused); set_focus(conn, t_ws->table[new_col][new_row]->currently_focused);
} }
/* /*
@ -123,7 +123,7 @@ static void focus_window(xcb_connection_t *connection, direction_t direction) {
* Returns true if the window could be moved, false otherwise. * Returns true if the window could be moved, false otherwise.
* *
*/ */
static bool move_current_window_in_container(xcb_connection_t *connection, Client *client, static bool move_current_window_in_container(xcb_connection_t *conn, Client *client,
direction_t direction) { direction_t direction) {
assert(client->container != NULL); assert(client->container != NULL);
@ -139,7 +139,7 @@ static bool move_current_window_in_container(xcb_connection_t *connection, Clien
if (direction == D_UP) if (direction == D_UP)
CIRCLEQ_INSERT_BEFORE(&(client->container->clients), other, client, clients); CIRCLEQ_INSERT_BEFORE(&(client->container->clients), other, client, clients);
else CIRCLEQ_INSERT_AFTER(&(client->container->clients), other, client, clients); else CIRCLEQ_INSERT_AFTER(&(client->container->clients), other, client, clients);
render_layout(connection); render_layout(conn);
return true; return true;
} }
@ -148,7 +148,7 @@ static bool move_current_window_in_container(xcb_connection_t *connection, Clien
* necessary * necessary
* *
*/ */
static void move_current_window(xcb_connection_t *connection, direction_t direction) { static void move_current_window(xcb_connection_t *conn, direction_t direction) {
printf("moving window to direction %s\n", (direction == D_UP ? "up" : (direction == D_DOWN ? "down" : printf("moving window to direction %s\n", (direction == D_UP ? "up" : (direction == D_DOWN ? "down" :
(direction == D_LEFT ? "left" : "right")))); (direction == D_LEFT ? "left" : "right"))));
/* Get current window */ /* Get current window */
@ -186,14 +186,14 @@ static void move_current_window(xcb_connection_t *connection, direction_t direct
break; break;
case D_UP: case D_UP:
/* TODO: if were at the up-most position, move the rest of the table down */ /* TODO: if were at the up-most position, move the rest of the table down */
if (move_current_window_in_container(connection, current_client, D_UP) || if (move_current_window_in_container(conn, current_client, D_UP) ||
current_row == 0) current_row == 0)
return; return;
new = CUR_TABLE[current_col][--current_row]; new = CUR_TABLE[current_col][--current_row];
break; break;
case D_DOWN: case D_DOWN:
if (move_current_window_in_container(connection, current_client, D_DOWN)) if (move_current_window_in_container(conn, current_client, D_DOWN))
return; return;
if (current_row == (c_ws->rows-1)) if (current_row == (c_ws->rows-1))
@ -213,10 +213,10 @@ static void move_current_window(xcb_connection_t *connection, direction_t direct
new->currently_focused = current_client; new->currently_focused = current_client;
/* delete all empty columns/rows */ /* delete all empty columns/rows */
cleanup_table(connection, container->workspace); cleanup_table(conn, container->workspace);
render_layout(connection); render_layout(conn);
set_focus(connection, current_client); set_focus(conn, current_client);
} }
/* /*
@ -224,7 +224,7 @@ static void move_current_window(xcb_connection_t *connection, direction_t direct
* to the given direction, that is, adjusts cellspan/rowspan * to the given direction, that is, adjusts cellspan/rowspan
* *
*/ */
static void snap_current_container(xcb_connection_t *connection, direction_t direction) { static void snap_current_container(xcb_connection_t *conn, direction_t direction) {
printf("snapping container to direction %d\n", direction); printf("snapping container to direction %d\n", direction);
Container *container = CUR_CELL; Container *container = CUR_CELL;
@ -234,8 +234,8 @@ static void snap_current_container(xcb_connection_t *connection, direction_t dir
switch (direction) { switch (direction) {
case D_LEFT: case D_LEFT:
/* Snap to the left is actually a move to the left and then a snap right */ /* Snap to the left is actually a move to the left and then a snap right */
move_current_window(connection, D_LEFT); move_current_window(conn, D_LEFT);
snap_current_container(connection, D_RIGHT); snap_current_container(conn, D_RIGHT);
return; return;
case D_RIGHT: case D_RIGHT:
/* Check if the cell is used */ /* Check if the cell is used */
@ -258,8 +258,8 @@ static void snap_current_container(xcb_connection_t *connection, direction_t dir
container->colspan++; container->colspan++;
break; break;
case D_UP: case D_UP:
move_current_window(connection, D_UP); move_current_window(conn, D_UP);
snap_current_container(connection, D_DOWN); snap_current_container(conn, D_DOWN);
return; return;
case D_DOWN: case D_DOWN:
printf("snapping down\n"); printf("snapping down\n");
@ -282,14 +282,14 @@ static void snap_current_container(xcb_connection_t *connection, direction_t dir
break; break;
} }
render_layout(connection); render_layout(conn);
} }
/* /*
* Moves the currently selected window to the given workspace * Moves the currently selected window to the given workspace
* *
*/ */
static void move_current_window_to_workspace(xcb_connection_t *connection, int workspace) { static void move_current_window_to_workspace(xcb_connection_t *conn, int workspace) {
printf("Moving current window to workspace %d\n", workspace); printf("Moving current window to workspace %d\n", workspace);
Container *container = CUR_CELL; Container *container = CUR_CELL;
@ -330,13 +330,13 @@ static void move_current_window_to_workspace(xcb_connection_t *connection, int w
/* If were moving it to an invisible screen, we need to unmap it */ /* If were moving it to an invisible screen, we need to unmap it */
if (to_container->workspace->screen->current_workspace != to_container->workspace->num) { if (to_container->workspace->screen->current_workspace != to_container->workspace->num) {
printf("This workspace is not visible, unmapping\n"); printf("This workspace is not visible, unmapping\n");
xcb_unmap_window(connection, current_client->frame); xcb_unmap_window(conn, current_client->frame);
} }
/* delete all empty columns/rows */ /* delete all empty columns/rows */
cleanup_table(connection, container->workspace); cleanup_table(conn, container->workspace);
render_layout(connection); render_layout(conn);
} }
static void show_workspace(xcb_connection_t *conn, int workspace) { static void show_workspace(xcb_connection_t *conn, int workspace) {

View File

@ -392,12 +392,12 @@ int handle_configure_event(void *prophs, xcb_connection_t *conn, xcb_configure_n
* so we better clean up before. * so we better clean up before.
* *
*/ */
int handle_unmap_notify_event(void *data, xcb_connection_t *c, xcb_unmap_notify_event_t *e) { int handle_unmap_notify_event(void *data, xcb_connection_t *conn, xcb_unmap_notify_event_t *event) {
xcb_window_t root = xcb_setup_roots_iterator(xcb_get_setup(c)).data->root; xcb_window_t root = xcb_setup_roots_iterator(xcb_get_setup(conn)).data->root;
ignore_notify_event = e->sequence; ignore_notify_event = event->sequence;
Client *client = table_get(byChild, e->window); Client *client = table_get(byChild, event->window);
/* First, we need to check if the client is awaiting an unmap-request which /* First, we need to check if the client is awaiting an unmap-request which
was generated by us reparenting the window. In that case, we just ignore it. */ was generated by us reparenting the window. In that case, we just ignore it. */
if (client != NULL && client->awaiting_useless_unmap) { if (client != NULL && client->awaiting_useless_unmap) {
@ -405,9 +405,9 @@ int handle_unmap_notify_event(void *data, xcb_connection_t *c, xcb_unmap_notify_
client->awaiting_useless_unmap = false; client->awaiting_useless_unmap = false;
return 1; return 1;
} }
client = table_remove(byChild, e->window); client = table_remove(byChild, event->window);
printf("UnmapNotify for 0x%08x (received from 0x%08x): ", e->window, e->event); printf("UnmapNotify for 0x%08x (received from 0x%08x): ", event->window, event->event);
if (client == NULL) { if (client == NULL) {
printf("not a managed window. Ignoring.\n"); printf("not a managed window. Ignoring.\n");
return 0; return 0;
@ -437,7 +437,7 @@ int handle_unmap_notify_event(void *data, xcb_connection_t *c, xcb_unmap_notify_
if (con->currently_focused == NULL && con->mode == MODE_STACK) { if (con->currently_focused == NULL && con->mode == MODE_STACK) {
struct Stack_Window *stack_win = &(con->stack_win); struct Stack_Window *stack_win = &(con->stack_win);
stack_win->height = 0; stack_win->height = 0;
xcb_unmap_window(c, stack_win->window); xcb_unmap_window(conn, stack_win->window);
} }
/* Remove the client from the list of clients */ /* Remove the client from the list of clients */
@ -445,20 +445,20 @@ int handle_unmap_notify_event(void *data, xcb_connection_t *c, xcb_unmap_notify_
/* Actually set focus, if there is a window which should get it */ /* Actually set focus, if there is a window which should get it */
if (to_focus != NULL) if (to_focus != NULL)
set_focus(c, to_focus); set_focus(conn, to_focus);
} }
printf("child of 0x%08x.\n", client->frame); printf("child of 0x%08x.\n", client->frame);
xcb_reparent_window(c, client->child, root, 0, 0); xcb_reparent_window(conn, client->child, root, 0, 0);
xcb_destroy_window(c, client->frame); xcb_destroy_window(conn, client->frame);
xcb_flush(c); xcb_flush(conn);
table_remove(byParent, client->frame); table_remove(byParent, client->frame);
cleanup_table(c, client->container->workspace); cleanup_table(conn, client->container->workspace);
free(client); free(client);
render_layout(c); render_layout(conn);
return 1; return 1;
} }
@ -491,20 +491,20 @@ int handle_windowname_change(void *data, xcb_connection_t *conn, uint8_t state,
* Expose event means we should redraw our windows (= title bar) * Expose event means we should redraw our windows (= title bar)
* *
*/ */
int handle_expose_event(void *data, xcb_connection_t *conn, xcb_expose_event_t *e) { int handle_expose_event(void *data, xcb_connection_t *conn, xcb_expose_event_t *event) {
printf("got expose_event\n"); printf("got expose_event\n");
/* e->count is the number of minimum remaining expose events for this window, so we /* event->count is the number of minimum remaining expose events for this window, so we
skip all events but the last one */ skip all events but the last one */
if (e->count != 0) if (event->count != 0)
return 1; return 1;
Client *client = table_get(byParent, e->window); Client *client = table_get(byParent, event->window);
if (client == NULL) { if (client == NULL) {
/* There was no client in the table, so this is probably an expose event for /* There was no client in the table, so this is probably an expose event for
one of our stack_windows. */ one of our stack_windows. */
struct Stack_Window *stack_win; struct Stack_Window *stack_win;
SLIST_FOREACH(stack_win, &stack_wins, stack_windows) SLIST_FOREACH(stack_win, &stack_wins, stack_windows)
if (stack_win->window == e->window) { if (stack_win->window == event->window) {
render_container(conn, stack_win->container); render_container(conn, stack_win->container);
return 1; return 1;
} }

View File

@ -159,23 +159,22 @@ void decorate_window(xcb_connection_t *conn, Client *client, xcb_drawable_t draw
* Pushes the clients x and y coordinates to X11 * Pushes the clients x and y coordinates to X11
* *
*/ */
static void reposition_client(xcb_connection_t *connection, Client *client) { static void reposition_client(xcb_connection_t *conn, Client *client) {
printf("frame needs to be pushed to %dx%d\n", client->rect.x, client->rect.y); printf("frame needs to be pushed to %dx%d\n", client->rect.x, client->rect.y);
/* Note: We can use a pointer to client->x like an array of uint32_ts /* Note: We can use a pointer to client->x like an array of uint32_ts
because it is followed by client->y by definition */ because it is followed by client->y by definition */
xcb_configure_window(connection, client->frame, xcb_configure_window(conn, client->frame, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, &(client->rect.x));
XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, &(client->rect.x));
} }
/* /*
* Pushes the clients width/height to X11 and resizes the child window * Pushes the clients width/height to X11 and resizes the child window
* *
*/ */
static void resize_client(xcb_connection_t *connection, Client *client) { static void resize_client(xcb_connection_t *conn, Client *client) {
i3Font *font = load_font(connection, config.font); i3Font *font = load_font(conn, config.font);
printf("resizing client to %d x %d\n", client->rect.width, client->rect.height); printf("resizing client to %d x %d\n", client->rect.width, client->rect.height);
xcb_configure_window(connection, client->frame, xcb_configure_window(conn, client->frame,
XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
&(client->rect.width)); &(client->rect.width));
@ -211,7 +210,7 @@ static void resize_client(xcb_connection_t *connection, Client *client) {
printf("child will be at %dx%d with size %dx%d\n", rect->x, rect->y, rect->width, rect->height); printf("child will be at %dx%d with size %dx%d\n", rect->x, rect->y, rect->width, rect->height);
xcb_configure_window(connection, client->child, mask, &(rect->x)); xcb_configure_window(conn, client->child, mask, &(rect->x));
/* After configuring a child window we need to fake a configure_notify_event according /* After configuring a child window we need to fake a configure_notify_event according
to ICCCM 4.2.3. This seems rather broken, especially since X sends exactly the same to ICCCM 4.2.3. This seems rather broken, especially since X sends exactly the same
@ -231,7 +230,7 @@ static void resize_client(xcb_connection_t *connection, Client *client) {
event.above_sibling = XCB_NONE; event.above_sibling = XCB_NONE;
event.override_redirect = false; event.override_redirect = false;
xcb_send_event(connection, false, client->child, XCB_EVENT_MASK_STRUCTURE_NOTIFY, (char*)&event); xcb_send_event(conn, false, client->child, XCB_EVENT_MASK_STRUCTURE_NOTIFY, (char*)&event);
} }
/* /*
@ -239,7 +238,7 @@ static void resize_client(xcb_connection_t *connection, Client *client) {
* when focus changes in a stacking container) * when focus changes in a stacking container)
* *
*/ */
void render_container(xcb_connection_t *connection, Container *container) { void render_container(xcb_connection_t *conn, Container *container) {
Client *client; Client *client;
int num_clients = 0, current_client = 0; int num_clients = 0, current_client = 0;
@ -258,36 +257,36 @@ void render_container(xcb_connection_t *connection, Container *container) {
HAS_CHANGED(old_value_1, client->rect.x, container->x) | HAS_CHANGED(old_value_1, client->rect.x, container->x) |
HAS_CHANGED(old_value_2, client->rect.y, container->y + HAS_CHANGED(old_value_2, client->rect.y, container->y +
(container->height / num_clients) * current_client)) (container->height / num_clients) * current_client))
reposition_client(connection, client); reposition_client(conn, client);
/* TODO: vertical default layout */ /* TODO: vertical default layout */
if (client->force_reconfigure | if (client->force_reconfigure |
HAS_CHANGED(old_value_1, client->rect.width, container->width) | HAS_CHANGED(old_value_1, client->rect.width, container->width) |
HAS_CHANGED(old_value_2, client->rect.height, container->height / num_clients)) HAS_CHANGED(old_value_2, client->rect.height, container->height / num_clients))
resize_client(connection, client); resize_client(conn, client);
client->force_reconfigure = false; client->force_reconfigure = false;
current_client++; current_client++;
} }
} else { } else {
i3Font *font = load_font(connection, config.font); i3Font *font = load_font(conn, config.font);
int decoration_height = (font->height + 2 + 2); int decoration_height = (font->height + 2 + 2);
struct Stack_Window *stack_win = &(container->stack_win); struct Stack_Window *stack_win = &(container->stack_win);
/* Check if we need to remap our stack title window, it gets unmapped when the container /* Check if we need to remap our stack title window, it gets unmapped when the container
is empty in src/handlers.c:unmap_notify() */ is empty in src/handlers.c:unmap_notify() */
if (stack_win->height == 0) if (stack_win->height == 0)
xcb_map_window(connection, stack_win->window); xcb_map_window(conn, stack_win->window);
/* Check if we need to reconfigure our stack title window */ /* Check if we need to reconfigure our stack title window */
if (HAS_CHANGED(old_value_1, stack_win->width, container->width) | if (HAS_CHANGED(old_value_1, stack_win->width, container->width) |
HAS_CHANGED(old_value_2, stack_win->height, decoration_height * num_clients)) { HAS_CHANGED(old_value_2, stack_win->height, decoration_height * num_clients)) {
xcb_configure_window(connection, stack_win->window, xcb_configure_window(conn, stack_win->window,
XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, &(stack_win->width)); XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, &(stack_win->width));
uint32_t values[] = { XCB_STACK_MODE_ABOVE }; uint32_t values[] = { XCB_STACK_MODE_ABOVE };
xcb_configure_window(connection, stack_win->window, XCB_CONFIG_WINDOW_STACK_MODE, values); xcb_configure_window(conn, stack_win->window, XCB_CONFIG_WINDOW_STACK_MODE, values);
} }
/* Reconfigure the currently focused client, if necessary. It is the only visible one */ /* Reconfigure the currently focused client, if necessary. It is the only visible one */
@ -298,48 +297,48 @@ void render_container(xcb_connection_t *connection, Container *container) {
if (client->force_reconfigure | if (client->force_reconfigure |
HAS_CHANGED(old_value_1, client->rect.x, container->x) | HAS_CHANGED(old_value_1, client->rect.x, container->x) |
HAS_CHANGED(old_value_2, client->rect.y, container->y + (decoration_height * num_clients))) HAS_CHANGED(old_value_2, client->rect.y, container->y + (decoration_height * num_clients)))
reposition_client(connection, client); reposition_client(conn, client);
if (client->force_reconfigure | if (client->force_reconfigure |
HAS_CHANGED(old_value_1, client->rect.width, container->width) | HAS_CHANGED(old_value_1, client->rect.width, container->width) |
HAS_CHANGED(old_value_2, client->rect.height, container->height - (decoration_height * num_clients))) HAS_CHANGED(old_value_2, client->rect.height, container->height - (decoration_height * num_clients)))
resize_client(connection, client); resize_client(conn, client);
client->force_reconfigure = false; client->force_reconfigure = false;
if (container->workspace->fullscreen_client == NULL) { if (container->workspace->fullscreen_client == NULL) {
uint32_t values[] = { XCB_STACK_MODE_ABOVE }; uint32_t values[] = { XCB_STACK_MODE_ABOVE };
xcb_configure_window(connection, client->frame, XCB_CONFIG_WINDOW_STACK_MODE, values); xcb_configure_window(conn, client->frame, XCB_CONFIG_WINDOW_STACK_MODE, values);
} }
/* Render the decorations of all clients */ /* Render the decorations of all clients */
CIRCLEQ_FOREACH(client, &(container->clients), clients) CIRCLEQ_FOREACH(client, &(container->clients), clients)
decorate_window(connection, client, stack_win->window, stack_win->gc, decorate_window(conn, client, stack_win->window, stack_win->gc,
current_client++ * decoration_height); current_client++ * decoration_height);
} }
} }
static void render_bars(xcb_connection_t *connection, Workspace *r_ws, int width, int *height) { static void render_bars(xcb_connection_t *conn, Workspace *r_ws, int width, int *height) {
Client *client; Client *client;
SLIST_FOREACH(client, &(r_ws->dock_clients), dock_clients) { SLIST_FOREACH(client, &(r_ws->dock_clients), dock_clients) {
if (client->force_reconfigure | if (client->force_reconfigure |
HAS_CHANGED(old_value_1, client->rect.x, 0) | HAS_CHANGED(old_value_1, client->rect.x, 0) |
HAS_CHANGED(old_value_2, client->rect.y, *height)) HAS_CHANGED(old_value_2, client->rect.y, *height))
reposition_client(connection, client); reposition_client(conn, client);
if (client->force_reconfigure | if (client->force_reconfigure |
HAS_CHANGED(old_value_1, client->rect.width, width) | HAS_CHANGED(old_value_1, client->rect.width, width) |
HAS_CHANGED(old_value_2, client->rect.height, client->desired_height)) HAS_CHANGED(old_value_2, client->rect.height, client->desired_height))
resize_client(connection, client); resize_client(conn, client);
client->force_reconfigure = false; client->force_reconfigure = false;
*height += client->desired_height; *height += client->desired_height;
} }
} }
static void render_internal_bar(xcb_connection_t *connection, Workspace *r_ws, int width, int height) { static void render_internal_bar(xcb_connection_t *conn, Workspace *r_ws, int width, int height) {
printf("Rendering internal bar\n"); printf("Rendering internal bar\n");
i3Font *font = load_font(connection, config.font); i3Font *font = load_font(conn, config.font);
i3Screen *screen = r_ws->screen; i3Screen *screen = r_ws->screen;
enum { SET_NORMAL = 0, SET_FOCUSED = 1 }; enum { SET_NORMAL = 0, SET_FOCUSED = 1 };
uint32_t background_color[2], uint32_t background_color[2],
@ -348,41 +347,41 @@ static void render_internal_bar(xcb_connection_t *connection, Workspace *r_ws, i
black; black;
char label[3]; char label[3];
black = get_colorpixel(connection, NULL, screen->bar, "#000000"); black = get_colorpixel(conn, NULL, screen->bar, "#000000");
background_color[SET_NORMAL] = get_colorpixel(connection, NULL, screen->bar, "#222222"); background_color[SET_NORMAL] = get_colorpixel(conn, NULL, screen->bar, "#222222");
text_color[SET_NORMAL] = get_colorpixel(connection, NULL, screen->bar, "#888888"); text_color[SET_NORMAL] = get_colorpixel(conn, NULL, screen->bar, "#888888");
border_color[SET_NORMAL] = get_colorpixel(connection, NULL, screen->bar, "#333333"); border_color[SET_NORMAL] = get_colorpixel(conn, NULL, screen->bar, "#333333");
background_color[SET_FOCUSED] = get_colorpixel(connection, NULL, screen->bar, "#285577"); background_color[SET_FOCUSED] = get_colorpixel(conn, NULL, screen->bar, "#285577");
text_color[SET_FOCUSED] = get_colorpixel(connection, NULL, screen->bar, "#ffffff"); text_color[SET_FOCUSED] = get_colorpixel(conn, NULL, screen->bar, "#ffffff");
border_color[SET_FOCUSED] = get_colorpixel(connection, NULL, screen->bar, "#4c7899"); border_color[SET_FOCUSED] = get_colorpixel(conn, NULL, screen->bar, "#4c7899");
/* Fill the whole bar in black */ /* Fill the whole bar in black */
xcb_change_gc_single(connection, screen->bargc, XCB_GC_FOREGROUND, black); xcb_change_gc_single(conn, screen->bargc, XCB_GC_FOREGROUND, black);
xcb_rectangle_t rect = {0, 0, width, height}; xcb_rectangle_t rect = {0, 0, width, height};
xcb_poly_fill_rectangle(connection, screen->bar, screen->bargc, 1, &rect); xcb_poly_fill_rectangle(conn, screen->bar, screen->bargc, 1, &rect);
/* Set font */ /* Set font */
xcb_change_gc_single(connection, screen->bargc, XCB_GC_FONT, font->id); xcb_change_gc_single(conn, screen->bargc, XCB_GC_FONT, font->id);
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); int set = (screen->current_workspace == c ? SET_FOCUSED : SET_NORMAL);
xcb_draw_rect(connection, screen->bar, screen->bargc, border_color[set], xcb_draw_rect(conn, screen->bar, screen->bargc, border_color[set],
drawn * height, 1, height - 2, height - 2); drawn * height, 1, height - 2, height - 2);
xcb_draw_rect(connection, screen->bar, screen->bargc, background_color[set], xcb_draw_rect(conn, screen->bar, screen->bargc, background_color[set],
drawn * height + 1, 2, height - 4, height - 4); drawn * height + 1, 2, height - 4, height - 4);
snprintf(label, sizeof(label), "%d", c+1); snprintf(label, sizeof(label), "%d", c+1);
xcb_change_gc_single(connection, screen->bargc, XCB_GC_FOREGROUND, text_color[set]); xcb_change_gc_single(conn, screen->bargc, XCB_GC_FOREGROUND, text_color[set]);
xcb_change_gc_single(connection, screen->bargc, XCB_GC_BACKGROUND, background_color[set]); xcb_change_gc_single(conn, screen->bargc, XCB_GC_BACKGROUND, background_color[set]);
xcb_void_cookie_t text_cookie = xcb_image_text_8_checked(connection, strlen(label), screen->bar, xcb_void_cookie_t text_cookie = xcb_image_text_8_checked(conn, strlen(label), screen->bar,
screen->bargc, drawn * height + 5 /* X */, screen->bargc, drawn * height + 5 /* X */,
font->height + 1 /* Y = baseline of font */, label); font->height + 1 /* Y = baseline of font */, label);
check_error(connection, text_cookie, "Could not draw workspace title"); check_error(conn, text_cookie, "Could not draw workspace title");
drawn++; drawn++;
} }
} }
@ -390,9 +389,9 @@ static void render_internal_bar(xcb_connection_t *connection, Workspace *r_ws, i
printf("done rendering internal\n"); printf("done rendering internal\n");
} }
void render_layout(xcb_connection_t *connection) { void render_layout(xcb_connection_t *conn) {
i3Screen *screen; i3Screen *screen;
i3Font *font = load_font(connection, config.font); i3Font *font = load_font(conn, config.font);
TAILQ_FOREACH(screen, virtual_screens, screens) { TAILQ_FOREACH(screen, virtual_screens, screens) {
/* r_ws (rendering workspace) is just a shortcut to the Workspace being currently rendered */ /* r_ws (rendering workspace) is just a shortcut to the Workspace being currently rendered */
@ -448,16 +447,16 @@ void render_layout(xcb_connection_t *connection) {
container->height *= container->rowspan; container->height *= container->rowspan;
/* Render the container if it is not empty */ /* Render the container if it is not empty */
render_container(connection, container); render_container(conn, container);
xoffset[rows] += container->width; xoffset[rows] += container->width;
yoffset[cols] += container->height; yoffset[cols] += container->height;
printf("==========\n"); printf("==========\n");
} }
render_bars(connection, r_ws, width, &height); render_bars(conn, r_ws, width, &height);
render_internal_bar(connection, r_ws, width, 18); render_internal_bar(conn, r_ws, width, 18);
} }
xcb_flush(connection); xcb_flush(conn);
} }

View File

@ -66,7 +66,7 @@ int num_screens = 0;
* Do some sanity checks and then reparent the window. * Do some sanity checks and then reparent the window.
* *
*/ */
void manage_window(xcb_property_handlers_t *prophs, xcb_connection_t *c, xcb_window_t window, window_attributes_t wa) { void manage_window(xcb_property_handlers_t *prophs, xcb_connection_t *conn, xcb_window_t window, window_attributes_t wa) {
printf("managing window.\n"); printf("managing window.\n");
xcb_drawable_t d = { window }; xcb_drawable_t d = { window };
xcb_get_geometry_cookie_t geomc; xcb_get_geometry_cookie_t geomc;
@ -76,7 +76,7 @@ void manage_window(xcb_property_handlers_t *prophs, xcb_connection_t *c, xcb_win
if (wa.tag == TAG_COOKIE) { if (wa.tag == TAG_COOKIE) {
/* Check if the window is mapped (it could be not mapped when intializing and /* Check if the window is mapped (it could be not mapped when intializing and
calling manage_window() for every window) */ calling manage_window() for every window) */
if ((attr = xcb_get_window_attributes_reply(c, wa.u.cookie, 0)) == NULL) if ((attr = xcb_get_window_attributes_reply(conn, wa.u.cookie, 0)) == NULL)
return; return;
if (attr->map_state != XCB_MAP_STATE_VIEWABLE) if (attr->map_state != XCB_MAP_STATE_VIEWABLE)
@ -95,15 +95,15 @@ void manage_window(xcb_property_handlers_t *prophs, xcb_connection_t *c, xcb_win
goto out; goto out;
/* Get the initial geometry (position, size, …) */ /* Get the initial geometry (position, size, …) */
geomc = xcb_get_geometry(c, d); geomc = xcb_get_geometry(conn, d);
if (!attr) { if (!attr) {
wa.tag = TAG_COOKIE; wa.tag = TAG_COOKIE;
wa.u.cookie = xcb_get_window_attributes(c, window); wa.u.cookie = xcb_get_window_attributes(conn, window);
attr = xcb_get_window_attributes_reply(c, wa.u.cookie, 0); attr = xcb_get_window_attributes_reply(conn, wa.u.cookie, 0);
} }
geom = xcb_get_geometry_reply(c, geomc, 0); geom = xcb_get_geometry_reply(conn, geomc, 0);
if (attr && geom) { if (attr && geom) {
reparent_window(c, window, attr->visual, geom->root, geom->depth, reparent_window(conn, window, attr->visual, geom->root, geom->depth,
geom->x, geom->y, geom->width, geom->height); geom->x, geom->y, geom->width, geom->height);
xcb_property_changed(prophs, XCB_PROPERTY_NEW_VALUE, window, WM_NAME); xcb_property_changed(prophs, XCB_PROPERTY_NEW_VALUE, window, WM_NAME);
} }
@ -254,14 +254,14 @@ void reparent_window(xcb_connection_t *conn, xcb_window_t child,
* Go through all existing windows (if the window manager is restarted) and manage them * Go through all existing windows (if the window manager is restarted) and manage them
* *
*/ */
void manage_existing_windows(xcb_connection_t *c, xcb_property_handlers_t *prophs, xcb_window_t root) { void manage_existing_windows(xcb_connection_t *conn, xcb_property_handlers_t *prophs, xcb_window_t root) {
xcb_query_tree_reply_t *reply; xcb_query_tree_reply_t *reply;
int i, len; int i, len;
xcb_window_t *children; xcb_window_t *children;
xcb_get_window_attributes_cookie_t *cookies; xcb_get_window_attributes_cookie_t *cookies;
/* Get the tree of windows whose parent is the root window (= all) */ /* Get the tree of windows whose parent is the root window (= all) */
if ((reply = xcb_query_tree_reply(c, xcb_query_tree(c, root), 0)) == NULL) if ((reply = xcb_query_tree_reply(conn, xcb_query_tree(conn, root), 0)) == NULL)
return; return;
len = xcb_query_tree_children_length(reply); len = xcb_query_tree_children_length(reply);
@ -270,12 +270,12 @@ void manage_existing_windows(xcb_connection_t *c, xcb_property_handlers_t *proph
/* Request the window attributes for every window */ /* Request the window attributes for every window */
children = xcb_query_tree_children(reply); children = xcb_query_tree_children(reply);
for(i = 0; i < len; ++i) for(i = 0; i < len; ++i)
cookies[i] = xcb_get_window_attributes(c, children[i]); cookies[i] = xcb_get_window_attributes(conn, children[i]);
/* Call manage_window with the attributes for every window */ /* Call manage_window with the attributes for every window */
for(i = 0; i < len; ++i) { for(i = 0; i < len; ++i) {
window_attributes_t wa = { TAG_COOKIE, { cookies[i] } }; window_attributes_t wa = { TAG_COOKIE, { cookies[i] } };
manage_window(prophs, c, children[i], wa); manage_window(prophs, conn, children[i], wa);
} }
free(reply); free(reply);
@ -283,7 +283,7 @@ void manage_existing_windows(xcb_connection_t *c, xcb_property_handlers_t *proph
int main(int argc, char *argv[], char *env[]) { int main(int argc, char *argv[], char *env[]) {
int i, screens; int i, screens;
xcb_connection_t *c; xcb_connection_t *conn;
xcb_property_handlers_t prophs; xcb_property_handlers_t prophs;
xcb_window_t root; xcb_window_t root;
xcb_intern_atom_cookie_t atom_cookies[NUM_ATOMS]; xcb_intern_atom_cookie_t atom_cookies[NUM_ATOMS];
@ -305,10 +305,10 @@ int main(int argc, char *argv[], char *env[]) {
load_configuration(NULL); load_configuration(NULL);
c = xcb_connect(NULL, &screens); conn = xcb_connect(NULL, &screens);
/* Place requests for the atoms we need as soon as possible */ /* Place requests for the atoms we need as soon as possible */
#define REQUEST_ATOM(name) atom_cookies[name] = xcb_intern_atom(c, 0, strlen(#name), #name); #define REQUEST_ATOM(name) atom_cookies[name] = xcb_intern_atom(conn, 0, strlen(#name), #name);
REQUEST_ATOM(_NET_SUPPORTED); REQUEST_ATOM(_NET_SUPPORTED);
REQUEST_ATOM(_NET_WM_STATE_FULLSCREEN); REQUEST_ATOM(_NET_WM_STATE_FULLSCREEN);
@ -341,7 +341,7 @@ int main(int argc, char *argv[], char *env[]) {
} }
/* end of ugliness */ /* end of ugliness */
xcb_event_handlers_init(c, &evenths); xcb_event_handlers_init(conn, &evenths);
/* DEBUG: Trap all events and print them */ /* DEBUG: Trap all events and print them */
for (i = 2; i < 128; ++i) for (i = 2; i < 128; ++i)
@ -385,7 +385,7 @@ int main(int argc, char *argv[], char *env[]) {
xcb_watch_wm_name(&prophs, 128, handle_windowname_change, 0); xcb_watch_wm_name(&prophs, 128, handle_windowname_change, 0);
/* Get the root window and set the event mask */ /* Get the root window and set the event mask */
root = xcb_aux_get_screen(c, screens)->root; root = xcb_aux_get_screen(conn, screens)->root;
uint32_t mask = XCB_CW_EVENT_MASK; uint32_t mask = XCB_CW_EVENT_MASK;
uint32_t values[] = { XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | uint32_t values[] = { XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY |
@ -394,11 +394,11 @@ int main(int argc, char *argv[], char *env[]) {
ConfigureNotify */ ConfigureNotify */
XCB_EVENT_MASK_PROPERTY_CHANGE | XCB_EVENT_MASK_PROPERTY_CHANGE |
XCB_EVENT_MASK_ENTER_WINDOW }; XCB_EVENT_MASK_ENTER_WINDOW };
xcb_change_window_attributes(c, root, mask, values); xcb_change_window_attributes(conn, root, mask, values);
/* Setup NetWM atoms */ /* Setup NetWM atoms */
#define GET_ATOM(name) { \ #define GET_ATOM(name) { \
xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(c, 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"); \ printf("Could not get atom " #name "\n"); \
exit(-1); \ exit(-1); \
@ -422,36 +422,36 @@ int main(int argc, char *argv[], char *env[]) {
/* TODO: In order to comply with EWMH, we have to watch _NET_WM_STRUT_PARTIAL */ /* TODO: In order to comply with EWMH, we have to watch _NET_WM_STRUT_PARTIAL */
/* Set up the atoms we support */ /* Set up the atoms we support */
check_error(c, xcb_change_property_checked(c, XCB_PROP_MODE_REPLACE, root, atoms[_NET_SUPPORTED], check_error(conn, xcb_change_property_checked(conn, XCB_PROP_MODE_REPLACE, root, atoms[_NET_SUPPORTED],
ATOM, 32, 7, atoms), "Could not set _NET_SUPPORTED"); ATOM, 32, 7, atoms), "Could not set _NET_SUPPORTED");
/* Set up the window managers name */ /* Set up the window managers name */
xcb_change_property(c, XCB_PROP_MODE_REPLACE, root, atoms[_NET_SUPPORTING_WM_CHECK], WINDOW, 32, 1, &root); xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root, atoms[_NET_SUPPORTING_WM_CHECK], WINDOW, 32, 1, &root);
xcb_change_property(c, XCB_PROP_MODE_REPLACE, root, atoms[_NET_WM_NAME], atoms[UTF8_STRING], 8, strlen("i3"), "i3"); xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root, atoms[_NET_WM_NAME], atoms[UTF8_STRING], 8, strlen("i3"), "i3");
/* Grab the bound keys */ /* Grab the bound keys */
Binding *bind; Binding *bind;
TAILQ_FOREACH(bind, &bindings, bindings) { TAILQ_FOREACH(bind, &bindings, bindings) {
printf("Grabbing %d\n", bind->keycode); printf("Grabbing %d\n", bind->keycode);
if (bind->mods & BIND_MODE_SWITCH) if (bind->mods & BIND_MODE_SWITCH)
xcb_grab_key(c, 0, root, 0, bind->keycode, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_SYNC); xcb_grab_key(conn, 0, root, 0, bind->keycode, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_SYNC);
else xcb_grab_key(c, 0, root, bind->mods, bind->keycode, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC); else xcb_grab_key(conn, 0, root, bind->mods, bind->keycode, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC);
} }
/* check for Xinerama */ /* check for Xinerama */
printf("Checking for Xinerama...\n"); printf("Checking for Xinerama...\n");
initialize_xinerama(c); initialize_xinerama(conn);
/* DEBUG: Start a terminal */ /* DEBUG: Start a terminal */
start_application(config.terminal); start_application(config.terminal);
xcb_flush(c); xcb_flush(conn);
manage_existing_windows(c, &prophs, root); manage_existing_windows(conn, &prophs, root);
/* Get pointer position to see on which screen were starting */ /* Get pointer position to see on which screen were starting */
xcb_query_pointer_reply_t *reply; xcb_query_pointer_reply_t *reply;
if ((reply = xcb_query_pointer_reply(c, xcb_query_pointer(c, root), NULL)) == NULL) { if ((reply = xcb_query_pointer_reply(conn, xcb_query_pointer(conn, root), NULL)) == NULL) {
printf("Could not get pointer position\n"); printf("Could not get pointer position\n");
return 1; return 1;
} }

View File

@ -105,11 +105,11 @@ void start_application(const char *command) {
* was an error. * was an error.
* *
*/ */
void check_error(xcb_connection_t *connection, xcb_void_cookie_t cookie, char *err_message) { void check_error(xcb_connection_t *conn, xcb_void_cookie_t cookie, char *err_message) {
xcb_generic_error_t *error = xcb_request_check(connection, cookie); xcb_generic_error_t *error = xcb_request_check(conn, cookie);
if (error != NULL) { if (error != NULL) {
fprintf(stderr, "ERROR: %s : %d\n", err_message , error->error_code); fprintf(stderr, "ERROR: %s : %d\n", err_message , error->error_code);
xcb_disconnect(connection); xcb_disconnect(conn);
exit(-1); exit(-1);
} }
} }
@ -223,10 +223,10 @@ void switch_layout_mode(xcb_connection_t *conn, Container *container, int mode)
* selecting it * selecting it
* *
*/ */
void warp_pointer_into(xcb_connection_t *connection, Client *client) { void warp_pointer_into(xcb_connection_t *conn, Client *client) {
int mid_x = client->rect.width / 2, int mid_x = client->rect.width / 2,
mid_y = client->rect.height / 2; mid_y = client->rect.height / 2;
xcb_warp_pointer(connection, XCB_NONE, client->child, 0, 0, 0, 0, mid_x, mid_y); xcb_warp_pointer(conn, XCB_NONE, client->child, 0, 0, 0, 0, mid_x, mid_y);
} }
/* /*

View File

@ -27,7 +27,7 @@ TAILQ_HEAD(cached_fonts_head, Font) cached_fonts = TAILQ_HEAD_INITIALIZER(cached
* maintains a cache. * maintains a cache.
* *
*/ */
i3Font *load_font(xcb_connection_t *connection, const char *pattern) { i3Font *load_font(xcb_connection_t *conn, const char *pattern) {
/* Check if we got the font cached */ /* Check if we got the font cached */
i3Font *font; i3Font *font;
TAILQ_FOREACH(font, &cached_fonts, fonts) TAILQ_FOREACH(font, &cached_fonts, fonts)
@ -39,14 +39,14 @@ i3Font *load_font(xcb_connection_t *connection, const char *pattern) {
xcb_list_fonts_with_info_cookie_t info_cookie; xcb_list_fonts_with_info_cookie_t info_cookie;
/* Send all our requests first */ /* Send all our requests first */
new->id = xcb_generate_id(connection); new->id = xcb_generate_id(conn);
font_cookie = xcb_open_font_checked(connection, new->id, strlen(pattern), pattern); font_cookie = xcb_open_font_checked(conn, new->id, strlen(pattern), pattern);
info_cookie = xcb_list_fonts_with_info(connection, 1, strlen(pattern), pattern); info_cookie = xcb_list_fonts_with_info(conn, 1, strlen(pattern), pattern);
check_error(connection, font_cookie, "Could not open font"); check_error(conn, font_cookie, "Could not open font");
/* Get information (height/name) for this font */ /* Get information (height/name) for this font */
xcb_list_fonts_with_info_reply_t *reply = xcb_list_fonts_with_info_reply(connection, info_cookie, NULL); xcb_list_fonts_with_info_reply_t *reply = xcb_list_fonts_with_info_reply(conn, info_cookie, NULL);
exit_if_null(reply, "Could not load font \"%s\"\n", pattern); exit_if_null(reply, "Could not load font \"%s\"\n", pattern);
if (asprintf(&(new->name), "%.*s", xcb_list_fonts_with_info_name_length(reply), if (asprintf(&(new->name), "%.*s", xcb_list_fonts_with_info_name_length(reply),
@ -187,9 +187,9 @@ void xcb_draw_line(xcb_connection_t *conn, xcb_drawable_t drawable, xcb_gcontext
* Draws a rectangle from x,y with width,height using the given color * Draws a rectangle from x,y with width,height using the given color
* *
*/ */
void xcb_draw_rect(xcb_connection_t *connection, xcb_drawable_t drawable, xcb_gcontext_t gc, void xcb_draw_rect(xcb_connection_t *conn, xcb_drawable_t drawable, xcb_gcontext_t gc,
uint32_t colorpixel, uint32_t x, uint32_t y, uint32_t width, uint32_t height) { uint32_t colorpixel, uint32_t x, uint32_t y, uint32_t width, uint32_t height) {
xcb_change_gc_single(connection, gc, XCB_GC_FOREGROUND, colorpixel); xcb_change_gc_single(conn, gc, XCB_GC_FOREGROUND, colorpixel);
xcb_rectangle_t rect = {x, y, width, height}; xcb_rectangle_t rect = {x, y, width, height};
xcb_poly_fill_rectangle(connection, drawable, gc, 1, &rect); xcb_poly_fill_rectangle(conn, drawable, gc, 1, &rect);
} }

View File

@ -66,8 +66,8 @@ i3Screen *get_screen_containing(int x, int y) {
* Fills virtual_screens with exactly one screen with width/height of the whole X server. * Fills virtual_screens with exactly one screen with width/height of the whole X server.
* *
*/ */
static void disable_xinerama(xcb_connection_t *connection) { static void disable_xinerama(xcb_connection_t *conn) {
xcb_screen_t *root_screen = xcb_setup_roots_iterator(xcb_get_setup(connection)).data; xcb_screen_t *root_screen = xcb_setup_roots_iterator(xcb_get_setup(conn)).data;
i3Screen *s = calloc(sizeof(i3Screen), 1); i3Screen *s = calloc(sizeof(i3Screen), 1);
@ -86,11 +86,11 @@ static void disable_xinerama(xcb_connection_t *connection) {
* Xinerama screen which are configured in clone mode) in the given screenlist * Xinerama screen which are configured in clone mode) in the given screenlist
* *
*/ */
static void query_screens(xcb_connection_t *connection, struct screens_head *screenlist) { static void query_screens(xcb_connection_t *conn, struct screens_head *screenlist) {
xcb_xinerama_query_screens_reply_t *reply; xcb_xinerama_query_screens_reply_t *reply;
xcb_xinerama_screen_info_t *screen_info; xcb_xinerama_screen_info_t *screen_info;
reply = xcb_xinerama_query_screens_reply(connection, xcb_xinerama_query_screens_unchecked(connection), NULL); reply = xcb_xinerama_query_screens_reply(conn, xcb_xinerama_query_screens_unchecked(conn), NULL);
if (!reply) { if (!reply) {
printf("Couldn't get Xinerama screens\n"); printf("Couldn't get Xinerama screens\n");
return; return;
@ -127,8 +127,8 @@ static void query_screens(xcb_connection_t *connection, struct screens_head *scr
free(reply); free(reply);
} }
static void initialize_screen(xcb_connection_t *connection, i3Screen *screen, Workspace *workspace) { static void initialize_screen(xcb_connection_t *conn, i3Screen *screen, Workspace *workspace) {
i3Font *font = load_font(connection, config.font); i3Font *font = load_font(conn, config.font);
workspace->screen = screen; workspace->screen = screen;
screen->current_workspace = workspace->num; screen->current_workspace = workspace->num;
@ -140,9 +140,9 @@ static void initialize_screen(xcb_connection_t *connection, i3Screen *screen, Wo
font->height + 6}; font->height + 6};
uint32_t mask = XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK; uint32_t mask = XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK;
uint32_t values[] = {1, XCB_EVENT_MASK_EXPOSURE}; uint32_t values[] = {1, XCB_EVENT_MASK_EXPOSURE};
screen->bar = create_window(connection, bar_rect, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_CURSOR_LEFT_PTR, mask, values); screen->bar = create_window(conn, bar_rect, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_CURSOR_LEFT_PTR, mask, values);
screen->bargc = xcb_generate_id(connection); screen->bargc = xcb_generate_id(conn);
xcb_create_gc(connection, screen->bargc, screen->bar, 0, 0); xcb_create_gc(conn, screen->bargc, screen->bar, 0, 0);
/* Copy dimensions */ /* Copy dimensions */
memcpy(&(workspace->rect), &(screen->rect), sizeof(Rect)); memcpy(&(workspace->rect), &(screen->rect), sizeof(Rect));
@ -155,30 +155,30 @@ static void initialize_screen(xcb_connection_t *connection, i3Screen *screen, Wo
* information to setup workspaces for each screen. * information to setup workspaces for each screen.
* *
*/ */
void initialize_xinerama(xcb_connection_t *connection) { void initialize_xinerama(xcb_connection_t *conn) {
virtual_screens = scalloc(sizeof(struct screens_head)); virtual_screens = scalloc(sizeof(struct screens_head));
TAILQ_INIT(virtual_screens); TAILQ_INIT(virtual_screens);
if (!xcb_get_extension_data(connection, &xcb_xinerama_id)->present) { if (!xcb_get_extension_data(conn, &xcb_xinerama_id)->present) {
printf("Xinerama extension not found, disabling.\n"); printf("Xinerama extension not found, disabling.\n");
disable_xinerama(connection); disable_xinerama(conn);
return; return;
} }
if (!xcb_xinerama_is_active_reply(connection, xcb_xinerama_is_active(connection), NULL)->state) { if (!xcb_xinerama_is_active_reply(conn, xcb_xinerama_is_active(conn), NULL)->state) {
printf("Xinerama is not active (in your X-Server), disabling.\n"); printf("Xinerama is not active (in your X-Server), disabling.\n");
disable_xinerama(connection); disable_xinerama(conn);
return; return;
} }
query_screens(connection, virtual_screens); query_screens(conn, virtual_screens);
i3Screen *s; i3Screen *s;
num_screens = 0; num_screens = 0;
/* Just go through each workspace and associate as many screens as we can. */ /* Just go through each workspace and associate as many screens as we can. */
TAILQ_FOREACH(s, virtual_screens, screens) { TAILQ_FOREACH(s, virtual_screens, screens) {
s->num = num_screens; s->num = num_screens;
initialize_screen(connection, s, &(workspaces[num_screens])); initialize_screen(conn, s, &(workspaces[num_screens]));
num_screens++; num_screens++;
} }
} }
@ -188,7 +188,7 @@ void initialize_xinerama(xcb_connection_t *connection) {
* number/position of the Xinerama screens could have changed. * number/position of the Xinerama screens could have changed.
* *
*/ */
void xinerama_requery_screens(xcb_connection_t *connection) { void xinerama_requery_screens(xcb_connection_t *conn) {
/* POSSIBLE PROBLEM: Is the order of the Xinerama screens always constant? That is, can /* POSSIBLE PROBLEM: Is the order of the Xinerama screens always constant? That is, can
it change when I move the --right-of video projector to --left-of? */ it change when I move the --right-of video projector to --left-of? */
@ -201,7 +201,7 @@ void xinerama_requery_screens(xcb_connection_t *connection) {
struct screens_head *new_screens = scalloc(sizeof(struct screens_head)); struct screens_head *new_screens = scalloc(sizeof(struct screens_head));
TAILQ_INIT(new_screens); TAILQ_INIT(new_screens);
query_screens(connection, new_screens); query_screens(conn, new_screens);
i3Screen *first = TAILQ_FIRST(new_screens), i3Screen *first = TAILQ_FIRST(new_screens),
*screen; *screen;
@ -233,7 +233,7 @@ void xinerama_requery_screens(xcb_connection_t *connection) {
for (int c = 0; c < 10; c++) for (int c = 0; c < 10; c++)
if (workspaces[c].screen == NULL) { if (workspaces[c].screen == NULL) {
printf("fix: initializing new workspace, setting num to %d\n", c); printf("fix: initializing new workspace, setting num to %d\n", c);
initialize_screen(connection, screen, &(workspaces[c])); initialize_screen(conn, screen, &(workspaces[c]));
break; break;
} }
} }
@ -245,7 +245,7 @@ void xinerama_requery_screens(xcb_connection_t *connection) {
if ((workspaces[c].screen != NULL) && if ((workspaces[c].screen != NULL) &&
(workspaces[c].screen->num >= num_screens)) { (workspaces[c].screen->num >= num_screens)) {
printf("Closing bar window\n"); printf("Closing bar window\n");
xcb_destroy_window(connection, workspaces[c].screen->bar); xcb_destroy_window(conn, workspaces[c].screen->bar);
printf("Workspace %d's screen out of bounds, assigning to first screen\n", c+1); printf("Workspace %d's screen out of bounds, assigning to first screen\n", c+1);
workspaces[c].screen = first; workspaces[c].screen = first;
@ -263,5 +263,5 @@ void xinerama_requery_screens(xcb_connection_t *connection) {
printf("Current workspace is now: %d\n", first->current_workspace); printf("Current workspace is now: %d\n", first->current_workspace);
render_layout(connection); render_layout(conn);
} }