From: Michael Stapelberg Date: Sat, 19 Dec 2009 21:39:00 +0000 (+0100) Subject: Touch each log message and classify it as DLOG (debug), ELOG (error) or LOG (verbose) X-Git-Tag: 3.e~6^2~197 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=6ef0d1fa79776383f2618151e07a20355173826a;p=i3%2Fi3 Touch each log message and classify it as DLOG (debug), ELOG (error) or LOG (verbose) --- diff --git a/include/client.h b/include/client.h index dced48ec..54035f6e 100644 --- a/include/client.h +++ b/include/client.h @@ -131,7 +131,7 @@ uint32_t client_min_width(Client *client); * */ #define CLIENT_LOG(client) do { \ - LOG("Window: frame 0x%08x, child 0x%08x\n", client->frame, client->child); \ + DLOG("Window: frame 0x%08x, child 0x%08x\n", client->frame, client->child); \ } while (0) #endif diff --git a/include/util.h b/include/util.h index ed85d539..f4e95604 100644 --- a/include/util.h +++ b/include/util.h @@ -3,7 +3,7 @@ * * i3 - an improved dynamic tiling window manager * - * (c) 2009 Michael Stapelberg and contributors + * © 2009 Michael Stapelberg and contributors * * See file LICENSE for license information. * @@ -34,10 +34,6 @@ } \ while (0) -/** ##__VA_ARGS__ means: leave out __VA_ARGS__ completely if it is empty, that - is, delete the preceding comma */ -#define LOG(fmt, ...) slog("%s:%s:%d - " fmt, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__) - TAILQ_HEAD(keyvalue_table_head, keyvalue_element); extern struct keyvalue_table_head by_parent; extern struct keyvalue_table_head by_child; @@ -45,13 +41,6 @@ extern struct keyvalue_table_head by_child; int min(int a, int b); int max(int a, int b); -/** - * Logs the given message to stdout while prefixing the current time to it. - * This is to be called by LOG() which includes filename/linenumber - * - */ -void slog(char *fmt, ...); - /** * Safe-wrapper around malloc which exits if malloc returns NULL (meaning that * there is no more memory available) diff --git a/src/cfgparse.y b/src/cfgparse.y index 878d2e17..030c51af 100644 --- a/src/cfgparse.y +++ b/src/cfgparse.y @@ -21,6 +21,7 @@ #include "table.h" #include "workspace.h" #include "xcb.h" +#include "log.h" typedef struct yy_buffer_state *YY_BUFFER_STATE; extern int yylex(void); @@ -94,7 +95,7 @@ void parse_file(const char *f) { new->key = sstrdup(v_key); new->value = sstrdup(v_value); SLIST_INSERT_HEAD(&variables, new, variables); - LOG("Got new variable %s = %s\n", v_key, v_value); + DLOG("Got new variable %s = %s\n", v_key, v_value); continue; } } @@ -324,7 +325,7 @@ modeline: floating_modifier: TOKFLOATING_MODIFIER WHITESPACE binding_modifiers { - LOG("floating modifier = %d\n", $3); + DLOG("floating modifier = %d\n", $3); config.floating_modifier = $3; } ; @@ -332,7 +333,7 @@ floating_modifier: new_container: TOKNEWCONTAINER WHITESPACE TOKCONTAINERMODE { - LOG("new containers will be in mode %d\n", $3); + DLOG("new containers will be in mode %d\n", $3); config.container_mode = $3; /* We also need to change the layout of the already existing @@ -354,7 +355,7 @@ new_container: } | TOKNEWCONTAINER WHITESPACE TOKSTACKLIMIT WHITESPACE TOKSTACKLIMIT WHITESPACE NUMBER { - LOG("stack-limit %d with val %d\n", $5, $7); + DLOG("stack-limit %d with val %d\n", $5, $7); config.container_stack_limit = $5; config.container_stack_limit_value = $7; @@ -373,7 +374,7 @@ new_container: new_window: TOKNEWWINDOW WHITESPACE WORD { - LOG("new windows should start in mode %s\n", $3); + DLOG("new windows should start in mode %s\n", $3); config.default_border = strdup($3); } ; @@ -383,7 +384,7 @@ workspace: { int ws_num = $3; if (ws_num < 1) { - LOG("Invalid workspace assignment, workspace number %d out of range\n", ws_num); + DLOG("Invalid workspace assignment, workspace number %d out of range\n", ws_num); } else { Workspace *ws = workspace_get(ws_num - 1); ws->preferred_screen = sstrdup($7); @@ -395,7 +396,7 @@ workspace: { int ws_num = $3; if (ws_num < 1) { - LOG("Invalid workspace assignment, workspace number %d out of range\n", ws_num); + DLOG("Invalid workspace assignment, workspace number %d out of range\n", ws_num); } else { if ($5 != NULL) workspace_set_name(workspace_get(ws_num - 1), $5); @@ -486,7 +487,7 @@ exec: terminal: TOKTERMINAL WHITESPACE STR { - LOG("The terminal option is DEPRECATED and has no effect. " + DLOG("The terminal option is DEPRECATED and has no effect. " "Please remove it from your configuration file."); } ; diff --git a/src/click.c b/src/click.c index efb26ad3..dccd5b4f 100644 --- a/src/click.c +++ b/src/click.c @@ -36,6 +36,7 @@ #include "commands.h" #include "floating.h" #include "resize.h" +#include "log.h" static struct Stack_Window *get_stack_window(xcb_window_t window_id) { struct Stack_Window *current; @@ -97,18 +98,18 @@ static bool button_press_stackwin(xcb_connection_t *conn, xcb_button_press_event int wrap = ceil((float)num_clients / container->stack_limit_value); int clicked_column = (event->event_x / (stack_win->rect.width / container->stack_limit_value)); int clicked_row = (event->event_y / decoration_height); - LOG("clicked on column %d, row %d\n", clicked_column, clicked_row); + DLOG("clicked on column %d, row %d\n", clicked_column, clicked_row); destination = (wrap * clicked_column) + clicked_row; } else { int width = (stack_win->rect.width / ceil((float)num_clients / container->stack_limit_value)); int clicked_column = (event->event_x / width); int clicked_row = (event->event_y / decoration_height); - LOG("clicked on column %d, row %d\n", clicked_column, clicked_row); + DLOG("clicked on column %d, row %d\n", clicked_column, clicked_row); destination = (container->stack_limit_value * clicked_column) + clicked_row; } } - LOG("Click on stack_win for client %d\n", destination); + DLOG("Click on stack_win for client %d\n", destination); CIRCLEQ_FOREACH(client, &(stack_win->container->clients), clients) if (c++ == destination) { set_focus(conn, client, true); @@ -129,7 +130,7 @@ static bool button_press_bar(xcb_connection_t *conn, xcb_button_press_event_t *e if (screen->bar != event->event) continue; - LOG("Click on a bar\n"); + DLOG("Click on a bar\n"); /* Check if the button was one of button4 or button5 (scroll up / scroll down) */ if (event->detail == XCB_BUTTON_INDEX_4 || event->detail == XCB_BUTTON_INDEX_5) { @@ -158,7 +159,7 @@ static bool button_press_bar(xcb_connection_t *conn, xcb_button_press_event_t *e TAILQ_FOREACH(ws, workspaces, workspaces) { if (ws->screen != screen) continue; - LOG("Checking if click was on workspace %d with drawn = %d, tw = %d\n", + DLOG("Checking if click was on workspace %d with drawn = %d, tw = %d\n", ws->num, drawn, ws->text_width); if (event->event_x > (drawn + 1) && event->event_x <= (drawn + 1 + ws->text_width + 5 + 5)) { @@ -201,7 +202,7 @@ static bool floating_mod_on_tiled_client(xcb_connection_t *conn, Client *client, Workspace *ws = con->workspace; int first = 0, second = 0; - LOG("click was %d px to the right, %d px to the left, %d px to top, %d px to bottom\n", + DLOG("click was %d px to the right, %d px to the left, %d px to top, %d px to bottom\n", to_right, to_left, to_top, to_bottom); if (to_right < to_left && @@ -209,7 +210,7 @@ static bool floating_mod_on_tiled_client(xcb_connection_t *conn, Client *client, to_right < to_bottom) { /* …right border */ first = con->col + (con->colspan - 1); - LOG("column %d\n", first); + DLOG("column %d\n", first); if (!cell_exists(first, con->row) || (first == (ws->cols-1))) @@ -251,7 +252,7 @@ static bool floating_mod_on_tiled_client(xcb_connection_t *conn, Client *client, } int handle_button_press(void *ignored, xcb_connection_t *conn, xcb_button_press_event_t *event) { - LOG("Button %d pressed\n", event->state); + DLOG("Button %d pressed\n", event->state); /* This was either a focus for a client’s parent (= titlebar)… */ Client *client = table_get(&by_child, event->event); bool border_click = false; @@ -265,20 +266,20 @@ int handle_button_press(void *ignored, xcb_connection_t *conn, xcb_button_press_ if (config.floating_modifier != 0 && (event->state & config.floating_modifier) != 0) { if (client == NULL) { - LOG("Not handling, floating_modifier was pressed and no client found\n"); + DLOG("Not handling, floating_modifier was pressed and no client found\n"); return 1; } if (client->fullscreen) { - LOG("Not handling, client is in fullscreen mode\n"); + DLOG("Not handling, client is in fullscreen mode\n"); return 1; } if (client_is_floating(client)) { - LOG("button %d pressed\n", event->detail); + DLOG("button %d pressed\n", event->detail); if (event->detail == 1) { - LOG("left mouse button, dragging\n"); + DLOG("left mouse button, dragging\n"); floating_drag_window(conn, client, event); } else if (event->detail == 3) { - LOG("right mouse button\n"); + DLOG("right mouse button\n"); floating_resize_window(conn, client, event); } return 1; @@ -301,7 +302,7 @@ int handle_button_press(void *ignored, xcb_connection_t *conn, xcb_button_press_ if (button_press_bar(conn, event)) return 1; - LOG("Could not handle this button press\n"); + DLOG("Could not handle this button press\n"); return 1; } @@ -309,19 +310,19 @@ int handle_button_press(void *ignored, xcb_connection_t *conn, xcb_button_press_ set_focus(conn, client, true); /* Let’s see if this was on the borders (= resize). If not, we’re done */ - LOG("press button on x=%d, y=%d\n", event->event_x, event->event_y); + DLOG("press button on x=%d, y=%d\n", event->event_x, event->event_y); resize_orientation_t orientation = O_VERTICAL; Container *con = client->container; int first, second; if (client->dock) { - LOG("dock. done.\n"); + DLOG("dock. done.\n"); xcb_allow_events(conn, XCB_ALLOW_REPLAY_POINTER, event->time); xcb_flush(conn); return 1; } - LOG("event->event_x = %d, client->rect.width = %d\n", event->event_x, client->rect.width); + DLOG("event->event_x = %d, client->rect.width = %d\n", event->event_x, client->rect.width); /* Some clients (xfontsel for example) seem to pass clicks on their * window to the parent window, thus we receive an event here which in @@ -331,12 +332,12 @@ int handle_button_press(void *ignored, xcb_connection_t *conn, xcb_button_press_ event->event_x <= (client->child_rect.x + client->child_rect.width) && event->event_y >= client->child_rect.y && event->event_y <= (client->child_rect.y + client->child_rect.height)) { - LOG("Fixing border_click = false because of click in child\n"); + DLOG("Fixing border_click = false because of click in child\n"); border_click = false; } if (!border_click) { - LOG("client. done.\n"); + DLOG("client. done.\n"); xcb_allow_events(conn, XCB_ALLOW_REPLAY_POINTER, event->time); /* Floating clients should be raised on click */ if (client_is_floating(client)) @@ -348,7 +349,7 @@ int handle_button_press(void *ignored, xcb_connection_t *conn, xcb_button_press_ /* Don’t handle events inside the titlebar, only borders are interesting */ i3Font *font = load_font(conn, config.font); if (event->event_y >= 2 && event->event_y <= (font->height + 2 + 2)) { - LOG("click on titlebar\n"); + DLOG("click on titlebar\n"); /* Floating clients can be dragged by grabbing their titlebar */ if (client_is_floating(client)) { @@ -392,7 +393,7 @@ int handle_button_press(void *ignored, xcb_connection_t *conn, xcb_button_press_ } else if (event->event_x > 2) { /* …right border */ first = con->col + (con->colspan - 1); - LOG("column %d\n", first); + DLOG("column %d\n", first); if (!cell_exists(first, con->row) || (first == (ws->cols-1))) diff --git a/src/client.c b/src/client.c index 2de501ea..c3113391 100644 --- a/src/client.c +++ b/src/client.c @@ -27,6 +27,7 @@ #include "table.h" #include "workspace.h" #include "config.h" +#include "log.h" /* * Removes the given client from the container, either because it will be inserted into another @@ -44,7 +45,7 @@ void client_remove_from_container(xcb_connection_t *conn, Client *client, Contai if (CIRCLEQ_EMPTY(&(container->clients)) && (container->mode == MODE_STACK || container->mode == MODE_TABBED)) { - LOG("Unmapping stack window\n"); + DLOG("Unmapping stack window\n"); struct Stack_Window *stack_win = &(container->stack_win); stack_win->rect.height = 0; xcb_unmap_window(conn, stack_win->window); @@ -169,7 +170,7 @@ void client_enter_fullscreen(xcb_connection_t *conn, Client *client) { workspace->rect.width, workspace->rect.height}; - LOG("child itself will be at %dx%d with size %dx%d\n", + DLOG("child itself will be at %dx%d with size %dx%d\n", values[0], values[1], values[2], values[3]); xcb_configure_window(conn, client->frame, mask, values); @@ -243,14 +244,14 @@ void client_set_below_floating(xcb_connection_t *conn, Client *client) { if (first_floating == TAILQ_END(&(ws->floating_clients))) return; - LOG("Setting below floating\n"); + DLOG("Setting below floating\n"); uint32_t values[] = { first_floating->frame, XCB_STACK_MODE_BELOW }; xcb_configure_window(conn, client->frame, XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE, values); if (client->workspace->fullscreen_client == NULL) return; - LOG("(and below fullscreen)\n"); + DLOG("(and below fullscreen)\n"); /* Ensure that the window is still below the fullscreen window */ values[0] = client->workspace->fullscreen_client->frame; xcb_configure_window(conn, client->frame, XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE, values); diff --git a/src/commands.c b/src/commands.c index 4ef03d9c..7cb0bdca 100644 --- a/src/commands.c +++ b/src/commands.c @@ -30,6 +30,7 @@ #include "workspace.h" #include "commands.h" #include "resize.h" +#include "log.h" bool focus_window_in_container(xcb_connection_t *conn, Container *container, direction_t direction) { /* If this container is empty, we’re done */ @@ -45,7 +46,7 @@ bool focus_window_in_container(xcb_connection_t *conn, Container *container, dir else if (direction == D_DOWN) { if ((candidate = CIRCLEQ_NEXT_OR_NULL(&(container->clients), container->currently_focused, clients)) == NULL) candidate = CIRCLEQ_FIRST(&(container->clients)); - } else LOG("Direction not implemented!\n"); + } else ELOG("Direction not implemented!\n"); /* If we could not switch, the container contains exactly one client. We return false */ if (candidate == container->currently_focused) @@ -74,11 +75,11 @@ static void jump_to_mark(xcb_connection_t *conn, const char *mark) { return; } - LOG("No window with this mark found\n"); + ELOG("No window with this mark found\n"); } static void focus_thing(xcb_connection_t *conn, direction_t direction, thing_t thing) { - LOG("focusing direction %d\n", direction); + DLOG("focusing direction %d\n", direction); int new_row = current_row, new_col = current_col; @@ -120,7 +121,7 @@ static void focus_thing(xcb_connection_t *conn, direction_t direction, thing_t t i3Screen *target = get_screen_containing(bounds.x, bounds.y); if (target == NULL) { - LOG("Target screen NULL\n"); + DLOG("Target screen NULL\n"); /* Wrap around if the target screen is out of bounds */ if (direction == D_RIGHT) target = get_screen_most(D_LEFT, cs); @@ -131,7 +132,7 @@ static void focus_thing(xcb_connection_t *conn, direction_t direction, thing_t t else target = get_screen_most(D_UP, cs); } - LOG("Switching to ws %d\n", target->current_workspace + 1); + DLOG("Switching to ws %d\n", target->current_workspace + 1); workspace_show(conn, target->current_workspace->num + 1); return; } @@ -159,11 +160,11 @@ static void focus_thing(xcb_connection_t *conn, direction_t direction, thing_t t } } else { /* Let’s see if there is a screen down/up there to which we can switch */ - LOG("container is at %d with height %d\n", container->y, container->height); + DLOG("container is at %d with height %d\n", container->y, container->height); i3Screen *screen; int destination_y = (direction == D_UP ? (container->y - 1) : (container->y + container->height + 1)); if ((screen = get_screen_containing(container->x, destination_y)) == NULL) { - LOG("Wrapping screen around vertically\n"); + DLOG("Wrapping screen around vertically\n"); /* No screen found? Then wrap */ screen = get_screen_most((direction == D_UP ? D_DOWN : D_UP), container->workspace->screen); } @@ -173,9 +174,9 @@ static void focus_thing(xcb_connection_t *conn, direction_t direction, thing_t t check_colrow_boundaries(); - LOG("new_col = %d, new_row = %d\n", new_col, new_row); + DLOG("new_col = %d, new_row = %d\n", new_col, new_row); if (t_ws->table[new_col][new_row]->currently_focused == NULL) { - LOG("Cell empty, checking for colspanned client above...\n"); + DLOG("Cell empty, checking for colspanned client above...\n"); for (int cols = 0; cols < new_col; cols += t_ws->table[cols][new_row]->colspan) { if (new_col > (cols + (t_ws->table[cols][new_row]->colspan - 1))) continue; @@ -183,7 +184,7 @@ static void focus_thing(xcb_connection_t *conn, direction_t direction, thing_t t new_col = cols; break; } - LOG("Fixed it to new col %d\n", new_col); + DLOG("Fixed it to new col %d\n", new_col); } } else if (direction == D_LEFT || direction == D_RIGHT) { if (direction == D_RIGHT && cell_exists(current_col+1, current_row)) @@ -202,11 +203,11 @@ static void focus_thing(xcb_connection_t *conn, direction_t direction, thing_t t } } else { /* Let’s see if there is a screen left/right here to which we can switch */ - LOG("container is at %d with width %d\n", container->x, container->width); + DLOG("container is at %d with width %d\n", container->x, container->width); i3Screen *screen; int destination_x = (direction == D_LEFT ? (container->x - 1) : (container->x + container->width + 1)); if ((screen = get_screen_containing(destination_x, container->y)) == NULL) { - LOG("Wrapping screen around horizontally\n"); + DLOG("Wrapping screen around horizontally\n"); screen = get_screen_most((direction == D_LEFT ? D_RIGHT : D_LEFT), container->workspace->screen); } t_ws = screen->current_workspace; @@ -215,9 +216,9 @@ static void focus_thing(xcb_connection_t *conn, direction_t direction, thing_t t check_colrow_boundaries(); - LOG("new_col = %d, new_row = %d\n", new_col, new_row); + DLOG("new_col = %d, new_row = %d\n", new_col, new_row); if (t_ws->table[new_col][new_row]->currently_focused == NULL) { - LOG("Cell empty, checking for rowspanned client above...\n"); + DLOG("Cell empty, checking for rowspanned client above...\n"); for (int rows = 0; rows < new_row; rows += t_ws->table[new_col][rows]->rowspan) { if (new_row > (rows + (t_ws->table[new_col][rows]->rowspan - 1))) continue; @@ -225,10 +226,10 @@ static void focus_thing(xcb_connection_t *conn, direction_t direction, thing_t t new_row = rows; break; } - LOG("Fixed it to new row %d\n", new_row); + DLOG("Fixed it to new row %d\n", new_row); } } else { - LOG("direction unhandled\n"); + ELOG("direction unhandled\n"); return; } @@ -254,7 +255,7 @@ static bool move_current_window_in_container(xcb_connection_t *conn, Client *cli if (other == CIRCLEQ_END(&(client->container->clients))) return false; - LOG("i can do that\n"); + DLOG("i can do that\n"); /* We can move the client inside its current container */ CIRCLEQ_REMOVE(&(client->container->clients), client, clients); if (direction == D_UP) @@ -411,7 +412,7 @@ static void move_current_container(xcb_connection_t *conn, direction_t direction return; } - LOG("old = %d,%d and new = %d,%d\n", container->col, container->row, new->col, new->row); + DLOG("old = %d,%d and new = %d,%d\n", container->col, container->row, new->col, new->row); /* Swap the containers */ int col = new->col; @@ -453,7 +454,7 @@ static void snap_current_container(xcb_connection_t *conn, direction_t direction /* Snap to the left is actually a move to the left and then a snap right */ if (!cell_exists(container->col - 1, container->row) || CUR_TABLE[container->col-1][container->row]->currently_focused != NULL) { - LOG("cannot snap to left - the cell is already used\n"); + ELOG("cannot snap to left - the cell is already used\n"); return; } @@ -466,18 +467,18 @@ static void snap_current_container(xcb_connection_t *conn, direction_t direction for (int i = 0; i < container->rowspan; i++) if (!cell_exists(new_col, container->row + i) || CUR_TABLE[new_col][container->row + i]->currently_focused != NULL) { - LOG("cannot snap to right - the cell is already used\n"); + ELOG("cannot snap to right - the cell is already used\n"); return; } /* Check if there are other cells with rowspan, which are in our way. * If so, reduce their rowspan. */ for (int i = container->row-1; i >= 0; i--) { - LOG("we got cell %d, %d with rowspan %d\n", + DLOG("we got cell %d, %d with rowspan %d\n", new_col, i, CUR_TABLE[new_col][i]->rowspan); while ((CUR_TABLE[new_col][i]->rowspan-1) >= (container->row - i)) CUR_TABLE[new_col][i]->rowspan--; - LOG("new rowspan = %d\n", CUR_TABLE[new_col][i]->rowspan); + DLOG("new rowspan = %d\n", CUR_TABLE[new_col][i]->rowspan); } container->colspan++; @@ -486,7 +487,7 @@ static void snap_current_container(xcb_connection_t *conn, direction_t direction case D_UP: if (!cell_exists(container->col, container->row - 1) || CUR_TABLE[container->col][container->row-1]->currently_focused != NULL) { - LOG("cannot snap to top - the cell is already used\n"); + ELOG("cannot snap to top - the cell is already used\n"); return; } @@ -494,21 +495,21 @@ static void snap_current_container(xcb_connection_t *conn, direction_t direction snap_current_container(conn, D_DOWN); return; case D_DOWN: { - LOG("snapping down\n"); + DLOG("snapping down\n"); int new_row = container->row + container->rowspan; for (int i = 0; i < container->colspan; i++) if (!cell_exists(container->col + i, new_row) || CUR_TABLE[container->col + i][new_row]->currently_focused != NULL) { - LOG("cannot snap down - the cell is already used\n"); + ELOG("cannot snap down - the cell is already used\n"); return; } for (int i = container->col-1; i >= 0; i--) { - LOG("we got cell %d, %d with colspan %d\n", + DLOG("we got cell %d, %d with colspan %d\n", i, new_row, CUR_TABLE[i][new_row]->colspan); while ((CUR_TABLE[i][new_row]->colspan-1) >= (container->col - i)) CUR_TABLE[i][new_row]->colspan--; - LOG("new colspan = %d\n", CUR_TABLE[i][new_row]->colspan); + DLOG("new colspan = %d\n", CUR_TABLE[i][new_row]->colspan); } @@ -535,7 +536,7 @@ static void move_floating_window_to_workspace(xcb_connection_t *conn, Client *cl /* Check if there is already a fullscreen client on the destination workspace and * stop moving if so. */ if (client->fullscreen && (t_ws->fullscreen_client != NULL)) { - LOG("Not moving: Fullscreen client already existing on destination workspace.\n"); + ELOG("Not moving: Fullscreen client already existing on destination workspace.\n"); return; } @@ -543,24 +544,24 @@ static void move_floating_window_to_workspace(xcb_connection_t *conn, Client *cl /* If we’re moving it to an invisible screen, we need to unmap it */ if (!workspace_is_visible(t_ws)) { - LOG("This workspace is not visible, unmapping\n"); + DLOG("This workspace is not visible, unmapping\n"); client_unmap(conn, client); } else { /* If this is not the case, we move the window to a workspace * which is on another screen, so we also need to adjust its * coordinates. */ - LOG("before x = %d, y = %d\n", client->rect.x, client->rect.y); + DLOG("before x = %d, y = %d\n", client->rect.x, client->rect.y); uint32_t relative_x = client->rect.x - old_ws->rect.x, relative_y = client->rect.y - old_ws->rect.y; - LOG("rel_x = %d, rel_y = %d\n", relative_x, relative_y); + DLOG("rel_x = %d, rel_y = %d\n", relative_x, relative_y); client->rect.x = t_ws->rect.x + relative_x; client->rect.y = t_ws->rect.y + relative_y; - LOG("after x = %d, y = %d\n", client->rect.x, client->rect.y); + DLOG("after x = %d, y = %d\n", client->rect.x, client->rect.y); reposition_client(conn, client); xcb_flush(conn); } - LOG("done\n"); + DLOG("done\n"); render_layout(conn); @@ -584,7 +585,7 @@ static void move_current_window_to_workspace(xcb_connection_t *conn, int workspa Client *current_client = container->currently_focused; if (current_client == NULL) { - LOG("No currently focused client in current container.\n"); + ELOG("No currently focused client in current container.\n"); return; } Client *to_focus = CIRCLEQ_NEXT_OR_NULL(&(container->clients), current_client, clients); @@ -595,7 +596,7 @@ static void move_current_window_to_workspace(xcb_connection_t *conn, int workspa /* Check if there is already a fullscreen client on the destination workspace and * stop moving if so. */ if (current_client->fullscreen && (t_ws->fullscreen_client != NULL)) { - LOG("Not moving: Fullscreen client already existing on destination workspace.\n"); + ELOG("Not moving: Fullscreen client already existing on destination workspace.\n"); return; } @@ -611,7 +612,7 @@ static void move_current_window_to_workspace(xcb_connection_t *conn, int workspa CIRCLEQ_INSERT_TAIL(&(to_container->clients), current_client, clients); SLIST_INSERT_HEAD(&(to_container->workspace->focus_stack), current_client, focus_clients); - LOG("Moved.\n"); + DLOG("Moved.\n"); current_client->container = to_container; current_client->workspace = to_container->workspace; @@ -620,11 +621,11 @@ static void move_current_window_to_workspace(xcb_connection_t *conn, int workspa /* If we’re moving it to an invisible screen, we need to unmap it */ if (!workspace_is_visible(to_container->workspace)) { - LOG("This workspace is not visible, unmapping\n"); + DLOG("This workspace is not visible, unmapping\n"); client_unmap(conn, current_client); } else { if (current_client->fullscreen) { - LOG("Calling client_enter_fullscreen again\n"); + DLOG("Calling client_enter_fullscreen again\n"); client_enter_fullscreen(conn, current_client); } } @@ -656,7 +657,7 @@ static void jump_to_window(xcb_connection_t *conn, const char *arguments) { if ((client = get_matching_client(conn, classtitle, NULL)) == NULL) { free(classtitle); - LOG("No matching client found.\n"); + ELOG("No matching client found.\n"); return; } @@ -678,7 +679,7 @@ static void jump_to_container(xcb_connection_t *conn, const char *arguments) { /* No match? Either no arguments were specified, or no numbers */ if (result < 1) { - LOG("At least one valid argument required\n"); + ELOG("At least one valid argument required\n"); return; } @@ -688,7 +689,7 @@ static void jump_to_container(xcb_connection_t *conn, const char *arguments) { if (result < 3) return; - LOG("Boundary-checking col %d, row %d... (max cols %d, max rows %d)\n", col, row, c_ws->cols, c_ws->rows); + DLOG("Boundary-checking col %d, row %d... (max cols %d, max rows %d)\n", col, row, c_ws->cols, c_ws->rows); /* Move to row/col */ if (row >= c_ws->rows) @@ -696,7 +697,7 @@ static void jump_to_container(xcb_connection_t *conn, const char *arguments) { if (col >= c_ws->cols) col = c_ws->cols - 1; - LOG("Jumping to col %d, row %d\n", col, row); + DLOG("Jumping to col %d, row %d\n", col, row); if (c_ws->table[col][row]->currently_focused != NULL) set_focus(conn, c_ws->table[col][row]->currently_focused, true); } @@ -725,7 +726,7 @@ static void travel_focus_stack(xcb_connection_t *conn, const char *arguments) { } else if (strcasecmp(arguments, "ft") == 0) { Client *last_focused = SLIST_FIRST(&(c_ws->focus_stack)); if (last_focused == SLIST_END(&(c_ws->focus_stack))) { - LOG("Cannot select the next floating/tiling client because there is no client at all\n"); + ELOG("Cannot select the next floating/tiling client because there is no client at all\n"); return; } @@ -733,17 +734,17 @@ static void travel_focus_stack(xcb_connection_t *conn, const char *arguments) { } else { /* …or a number was specified */ if (sscanf(arguments, "%u", ×) != 1) { - LOG("No or invalid argument given (\"%s\"), using default of 1 times\n", arguments); + ELOG("No or invalid argument given (\"%s\"), using default of 1 times\n", arguments); times = 1; } SLIST_FOREACH(current, &(CUR_CELL->workspace->focus_stack), focus_clients) { if (++count < times) { - LOG("Skipping\n"); + DLOG("Skipping\n"); continue; } - LOG("Focussing\n"); + DLOG("Focussing\n"); set_focus(conn, current, true); break; } @@ -767,7 +768,7 @@ static void travel_focus_stack(xcb_connection_t *conn, const char *arguments) { static char **append_argument(char **original, char *argument) { int num_args; for (num_args = 0; original[num_args] != NULL; num_args++) { - LOG("original argument: \"%s\"\n", original[num_args]); + DLOG("original argument: \"%s\"\n", original[num_args]); /* If the argument is already present we return the original pointer */ if (strcmp(original[num_args], argument) == 0) return original; @@ -821,7 +822,7 @@ static void parse_resize_command(xcb_connection_t *conn, Client *last_focused, c command += strlen("left"); } else if (STARTS_WITH(command, "right")) { first = con->col + (con->colspan - 1); - LOG("column %d\n", first); + DLOG("column %d\n", first); if (!cell_exists(first, con->row) || (first == (ws->cols-1))) @@ -846,7 +847,7 @@ static void parse_resize_command(xcb_connection_t *conn, Client *last_focused, c orientation = O_HORIZONTAL; command += strlen("bottom"); } else { - LOG("Syntax: resize [+|-]\n"); + ELOG("Syntax: resize [+|-]\n"); return; } @@ -882,14 +883,14 @@ void parse_command(xcb_connection_t *conn, const char *command) { if (STARTS_WITH(command, "mark")) { if (last_focused == NULL) { - LOG("There is no window to mark\n"); + ELOG("There is no window to mark\n"); return; } const char *rest = command + strlen("mark"); while (*rest == ' ') rest++; if (*rest == '\0') { - LOG("interactive mark starting\n"); + DLOG("interactive mark starting\n"); start_application("i3-input -p 'mark ' -l 1 -P 'Mark: '"); } else { LOG("mark with \"%s\"\n", rest); @@ -903,7 +904,7 @@ void parse_command(xcb_connection_t *conn, const char *command) { while (*rest == ' ') rest++; if (*rest == '\0') { - LOG("interactive go to mark starting\n"); + DLOG("interactive go to mark starting\n"); start_application("i3-input -p 'goto ' -l 1 -P 'Goto: '"); } else { LOG("go to \"%s\"\n", rest); @@ -914,7 +915,7 @@ void parse_command(xcb_connection_t *conn, const char *command) { if (STARTS_WITH(command, "stack-limit ")) { if (last_focused == NULL || client_is_floating(last_focused)) { - LOG("No container focused\n"); + ELOG("No container focused\n"); return; } const char *rest = command + strlen("stack-limit "); @@ -925,7 +926,7 @@ void parse_command(xcb_connection_t *conn, const char *command) { last_focused->container->stack_limit = STACK_LIMIT_COLS; rest += strlen("cols "); } else { - LOG("Syntax: stack-limit \n"); + ELOG("Syntax: stack-limit \n"); return; } @@ -974,7 +975,7 @@ void parse_command(xcb_connection_t *conn, const char *command) { if (STARTS_WITH(command, "kill")) { if (last_focused == NULL) { - LOG("There is no window to kill\n"); + ELOG("There is no window to kill\n"); return; } @@ -1010,7 +1011,7 @@ void parse_command(xcb_connection_t *conn, const char *command) { /* Is it just 's' for stacking or 'd' for default? */ if ((command[0] == 's' || command[0] == 'd' || command[0] == 'T') && (command[1] == '\0')) { if (last_focused != NULL && client_is_floating(last_focused)) { - LOG("not switching, this is a floating client\n"); + ELOG("not switching, this is a floating client\n"); return; } LOG("Switching mode for current container\n"); @@ -1027,7 +1028,7 @@ void parse_command(xcb_connection_t *conn, const char *command) { /* or even 'bt' (toggle border: 'bp' -> 'bb' -> 'bn' ) */ if (command[0] == 'b') { if (last_focused == NULL) { - LOG("No window focused, cannot change border type\n"); + ELOG("No window focused, cannot change border type\n"); return; } @@ -1068,7 +1069,7 @@ void parse_command(xcb_connection_t *conn, const char *command) { with = WITH_SCREEN; command++; } else { - LOG("not yet implemented.\n"); + ELOG("not yet implemented.\n"); return; } } @@ -1081,7 +1082,7 @@ void parse_command(xcb_connection_t *conn, const char *command) { return; } if (last_focused == NULL) { - LOG("Cannot toggle tiling/floating: workspace empty\n"); + ELOG("Cannot toggle tiling/floating: workspace empty\n"); return; } @@ -1115,7 +1116,7 @@ void parse_command(xcb_connection_t *conn, const char *command) { direction_t direction; int times = strtol(command, &rest, 10); if (rest == NULL) { - LOG("Invalid command (\"%s\")\n", command); + ELOG("Invalid command (\"%s\")\n", command); return; } @@ -1133,7 +1134,7 @@ void parse_command(xcb_connection_t *conn, const char *command) { int workspace = strtol(rest, &rest, 10); if (rest == NULL) { - LOG("Invalid command (\"%s\")\n", command); + ELOG("Invalid command (\"%s\")\n", command); return; } @@ -1145,13 +1146,13 @@ void parse_command(xcb_connection_t *conn, const char *command) { } if (last_focused == NULL) { - LOG("Not performing (no window found)\n"); + ELOG("Not performing (no window found)\n"); return; } if (client_is_floating(last_focused) && (action != ACTION_FOCUS && action != ACTION_MOVE)) { - LOG("Not performing (floating)\n"); + ELOG("Not performing (floating)\n"); return; } @@ -1166,7 +1167,7 @@ void parse_command(xcb_connection_t *conn, const char *command) { else if (*rest == 'l') direction = D_RIGHT; else { - LOG("unknown direction: %c\n", *rest); + ELOG("unknown direction: %c\n", *rest); return; } rest++; @@ -1189,7 +1190,7 @@ void parse_command(xcb_connection_t *conn, const char *command) { /* TODO: this should swap the screen’s contents * (e.g. all workspaces) with the next/previous/… * screen */ - LOG("Not yet implemented\n"); + ELOG("Not yet implemented\n"); continue; } if (client_is_floating(last_focused)) { @@ -1204,7 +1205,7 @@ void parse_command(xcb_connection_t *conn, const char *command) { if (action == ACTION_SNAP) { if (with == WITH_SCREEN) { - LOG("You cannot snap a screen (it makes no sense).\n"); + ELOG("You cannot snap a screen (it makes no sense).\n"); continue; } snap_current_container(conn, direction); diff --git a/src/config.c b/src/config.c index 69506578..930b09c5 100644 --- a/src/config.c +++ b/src/config.c @@ -29,6 +29,7 @@ #include "xcb.h" #include "table.h" #include "workspace.h" +#include "log.h" Config config; struct modes_head modes; @@ -52,12 +53,12 @@ static char *glob_path(const char *path) { * */ void ungrab_all_keys(xcb_connection_t *conn) { - LOG("Ungrabbing all keys\n"); + DLOG("Ungrabbing all keys\n"); xcb_ungrab_key(conn, XCB_GRAB_ANY, root, XCB_BUTTON_MASK_ANY); } static void grab_keycode_for_binding(xcb_connection_t *conn, Binding *bind, uint32_t keycode) { - LOG("Grabbing %d\n", keycode); + DLOG("Grabbing %d\n", keycode); if ((bind->mods & BIND_MODE_SWITCH) != 0) xcb_grab_key(conn, 0, root, 0, keycode, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_SYNC); @@ -87,14 +88,14 @@ void grab_all_keys(xcb_connection_t *conn) { /* We need to translate the symbol to a keycode */ xcb_keysym_t keysym = XStringToKeysym(bind->symbol); if (keysym == NoSymbol) { - LOG("Could not translate string to key symbol: \"%s\"\n", bind->symbol); + ELOG("Could not translate string to key symbol: \"%s\"\n", bind->symbol); continue; } #ifdef OLD_XCB_KEYSYMS_API bind->number_keycodes = 1; xcb_keycode_t code = xcb_key_symbols_get_keycode(keysyms, keysym); - LOG("Translated symbol \"%s\" to 1 keycode (%d)\n", bind->symbol, code); + DLOG("Translated symbol \"%s\" to 1 keycode (%d)\n", bind->symbol, code); grab_keycode_for_binding(conn, bind, code); bind->translated_to = smalloc(sizeof(xcb_keycode_t)); memcpy(bind->translated_to, &code, sizeof(xcb_keycode_t)); @@ -102,7 +103,7 @@ void grab_all_keys(xcb_connection_t *conn) { uint32_t last_keycode = 0; xcb_keycode_t *keycodes = xcb_key_symbols_get_keycode(keysyms, keysym); if (keycodes == NULL) { - LOG("Could not translate symbol \"%s\"\n", bind->symbol); + DLOG("Could not translate symbol \"%s\"\n", bind->symbol); continue; } @@ -117,7 +118,7 @@ void grab_all_keys(xcb_connection_t *conn) { last_keycode = *walk; bind->number_keycodes++; } - LOG("Translated symbol \"%s\" to %d keycode\n", bind->symbol, bind->number_keycodes); + DLOG("Translated symbol \"%s\" to %d keycode\n", bind->symbol, bind->number_keycodes); bind->translated_to = smalloc(bind->number_keycodes * sizeof(xcb_keycode_t)); memcpy(bind->translated_to, keycodes, bind->number_keycodes * sizeof(xcb_keycode_t)); free(keycodes); @@ -144,7 +145,7 @@ void switch_mode(xcb_connection_t *conn, const char *new_mode) { return; } - LOG("ERROR: Mode not found\n"); + ELOG("ERROR: Mode not found\n"); } /* diff --git a/src/floating.c b/src/floating.c index a8557416..2facc6cf 100644 --- a/src/floating.c +++ b/src/floating.c @@ -27,6 +27,7 @@ #include "client.h" #include "floating.h" #include "workspace.h" +#include "log.h" /* * Toggles floating mode for the given client. @@ -42,7 +43,7 @@ void toggle_floating_mode(xcb_connection_t *conn, Client *client, bool automatic i3Font *font = load_font(conn, config.font); if (con == NULL) { - LOG("This client is already in floating (container == NULL), re-inserting\n"); + DLOG("This client is already in floating (container == NULL), re-inserting\n"); Client *next_tiling; Workspace *ws = client->workspace; SLIST_FOREACH(next_tiling, &(ws->focus_stack), focus_clients) @@ -57,7 +58,7 @@ void toggle_floating_mode(xcb_connection_t *conn, Client *client, bool automatic /* Remove the client from the list of floating clients */ TAILQ_REMOVE(&(ws->floating_clients), client, floating_clients); - LOG("destination container = %p\n", con); + DLOG("destination container = %p\n", con); Client *old_focused = con->currently_focused; /* Preserve position/size */ memcpy(&(client->floating_rect), &(client->rect), sizeof(Rect)); @@ -69,7 +70,7 @@ void toggle_floating_mode(xcb_connection_t *conn, Client *client, bool automatic CIRCLEQ_INSERT_AFTER(&(con->clients), old_focused, client, clients); else CIRCLEQ_INSERT_TAIL(&(con->clients), client, clients); - LOG("Re-inserted the client into the matrix.\n"); + DLOG("Re-inserted the window.\n"); con->currently_focused = client; client_set_below_floating(conn, client); @@ -80,7 +81,7 @@ void toggle_floating_mode(xcb_connection_t *conn, Client *client, bool automatic return; } - LOG("Entering floating for client %08x\n", client->child); + DLOG("Entering floating for client %08x\n", client->child); /* Remove the client of its container */ client_remove_from_container(conn, client, con, false); @@ -90,7 +91,7 @@ void toggle_floating_mode(xcb_connection_t *conn, Client *client, bool automatic TAILQ_INSERT_TAIL(&(client->workspace->floating_clients), client, floating_clients); if (con->currently_focused == client) { - LOG("Need to re-adjust currently_focused\n"); + DLOG("Need to re-adjust currently_focused\n"); /* Get the next client in the focus stack for this particular container */ con->currently_focused = get_last_focused_client(conn, con, NULL); } @@ -113,11 +114,11 @@ void toggle_floating_mode(xcb_connection_t *conn, Client *client, bool automatic client->rect.width = client->child_rect.width + 2 + 2; client->rect.height = client->child_rect.height + (font->height + 2 + 2) + 2; - LOG("copying size from tiling (%d, %d) size (%d, %d)\n", client->floating_rect.x, client->floating_rect.y, + DLOG("copying size from tiling (%d, %d) size (%d, %d)\n", client->floating_rect.x, client->floating_rect.y, client->floating_rect.width, client->floating_rect.height); } else { /* If the client was already in floating before we restore the old position / size */ - LOG("using: (%d, %d) size (%d, %d)\n", client->floating_rect.x, client->floating_rect.y, + DLOG("using: (%d, %d) size (%d, %d)\n", client->floating_rect.x, client->floating_rect.y, client->floating_rect.width, client->floating_rect.height); memcpy(&(client->rect), &(client->floating_rect), sizeof(Rect)); } @@ -163,8 +164,7 @@ void floating_assign_to_workspace(Client *client, Workspace *new_workspace) { * */ int floating_border_click(xcb_connection_t *conn, Client *client, xcb_button_press_event_t *event) { - - LOG("floating border click\n"); + DLOG("floating border click\n"); border_t border; @@ -225,11 +225,11 @@ int floating_border_click(xcb_connection_t *conn, Client *client, xcb_button_pre else if (event->event_x >= (client->rect.width - 2)) border = BORDER_RIGHT; else { - LOG("Not on any border, not doing anything.\n"); + DLOG("Not on any border, not doing anything.\n"); return 1; } - LOG("border = %d\n", border); + DLOG("border = %d\n", border); drag_pointer(conn, client, event, XCB_NONE, border, resize_callback); @@ -243,7 +243,7 @@ int floating_border_click(xcb_connection_t *conn, Client *client, xcb_button_pre * */ void floating_drag_window(xcb_connection_t *conn, Client *client, xcb_button_press_event_t *event) { - LOG("floating_drag_window\n"); + DLOG("floating_drag_window\n"); void drag_window_callback(Rect *old_rect, uint32_t new_x, uint32_t new_y) { /* Reposition the client correctly while moving */ @@ -266,7 +266,7 @@ void floating_drag_window(xcb_connection_t *conn, Client *client, xcb_button_pre * */ void floating_resize_window(xcb_connection_t *conn, Client *client, xcb_button_press_event_t *event) { - LOG("floating_resize_window\n"); + DLOG("floating_resize_window\n"); void resize_window_callback(Rect *old_rect, uint32_t new_x, uint32_t new_y) { int32_t new_width = old_rect->width + (new_x - event->root_x); @@ -346,12 +346,12 @@ void drag_pointer(xcb_connection_t *conn, Client *client, xcb_button_press_event break; case XCB_UNMAP_NOTIFY: - LOG("Unmap-notify, aborting\n"); + DLOG("Unmap-notify, aborting\n"); xcb_event_handle(&evenths, inside_event); goto done; default: - LOG("Passing to original handler\n"); + DLOG("Passing to original handler\n"); /* Use original handler */ xcb_event_handle(&evenths, inside_event); break; @@ -382,7 +382,7 @@ done: * */ void floating_focus_direction(xcb_connection_t *conn, Client *currently_focused, direction_t direction) { - LOG("floating focus\n"); + DLOG("floating focus\n"); if (direction == D_LEFT || direction == D_RIGHT) { /* Go to the next/previous floating client */ @@ -404,7 +404,7 @@ void floating_focus_direction(xcb_connection_t *conn, Client *currently_focused, * */ void floating_move(xcb_connection_t *conn, Client *currently_focused, direction_t direction) { - LOG("floating move\n"); + DLOG("floating move\n"); switch (direction) { case D_LEFT: @@ -445,7 +445,7 @@ void floating_toggle_hide(xcb_connection_t *conn, Workspace *workspace) { Client *client; workspace->floating_hidden = !workspace->floating_hidden; - LOG("floating_hidden is now: %d\n", workspace->floating_hidden); + DLOG("floating_hidden is now: %d\n", workspace->floating_hidden); TAILQ_FOREACH(client, &(workspace->floating_clients), floating_clients) { if (workspace->floating_hidden) client_unmap(conn, client); diff --git a/src/handlers.c b/src/handlers.c index 560fad25..823ed8b8 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -36,6 +36,7 @@ #include "manage.h" #include "floating.h" #include "workspace.h" +#include "log.h" /* After mapping/unmapping windows, a notify event is generated. However, we don’t want it, since it’d trigger an infinite loop of switching between the different windows when @@ -95,15 +96,15 @@ int handle_key_release(void *ignored, xcb_connection_t *conn, xcb_key_release_ev * */ int handle_key_press(void *ignored, xcb_connection_t *conn, xcb_key_press_event_t *event) { - LOG("Keypress %d, state raw = %d\n", event->detail, event->state); + DLOG("Keypress %d, state raw = %d\n", event->detail, event->state); /* Remove the numlock bit, all other bits are modifiers we can bind to */ uint16_t state_filtered = event->state & ~(xcb_numlock_mask | XCB_MOD_MASK_LOCK); - LOG("(removed numlock, state = %d)\n", state_filtered); + DLOG("(removed numlock, state = %d)\n", state_filtered); /* Only use the lower 8 bits of the state (modifier masks) so that mouse * button masks are filtered out */ state_filtered &= 0xFF; - LOG("(removed upper 8 bits, state = %d)\n", state_filtered); + DLOG("(removed upper 8 bits, state = %d)\n", state_filtered); if (xkb_supported) { /* We need to get the keysym group (There are group 1 to group 4, each holding @@ -114,7 +115,7 @@ int handle_key_press(void *ignored, xcb_connection_t *conn, xcb_key_press_event_ state_filtered |= BIND_MODE_SWITCH; } - LOG("(checked mode_switch, state %d)\n", state_filtered); + DLOG("(checked mode_switch, state %d)\n", state_filtered); /* Find the binding */ Binding *bind; @@ -147,7 +148,7 @@ int handle_key_press(void *ignored, xcb_connection_t *conn, xcb_key_press_event_ parse_command(conn, bind->command); if (state_filtered & BIND_MODE_SWITCH) { - LOG("Mode_switch -> allow_events(SyncKeyboard)\n"); + DLOG("Mode_switch -> allow_events(SyncKeyboard)\n"); xcb_allow_events(conn, SyncKeyboard, event->time); xcb_flush(conn); } @@ -164,7 +165,7 @@ static void check_crossing_screen_boundary(uint32_t x, uint32_t y) { i3Screen *screen; if ((screen = get_screen_containing(x, y)) == NULL) { - LOG("ERROR: No such screen\n"); + ELOG("ERROR: No such screen\n"); return; } if (screen == c_ws->screen) @@ -175,7 +176,7 @@ static void check_crossing_screen_boundary(uint32_t x, uint32_t y) { c_ws = screen->current_workspace; current_row = c_ws->current_row; current_col = c_ws->current_col; - LOG("We're now on virtual screen number %d\n", screen->num); + DLOG("We're now on virtual screen number %d\n", screen->num); } /* @@ -183,9 +184,9 @@ static void check_crossing_screen_boundary(uint32_t x, uint32_t y) { * */ int handle_enter_notify(void *ignored, xcb_connection_t *conn, xcb_enter_notify_event_t *event) { - LOG("enter_notify for %08x, mode = %d, detail %d, serial %d\n", event->event, event->mode, event->detail, event->sequence); + DLOG("enter_notify for %08x, mode = %d, detail %d, serial %d\n", event->event, event->mode, event->detail, event->sequence); if (event->mode != XCB_NOTIFY_MODE_NORMAL) { - LOG("This was not a normal notify, ignoring\n"); + DLOG("This was not a normal notify, ignoring\n"); return 1; } /* Some events are not interesting, because they were not generated actively by the @@ -212,7 +213,7 @@ int handle_enter_notify(void *ignored, xcb_connection_t *conn, xcb_enter_notify_ /* If not, then the user moved his cursor to the root window. In that case, we adjust c_ws */ if (client == NULL) { - LOG("Getting screen at %d x %d\n", event->root_x, event->root_y); + DLOG("Getting screen at %d x %d\n", event->root_x, event->root_y); check_crossing_screen_boundary(event->root_x, event->root_y); return 1; } @@ -222,7 +223,7 @@ int handle_enter_notify(void *ignored, xcb_connection_t *conn, xcb_enter_notify_ if (client->container != NULL && client->container->mode == MODE_STACK && client->container->currently_focused != client) { - LOG("Plausibility check says: no\n"); + DLOG("Plausibility check says: no\n"); return 1; } @@ -230,7 +231,7 @@ int handle_enter_notify(void *ignored, xcb_connection_t *conn, xcb_enter_notify_ /* This can happen when a client gets assigned to a different workspace than * the current one (see src/mainx.c:reparent_window). Shortly after it was created, * an enter_notify will follow. */ - LOG("enter_notify for a client on a different workspace but the same screen, ignoring\n"); + DLOG("enter_notify for a client on a different workspace but the same screen, ignoring\n"); return 1; } @@ -266,7 +267,7 @@ int handle_mapping_notify(void *ignored, xcb_connection_t *conn, xcb_mapping_not event->request != XCB_MAPPING_MODIFIER) return 0; - LOG("Received mapping_notify for keyboard or modifier mapping, re-grabbing keys\n"); + DLOG("Received mapping_notify for keyboard or modifier mapping, re-grabbing keys\n"); xcb_refresh_keyboard_mapping(keysyms, event); xcb_get_numlock_mask(conn); @@ -286,7 +287,7 @@ int handle_map_request(void *prophs, xcb_connection_t *conn, xcb_map_request_eve cookie = xcb_get_window_attributes_unchecked(conn, event->window); - LOG("window = 0x%08x, serial is %d.\n", event->window, event->sequence); + DLOG("window = 0x%08x, serial is %d.\n", event->window, event->sequence); add_ignore_event(event->sequence); manage_window(prophs, conn, event->window, cookie, false); @@ -300,7 +301,7 @@ int handle_map_request(void *prophs, xcb_connection_t *conn, xcb_map_request_eve * */ int handle_configure_request(void *prophs, xcb_connection_t *conn, xcb_configure_request_event_t *event) { - LOG("window 0x%08x wants to be at %dx%d with %dx%d\n", + DLOG("window 0x%08x wants to be at %dx%d with %dx%d\n", event->window, event->x, event->y, event->width, event->height); Client *client = table_get(&by_child, event->window); @@ -330,7 +331,7 @@ int handle_configure_request(void *prophs, xcb_connection_t *conn, xcb_configure } if (client->fullscreen) { - LOG("Client is in fullscreen mode\n"); + DLOG("Client is in fullscreen mode\n"); Rect child_rect = client->workspace->rect; child_rect.x = child_rect.y = 0; @@ -371,7 +372,7 @@ int handle_configure_request(void *prophs, xcb_connection_t *conn, xcb_configure } } - LOG("Accepted new position/size for floating client: (%d, %d) size %d x %d\n", + DLOG("Accepted new position/size for floating client: (%d, %d) size %d x %d\n", client->rect.x, client->rect.y, client->rect.width, client->rect.height); /* Push the new position/size to X11 */ @@ -384,10 +385,10 @@ int handle_configure_request(void *prophs, xcb_connection_t *conn, xcb_configure /* Dock clients can be reconfigured in their height */ if (client->dock) { - LOG("Reconfiguring height of this dock client\n"); + DLOG("Reconfiguring height of this dock client\n"); if (!(event->value_mask & XCB_CONFIG_WINDOW_HEIGHT)) { - LOG("Ignoring configure request, no height given\n"); + DLOG("Ignoring configure request, no height given\n"); return 1; } @@ -399,7 +400,7 @@ int handle_configure_request(void *prophs, xcb_connection_t *conn, xcb_configure } if (client->fullscreen) { - LOG("Client is in fullscreen mode\n"); + DLOG("Client is in fullscreen mode\n"); Rect child_rect = client->container->workspace->rect; child_rect.x = child_rect.y = 0; @@ -426,8 +427,8 @@ int handle_configure_event(void *prophs, xcb_connection_t *conn, xcb_configure_n add_ignore_event(event->sequence); if (event->event == root) { - LOG("event->x = %d, ->y = %d, ->width = %d, ->height = %d\n", event->x, event->y, event->width, event->height); - LOG("reconfigure of the root window, need to xinerama\n"); + DLOG("event->x = %d, ->y = %d, ->width = %d, ->height = %d\n", event->x, event->y, event->width, event->height); + DLOG("reconfigure of the root window, need to xinerama\n"); /* FIXME: Somehow, this is occuring too often. Therefore, we check for 0/0, but is there a better way? */ if (event->x == 0 && event->y == 0) @@ -456,10 +457,10 @@ int handle_unmap_notify_event(void *data, xcb_connection_t *conn, xcb_unmap_noti return 1; } - LOG("event->window = %08x, event->event = %08x\n", event->window, event->event); - LOG("UnmapNotify for 0x%08x (received from 0x%08x)\n", event->window, event->event); + DLOG("event->window = %08x, event->event = %08x\n", event->window, event->event); + DLOG("UnmapNotify for 0x%08x (received from 0x%08x)\n", event->window, event->event); if (client == NULL) { - LOG("not a managed window. Ignoring.\n"); + DLOG("not a managed window. Ignoring.\n"); /* This was most likely the destroyed frame of a client which is * currently being unmapped, so we add this sequence (again!) to @@ -490,17 +491,17 @@ int handle_unmap_notify_event(void *data, xcb_connection_t *conn, xcb_unmap_noti if ((con->currently_focused != NULL) && ((con == CUR_CELL) || client->fullscreen)) set_focus(conn, con->currently_focused, true); } else if (client_is_floating(client)) { - LOG("Removing from floating clients\n"); + DLOG("Removing from floating clients\n"); TAILQ_REMOVE(&(client->workspace->floating_clients), client, floating_clients); SLIST_REMOVE(&(client->workspace->focus_stack), client, Client, focus_clients); } if (client->dock) { - LOG("Removing from dock clients\n"); + DLOG("Removing from dock clients\n"); SLIST_REMOVE(&(client->workspace->screen->dock_clients), client, Client, dock_clients); } - LOG("child of 0x%08x.\n", client->frame); + DLOG("child of 0x%08x.\n", client->frame); xcb_reparent_window(conn, client->child, root, 0, 0); client_unmap(conn, client); @@ -550,7 +551,7 @@ int handle_unmap_notify_event(void *data, xcb_connection_t *conn, xcb_unmap_noti if (to_focus != NULL) set_focus(conn, to_focus, true); else { - LOG("Restoring focus to root screen\n"); + DLOG("Restoring focus to root screen\n"); xcb_set_input_focus(conn, XCB_INPUT_FOCUS_POINTER_ROOT, root, XCB_CURRENT_TIME); xcb_flush(conn); } @@ -566,7 +567,7 @@ int handle_unmap_notify_event(void *data, xcb_connection_t *conn, xcb_unmap_noti int handle_windowname_change(void *data, xcb_connection_t *conn, uint8_t state, xcb_window_t window, xcb_atom_t atom, xcb_get_property_reply_t *prop) { if (prop == NULL || xcb_get_property_value_length(prop) == 0) { - LOG("_NET_WM_NAME not specified, not changing\n"); + DLOG("_NET_WM_NAME not specified, not changing\n"); return 1; } Client *client = table_get(&by_child, window); @@ -628,7 +629,7 @@ int handle_windowname_change(void *data, xcb_connection_t *conn, uint8_t state, int handle_windowname_change_legacy(void *data, xcb_connection_t *conn, uint8_t state, xcb_window_t window, xcb_atom_t atom, xcb_get_property_reply_t *prop) { if (prop == NULL || xcb_get_property_value_length(prop) == 0) { - LOG("prop == NULL\n"); + DLOG("prop == NULL\n"); return 1; } Client *client = table_get(&by_child, window); @@ -643,7 +644,7 @@ int handle_windowname_change_legacy(void *data, xcb_connection_t *conn, uint8_t char *new_name; if (asprintf(&new_name, "%.*s", xcb_get_property_value_length(prop), (char*)xcb_get_property_value(prop)) == -1) { perror("Could not get old name"); - LOG("Could not get old name\n"); + DLOG("Could not get old name\n"); return 1; } /* Convert it to UCS-2 here for not having to convert it later every time we want to pass it to X */ @@ -688,7 +689,7 @@ int handle_windowname_change_legacy(void *data, xcb_connection_t *conn, uint8_t int handle_windowclass_change(void *data, xcb_connection_t *conn, uint8_t state, xcb_window_t window, xcb_atom_t atom, xcb_get_property_reply_t *prop) { if (prop == NULL || xcb_get_property_value_length(prop) == 0) { - LOG("prop == NULL\n"); + DLOG("prop == NULL\n"); return 1; } Client *client = table_get(&by_child, window); @@ -697,7 +698,7 @@ int handle_windowclass_change(void *data, xcb_connection_t *conn, uint8_t state, char *new_class; if (asprintf(&new_class, "%.*s", xcb_get_property_value_length(prop), (char*)xcb_get_property_value(prop)) == -1) { perror("Could not get window class"); - LOG("Could not get window class\n"); + DLOG("Could not get window class\n"); return 1; } @@ -710,7 +711,7 @@ int handle_windowclass_change(void *data, xcb_connection_t *conn, uint8_t state, return 1; if (strcmp(new_class, "tools") == 0 || strcmp(new_class, "Dialog") == 0) { - LOG("tool/dialog window, should we put it floating?\n"); + DLOG("tool/dialog window, should we put it floating?\n"); if (client->floating == FLOATING_AUTO_OFF) toggle_floating_mode(conn, client, true); } @@ -727,7 +728,7 @@ int handle_expose_event(void *data, xcb_connection_t *conn, xcb_expose_event_t * skip all events but the last one */ if (event->count != 0) return 1; - LOG("window = %08x\n", event->window); + DLOG("window = %08x\n", event->window); Client *client = table_get(&by_parent, event->window); if (client == NULL) { @@ -812,7 +813,7 @@ int handle_client_message(void *data, xcb_connection_t *conn, xcb_client_message event->data.data32[0] == _NET_WM_STATE_TOGGLE))) client_toggle_fullscreen(conn, client); } else { - LOG("unhandled clientmessage\n"); + ELOG("unhandled clientmessage\n"); return 0; } @@ -823,7 +824,7 @@ int handle_window_type(void *data, xcb_connection_t *conn, uint8_t state, xcb_wi xcb_atom_t atom, xcb_get_property_reply_t *property) { /* TODO: Implement this one. To do this, implement a little test program which sleep(1)s before changing this property. */ - LOG("_NET_WM_WINDOW_TYPE changed, this is not yet implemented.\n"); + ELOG("_NET_WM_WINDOW_TYPE changed, this is not yet implemented.\n"); return 0; } @@ -838,7 +839,7 @@ int handle_normal_hints(void *data, xcb_connection_t *conn, uint8_t state, xcb_w xcb_atom_t name, xcb_get_property_reply_t *reply) { Client *client = table_get(&by_child, window); if (client == NULL) { - LOG("Received WM_SIZE_HINTS for unknown client\n"); + DLOG("Received WM_SIZE_HINTS for unknown client\n"); return 1; } xcb_size_hints_t size_hints; @@ -893,9 +894,9 @@ int handle_normal_hints(void *data, xcb_connection_t *conn, uint8_t state, xcb_w base_height != client->base_height) { client->base_width = base_width; client->base_height = base_height; - LOG("client's base_height changed to %d\n", base_height); + DLOG("client's base_height changed to %d\n", base_height); if (client->fullscreen) - LOG("Not resizing client, it is in fullscreen mode\n"); + DLOG("Not resizing client, it is in fullscreen mode\n"); else resize_client(conn, client); } @@ -913,8 +914,8 @@ int handle_normal_hints(void *data, xcb_connection_t *conn, uint8_t state, xcb_w double min_aspect = (double)size_hints.min_aspect_num / size_hints.min_aspect_den; double max_aspect = (double)size_hints.max_aspect_num / size_hints.min_aspect_den; - LOG("Aspect ratio set: minimum %f, maximum %f\n", min_aspect, max_aspect); - LOG("width = %f, height = %f\n", width, height); + DLOG("Aspect ratio set: minimum %f, maximum %f\n", min_aspect, max_aspect); + DLOG("width = %f, height = %f\n", width, height); /* Sanity checks, this is user-input, in a way */ if (max_aspect <= 0 || min_aspect <= 0 || height == 0 || (width / height) <= 0) @@ -947,7 +948,7 @@ int handle_hints(void *data, xcb_connection_t *conn, uint8_t state, xcb_window_t xcb_atom_t name, xcb_get_property_reply_t *reply) { Client *client = table_get(&by_child, window); if (client == NULL) { - LOG("Received WM_HINTS for unknown client\n"); + DLOG("Received WM_HINTS for unknown client\n"); return 1; } xcb_wm_hints_t hints; @@ -962,7 +963,7 @@ int handle_hints(void *data, xcb_connection_t *conn, uint8_t state, xcb_window_t Client *last_focused = SLIST_FIRST(&(c_ws->focus_stack)); if (!client->urgent && client == last_focused) { - LOG("Ignoring urgency flag for current client\n"); + DLOG("Ignoring urgency flag for current client\n"); return 1; } @@ -996,7 +997,7 @@ int handle_transient_for(void *data, xcb_connection_t *conn, uint8_t state, xcb_ xcb_atom_t name, xcb_get_property_reply_t *reply) { Client *client = table_get(&by_child, window); if (client == NULL) { - LOG("No such client\n"); + DLOG("No such client\n"); return 1; } @@ -1012,7 +1013,7 @@ int handle_transient_for(void *data, xcb_connection_t *conn, uint8_t state, xcb_ } if (client->floating == FLOATING_AUTO_OFF) { - LOG("This is a popup window, putting into floating\n"); + DLOG("This is a popup window, putting into floating\n"); toggle_floating_mode(conn, client, true); } @@ -1041,7 +1042,7 @@ int handle_clientleader_change(void *data, xcb_connection_t *conn, uint8_t state if (leader == NULL || *leader == 0) return 1; - LOG("Client leader changed to %08x\n", *leader); + DLOG("Client leader changed to %08x\n", *leader); client->leader = *leader; diff --git a/src/ipc.c b/src/ipc.c index 0bef2ea2..9e56fd0e 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -28,6 +28,7 @@ #include "i3.h" #include "util.h" #include "commands.h" +#include "log.h" typedef struct ipc_client { int fd; @@ -71,10 +72,10 @@ void broadcast(EV_P_ struct ev_timer *t, int revents) { */ static void ipc_handle_message(uint8_t *message, int size, uint32_t message_size, uint32_t message_type) { - LOG("handling message of size %d\n", size); - LOG("sender specified size %d\n", message_size); - LOG("sender specified type %d\n", message_type); - LOG("payload as a string = %s\n", message); + DLOG("handling message of size %d\n", size); + DLOG("sender specified size %d\n", message_size); + DLOG("sender specified type %d\n", message_type); + DLOG("payload as a string = %s\n", message); switch (message_type) { case I3_IPC_MESSAGE_TYPE_COMMAND: { @@ -88,7 +89,7 @@ static void ipc_handle_message(uint8_t *message, int size, break; } default: - LOG("unhandled ipc message\n"); + DLOG("unhandled ipc message\n"); break; } } @@ -135,7 +136,7 @@ static void ipc_receive_message(EV_P_ struct ev_io *w, int revents) { ev_io_stop(EV_A_ w); - LOG("IPC: client disconnected\n"); + DLOG("IPC: client disconnected\n"); return; } @@ -144,18 +145,18 @@ static void ipc_receive_message(EV_P_ struct ev_io *w, int revents) { /* Check if the message starts with the i3 IPC magic code */ if (n < strlen(I3_IPC_MAGIC)) { - LOG("IPC: message too short, ignoring\n"); + DLOG("IPC: message too short, ignoring\n"); return; } if (strncmp(buf, I3_IPC_MAGIC, strlen(I3_IPC_MAGIC)) != 0) { - LOG("IPC: message does not start with the IPC magic\n"); + DLOG("IPC: message does not start with the IPC magic\n"); return; } uint8_t *message = (uint8_t*)buf; while (n > 0) { - LOG("IPC: n = %d\n", n); + DLOG("IPC: n = %d\n", n); message += strlen(I3_IPC_MAGIC); n -= strlen(I3_IPC_MAGIC); @@ -165,7 +166,7 @@ static void ipc_receive_message(EV_P_ struct ev_io *w, int revents) { n -= sizeof(uint32_t); if (message_size > n) { - LOG("IPC: Either the message size was wrong or the message was not read completely, dropping\n"); + DLOG("IPC: Either the message size was wrong or the message was not read completely, dropping\n"); return; } @@ -204,7 +205,7 @@ void ipc_new_client(EV_P_ struct ev_io *w, int revents) { ev_io_init(package, ipc_receive_message, client, EV_READ); ev_io_start(EV_A_ package); - LOG("IPC: new client connected\n"); + DLOG("IPC: new client connected\n"); struct ipc_client *new = calloc(sizeof(struct ipc_client), 1); new->fd = client; diff --git a/src/layout.c b/src/layout.c index c626edbd..fe9c1cfd 100644 --- a/src/layout.c +++ b/src/layout.c @@ -28,6 +28,7 @@ #include "floating.h" #include "handlers.h" #include "workspace.h" +#include "log.h" /* * Updates *destination with new_value and returns true if it was changed or false @@ -50,16 +51,16 @@ int get_unoccupied_x(Workspace *workspace) { double unoccupied = workspace->rect.width; double default_factor = ((float)workspace->rect.width / workspace->cols) / workspace->rect.width; - LOG("get_unoccupied_x(), starting with %f, default_factor = %f\n", unoccupied, default_factor); + DLOG("get_unoccupied_x(), starting with %f, default_factor = %f\n", unoccupied, default_factor); for (int cols = 0; cols < workspace->cols; cols++) { - LOG("width_factor[%d] = %f, unoccupied = %f\n", cols, workspace->width_factor[cols], unoccupied); + DLOG("width_factor[%d] = %f, unoccupied = %f\n", cols, workspace->width_factor[cols], unoccupied); if (workspace->width_factor[cols] == 0) unoccupied -= workspace->rect.width * default_factor; } - LOG("unoccupied space: %f\n", unoccupied); + DLOG("unoccupied space: %f\n", unoccupied); return unoccupied; } @@ -69,15 +70,15 @@ int get_unoccupied_y(Workspace *workspace) { double unoccupied = height; double default_factor = ((float)height / workspace->rows) / height; - LOG("get_unoccupied_y(), starting with %f, default_factor = %f\n", unoccupied, default_factor); + DLOG("get_unoccupied_y(), starting with %f, default_factor = %f\n", unoccupied, default_factor); for (int rows = 0; rows < workspace->rows; rows++) { - LOG("height_factor[%d] = %f, unoccupied = %f\n", rows, workspace->height_factor[rows], unoccupied); + DLOG("height_factor[%d] = %f, unoccupied = %f\n", rows, workspace->height_factor[rows], unoccupied); if (workspace->height_factor[rows] == 0) unoccupied -= height * default_factor; } - LOG("unoccupied space: %f\n", unoccupied); + DLOG("unoccupied space: %f\n", unoccupied); return unoccupied; } @@ -217,7 +218,7 @@ void decorate_window(xcb_connection_t *conn, Client *client, xcb_drawable_t draw void reposition_client(xcb_connection_t *conn, Client *client) { i3Screen *screen; - LOG("frame 0x%08x needs to be pushed to %dx%d\n", client->frame, client->rect.x, client->rect.y); + DLOG("frame 0x%08x needs to be pushed to %dx%d\n", client->frame, client->rect.x, client->rect.y); /* Note: We can use a pointer to client->x like an array of uint32_ts because it is followed by client->y by definition */ xcb_configure_window(conn, client->frame, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, &(client->rect.x)); @@ -230,12 +231,12 @@ void reposition_client(xcb_connection_t *conn, Client *client) { return; if (screen == NULL) { - LOG("Boundary checking disabled, no screen found for (%d, %d)\n", client->rect.x, client->rect.y); + DLOG("Boundary checking disabled, no screen found for (%d, %d)\n", client->rect.x, client->rect.y); return; } - LOG("Client is on workspace %p with screen %p\n", client->workspace, client->workspace->screen); - LOG("but screen at %d, %d is %p\n", client->rect.x, client->rect.y, screen); + DLOG("Client is on workspace %p with screen %p\n", client->workspace, client->workspace->screen); + DLOG("but screen at %d, %d is %p\n", client->rect.x, client->rect.y, screen); floating_assign_to_workspace(client, screen->current_workspace); } @@ -249,8 +250,8 @@ void reposition_client(xcb_connection_t *conn, Client *client) { void resize_client(xcb_connection_t *conn, Client *client) { i3Font *font = load_font(conn, config.font); - LOG("frame 0x%08x needs to be pushed to %dx%d\n", client->frame, client->rect.x, client->rect.y); - LOG("resizing client 0x%08x to %d x %d\n", client->frame, client->rect.width, client->rect.height); + DLOG("frame 0x%08x needs to be pushed to %dx%d\n", client->frame, client->rect.x, client->rect.y); + DLOG("resizing client 0x%08x to %d x %d\n", client->frame, client->rect.width, client->rect.height); xcb_configure_window(conn, client->frame, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | @@ -300,7 +301,7 @@ void resize_client(xcb_connection_t *conn, Client *client) { /* Obey the ratio, if any */ if (client->proportional_height != 0 && client->proportional_width != 0) { - LOG("proportional height = %d, width = %d\n", client->proportional_height, client->proportional_width); + DLOG("proportional height = %d, width = %d\n", client->proportional_height, client->proportional_width); double new_height = rect->height + 1; int new_width = rect->width; @@ -316,24 +317,24 @@ void resize_client(xcb_connection_t *conn, Client *client) { rect->height = new_height; rect->width = new_width; - LOG("new_height = %f, new_width = %d\n", new_height, new_width); + DLOG("new_height = %f, new_width = %d\n", new_height, new_width); } if (client->height_increment > 1) { int old_height = rect->height; rect->height -= (rect->height - client->base_height) % client->height_increment; - LOG("Lost %d pixel due to client's height_increment (%d px, base_height = %d)\n", + DLOG("Lost %d pixel due to client's height_increment (%d px, base_height = %d)\n", old_height - rect->height, client->height_increment, client->base_height); } if (client->width_increment > 1) { int old_width = rect->width; rect->width -= (rect->width - client->base_width) % client->width_increment; - LOG("Lost %d pixel due to client's width_increment (%d px, base_width = %d)\n", + DLOG("Lost %d pixel due to client's width_increment (%d px, base_width = %d)\n", old_width - rect->width, client->width_increment, client->base_width); } - LOG("child will be at %dx%d with size %dx%d\n", rect->x, rect->y, rect->width, rect->height); + DLOG("child will be at %dx%d with size %dx%d\n", rect->x, rect->y, rect->width, rect->height); xcb_configure_window(conn, client->child, mask, &(rect->x)); @@ -365,7 +366,7 @@ void render_container(xcb_connection_t *conn, Container *container) { if (container->mode == MODE_DEFAULT) { int height = (container->height / max(1, num_clients)); int rest_pixels = (container->height % max(1, num_clients)); - LOG("height per client = %d, rest = %d\n", height, rest_pixels); + DLOG("height per client = %d, rest = %d\n", height, rest_pixels); CIRCLEQ_FOREACH(client, &(container->clients), clients) { /* If the client is in fullscreen mode, it does not get reconfigured */ @@ -409,15 +410,15 @@ void render_container(xcb_connection_t *conn, Container *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() */ if (stack_win->rect.height == 0 && num_clients > 0) { - LOG("remapping stack win\n"); + DLOG("remapping stack win\n"); xcb_map_window(conn, stack_win->window); - } else LOG("not remapping stackwin, height = %d, num_clients = %d\n", + } else DLOG("not remapping stackwin, height = %d, num_clients = %d\n", stack_win->rect.height, num_clients); if (container->mode == MODE_TABBED) { /* By setting num_clients to 1 we force that the stack window will be only one line * high. The rest of the code is useful in both cases. */ - LOG("tabbed mode, setting num_clients = 1\n"); + DLOG("tabbed mode, setting num_clients = 1\n"); if (stack_lines > 1) stack_lines = 1; } @@ -530,7 +531,7 @@ void render_container(xcb_connection_t *conn, Container *container) { current_client++; } else if (container->mode == MODE_TABBED) { if (container->stack_limit == STACK_LIMIT_ROWS) { - LOG("You limited this container in its rows. " + LOG("You limited a tabbed container in its rows. " "This makes no sense in tabbing mode.\n"); } offset_x = current_client++ * size_each; @@ -571,7 +572,7 @@ void render_container(xcb_connection_t *conn, Container *container) { static void render_bars(xcb_connection_t *conn, Workspace *r_ws, int width, int *height) { Client *client; SLIST_FOREACH(client, &(r_ws->screen->dock_clients), dock_clients) { - LOG("client is at %d, should be at %d\n", client->rect.y, *height); + DLOG("client is at %d, should be at %d\n", client->rect.y, *height); if (client->force_reconfigure | update_if_necessary(&(client->rect.x), r_ws->rect.x) | update_if_necessary(&(client->rect.y), *height)) @@ -583,7 +584,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); + DLOG("desired_height = %d\n", client->desired_height); *height += client->desired_height; } } @@ -717,7 +718,7 @@ void render_workspace(xcb_connection_t *conn, i3Screen *screen, Workspace *r_ws) single_width = container->width; } - LOG("height is %d\n", height); + DLOG("height is %d\n", height); container->height = 0; diff --git a/src/mainx.c b/src/mainx.c index 0090d587..1706294c 100644 --- a/src/mainx.c +++ b/src/mainx.c @@ -124,7 +124,7 @@ static void xcb_check_cb(EV_P_ ev_check *w, int revents) { * */ static void xkb_got_event(EV_P_ struct ev_io *w, int revents) { - LOG("got xkb event, yay\n"); + DLOG("Handling XKB event\n"); XEvent ev; /* When using xmodmap, every change (!) gets an own event. * Therefore, we just read all events and only handle the @@ -139,9 +139,9 @@ static void xkb_got_event(EV_P_ struct ev_io *w, int revents) { xcb_get_numlock_mask(global_conn); ungrab_all_keys(global_conn); - LOG("Re-grabbing...\n"); + DLOG("Re-grabbing...\n"); grab_all_keys(global_conn); - LOG("Done\n"); + DLOG("Done\n"); } @@ -258,7 +258,7 @@ int main(int argc, char *argv[], char *env[]) { int evBase, errBase; if ((xkbdpy = XkbOpenDisplay(getenv("DISPLAY"), &evBase, &errBase, &major, &minor, &error)) == NULL) { - LOG("ERROR: XkbOpenDisplay() failed, disabling XKB support\n"); + ELOG("ERROR: XkbOpenDisplay() failed, disabling XKB support\n"); xkb_supported = false; } @@ -383,7 +383,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) { \ - LOG("Could not get atom " #name "\n"); \ + ELOG("Could not get atom " #name "\n"); \ exit(-1); \ } \ atoms[name] = reply->atom; \ @@ -453,7 +453,7 @@ int main(int argc, char *argv[], char *env[]) { } /* check for Xinerama */ - LOG("Checking for Xinerama...\n"); + DLOG("Checking for Xinerama...\n"); initialize_xinerama(conn); xcb_flush(conn); @@ -461,18 +461,18 @@ int main(int argc, char *argv[], char *env[]) { /* Get pointer position to see on which screen we’re starting */ xcb_query_pointer_reply_t *reply; if ((reply = xcb_query_pointer_reply(conn, xcb_query_pointer(conn, root), NULL)) == NULL) { - LOG("Could not get pointer position\n"); + ELOG("Could not get pointer position\n"); return 1; } i3Screen *screen = get_screen_containing(reply->root_x, reply->root_y); if (screen == NULL) { - LOG("ERROR: No screen at %d x %d, starting on the first screen\n", + ELOG("ERROR: No screen at %d x %d, starting on the first screen\n", reply->root_x, reply->root_y); screen = TAILQ_FIRST(virtual_screens); } - LOG("Starting on %d\n", screen->current_workspace); + DLOG("Starting on %d\n", screen->current_workspace); c_ws = screen->current_workspace; manage_existing_windows(conn, &prophs, root); @@ -481,7 +481,7 @@ int main(int argc, char *argv[], char *env[]) { if (config.ipc_socket_path != NULL) { int ipc_socket = ipc_create_socket(config.ipc_socket_path); if (ipc_socket == -1) { - LOG("Could not create the IPC socket, IPC disabled\n"); + ELOG("Could not create the IPC socket, IPC disabled\n"); } else { struct ev_io *ipc_io = scalloc(sizeof(struct ev_io)); ev_io_init(ipc_io, ipc_new_client, ipc_socket, EV_READ); diff --git a/src/manage.c b/src/manage.c index da5ec175..54e02fe4 100644 --- a/src/manage.c +++ b/src/manage.c @@ -30,6 +30,7 @@ #include "floating.h" #include "client.h" #include "workspace.h" +#include "log.h" /* * Go through all existing windows (if the window manager is restarted) and manage them @@ -78,7 +79,7 @@ void manage_window(xcb_property_handlers_t *prophs, xcb_connection_t *conn, /* Check if the window is mapped (it could be not mapped when intializing and calling manage_window() for every window) */ if ((attr = xcb_get_window_attributes_reply(conn, cookie, 0)) == NULL) { - LOG("Could not get attributes\n"); + ELOG("Could not get attributes\n"); return; } @@ -156,8 +157,8 @@ void reparent_window(xcb_connection_t *conn, xcb_window_t child, /* Events for already managed windows should already be filtered in manage_window() */ assert(new == NULL); - LOG("Reparenting window 0x%08x\n", child); - LOG("x = %d, y = %d, width = %d, height = %d\n", x, y, width, height); + LOG("Managing window 0x%08x\n", child); + DLOG("x = %d, y = %d, width = %d, height = %d\n", x, y, width, height); new = calloc(sizeof(Client), 1); new->force_reconfigure = true; @@ -220,7 +221,7 @@ void reparent_window(xcb_connection_t *conn, xcb_window_t child, new->awaiting_useless_unmap = true; xcb_void_cookie_t cookie = xcb_reparent_window_checked(conn, child, new->frame, 0, font->height); if (xcb_request_check(conn, cookie) != NULL) { - LOG("Could not reparent the window, aborting\n"); + DLOG("Could not reparent the window, aborting\n"); xcb_destroy_window(conn, new->frame); free(new); return; @@ -247,7 +248,7 @@ void reparent_window(xcb_connection_t *conn, xcb_window_t child, if (preply != NULL && preply->value_len > 0 && (atom = xcb_get_property_value(preply))) { for (int i = 0; i < xcb_get_property_value_length(preply); i++) if (atom[i] == atoms[_NET_WM_WINDOW_TYPE_DOCK]) { - LOG("Window is a dock.\n"); + DLOG("Window is a dock.\n"); new->dock = true; new->borderless = true; new->titlebar_position = TITLEBAR_OFF; @@ -263,19 +264,19 @@ void reparent_window(xcb_connection_t *conn, xcb_window_t child, atom[i] == atoms[_NET_WM_WINDOW_TYPE_SPLASH]) { /* Set the dialog window to automatically floating, will be used below */ new->floating = FLOATING_AUTO_ON; - LOG("dialog/utility/toolbar/splash window, automatically floating\n"); + DLOG("dialog/utility/toolbar/splash window, automatically floating\n"); } } /* All clients which have a leader should be floating */ if (!new->dock && !client_is_floating(new) && new->leader != 0) { - LOG("Client has WM_CLIENT_LEADER hint set, setting floating\n"); + DLOG("Client has WM_CLIENT_LEADER hint set, setting floating\n"); new->floating = FLOATING_AUTO_ON; } if (new->workspace->auto_float) { new->floating = FLOATING_AUTO_ON; - LOG("workspace is in autofloat mode, setting floating\n"); + DLOG("workspace is in autofloat mode, setting floating\n"); } if (new->dock) { @@ -289,12 +290,12 @@ void reparent_window(xcb_connection_t *conn, xcb_window_t child, TODO: bars at the top */ new->desired_height = strut[3]; if (new->desired_height == 0) { - LOG("Client wanted to be 0 pixels high, using the window's height (%d)\n", original_height); + DLOG("Client wanted to be 0 pixels high, using the window's height (%d)\n", original_height); new->desired_height = original_height; } - LOG("the client wants to be %d pixels high\n", new->desired_height); + DLOG("the client wants to be %d pixels high\n", new->desired_height); } else { - LOG("The client didn't specify space to reserve at the screen edge, using its height (%d)\n", original_height); + DLOG("The client didn't specify space to reserve at the screen edge, using its height (%d)\n", original_height); new->desired_height = original_height; } } else { @@ -333,11 +334,11 @@ void reparent_window(xcb_connection_t *conn, xcb_window_t child, assign->windowclass_title, assign->workspace); if (c_ws->screen->current_workspace->num == (assign->workspace-1)) { - LOG("We are already there, no need to do anything\n"); + DLOG("We are already there, no need to do anything\n"); break; } - LOG("Changing container/workspace and unmapping the client\n"); + DLOG("Changing container/workspace and unmapping the client\n"); Workspace *t_ws = workspace_get(assign->workspace-1); workspace_initialize(t_ws, c_ws->screen); @@ -351,7 +352,7 @@ void reparent_window(xcb_connection_t *conn, xcb_window_t child, } if (new->workspace->fullscreen_client != NULL) { - LOG("Setting below fullscreen window\n"); + DLOG("Setting below fullscreen window\n"); /* If we are in fullscreen, we should lower the window to not be annoying */ uint32_t values[] = { XCB_STACK_MODE_BELOW }; @@ -388,10 +389,10 @@ void reparent_window(xcb_connection_t *conn, xcb_window_t child, * to (0, 0), so we push them to a reasonable position * (centered over their leader) */ if (new->leader != 0 && x == 0 && y == 0) { - LOG("Floating client wants to (0x0), moving it over its leader instead\n"); + DLOG("Floating client wants to (0x0), moving it over its leader instead\n"); Client *leader = table_get(&by_child, new->leader); if (leader == NULL) { - LOG("leader is NULL, centering it over current workspace\n"); + DLOG("leader is NULL, centering it over current workspace\n"); x = c_ws->rect.x + (c_ws->rect.width / 2) - (new->rect.width / 2); y = c_ws->rect.y + (c_ws->rect.height / 2) - (new->rect.height / 2); @@ -402,10 +403,10 @@ void reparent_window(xcb_connection_t *conn, xcb_window_t child, } new->floating_rect.x = new->rect.x = x; new->floating_rect.y = new->rect.y = y; - LOG("copying floating_rect from tiling (%d, %d) size (%d, %d)\n", + DLOG("copying floating_rect from tiling (%d, %d) size (%d, %d)\n", new->floating_rect.x, new->floating_rect.y, new->floating_rect.width, new->floating_rect.height); - LOG("outer rect (%d, %d) size (%d, %d)\n", + DLOG("outer rect (%d, %d) size (%d, %d)\n", new->rect.x, new->rect.y, new->rect.width, new->rect.height); /* Make sure it is on top of the other windows */ diff --git a/src/resize.c b/src/resize.c index b9127f5b..db8e7442 100644 --- a/src/resize.c +++ b/src/resize.c @@ -28,6 +28,7 @@ #include "config.h" #include "floating.h" #include "workspace.h" +#include "log.h" /* * Renders the resize window between the first/second container and resizes @@ -39,7 +40,7 @@ int resize_graphical_handler(xcb_connection_t *conn, Workspace *ws, int first, i int new_position; i3Screen *screen = get_screen_containing(event->root_x, event->root_y); if (screen == NULL) { - LOG("BUG: No screen found at this position (%d, %d)\n", event->root_x, event->root_y); + ELOG("BUG: No screen found at this position (%d, %d)\n", event->root_x, event->root_y); return 1; } @@ -51,9 +52,9 @@ int resize_graphical_handler(xcb_connection_t *conn, Workspace *ws, int first, i i3Screen *most_right = get_screen_most(D_RIGHT, screen), *most_bottom = get_screen_most(D_DOWN, screen); - LOG("event->event_x = %d, event->root_x = %d\n", event->event_x, event->root_x); + DLOG("event->event_x = %d, event->root_x = %d\n", event->event_x, event->root_x); - LOG("Screen dimensions: (%d, %d) %d x %d\n", screen->rect.x, screen->rect.y, screen->rect.width, screen->rect.height); + DLOG("Screen dimensions: (%d, %d) %d x %d\n", screen->rect.x, screen->rect.y, screen->rect.width, screen->rect.height); uint32_t mask = 0; uint32_t values[2]; @@ -100,7 +101,7 @@ int resize_graphical_handler(xcb_connection_t *conn, Workspace *ws, int first, i xcb_flush(conn); void resize_callback(Rect *old_rect, uint32_t new_x, uint32_t new_y) { - LOG("new x = %d, y = %d\n", new_x, new_y); + DLOG("new x = %d, y = %d\n", new_x, new_y); if (orientation == O_VERTICAL) { /* Check if the new coordinates are within screen boundaries */ if (new_x > (screen->rect.x + screen->rect.width - 25) || @@ -163,8 +164,8 @@ void resize_container(xcb_connection_t *conn, Workspace *ws, int first, int seco if (ws->width_factor[second] == 0) new_unoccupied_x += default_width; - LOG("\n\n\n"); - LOG("old = %d, new = %d\n", old_unoccupied_x, new_unoccupied_x); + DLOG("\n\n\n"); + DLOG("old = %d, new = %d\n", old_unoccupied_x, new_unoccupied_x); int cols_without_wf = 0; int old_width, old_second_width; @@ -172,20 +173,20 @@ void resize_container(xcb_connection_t *conn, Workspace *ws, int first, int seco if (ws->width_factor[col] == 0) cols_without_wf++; - LOG("old_unoccupied_x = %d\n", old_unoccupied_x); + DLOG("old_unoccupied_x = %d\n", old_unoccupied_x); - LOG("Updating first (before = %f)\n", ws->width_factor[first]); + DLOG("Updating first (before = %f)\n", ws->width_factor[first]); /* Convert 0 (for default width_factor) to actual numbers */ if (ws->width_factor[first] == 0) old_width = (old_unoccupied_x / max(cols_without_wf, 1)); else old_width = ws->width_factor[first] * old_unoccupied_x; - LOG("second (before = %f)\n", ws->width_factor[second]); + DLOG("second (before = %f)\n", ws->width_factor[second]); if (ws->width_factor[second] == 0) old_second_width = (old_unoccupied_x / max(cols_without_wf, 1)); else old_second_width = ws->width_factor[second] * old_unoccupied_x; - LOG("middle = %f\n", ws->width_factor[first]); + DLOG("middle = %f\n", ws->width_factor[first]); /* If the space used for customly resized columns has changed we need to adapt the * other customly resized columns, if any */ @@ -194,33 +195,33 @@ void resize_container(xcb_connection_t *conn, Workspace *ws, int first, int seco if (ws->width_factor[col] == 0) continue; - LOG("Updating other column (%d) (current width_factor = %f)\n", col, ws->width_factor[col]); + DLOG("Updating other column (%d) (current width_factor = %f)\n", col, ws->width_factor[col]); ws->width_factor[col] = (ws->width_factor[col] * old_unoccupied_x) / new_unoccupied_x; - LOG("to %f\n", ws->width_factor[col]); + DLOG("to %f\n", ws->width_factor[col]); } - LOG("Updating first (before = %f)\n", ws->width_factor[first]); + DLOG("Updating first (before = %f)\n", ws->width_factor[first]); /* Convert 0 (for default width_factor) to actual numbers */ if (ws->width_factor[first] == 0) ws->width_factor[first] = ((float)ws->rect.width / ws->cols) / new_unoccupied_x; - LOG("first->width = %d, pixels = %d\n", old_width, pixels); + DLOG("first->width = %d, pixels = %d\n", old_width, pixels); ws->width_factor[first] *= (float)(old_width + pixels) / old_width; - LOG("-> %f\n", ws->width_factor[first]); + DLOG("-> %f\n", ws->width_factor[first]); - LOG("Updating second (before = %f)\n", ws->width_factor[second]); + DLOG("Updating second (before = %f)\n", ws->width_factor[second]); if (ws->width_factor[second] == 0) ws->width_factor[second] = ((float)ws->rect.width / ws->cols) / new_unoccupied_x; - LOG("middle = %f\n", ws->width_factor[second]); - LOG("second->width = %d, pixels = %d\n", old_second_width, pixels); + DLOG("middle = %f\n", ws->width_factor[second]); + DLOG("second->width = %d, pixels = %d\n", old_second_width, pixels); ws->width_factor[second] *= (float)(old_second_width - pixels) / old_second_width; - LOG("-> %f\n", ws->width_factor[second]); + DLOG("-> %f\n", ws->width_factor[second]); - LOG("new unoccupied_x = %d\n", get_unoccupied_x(ws)); + DLOG("new unoccupied_x = %d\n", get_unoccupied_x(ws)); - LOG("\n\n\n"); + DLOG("\n\n\n"); } else { int ws_height = workspace_height(ws); int default_height = ws_height / ws->rows; @@ -245,24 +246,24 @@ void resize_container(xcb_connection_t *conn, Workspace *ws, int first, int seco if (ws->height_factor[row] == 0) cols_without_hf++; - LOG("old_unoccupied_y = %d\n", old_unoccupied_y); + DLOG("old_unoccupied_y = %d\n", old_unoccupied_y); - LOG("Updating first (before = %f)\n", ws->height_factor[first]); + DLOG("Updating first (before = %f)\n", ws->height_factor[first]); /* Convert 0 (for default width_factor) to actual numbers */ if (ws->height_factor[first] == 0) old_height = (old_unoccupied_y / max(cols_without_hf, 1)); else old_height = ws->height_factor[first] * old_unoccupied_y; - LOG("second (before = %f)\n", ws->height_factor[second]); + DLOG("second (before = %f)\n", ws->height_factor[second]); if (ws->height_factor[second] == 0) old_second_height = (old_unoccupied_y / max(cols_without_hf, 1)); else old_second_height = ws->height_factor[second] * old_unoccupied_y; - LOG("middle = %f\n", ws->height_factor[first]); + DLOG("middle = %f\n", ws->height_factor[first]); - LOG("\n\n\n"); - LOG("old = %d, new = %d\n", old_unoccupied_y, new_unoccupied_y); + DLOG("\n\n\n"); + DLOG("old = %d, new = %d\n", old_unoccupied_y, new_unoccupied_y); /* If the space used for customly resized columns has changed we need to adapt the * other customly resized columns, if any */ @@ -271,33 +272,33 @@ void resize_container(xcb_connection_t *conn, Workspace *ws, int first, int seco if (ws->height_factor[row] == 0) continue; - LOG("Updating other column (%d) (current width_factor = %f)\n", row, ws->height_factor[row]); + DLOG("Updating other column (%d) (current width_factor = %f)\n", row, ws->height_factor[row]); ws->height_factor[row] = (ws->height_factor[row] * old_unoccupied_y) / new_unoccupied_y; - LOG("to %f\n", ws->height_factor[row]); + DLOG("to %f\n", ws->height_factor[row]); } - LOG("Updating first (before = %f)\n", ws->height_factor[first]); + DLOG("Updating first (before = %f)\n", ws->height_factor[first]); /* Convert 0 (for default width_factor) to actual numbers */ if (ws->height_factor[first] == 0) ws->height_factor[first] = ((float)ws_height / ws->rows) / new_unoccupied_y; - LOG("first->width = %d, pixels = %d\n", old_height, pixels); + DLOG("first->width = %d, pixels = %d\n", old_height, pixels); ws->height_factor[first] *= (float)(old_height + pixels) / old_height; - LOG("-> %f\n", ws->height_factor[first]); + DLOG("-> %f\n", ws->height_factor[first]); - LOG("Updating second (before = %f)\n", ws->height_factor[second]); + DLOG("Updating second (before = %f)\n", ws->height_factor[second]); if (ws->height_factor[second] == 0) ws->height_factor[second] = ((float)ws_height / ws->rows) / new_unoccupied_y; - LOG("middle = %f\n", ws->height_factor[second]); - LOG("second->width = %d, pixels = %d\n", old_second_height, pixels); + DLOG("middle = %f\n", ws->height_factor[second]); + DLOG("second->width = %d, pixels = %d\n", old_second_height, pixels); ws->height_factor[second] *= (float)(old_second_height - pixels) / old_second_height; - LOG("-> %f\n", ws->height_factor[second]); + DLOG("-> %f\n", ws->height_factor[second]); - LOG("new unoccupied_y = %d\n", get_unoccupied_y(ws)); + DLOG("new unoccupied_y = %d\n", get_unoccupied_y(ws)); - LOG("\n\n\n"); + DLOG("\n\n\n"); } render_layout(conn); diff --git a/src/table.c b/src/table.c index eebe8de0..8aa02fba 100644 --- a/src/table.c +++ b/src/table.c @@ -27,6 +27,7 @@ #include "layout.h" #include "config.h" #include "workspace.h" +#include "log.h" int current_workspace = 0; int num_workspaces = 1; @@ -96,9 +97,9 @@ void expand_table_rows_at_head(Workspace *workspace) { workspace->height_factor = realloc(workspace->height_factor, sizeof(float) * workspace->rows); - LOG("rows = %d\n", workspace->rows); + DLOG("rows = %d\n", workspace->rows); for (int rows = (workspace->rows - 1); rows >= 1; rows--) { - LOG("Moving height_factor %d (%f) to %d\n", rows-1, workspace->height_factor[rows-1], rows); + DLOG("Moving height_factor %d (%f) to %d\n", rows-1, workspace->height_factor[rows-1], rows); workspace->height_factor[rows] = workspace->height_factor[rows-1]; } @@ -110,7 +111,7 @@ void expand_table_rows_at_head(Workspace *workspace) { /* Move the other rows */ for (int cols = 0; cols < workspace->cols; cols++) for (int rows = workspace->rows - 1; rows > 0; rows--) { - LOG("Moving row %d to %d\n", rows-1, rows); + DLOG("Moving row %d to %d\n", rows-1, rows); workspace->table[cols][rows] = workspace->table[cols][rows-1]; workspace->table[cols][rows]->row = rows; } @@ -148,9 +149,9 @@ void expand_table_cols_at_head(Workspace *workspace) { workspace->width_factor = realloc(workspace->width_factor, sizeof(float) * workspace->cols); - LOG("cols = %d\n", workspace->cols); + DLOG("cols = %d\n", workspace->cols); for (int cols = (workspace->cols - 1); cols >= 1; cols--) { - LOG("Moving width_factor %d (%f) to %d\n", cols-1, workspace->width_factor[cols-1], cols); + DLOG("Moving width_factor %d (%f) to %d\n", cols-1, workspace->width_factor[cols-1], cols); workspace->width_factor[cols] = workspace->width_factor[cols-1]; } @@ -162,7 +163,7 @@ void expand_table_cols_at_head(Workspace *workspace) { /* Move the other columns */ for (int rows = 0; rows < workspace->rows; rows++) for (int cols = workspace->cols - 1; cols > 0; cols--) { - LOG("Moving col %d to %d\n", cols-1, cols); + DLOG("Moving col %d to %d\n", cols-1, cols); workspace->table[cols][rows] = workspace->table[cols-1][rows]; workspace->table[cols][rows]->col = cols; } @@ -201,7 +202,7 @@ static void shrink_table_cols(Workspace *workspace) { if (workspace->width_factor[cols] == 0) continue; - LOG("Added free space (%f) to %d (had %f)\n", free_space, cols, + DLOG("Added free space (%f) to %d (had %f)\n", free_space, cols, workspace->width_factor[cols]); workspace->width_factor[cols] += free_space; break; @@ -230,7 +231,7 @@ static void shrink_table_rows(Workspace *workspace) { if (workspace->height_factor[rows] == 0) continue; - LOG("Added free space (%f) to %d (had %f)\n", free_space, rows, + DLOG("Added free space (%f) to %d (had %f)\n", free_space, rows, workspace->height_factor[rows]); workspace->height_factor[rows] += free_space; break; @@ -256,7 +257,7 @@ static void free_container(xcb_connection_t *conn, Workspace *workspace, int col } static void move_columns_from(xcb_connection_t *conn, Workspace *workspace, int cols) { - LOG("firstly freeing \n"); + DLOG("firstly freeing \n"); /* Free the columns which are cleaned up */ for (int rows = 0; rows < workspace->rows; rows++) @@ -264,10 +265,10 @@ static void move_columns_from(xcb_connection_t *conn, Workspace *workspace, int for (; cols < workspace->cols; cols++) for (int rows = 0; rows < workspace->rows; rows++) { - LOG("at col = %d, row = %d\n", cols, rows); + DLOG("at col = %d, row = %d\n", cols, rows); Container *new_container = workspace->table[cols][rows]; - LOG("moving cols = %d to cols -1 = %d\n", cols, cols-1); + DLOG("moving cols = %d to cols -1 = %d\n", cols, cols-1); workspace->table[cols-1][rows] = new_container; new_container->row = rows; @@ -283,7 +284,7 @@ static void move_rows_from(xcb_connection_t *conn, Workspace *workspace, int row for (int cols = 0; cols < workspace->cols; cols++) { Container *new_container = workspace->table[cols][rows]; - LOG("moving rows = %d to rows -1 = %d\n", rows, rows - 1); + DLOG("moving rows = %d to rows -1 = %d\n", rows, rows - 1); workspace->table[cols][rows-1] = new_container; new_container->row = rows-1; @@ -296,19 +297,19 @@ static void move_rows_from(xcb_connection_t *conn, Workspace *workspace, int row * */ void dump_table(xcb_connection_t *conn, Workspace *workspace) { - LOG("dump_table()\n"); + DLOG("dump_table()\n"); FOR_TABLE(workspace) { Container *con = workspace->table[cols][rows]; - LOG("----\n"); - LOG("at col=%d, row=%d\n", cols, rows); - LOG("currently_focused = %p\n", con->currently_focused); + DLOG("----\n"); + DLOG("at col=%d, row=%d\n", cols, rows); + DLOG("currently_focused = %p\n", con->currently_focused); Client *loop; CIRCLEQ_FOREACH(loop, &(con->clients), clients) { - LOG("got client %08x / %s\n", loop->child, loop->name); + DLOG("got client %08x / %s\n", loop->child, loop->name); } - LOG("----\n"); + DLOG("----\n"); } - LOG("done\n"); + DLOG("done\n"); } /* @@ -316,7 +317,7 @@ void dump_table(xcb_connection_t *conn, Workspace *workspace) { * */ void cleanup_table(xcb_connection_t *conn, Workspace *workspace) { - LOG("cleanup_table()\n"); + DLOG("cleanup_table()\n"); /* Check for empty columns if we got more than one column */ for (int cols = 0; (workspace->cols > 1) && (cols < workspace->cols);) { @@ -327,7 +328,7 @@ void cleanup_table(xcb_connection_t *conn, Workspace *workspace) { break; } if (completely_empty) { - LOG("Removing completely empty column %d\n", cols); + DLOG("Removing completely empty column %d\n", cols); if (cols < (workspace->cols - 1)) move_columns_from(conn, workspace, cols+1); else { @@ -344,14 +345,14 @@ void cleanup_table(xcb_connection_t *conn, Workspace *workspace) { /* Check for empty rows if we got more than one row */ for (int rows = 0; (workspace->rows > 1) && (rows < workspace->rows);) { bool completely_empty = true; - LOG("Checking row %d\n", rows); + DLOG("Checking row %d\n", rows); for (int cols = 0; cols < workspace->cols; cols++) if (workspace->table[cols][rows]->currently_focused != NULL) { completely_empty = false; break; } if (completely_empty) { - LOG("Removing completely empty row %d\n", rows); + DLOG("Removing completely empty row %d\n", rows); if (rows < (workspace->rows - 1)) move_rows_from(conn, workspace, rows+1); else { @@ -381,25 +382,25 @@ void cleanup_table(xcb_connection_t *conn, Workspace *workspace) { * */ void fix_colrowspan(xcb_connection_t *conn, Workspace *workspace) { - LOG("Fixing col/rowspan\n"); + DLOG("Fixing col/rowspan\n"); FOR_TABLE(workspace) { Container *con = workspace->table[cols][rows]; if (con->colspan > 1) { - LOG("gots one with colspan %d (at %d c, %d r)\n", con->colspan, cols, rows); + DLOG("gots one with colspan %d (at %d c, %d r)\n", con->colspan, cols, rows); while (con->colspan > 1 && (!cell_exists(cols + (con->colspan-1), rows) || workspace->table[cols + (con->colspan - 1)][rows]->currently_focused != NULL)) con->colspan--; - LOG("fixed it to %d\n", con->colspan); + DLOG("fixed it to %d\n", con->colspan); } if (con->rowspan > 1) { - LOG("gots one with rowspan %d (at %d c, %d r)\n", con->rowspan, cols, rows); + DLOG("gots one with rowspan %d (at %d c, %d r)\n", con->rowspan, cols, rows); while (con->rowspan > 1 && (!cell_exists(cols, rows + (con->rowspan - 1)) || workspace->table[cols][rows + (con->rowspan - 1)]->currently_focused != NULL)) con->rowspan--; - LOG("fixed it to %d\n", con->rowspan); + DLOG("fixed it to %d\n", con->rowspan); } } } diff --git a/src/util.c b/src/util.c index f17bd6e1..47bcc8fd 100644 --- a/src/util.c +++ b/src/util.c @@ -31,6 +31,7 @@ #include "util.h" #include "xcb.h" #include "client.h" +#include "log.h" static iconv_t conversion_descriptor = 0; struct keyvalue_table_head by_parent = TAILQ_HEAD_INITIALIZER(by_parent); @@ -44,27 +45,6 @@ int max(int a, int b) { return (a > b ? a : b); } -/* - * Logs the given message to stdout while prefixing the current time to it. - * This is to be called by LOG() which includes filename/linenumber - * - */ -void slog(char *fmt, ...) { - va_list args; - char timebuf[64]; - - va_start(args, fmt); - /* Get current time */ - time_t t = time(NULL); - /* Convert time to local time (determined by the locale) */ - struct tm *tmp = localtime(&t); - /* Generate time prefix */ - strftime(timebuf, sizeof(timebuf), "%x %X - ", tmp); - printf("%s", timebuf); - vprintf(fmt, args); - va_end(args); -} - /* * The s* functions (safe) are wrappers around malloc, strdup, …, which exits if one of * the called functions returns NULL, meaning that there is no more memory available @@ -280,7 +260,7 @@ void set_focus(xcb_connection_t *conn, Client *client, bool set_anyways) { Client *last_focused = get_last_focused_client(conn, client->container, client); if (last_focused != NULL) { - LOG("raising above frame %p / child %p\n", last_focused->frame, last_focused->child); + DLOG("raising above frame %p / child %p\n", last_focused->frame, last_focused->child); uint32_t values[] = { last_focused->frame, XCB_STACK_MODE_ABOVE }; xcb_configure_window(conn, client->frame, XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE, values); } @@ -294,13 +274,13 @@ void set_focus(xcb_connection_t *conn, Client *client, bool set_anyways) { /* If the last client was a floating client, we need to go to the next * tiling client in stack and re-decorate it. */ if (old_client != NULL && client_is_floating(old_client)) { - LOG("Coming from floating client, searching next tiling...\n"); + DLOG("Coming from floating client, searching next tiling...\n"); Client *current; SLIST_FOREACH(current, &(client->workspace->focus_stack), focus_clients) { if (client_is_floating(current)) continue; - LOG("Found window: %p / child %p\n", current->frame, current->child); + DLOG("Found window: %p / child %p\n", current->frame, current->child); redecorate_window(conn, current); break; } @@ -411,14 +391,14 @@ after_stackwin: if (client == container->currently_focused || client == last_focused) continue; - LOG("setting %08x below %08x / %08x\n", client->frame, container->currently_focused->frame); + DLOG("setting %08x below %08x / %08x\n", client->frame, container->currently_focused->frame); uint32_t values[] = { container->currently_focused->frame, XCB_STACK_MODE_BELOW }; xcb_configure_window(conn, client->frame, XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE, values); } if (last_focused != NULL) { - LOG("Putting last_focused directly underneath the currently focused\n"); + DLOG("Putting last_focused directly underneath the currently focused\n"); uint32_t values[] = { container->currently_focused->frame, XCB_STACK_MODE_BELOW }; xcb_configure_window(conn, last_focused->frame, XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE, values); @@ -457,7 +437,7 @@ Client *get_matching_client(xcb_connection_t *conn, const char *window_classtitl goto done; } - LOG("Getting clients for class \"%s\" / title \"%s\"\n", to_class, to_title); + DLOG("Getting clients for class \"%s\" / title \"%s\"\n", to_class, to_title); Workspace *ws; TAILQ_FOREACH(ws, workspaces, workspaces) { if (ws->screen == NULL) @@ -465,7 +445,7 @@ Client *get_matching_client(xcb_connection_t *conn, const char *window_classtitl Client *client; SLIST_FOREACH(client, &(ws->focus_stack), focus_clients) { - LOG("Checking client with class=%s, name=%s\n", client->window_class, client->name); + DLOG("Checking client with class=%s, name=%s\n", client->window_class, client->name); if (!client_matches_class_name(client, to_class, to_title, to_title_ucs, to_title_ucs_len)) continue; diff --git a/src/workspace.c b/src/workspace.c index 774b7c41..bca0544c 100644 --- a/src/workspace.c +++ b/src/workspace.c @@ -26,6 +26,7 @@ #include "layout.h" #include "workspace.h" #include "client.h" +#include "log.h" /* * Returns a pointer to the workspace with the given number (starting at 0), @@ -42,10 +43,10 @@ Workspace *workspace_get(int number) { /* If we are still there, we could not find the requested workspace. */ int last_ws = TAILQ_LAST(workspaces, workspaces_head)->num; - LOG("We need to initialize that one, last ws = %d\n", last_ws); + DLOG("We need to initialize that one, last ws = %d\n", last_ws); for (int c = last_ws; c < number; c++) { - LOG("Creating new ws\n"); + DLOG("Creating new ws\n"); ws = scalloc(sizeof(Workspace)); ws->num = c+1; @@ -56,7 +57,7 @@ Workspace *workspace_get(int number) { TAILQ_INSERT_TAIL(workspaces, ws, workspaces); } - LOG("done\n"); + DLOG("done\n"); return ws; } @@ -109,7 +110,7 @@ void workspace_show(xcb_connection_t *conn, int workspace) { /* t_ws (to workspace) is just a convenience pointer to the workspace we’re switching to */ Workspace *t_ws = workspace_get(workspace-1); - LOG("show_workspace(%d)\n", workspace); + DLOG("show_workspace(%d)\n", workspace); /* Store current_row/current_col */ c_ws->current_row = current_row; @@ -120,7 +121,7 @@ void workspace_show(xcb_connection_t *conn, int workspace) { if (c_ws->screen != t_ws->screen) { /* We need to switch to the other screen first */ - LOG("moving over to other screen.\n"); + DLOG("moving over to other screen.\n"); /* Store the old client */ Client *old_client = CUR_CELL->currently_focused; @@ -163,7 +164,7 @@ void workspace_show(xcb_connection_t *conn, int workspace) { current_row = c_ws->current_row; current_col = c_ws->current_col; - LOG("new current row = %d, current col = %d\n", current_row, current_col); + DLOG("new current row = %d, current col = %d\n", current_row, current_col); workspace_map_clients(conn, c_ws); @@ -206,7 +207,7 @@ static i3Screen *get_screen_from_preference(struct screens_head *slist, char *pr char *rest; int preferred_screen = strtol(preference, &rest, 10); - LOG("Getting screen for preference \"%s\" (%d)\n", preference, preferred_screen); + DLOG("Getting screen for preference \"%s\" (%d)\n", preference, preferred_screen); if ((rest == preference) || (preferred_screen >= num_screens)) { int x = INT_MAX, y = INT_MAX; @@ -222,16 +223,16 @@ static i3Screen *get_screen_from_preference(struct screens_head *slist, char *pr x = atoi(preference); } - LOG("Looking for screen at %d x %d\n", x, y); + DLOG("Looking for screen at %d x %d\n", x, y); TAILQ_FOREACH(screen, slist, screens) if ((x == INT_MAX || screen->rect.x == x) && (y == INT_MAX || screen->rect.y == y)) { - LOG("found %p\n", screen); + DLOG("found %p\n", screen); return screen; } - LOG("none found\n"); + DLOG("none found\n"); return NULL; } else { int c = 0; @@ -252,7 +253,7 @@ static i3Screen *get_screen_from_preference(struct screens_head *slist, char *pr */ void workspace_initialize(Workspace *ws, i3Screen *screen) { if (ws->screen != NULL) { - LOG("Workspace already initialized\n"); + DLOG("Workspace already initialized\n"); return; } @@ -298,7 +299,7 @@ Workspace *get_first_workspace_for_screen(struct screens_head *slist, i3Screen * } if (result == NULL) { - LOG("No existing free workspace found to assign, creating a new one\n"); + DLOG("No existing free workspace found to assign, creating a new one\n"); Workspace *ws; int last_ws = 0; @@ -359,7 +360,7 @@ void workspace_unmap_clients(xcb_connection_t *conn, Workspace *u_ws) { int unmapped_clients = 0; FOR_TABLE(u_ws) CIRCLEQ_FOREACH(client, &(u_ws->table[cols][rows]->clients), clients) { - LOG("unmapping normal client %p / %p / %p\n", client, client->frame, client->child); + DLOG("unmapping normal client %p / %p / %p\n", client, client->frame, client->child); client_unmap(conn, client); unmapped_clients++; } @@ -369,7 +370,7 @@ void workspace_unmap_clients(xcb_connection_t *conn, Workspace *u_ws) { if (!client_is_floating(client)) continue; - LOG("unmapping floating client %p / %p / %p\n", client, client->frame, client->child); + DLOG("unmapping floating client %p / %p / %p\n", client, client->frame, client->child); client_unmap(conn, client); unmapped_clients++; @@ -380,12 +381,12 @@ void workspace_unmap_clients(xcb_connection_t *conn, Workspace *u_ws) { if (unmapped_clients == 0 && u_ws != c_ws) { /* Re-assign the workspace of all dock clients which use this workspace */ Client *dock; - LOG("workspace %p is empty\n", u_ws); + DLOG("workspace %p is empty\n", u_ws); SLIST_FOREACH(dock, &(u_ws->screen->dock_clients), dock_clients) { if (dock->workspace != u_ws) continue; - LOG("Re-assigning dock client to c_ws (%p)\n", c_ws); + DLOG("Re-assigning dock client to c_ws (%p)\n", c_ws); dock->workspace = c_ws; } u_ws->screen = NULL; diff --git a/src/xcb.c b/src/xcb.c index a2f813b0..07286d0f 100644 --- a/src/xcb.c +++ b/src/xcb.c @@ -21,6 +21,7 @@ #include "i3.h" #include "util.h" #include "xcb.h" +#include "log.h" TAILQ_HEAD(cached_fonts_head, Font) cached_fonts = TAILQ_HEAD_INITIALIZER(cached_fonts); unsigned int xcb_numlock_mask; @@ -270,7 +271,7 @@ void xcb_raise_window(xcb_connection_t *conn, xcb_window_t window) { * */ void cached_pixmap_prepare(xcb_connection_t *conn, struct Cached_Pixmap *pixmap) { - LOG("preparing pixmap\n"); + DLOG("preparing pixmap\n"); /* If the Rect did not change, the pixmap does not need to be recreated */ if (memcmp(&(pixmap->rect), pixmap->referred_rect, sizeof(Rect)) == 0) @@ -279,11 +280,11 @@ void cached_pixmap_prepare(xcb_connection_t *conn, struct Cached_Pixmap *pixmap) memcpy(&(pixmap->rect), pixmap->referred_rect, sizeof(Rect)); if (pixmap->id == 0 || pixmap->gc == 0) { - LOG("Creating new pixmap...\n"); + DLOG("Creating new pixmap...\n"); pixmap->id = xcb_generate_id(conn); pixmap->gc = xcb_generate_id(conn); } else { - LOG("Re-creating this pixmap...\n"); + DLOG("Re-creating this pixmap...\n"); xcb_free_gc(conn, pixmap->gc); xcb_free_pixmap(conn, pixmap->id); } diff --git a/src/xinerama.c b/src/xinerama.c index fcc3a44b..79483c66 100644 --- a/src/xinerama.c +++ b/src/xinerama.c @@ -29,6 +29,7 @@ #include "xcb.h" #include "config.h" #include "workspace.h" +#include "log.h" /* This TAILQ of i3Screens stores the virtual screens, used for handling overlapping screens * (xrandr --same-as) */ @@ -75,7 +76,7 @@ i3Screen *get_screen_at(int x, int y, struct screens_head *screenlist) { i3Screen *get_screen_containing(int x, int y) { i3Screen *screen; TAILQ_FOREACH(screen, virtual_screens, screens) { - LOG("comparing x=%d y=%d with x=%d and y=%d width %d height %d\n", + DLOG("comparing x=%d y=%d with x=%d and y=%d width %d height %d\n", x, y, screen->rect.x, screen->rect.y, screen->rect.width, screen->rect.height); if (x >= screen->rect.x && x < (screen->rect.x + screen->rect.width) && y >= screen->rect.y && y < (screen->rect.y + screen->rect.height)) @@ -149,7 +150,7 @@ static void initialize_screen(xcb_connection_t *conn, i3Screen *screen, Workspac SLIST_INIT(&(screen->dock_clients)); - LOG("that is virtual screen at %d x %d with %d x %d\n", + DLOG("that is virtual screen at %d x %d with %d x %d\n", screen->rect.x, screen->rect.y, screen->rect.width, screen->rect.height); } @@ -192,7 +193,7 @@ static void query_screens(xcb_connection_t *conn, struct screens_head *screenlis while ((time(NULL) - before_trying) < 10) { reply = xcb_xinerama_query_screens_reply(conn, xcb_xinerama_query_screens_unchecked(conn), NULL); if (!reply) { - LOG("Couldn't get Xinerama screens\n"); + DLOG("Couldn't get Xinerama screens\n"); return; } screen_info = xcb_xinerama_query_screens_screen_info(reply); @@ -219,7 +220,7 @@ static void query_screens(xcb_connection_t *conn, struct screens_head *screenlis num_screens++; } - LOG("found Xinerama screen: %d x %d at %d x %d\n", + DLOG("found Xinerama screen: %d x %d at %d x %d\n", screen_info[screen].width, screen_info[screen].height, screen_info[screen].x_org, screen_info[screen].y_org); } @@ -227,7 +228,7 @@ static void query_screens(xcb_connection_t *conn, struct screens_head *screenlis free(reply); if (num_screens == 0) { - LOG("No screens found. This is weird. Trying again...\n"); + DLOG("No screens found. This is weird. Trying again...\n"); /* Give the scheduler a chance to do something else * and don’t hog the CPU */ usleep(250); @@ -238,7 +239,7 @@ static void query_screens(xcb_connection_t *conn, struct screens_head *screenlis } if (num_screens == 0) { - LOG("No screens found for 10 seconds. Please fix your setup. i3 will exit now.\n"); + DLOG("No screens found for 10 seconds. Please fix your setup. i3 will exit now.\n"); exit(0); } } @@ -253,14 +254,14 @@ void initialize_xinerama(xcb_connection_t *conn) { TAILQ_INIT(virtual_screens); if (!xcb_get_extension_data(conn, &xcb_xinerama_id)->present) { - LOG("Xinerama extension not found, disabling.\n"); + DLOG("Xinerama extension not found, disabling.\n"); disable_xinerama(conn); } else { xcb_xinerama_is_active_reply_t *reply; reply = xcb_xinerama_is_active_reply(conn, xcb_xinerama_is_active(conn), NULL); if (reply == NULL || !reply->state) { - LOG("Xinerama is not active (in your X-Server), disabling.\n"); + DLOG("Xinerama is not active (in your X-Server), disabling.\n"); disable_xinerama(conn); } else query_screens(conn, virtual_screens); @@ -291,7 +292,7 @@ void xinerama_requery_screens(xcb_connection_t *conn) { it change when I move the --right-of video projector to --left-of? */ if (!xinerama_enabled) { - LOG("Xinerama is disabled\n"); + DLOG("Xinerama is disabled\n"); return; } @@ -319,21 +320,21 @@ void xinerama_requery_screens(xcb_connection_t *conn) { if (old_screen->num != screen_count) continue; - LOG("Found a matching screen\n"); + DLOG("Found a matching screen\n"); /* Use the same workspace */ screen->current_workspace = old_screen->current_workspace; /* Re-use the old bar window */ screen->bar = old_screen->bar; screen->bargc = old_screen->bargc; - LOG("old_screen->bar = %p\n", old_screen->bar); + DLOG("old_screen->bar = %p\n", old_screen->bar); Rect bar_rect = {screen->rect.x, screen->rect.y + screen->rect.height - (font->height + 6), screen->rect.x + screen->rect.width, font->height + 6}; - LOG("configuring bar to be at %d x %d with %d x %d\n", + DLOG("configuring bar to be at %d x %d with %d x %d\n", bar_rect.x, bar_rect.y, bar_rect.height, bar_rect.width); xcb_configure_window(conn, screen->bar, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | @@ -350,7 +351,7 @@ void xinerama_requery_screens(xcb_connection_t *conn) { if (ws->screen != old_screen) continue; - LOG("re-assigning ws %d\n", ws->num); + DLOG("re-assigning ws %d\n", ws->num); memcpy(&(ws->rect), &(screen->rect), sizeof(Rect)); ws->screen = screen; ws->reassigned = true; @@ -362,7 +363,7 @@ void xinerama_requery_screens(xcb_connection_t *conn) { /* Find the first unused workspace, preferring the ones * which are assigned to this screen and initialize * the screen with it. */ - LOG("getting first ws for screen %p\n", screen); + DLOG("getting first ws for screen %p\n", screen); Workspace *ws = get_first_workspace_for_screen(new_screens, screen); initialize_screen(conn, screen, ws); ws->reassigned = true; @@ -379,7 +380,7 @@ void xinerama_requery_screens(xcb_connection_t *conn) { if (SLIST_EMPTY(&(old_screen->dock_clients))) continue; - LOG("dock_clients out of bounds at screen %p, reassigning\n", old_screen); + DLOG("dock_clients out of bounds at screen %p, reassigning\n", old_screen); if (SLIST_EMPTY(&(first->dock_clients))) { first->dock_clients = old_screen->dock_clients; continue; @@ -402,10 +403,10 @@ void xinerama_requery_screens(xcb_connection_t *conn) { Client *client; - LOG("Closing bar window (%p)\n", ws->screen->bar); + DLOG("Closing bar window (%p)\n", ws->screen->bar); xcb_destroy_window(conn, ws->screen->bar); - LOG("Workspace %d's screen out of bounds, assigning to first screen\n", ws->num + 1); + DLOG("Workspace %d's screen out of bounds, assigning to first screen\n", ws->num + 1); ws->screen = first; memcpy(&(ws->rect), &(first->rect), sizeof(Rect)); @@ -424,7 +425,7 @@ void xinerama_requery_screens(xcb_connection_t *conn) { workspace_unmap_clients(conn, ws); if (c_ws == ws) { - LOG("Need to adjust c_ws...\n"); + DLOG("Need to adjust c_ws...\n"); c_ws = first->current_workspace; } } @@ -440,7 +441,7 @@ void xinerama_requery_screens(xcb_connection_t *conn) { virtual_screens = new_screens; - LOG("Current workspace is now: %d\n", first->current_workspace); + DLOG("Current workspace is now: %d\n", first->current_workspace); render_layout(conn); }