From: Axel Wagner Date: Fri, 17 Sep 2010 03:26:31 +0000 (+0200) Subject: Add some more comments X-Git-Tag: 4.0.1~7^2~58 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=93453c64f2db520416e381f2fb64cc0ca58fce79;p=i3%2Fi3 Add some more comments --- diff --git a/i3bar/src/child.c b/i3bar/src/child.c index 1ed429c0..f57da9e1 100644 --- a/i3bar/src/child.c +++ b/i3bar/src/child.c @@ -114,6 +114,7 @@ void start_child(char *command) { printf("ERROR: Couldn't fork()"); exit(EXIT_FAILURE); case 0: + /* Child-process. Reroute stdout and start shell */ close(fd[0]); dup2(fd[1], STDOUT_FILENO); @@ -126,6 +127,7 @@ void start_child(char *command) { execl(shell, shell, "-c", command, (char*) NULL); return; default: + /* Parent-process. Rerout stdin */ close(fd[1]); dup2(fd[0], STDIN_FILENO); @@ -134,6 +136,7 @@ void start_child(char *command) { } } + /* We set O_NONBLOCK because blocking is evil in event-driven software */ fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK); stdin_io = malloc(sizeof(ev_io)); diff --git a/i3bar/src/ipc.c b/i3bar/src/ipc.c index 59563636..da9378f5 100644 --- a/i3bar/src/ipc.c +++ b/i3bar/src/ipc.c @@ -51,7 +51,7 @@ int get_ipc_fd(const char *socket_path) { * */ void got_command_reply(char *reply) { - /* FIXME: Error handling for command-replies */ + /* TODO: Error handling for command-replies */ } /* @@ -71,7 +71,7 @@ void got_workspace_reply(char *reply) { */ void got_subscribe_reply(char *reply) { printf("Got Subscribe Reply: %s\n", reply); - /* FIXME: Error handling for subscribe-commands */ + /* TODO: Error handling for subscribe-commands */ } /* @@ -134,6 +134,8 @@ void got_data(struct ev_loop *loop, ev_io *watcher, int events) { exit(EXIT_FAILURE); } + /* We first parse the fixed-length IPC-header, to know, how much data + * we have to expect */ uint32_t rec = 0; while (rec < header_len) { int n = read(fd, header + rec, header_len - rec); @@ -156,11 +158,13 @@ void got_data(struct ev_loop *loop, ev_io *watcher, int events) { exit(EXIT_FAILURE); } - /* Know we read the rest of the message */ char *walk = header + strlen(I3_IPC_MAGIC); uint32_t size = *((uint32_t*) walk); walk += sizeof(uint32_t); uint32_t type = *((uint32_t*) walk); + + /* Now that we know, what to expect, we can start read()ing the rest + * of the message */ char *buffer = malloc(size + 1); if (buffer == NULL) { printf("ERROR: Could not allocate memory!\n"); @@ -205,7 +209,11 @@ int i3_send_msg(uint32_t type, const char *payload) { len = strlen(payload); } + /* We are a wellbehaved client and send a proper header first */ uint32_t to_write = strlen (I3_IPC_MAGIC) + sizeof(uint32_t)*2 + len; + /* TODO: I'm not entirely sure if this buffer really has to contain more + * than the pure header (why not just write() the payload from *payload?), + * but we leave it for now */ char *buffer = malloc(to_write); if (buffer == NULL) { printf("ERROR: Could not allocate memory\n"); diff --git a/i3bar/src/main.c b/i3bar/src/main.c index 07dcf5b9..118c2947 100644 --- a/i3bar/src/main.c +++ b/i3bar/src/main.c @@ -18,7 +18,10 @@ #include "common.h" - +/* + * Glob path, i.e. expand ~ + * + */ char *expand_path(char *path) { static glob_t globbuf; if (glob(path, GLOB_NOCHECK | GLOB_TILDE, NULL, &globbuf) < 0) { @@ -92,6 +95,9 @@ int main(int argc, char **argv) { } if (fontname == NULL) { + /* This is a very restrictive default. More sensefull would be something like + * "-misc-*-*-*-*--*-*-*-*-*-*-*-*". But since that produces very ugly results + * on my machine, let's stick with this until we have a configfile */ fontname = "-misc-fixed-medium-r-semicondensed--12-110-75-75-c-60-iso10646-1"; } @@ -108,13 +114,21 @@ int main(int argc, char **argv) { FREE(socket_path); + /* We subscribe to the i3-events we need */ subscribe_events(); + /* We initiate the main-function by requesting infos about the outputs and + * workspaces. Everything else (creating the bars, showing the right workspace- + * buttons and more) is taken care of by the event-driveniness of the code */ i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_OUTPUTS, NULL); i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_WORKSPACES, NULL); + /* The name of this function is actually misleading. Even if no -c is specified, + * this function initiates the watchers to listen on stdin and react accordingly */ start_child(command); + /* From here on everything should run smooth for itself, just start listening for + * events. We stop simply stop the event-loop, when we are finished */ ev_loop(main_loop, 0); kill_child(); diff --git a/i3bar/src/xcb.c b/i3bar/src/xcb.c index f4f064a1..4939d6ab 100644 --- a/i3bar/src/xcb.c +++ b/i3bar/src/xcb.c @@ -441,6 +441,9 @@ void init_xcb(char *fontname) { query_font_cookie = xcb_query_font(xcb_connection, xcb_font); + /* To grab modifiers without blocking other applications from receiving key-events + * involving that modifier, we sadly have to use xkb which is not yet fully supported + * in xcb */ if (config.hide_on_modifier) { int xkb_major, xkb_minor, xkb_errbase, xkb_err; xkb_major = XkbMajorVersion; @@ -494,6 +497,8 @@ void init_xcb(char *fontname) { mask, vals); + /* We only generate an id for the pixmap, because the width of it is dependent on the + * input we get */ statusline_pm = xcb_generate_id(xcb_connection); /* The varios Watchers to communicate with xcb */ @@ -512,7 +517,7 @@ void init_xcb(char *fontname) { /* Now we get the atoms and save them in a nice data-structure */ get_atoms(); - /* Now we calculate the font-height */ + /* Now we save the font-infos */ font_info = xcb_query_font_reply(xcb_connection, query_font_cookie, &err); @@ -637,6 +642,7 @@ void reconfig_windows() { mask, values); + /* The double-buffer we use to render stuff off-screen */ xcb_void_cookie_t pm_cookie = xcb_create_pixmap_checked(xcb_connection, xcb_screens->root_depth, walk->buffer, @@ -644,7 +650,8 @@ void reconfig_windows() { walk->rect.w, walk->rect.h); - /* We want dock-windows (for now) */ + /* We want dock-windows (for now). When override_redirect is set, i3 is ignoring + * this one */ xcb_void_cookie_t prop_cookie = xcb_change_property(xcb_connection, XCB_PROP_MODE_REPLACE, walk->bar, @@ -653,7 +660,9 @@ void reconfig_windows() { 32, 1, (unsigned char*) &atoms[_NET_WM_WINDOW_TYPE_DOCK]); - /* We also want a graphics-context (the "canvas" on which we draw) */ + + /* We also want a graphics-context for the bars (it defines the properties + * with which we draw to them) */ walk->bargc = xcb_generate_id(xcb_connection); mask = XCB_GC_FONT; values[0] = xcb_font; @@ -733,8 +742,10 @@ void draw_bars() { continue; } if (outputs_walk->bar == XCB_NONE) { + /* Oh shit, an active output without an own bar. Create it now! */ reconfig_windows(); } + /* First things first: clear the backbuffer */ uint32_t color = get_colorpixel("000000"); xcb_change_gc(xcb_connection, outputs_walk->bargc, @@ -746,9 +757,13 @@ void draw_bars() { outputs_walk->bargc, 1, &rect); + if (statusline != NULL) { printf("Printing statusline!\n"); + /* Luckily we already prepared a seperate pixmap containing the rendered + * statusline, we just have to copy the relevant parts to the relevant + * position */ xcb_copy_area(xcb_connection, statusline_pm, outputs_walk->buffer,