From: Axel Wagner Date: Tue, 3 Aug 2010 19:20:11 +0000 (+0200) Subject: Change the indention-style X-Git-Tag: 4.0.1~7^2~97 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=8595d3bb48e75d2072a2023f92d8c182a085a59c;p=i3%2Fi3 Change the indention-style --- diff --git a/i3bar/include/outputs.h b/i3bar/include/outputs.h index 50862bd5..1c6abe3a 100644 --- a/i3bar/include/outputs.h +++ b/i3bar/include/outputs.h @@ -11,9 +11,9 @@ typedef struct i3_output i3_output; SLIST_HEAD(outputs_head, i3_output); struct outputs_head *outputs; -void parse_outputs_json(char* json); -void free_outputs(); -i3_output* get_output_by_name(char* name); +void parse_outputs_json(char* json); +void free_outputs(); +i3_output* get_output_by_name(char* name); struct i3_output { char* name; diff --git a/i3bar/include/util.h b/i3bar/include/util.h index a3fe76d9..08bdc335 100644 --- a/i3bar/include/util.h +++ b/i3bar/include/util.h @@ -5,30 +5,30 @@ /* Securely free p */ #define FREE(p) do { \ - if (p != NULL) { \ - free(p); \ - p = NULL; \ - } \ + if (p != NULL) { \ + free(p); \ + p = NULL; \ + } \ } while (0) /* Securely fee single-linked list */ #define FREE_SLIST(l, type) do { \ - type *walk = SLIST_FIRST(l); \ - while (!SLIST_EMPTY(l)) { \ - SLIST_REMOVE_HEAD(l, slist); \ - FREE(walk); \ - walk = SLIST_FIRST(l); \ - } \ + type *walk = SLIST_FIRST(l); \ + while (!SLIST_EMPTY(l)) { \ + SLIST_REMOVE_HEAD(l, slist); \ + FREE(walk); \ + walk = SLIST_FIRST(l); \ + } \ } while (0) #endif /* Securely fee tail-queues */ #define FREE_TAILQ(l, type) do { \ - type *walk = TAILQ_FIRST(l); \ - while (!TAILQ_EMPTY(l)) { \ - TAILQ_REMOVE(l, TAILQ_FIRST(l), tailq); \ - FREE(walk); \ - walk = TAILQ_FIRST(l); \ - } \ + type *walk = TAILQ_FIRST(l); \ + while (!TAILQ_EMPTY(l)) { \ + TAILQ_REMOVE(l, TAILQ_FIRST(l), tailq); \ + FREE(walk); \ + walk = TAILQ_FIRST(l); \ + } \ } while (0) diff --git a/i3bar/include/workspaces.h b/i3bar/include/workspaces.h index 56e36627..64c1065e 100644 --- a/i3bar/include/workspaces.h +++ b/i3bar/include/workspaces.h @@ -12,16 +12,16 @@ void parse_workspaces_json(); void free_workspaces(); struct i3_ws { - int num; - char *name; - int name_width; - bool visible; - bool focused; - bool urgent; - rect rect; - struct i3_output *output; + int num; + char *name; + int name_width; + bool visible; + bool focused; + bool urgent; + rect rect; + struct i3_output *output; - TAILQ_ENTRY(i3_ws) tailq; + TAILQ_ENTRY(i3_ws) tailq; }; #endif diff --git a/i3bar/include/xcb.h b/i3bar/include/xcb.h index 24cba56e..230ff6e6 100644 --- a/i3bar/include/xcb.h +++ b/i3bar/include/xcb.h @@ -12,11 +12,11 @@ enum { xcb_atom_t atoms[NUM_ATOMS]; -xcb_connection_t* xcb_connection; -xcb_screen_t* xcb_screens; -xcb_window_t xcb_root; -xcb_font_t xcb_font; -int font_height; +xcb_connection_t *xcb_connection; +xcb_screen_t *xcb_screens; +xcb_window_t xcb_root; +xcb_font_t xcb_font; +int font_height; void init_xcb(); void clean_xcb(); diff --git a/i3bar/src/ipc.c b/i3bar/src/ipc.c index 46c1e8ca..1553fc20 100644 --- a/i3bar/src/ipc.c +++ b/i3bar/src/ipc.c @@ -12,193 +12,193 @@ #include "xcb.h" #include "ipc.h" -ev_io* i3_connection; +ev_io *i3_connection; typedef void(*handler_t)(char*); -int get_ipc_fd(const char* socket_path) { - int sockfd = socket(AF_LOCAL, SOCK_STREAM, 0); - if (sockfd == -1) { - printf("ERROR: Could not create Socket!\n"); - exit(EXIT_FAILURE); - } - - struct sockaddr_un addr; - memset(&addr, 0, sizeof(struct sockaddr_un)); - addr.sun_family = AF_LOCAL; - strcpy(addr.sun_path, socket_path); - if (connect(sockfd, (const struct sockaddr*) &addr, sizeof(struct sockaddr_un)) < 0) { - printf("ERROR: Could not connct to i3\n"); - exit(EXIT_FAILURE); - } - return sockfd; +int get_ipc_fd(const char *socket_path) { + int sockfd = socket(AF_LOCAL, SOCK_STREAM, 0); + if (sockfd == -1) { + printf("ERROR: Could not create Socket!\n"); + exit(EXIT_FAILURE); + } + + struct sockaddr_un addr; + memset(&addr, 0, sizeof(struct sockaddr_un)); + addr.sun_family = AF_LOCAL; + strcpy(addr.sun_path, socket_path); + if (connect(sockfd, (const struct sockaddr*) &addr, sizeof(struct sockaddr_un)) < 0) { + printf("ERROR: Could not connct to i3\n"); + exit(EXIT_FAILURE); + } + return sockfd; } void got_command_reply(char *reply) { - /* FIXME: Error handling for command-replies */ + /* FIXME: Error handling for command-replies */ } void got_workspace_reply(char *reply) { - printf("Got Workspace-Data!\n"); - parse_workspaces_json(reply); - draw_buttons(); + printf("Got Workspace-Data!\n"); + parse_workspaces_json(reply); + draw_buttons(); } void got_subscribe_reply(char *reply) { - printf("Got Subscribe Reply: %s\n", reply); - /* FIXME: Error handling for subscribe-commands */ + printf("Got Subscribe Reply: %s\n", reply); + /* FIXME: Error handling for subscribe-commands */ } void got_output_reply(char *reply) { - printf("Got Outputs-Data!\nDestroying Windows...\n"); - destroy_windows(); - printf("Parsing JSON...\n"); - parse_outputs_json(reply); - printf("Creating_Windows...\n"); - create_windows(); + printf("Got Outputs-Data!\nDestroying Windows...\n"); + destroy_windows(); + printf("Parsing JSON...\n"); + parse_outputs_json(reply); + printf("Creating_Windows...\n"); + create_windows(); } handler_t reply_handlers[] = { - &got_command_reply, - &got_workspace_reply, - &got_subscribe_reply, - &got_output_reply, + &got_command_reply, + &got_workspace_reply, + &got_subscribe_reply, + &got_output_reply, }; void got_workspace_event(char *event) { - printf("Got Workspace Event!\n"); - i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_WORKSPACES, NULL); + printf("Got Workspace Event!\n"); + i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_WORKSPACES, NULL); } void got_output_event(char *event) { - printf("Got Output Event!\n"); - i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_OUTPUTS, NULL); + printf("Got Output Event!\n"); + i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_OUTPUTS, NULL); } handler_t event_handlers[] = { - &got_workspace_event, - &got_output_event + &got_workspace_event, + &got_output_event }; void got_data(struct ev_loop *loop, ev_io *watcher, int events) { - printf("Got data!\n"); - int fd = watcher->fd; - uint32_t header_len = strlen(I3_IPC_MAGIC) + sizeof(uint32_t)*2; - char *header = malloc(header_len); - if (header == NULL) { - printf("ERROR: Could not allocate memory!\n"); - exit(EXIT_FAILURE); - } - - uint32_t rec = 0; - while (rec < header_len) { - int n = read(fd, header + rec, header_len - rec); - if (n == -1) { - printf("ERROR: read() failed!\n"); - exit(EXIT_FAILURE); - } - if (n == 0) { - printf("ERROR: Nothing to read!\n"); - exit(EXIT_FAILURE); - } - rec += n; - } - - if (strncmp(header, I3_IPC_MAGIC, strlen(I3_IPC_MAGIC))) { - printf("ERROR: Wrong magic code: %.*s\n Expected: %s\n", - (int) strlen(I3_IPC_MAGIC), - header, - I3_IPC_MAGIC); - exit(EXIT_FAILURE); - } - - char *walk = header + strlen(I3_IPC_MAGIC); - uint32_t size = *((uint32_t*) walk); - walk += sizeof(uint32_t); - uint32_t type = *((uint32_t*) walk); - char *buffer = malloc(size + 1); - if (buffer == NULL) { - printf("ERROR: Could not allocate memory!\n"); - exit(EXIT_FAILURE); - } - rec = 0; - - while (rec < size) { - int n = read(fd, buffer + rec, size - rec); - if (n == -1) { - printf("ERROR: read() failed!\n"); - exit(EXIT_FAILURE); - } - if (n == 0) { - printf("ERROR: Nothing to read!\n"); - exit(EXIT_FAILURE); - } - rec += n; - } - buffer[size] = '\0'; - - if (type & (1 << 31)) { - type ^= 1 << 31; - event_handlers[type](buffer); - } else { - reply_handlers[type](buffer); - } - - FREE(buffer); + printf("Got data!\n"); + int fd = watcher->fd; + uint32_t header_len = strlen(I3_IPC_MAGIC) + sizeof(uint32_t)*2; + char *header = malloc(header_len); + if (header == NULL) { + printf("ERROR: Could not allocate memory!\n"); + exit(EXIT_FAILURE); + } + + uint32_t rec = 0; + while (rec < header_len) { + int n = read(fd, header + rec, header_len - rec); + if (n == -1) { + printf("ERROR: read() failed!\n"); + exit(EXIT_FAILURE); + } + if (n == 0) { + printf("ERROR: Nothing to read!\n"); + exit(EXIT_FAILURE); + } + rec += n; + } + + if (strncmp(header, I3_IPC_MAGIC, strlen(I3_IPC_MAGIC))) { + printf("ERROR: Wrong magic code: %.*s\n Expected: %s\n", + (int) strlen(I3_IPC_MAGIC), + header, + I3_IPC_MAGIC); + exit(EXIT_FAILURE); + } + + char *walk = header + strlen(I3_IPC_MAGIC); + uint32_t size = *((uint32_t*) walk); + walk += sizeof(uint32_t); + uint32_t type = *((uint32_t*) walk); + char *buffer = malloc(size + 1); + if (buffer == NULL) { + printf("ERROR: Could not allocate memory!\n"); + exit(EXIT_FAILURE); + } + rec = 0; + + while (rec < size) { + int n = read(fd, buffer + rec, size - rec); + if (n == -1) { + printf("ERROR: read() failed!\n"); + exit(EXIT_FAILURE); + } + if (n == 0) { + printf("ERROR: Nothing to read!\n"); + exit(EXIT_FAILURE); + } + rec += n; + } + buffer[size] = '\0'; + + if (type & (1 << 31)) { + type ^= 1 << 31; + event_handlers[type](buffer); + } else { + reply_handlers[type](buffer); + } + + FREE(buffer); } -int i3_send_msg(uint32_t type, const char* payload) { - uint32_t len = 0; - if (payload != NULL) { - len = strlen(payload); - } - - uint32_t to_write = strlen (I3_IPC_MAGIC) + sizeof(uint32_t)*2 + len; - char *buffer = malloc(to_write); - if (buffer == NULL) { - printf("ERROR: Could not allocate memory\n"); - exit(EXIT_FAILURE); - } - - char *walk = buffer; - - strncpy(buffer, I3_IPC_MAGIC, strlen(I3_IPC_MAGIC)); - walk += strlen(I3_IPC_MAGIC); - memcpy(walk, &len, sizeof(uint32_t)); - walk += sizeof(uint32_t); - memcpy(walk, &type, sizeof(uint32_t)); - walk += sizeof(uint32_t); - - strncpy(walk, payload, len); - - uint32_t written = 0; - - while (to_write > 0) { - int n = write(i3_connection->fd, buffer + written, to_write); - if (n == -1) { - printf("ERROR: write() failed!\n"); - exit(EXIT_FAILURE); - } - - to_write -= n; - written += n; - } - - FREE(buffer); - - return 1; +int i3_send_msg(uint32_t type, const char *payload) { + uint32_t len = 0; + if (payload != NULL) { + len = strlen(payload); + } + + uint32_t to_write = strlen (I3_IPC_MAGIC) + sizeof(uint32_t)*2 + len; + char *buffer = malloc(to_write); + if (buffer == NULL) { + printf("ERROR: Could not allocate memory\n"); + exit(EXIT_FAILURE); + } + + char *walk = buffer; + + strncpy(buffer, I3_IPC_MAGIC, strlen(I3_IPC_MAGIC)); + walk += strlen(I3_IPC_MAGIC); + memcpy(walk, &len, sizeof(uint32_t)); + walk += sizeof(uint32_t); + memcpy(walk, &type, sizeof(uint32_t)); + walk += sizeof(uint32_t); + + strncpy(walk, payload, len); + + uint32_t written = 0; + + while (to_write > 0) { + int n = write(i3_connection->fd, buffer + written, to_write); + if (n == -1) { + printf("ERROR: write() failed!\n"); + exit(EXIT_FAILURE); + } + + to_write -= n; + written += n; + } + + FREE(buffer); + + return 1; } int init_connection(const char *socket_path) { - int sockfd = get_ipc_fd(socket_path); + int sockfd = get_ipc_fd(socket_path); - i3_connection = malloc(sizeof(ev_io)); - ev_io_init(i3_connection, &got_data, sockfd, EV_READ); - ev_io_start(main_loop, i3_connection); + i3_connection = malloc(sizeof(ev_io)); + ev_io_init(i3_connection, &got_data, sockfd, EV_READ); + ev_io_start(main_loop, i3_connection); - return 1; + return 1; } void subscribe_events() { - i3_send_msg(I3_IPC_MESSAGE_TYPE_SUBSCRIBE, "[ \"workspace\", \"output\" ]"); + i3_send_msg(I3_IPC_MESSAGE_TYPE_SUBSCRIBE, "[ \"workspace\", \"output\" ]"); } diff --git a/i3bar/src/main.c b/i3bar/src/main.c index d0ce4162..9465fc12 100644 --- a/i3bar/src/main.c +++ b/i3bar/src/main.c @@ -13,55 +13,55 @@ #include "xcb.h" void ev_prepare_cb(struct ev_loop *loop, ev_prepare *w, int revents) { - xcb_flush(xcb_connection); + xcb_flush(xcb_connection); } void ev_check_cb(struct ev_loop *loop, ev_check *w, int revents) { - xcb_generic_event_t *event; - if ((event = xcb_poll_for_event(xcb_connection)) != NULL) { - handle_xcb_event(event); - } - free(event); + xcb_generic_event_t *event; + if ((event = xcb_poll_for_event(xcb_connection)) != NULL) { + handle_xcb_event(event); + } + free(event); } void xcb_io_cb(struct ev_loop *loop, ev_io *w, int revents) { } int main(int argc, char **argv) { - main_loop = ev_default_loop(0); + main_loop = ev_default_loop(0); - init_xcb(); - init_connection("/home/mero/.i3/ipc.sock"); + init_xcb(); + init_connection("/home/mero/.i3/ipc.sock"); - subscribe_events(); + subscribe_events(); - ev_io *xcb_io = malloc(sizeof(ev_io)); - ev_prepare *ev_prep = malloc(sizeof(ev_prepare)); - ev_check *ev_chk = malloc(sizeof(ev_check)); + ev_io *xcb_io = malloc(sizeof(ev_io)); + ev_prepare *ev_prep = malloc(sizeof(ev_prepare)); + ev_check *ev_chk = malloc(sizeof(ev_check)); - ev_io_init(xcb_io, &xcb_io_cb, xcb_get_file_descriptor(xcb_connection), EV_READ); - ev_prepare_init(ev_prep, &ev_prepare_cb); - ev_check_init(ev_chk, &ev_check_cb); + ev_io_init(xcb_io, &xcb_io_cb, xcb_get_file_descriptor(xcb_connection), EV_READ); + ev_prepare_init(ev_prep, &ev_prepare_cb); + ev_check_init(ev_chk, &ev_check_cb); - ev_io_start(main_loop, xcb_io); - ev_prepare_start(main_loop, ev_prep); - ev_check_start(main_loop, ev_chk); + ev_io_start(main_loop, xcb_io); + ev_prepare_start(main_loop, ev_prep); + ev_check_start(main_loop, ev_chk); - i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_OUTPUTS, NULL); - i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_WORKSPACES, NULL); + i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_OUTPUTS, NULL); + i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_WORKSPACES, NULL); - ev_loop(main_loop, 0); + ev_loop(main_loop, 0); - ev_prepare_stop(main_loop, ev_prep); - ev_check_stop(main_loop, ev_chk); - FREE(ev_prep); - FREE(ev_chk); + ev_prepare_stop(main_loop, ev_prep); + ev_check_stop(main_loop, ev_chk); + FREE(ev_prep); + FREE(ev_chk); - ev_default_destroy(); - clean_xcb(); + ev_default_destroy(); + clean_xcb(); - free_workspaces(); - FREE_SLIST(outputs, i3_output); + free_workspaces(); + FREE_SLIST(outputs, i3_output); - return 0; + return 0; } diff --git a/i3bar/src/outputs.c b/i3bar/src/outputs.c index 1969c5dd..18abff51 100644 --- a/i3bar/src/outputs.c +++ b/i3bar/src/outputs.c @@ -10,187 +10,187 @@ #include "ipc.h" struct outputs_json_params { - struct outputs_head *outputs; - i3_output *outputs_walk; - char* cur_key; - char* json; + struct outputs_head *outputs; + i3_output *outputs_walk; + char *cur_key; + char *json; }; -static int outputs_null_cb(void* params_) { - struct outputs_json_params* params = (struct outputs_json_params*) params_; +static int outputs_null_cb(void *params_) { + struct outputs_json_params *params = (struct outputs_json_params*) params_; - if (strcmp(params->cur_key, "current_workspace")) { - return 0; - } + if (strcmp(params->cur_key, "current_workspace")) { + return 0; + } - FREE(params->cur_key); + FREE(params->cur_key); - return 1; + return 1; } -static int outputs_boolean_cb(void* params_, bool val) { - struct outputs_json_params* params = (struct outputs_json_params*) params_; +static int outputs_boolean_cb(void *params_, bool val) { + struct outputs_json_params *params = (struct outputs_json_params*) params_; - if (strcmp(params->cur_key, "active")) { - return 0; - } + if (strcmp(params->cur_key, "active")) { + return 0; + } - params->outputs_walk->active = val; + params->outputs_walk->active = val; - FREE(params->cur_key); + FREE(params->cur_key); - return 1; + return 1; } -static int outputs_integer_cb(void* params_, long val) { - struct outputs_json_params* params = (struct outputs_json_params*) params_; - - if (!strcmp(params->cur_key, "current_workspace")) { - params->outputs_walk->ws = (int) val; - FREE(params->cur_key); - return 1; - } - - if (!strcmp(params->cur_key, "x")) { - params->outputs_walk->rect.x = (int) val; - FREE(params->cur_key); - return 1; - } - - if (!strcmp(params->cur_key, "y")) { - params->outputs_walk->rect.y = (int) val; - FREE(params->cur_key); - return 1; - } - - if (!strcmp(params->cur_key, "width")) { - params->outputs_walk->rect.w = (int) val; - FREE(params->cur_key); - return 1; - } - - if (!strcmp(params->cur_key, "height")) { - params->outputs_walk->rect.h = (int) val; - FREE(params->cur_key); - return 1; - } - - return 0; +static int outputs_integer_cb(void *params_, long val) { + struct outputs_json_params *params = (struct outputs_json_params*) params_; + + if (!strcmp(params->cur_key, "current_workspace")) { + params->outputs_walk->ws = (int) val; + FREE(params->cur_key); + return 1; + } + + if (!strcmp(params->cur_key, "x")) { + params->outputs_walk->rect.x = (int) val; + FREE(params->cur_key); + return 1; + } + + if (!strcmp(params->cur_key, "y")) { + params->outputs_walk->rect.y = (int) val; + FREE(params->cur_key); + return 1; + } + + if (!strcmp(params->cur_key, "width")) { + params->outputs_walk->rect.w = (int) val; + FREE(params->cur_key); + return 1; + } + + if (!strcmp(params->cur_key, "height")) { + params->outputs_walk->rect.h = (int) val; + FREE(params->cur_key); + return 1; + } + + return 0; } -static int outputs_string_cb(void* params_, const unsigned char* val, unsigned int len) { - struct outputs_json_params* params = (struct outputs_json_params*) params_; - - if (strcmp(params->cur_key, "name")) { - return 0; - } +static int outputs_string_cb(void *params_, const unsigned char *val, unsigned int len) { + struct outputs_json_params *params = (struct outputs_json_params*) params_; - params->outputs_walk->name = malloc(sizeof(const unsigned char) * (len + 1)); - strncpy(params->outputs_walk->name, (const char*) val, len); - params->outputs_walk->name[len] = '\0'; + if (strcmp(params->cur_key, "name")) { + return 0; + } - FREE(params->cur_key); - - return 1; + params->outputs_walk->name = malloc(sizeof(const unsigned char) * (len + 1)); + strncpy(params->outputs_walk->name, (const char*) val, len); + params->outputs_walk->name[len] = '\0'; + + FREE(params->cur_key); + + return 1; } -static int outputs_start_map_cb(void* params_) { - struct outputs_json_params* params = (struct outputs_json_params*) params_; - i3_output *new_output = NULL; +static int outputs_start_map_cb(void *params_) { + struct outputs_json_params *params = (struct outputs_json_params*) params_; + i3_output *new_output = NULL; - if (params->cur_key == NULL) { - new_output = malloc(sizeof(i3_output)); - new_output->name = NULL; - new_output->ws = 0, - memset(&new_output->rect, 0, sizeof(rect)); - new_output->bar = XCB_NONE; + if (params->cur_key == NULL) { + new_output = malloc(sizeof(i3_output)); + new_output->name = NULL; + new_output->ws = 0, + memset(&new_output->rect, 0, sizeof(rect)); + new_output->bar = XCB_NONE; - new_output->workspaces = malloc(sizeof(struct ws_head)); - TAILQ_INIT(new_output->workspaces); + new_output->workspaces = malloc(sizeof(struct ws_head)); + TAILQ_INIT(new_output->workspaces); - SLIST_INSERT_HEAD(params->outputs, new_output, slist); + SLIST_INSERT_HEAD(params->outputs, new_output, slist); - params->outputs_walk = SLIST_FIRST(params->outputs); + params->outputs_walk = SLIST_FIRST(params->outputs); - return 1; - } + return 1; + } - return 1; + return 1; } -static int outputs_map_key_cb(void* params_, const unsigned char* keyVal, unsigned int keyLen) { - struct outputs_json_params* params = (struct outputs_json_params*) params_; - FREE(params->cur_key); +static int outputs_map_key_cb(void *params_, const unsigned char *keyVal, unsigned int keyLen) { + struct outputs_json_params *params = (struct outputs_json_params*) params_; + FREE(params->cur_key); - params->cur_key = malloc(sizeof(unsigned char) * (keyLen + 1)); - strncpy(params->cur_key, (const char*) keyVal, keyLen); - params->cur_key[keyLen] = '\0'; + params->cur_key = malloc(sizeof(unsigned char) * (keyLen + 1)); + strncpy(params->cur_key, (const char*) keyVal, keyLen); + params->cur_key[keyLen] = '\0'; - return 1; + return 1; } yajl_callbacks outputs_callbacks = { - &outputs_null_cb, - &outputs_boolean_cb, - &outputs_integer_cb, - NULL, - NULL, - &outputs_string_cb, - &outputs_start_map_cb, - &outputs_map_key_cb, - NULL, - NULL, - NULL + &outputs_null_cb, + &outputs_boolean_cb, + &outputs_integer_cb, + NULL, + NULL, + &outputs_string_cb, + &outputs_start_map_cb, + &outputs_map_key_cb, + NULL, + NULL, + NULL }; -void parse_outputs_json(char* json) { - /* FIXME: Fasciliate stream-processing, i.e. allow starting to interpret - * JSON in chunks */ - struct outputs_json_params params; - printf(json); - params.outputs = malloc(sizeof(struct outputs_head)); - SLIST_INIT(params.outputs); - - params.outputs_walk = NULL; - params.cur_key = NULL; - params.json = json; - - yajl_handle handle; - yajl_parser_config parse_conf = { 0, 0 }; - yajl_status state; - - handle = yajl_alloc(&outputs_callbacks, &parse_conf, NULL, (void*) ¶ms); - - state = yajl_parse(handle, (const unsigned char*) json, strlen(json)); - - /* FIXME: Propper errorhandling for JSON-parsing */ - switch (state) { - case yajl_status_ok: - break; - case yajl_status_client_canceled: - case yajl_status_insufficient_data: - case yajl_status_error: - printf("ERROR: Could not parse outputs-reply!\n"); - exit(EXIT_FAILURE); - break; - } - - yajl_free(handle); - - if (outputs != NULL) { - FREE_SLIST(outputs, i3_output); - } - - outputs = params.outputs; +void parse_outputs_json(char *json) { + /* FIXME: Fasciliate stream-processing, i.e. allow starting to interpret + * JSON in chunks */ + struct outputs_json_params params; + printf(json); + params.outputs = malloc(sizeof(struct outputs_head)); + SLIST_INIT(params.outputs); + + params.outputs_walk = NULL; + params.cur_key = NULL; + params.json = json; + + yajl_handle handle; + yajl_parser_config parse_conf = { 0, 0 }; + yajl_status state; + + handle = yajl_alloc(&outputs_callbacks, &parse_conf, NULL, (void*) ¶ms); + + state = yajl_parse(handle, (const unsigned char*) json, strlen(json)); + + /* FIXME: Propper errorhandling for JSON-parsing */ + switch (state) { + case yajl_status_ok: + break; + case yajl_status_client_canceled: + case yajl_status_insufficient_data: + case yajl_status_error: + printf("ERROR: Could not parse outputs-reply!\n"); + exit(EXIT_FAILURE); + break; + } + + yajl_free(handle); + + if (outputs != NULL) { + FREE_SLIST(outputs, i3_output); + } + + outputs = params.outputs; } -i3_output* get_output_by_name(char* name) { - i3_output *walk; - SLIST_FOREACH(walk, outputs, slist) { - if (!strcmp(walk->name, name)) { - break; - } - } +i3_output *get_output_by_name(char *name) { + i3_output *walk; + SLIST_FOREACH(walk, outputs, slist) { + if (!strcmp(walk->name, name)) { + break; + } + } - return walk; + return walk; } diff --git a/i3bar/src/workspaces.c b/i3bar/src/workspaces.c index 9087275b..ee54c8b6 100644 --- a/i3bar/src/workspaces.c +++ b/i3bar/src/workspaces.c @@ -10,103 +10,103 @@ #include "ipc.h" struct workspaces_json_params { - struct ws_head *workspaces; - i3_ws *workspaces_walk; - char *cur_key; - char *json; + struct ws_head *workspaces; + i3_ws *workspaces_walk; + char *cur_key; + char *json; }; -static int workspaces_null_cb(void* params_) { - struct workspaces_json_params* params = (struct workspaces_json_params*) params_; +static int workspaces_null_cb(void *params_) { + struct workspaces_json_params *params = (struct workspaces_json_params*) params_; - if (strcmp(params->cur_key, "current_workspace")) { - return 0; - } + if (strcmp(params->cur_key, "current_workspace")) { + return 0; + } - FREE(params->cur_key); + FREE(params->cur_key); - return 1; + return 1; } -static int workspaces_boolean_cb(void* params_, bool val) { - struct workspaces_json_params* params = (struct workspaces_json_params*) params_; +static int workspaces_boolean_cb(void *params_, bool val) { + struct workspaces_json_params *params = (struct workspaces_json_params*) params_; - if (!strcmp(params->cur_key, "visible")) { - params->workspaces_walk->visible = val; - FREE(params->cur_key); - return 1; - } + if (!strcmp(params->cur_key, "visible")) { + params->workspaces_walk->visible = val; + FREE(params->cur_key); + return 1; + } - if (!strcmp(params->cur_key, "focused")) { - params->workspaces_walk->focused = val; - FREE(params->cur_key); - return 1; - } + if (!strcmp(params->cur_key, "focused")) { + params->workspaces_walk->focused = val; + FREE(params->cur_key); + return 1; + } - if (!strcmp(params->cur_key, "urgent")) { - params->workspaces_walk->urgent = val; - FREE(params->cur_key); - return 1; - } + if (!strcmp(params->cur_key, "urgent")) { + params->workspaces_walk->urgent = val; + FREE(params->cur_key); + return 1; + } - FREE(params->cur_key); + FREE(params->cur_key); - return 0; + return 0; } -static int workspaces_integer_cb(void* params_, long val) { - struct workspaces_json_params* params = (struct workspaces_json_params*) params_; - - if (!strcmp(params->cur_key, "num")) { - params->workspaces_walk->num = (int) val; - FREE(params->cur_key); - return 1; - } - - if (!strcmp(params->cur_key, "x")) { - params->workspaces_walk->rect.x = (int) val; - FREE(params->cur_key); - return 1; - } - - if (!strcmp(params->cur_key, "y")) { - params->workspaces_walk->rect.y = (int) val; - FREE(params->cur_key); - return 1; - } - - if (!strcmp(params->cur_key, "width")) { - params->workspaces_walk->rect.w = (int) val; - FREE(params->cur_key); - return 1; - } - - if (!strcmp(params->cur_key, "height")) { - params->workspaces_walk->rect.h = (int) val; - FREE(params->cur_key); - return 1; - } - - FREE(params->cur_key); - return 0; +static int workspaces_integer_cb(void *params_, long val) { + struct workspaces_json_params *params = (struct workspaces_json_params*) params_; + + if (!strcmp(params->cur_key, "num")) { + params->workspaces_walk->num = (int) val; + FREE(params->cur_key); + return 1; + } + + if (!strcmp(params->cur_key, "x")) { + params->workspaces_walk->rect.x = (int) val; + FREE(params->cur_key); + return 1; + } + + if (!strcmp(params->cur_key, "y")) { + params->workspaces_walk->rect.y = (int) val; + FREE(params->cur_key); + return 1; + } + + if (!strcmp(params->cur_key, "width")) { + params->workspaces_walk->rect.w = (int) val; + FREE(params->cur_key); + return 1; + } + + if (!strcmp(params->cur_key, "height")) { + params->workspaces_walk->rect.h = (int) val; + FREE(params->cur_key); + return 1; + } + + FREE(params->cur_key); + return 0; } -static int workspaces_string_cb(void* params_, const unsigned char* val, unsigned int len) { +static int workspaces_string_cb(void *params_, const unsigned char *val, unsigned int len) { - struct workspaces_json_params* params = (struct workspaces_json_params*) params_; + struct workspaces_json_params *params = (struct workspaces_json_params*) params_; - char* output_name; + char *output_name; if (!strcmp(params->cur_key, "name")) { params->workspaces_walk->name = malloc(sizeof(const unsigned char) * (len + 1)); strncpy(params->workspaces_walk->name, (const char*) val, len); - params->workspaces_walk->name[len] = '\0'; + params->workspaces_walk->name[len] = '\0'; - params->workspaces_walk->name_width = get_string_width(params->workspaces_walk->name); + params->workspaces_walk->name_width = get_string_width(params->workspaces_walk->name); - printf("Got Workspace %s, name_width: %d\n", - params->workspaces_walk->name, - params->workspaces_walk->name_width); + printf("Got Workspace %s, name_width: %d\n", + params->workspaces_walk->name, + params->workspaces_walk->name_width); FREE(params->cur_key); return 1; @@ -115,12 +115,12 @@ static int workspaces_string_cb(void* params_, const unsigned char* val, unsigne if (!strcmp(params->cur_key, "output")) { output_name = malloc(sizeof(const unsigned char) * (len + 1)); strncpy(output_name, (const char*) val, len); - output_name[len] = '\0'; + output_name[len] = '\0'; params->workspaces_walk->output = get_output_by_name(output_name); - TAILQ_INSERT_TAIL(params->workspaces_walk->output->workspaces, - params->workspaces_walk, - tailq); + TAILQ_INSERT_TAIL(params->workspaces_walk->output->workspaces, + params->workspaces_walk, + tailq); free(output_name); return 1; @@ -129,98 +129,98 @@ static int workspaces_string_cb(void* params_, const unsigned char* val, unsigne return 0; } -static int workspaces_start_map_cb(void* params_) { - struct workspaces_json_params* params = (struct workspaces_json_params*) params_; +static int workspaces_start_map_cb(void *params_) { + struct workspaces_json_params *params = (struct workspaces_json_params*) params_; - i3_ws *new_workspace = NULL; + i3_ws *new_workspace = NULL; - if (params->cur_key == NULL) { - new_workspace = malloc(sizeof(i3_ws)); - new_workspace->num = -1; - new_workspace->name = NULL; - new_workspace->visible = 0; - new_workspace->focused = 0; - new_workspace->urgent = 0; - memset(&new_workspace->rect, 0, sizeof(rect)); - new_workspace->output = NULL; + if (params->cur_key == NULL) { + new_workspace = malloc(sizeof(i3_ws)); + new_workspace->num = -1; + new_workspace->name = NULL; + new_workspace->visible = 0; + new_workspace->focused = 0; + new_workspace->urgent = 0; + memset(&new_workspace->rect, 0, sizeof(rect)); + new_workspace->output = NULL; - params->workspaces_walk = new_workspace; - return 1; - } + params->workspaces_walk = new_workspace; + return 1; + } - return 1; + return 1; } -static int workspaces_map_key_cb(void* params_, const unsigned char* keyVal, unsigned int keyLen) { - struct workspaces_json_params* params = (struct workspaces_json_params*) params_; - FREE(params->cur_key); +static int workspaces_map_key_cb(void *params_, const unsigned char *keyVal, unsigned int keyLen) { + struct workspaces_json_params *params = (struct workspaces_json_params*) params_; + FREE(params->cur_key); - params->cur_key = malloc(sizeof(unsigned char) * (keyLen + 1)); - if (params->cur_key == NULL) { - printf("ERROR: Could not allocate memory!\n"); - exit(EXIT_FAILURE); - } - strncpy(params->cur_key, (const char*) keyVal, keyLen); - params->cur_key[keyLen] = '\0'; + params->cur_key = malloc(sizeof(unsigned char) * (keyLen + 1)); + if (params->cur_key == NULL) { + printf("ERROR: Could not allocate memory!\n"); + exit(EXIT_FAILURE); + } + strncpy(params->cur_key, (const char*) keyVal, keyLen); + params->cur_key[keyLen] = '\0'; - return 1; + return 1; } yajl_callbacks workspaces_callbacks = { - &workspaces_null_cb, - &workspaces_boolean_cb, - &workspaces_integer_cb, - NULL, - NULL, - &workspaces_string_cb, - &workspaces_start_map_cb, - &workspaces_map_key_cb, - NULL, - NULL, - NULL + &workspaces_null_cb, + &workspaces_boolean_cb, + &workspaces_integer_cb, + NULL, + NULL, + &workspaces_string_cb, + &workspaces_start_map_cb, + &workspaces_map_key_cb, + NULL, + NULL, + NULL }; -void parse_workspaces_json(char* json) { - /* FIXME: Fasciliate stream-processing, i.e. allow starting to interpret - * JSON in chunks */ - struct workspaces_json_params params; - - free_workspaces(); - - params.workspaces_walk = NULL; - params.cur_key = NULL; - params.json = json; - - yajl_handle handle; - yajl_parser_config parse_conf = { 0, 0 }; - yajl_status state; - - handle = yajl_alloc(&workspaces_callbacks, &parse_conf, NULL, (void*) ¶ms); - - state = yajl_parse(handle, (const unsigned char*) json, strlen(json)); - - /* FIXME: Propper errorhandling for JSON-parsing */ - switch (state) { - case yajl_status_ok: - break; - case yajl_status_client_canceled: - case yajl_status_insufficient_data: - case yajl_status_error: - printf("ERROR: Could not parse workspaces-reply!\n"); - exit(EXIT_FAILURE); - break; - } - - yajl_free(handle); - - FREE(params.cur_key); +void parse_workspaces_json(char *json) { + /* FIXME: Fasciliate stream-processing, i.e. allow starting to interpret + * JSON in chunks */ + struct workspaces_json_params params; + + free_workspaces(); + + params.workspaces_walk = NULL; + params.cur_key = NULL; + params.json = json; + + yajl_handle handle; + yajl_parser_config parse_conf = { 0, 0 }; + yajl_status state; + + handle = yajl_alloc(&workspaces_callbacks, &parse_conf, NULL, (void*) ¶ms); + + state = yajl_parse(handle, (const unsigned char*) json, strlen(json)); + + /* FIXME: Propper errorhandling for JSON-parsing */ + switch (state) { + case yajl_status_ok: + break; + case yajl_status_client_canceled: + case yajl_status_insufficient_data: + case yajl_status_error: + printf("ERROR: Could not parse workspaces-reply!\n"); + exit(EXIT_FAILURE); + break; + } + + yajl_free(handle); + + FREE(params.cur_key); } void free_workspaces() { - i3_output *outputs_walk; - SLIST_FOREACH(outputs_walk, outputs, slist) { - if (outputs_walk->workspaces != NULL && !TAILQ_EMPTY(outputs_walk->workspaces)) { - FREE_TAILQ(outputs_walk->workspaces, i3_ws); - } - } + i3_output *outputs_walk; + SLIST_FOREACH(outputs_walk, outputs, slist) { + if (outputs_walk->workspaces != NULL && !TAILQ_EMPTY(outputs_walk->workspaces)) { + FREE_TAILQ(outputs_walk->workspaces, i3_ws); + } + } } diff --git a/i3bar/src/xcb.c b/i3bar/src/xcb.c index 98ec186c..6d7a38b3 100644 --- a/i3bar/src/xcb.c +++ b/i3bar/src/xcb.c @@ -12,288 +12,288 @@ xcb_intern_atom_cookie_t atom_cookies[NUM_ATOMS]; uint32_t get_colorpixel(const char *s) { - char strings[3][3] = { { s[0], s[1], '\0'} , - { s[2], s[3], '\0'} , - { s[4], s[5], '\0'} }; - uint8_t r = strtol(strings[0], NULL, 16); - uint8_t g = strtol(strings[1], NULL, 16); - uint8_t b = strtol(strings[2], NULL, 16); - return (r << 16 | g << 8 | b); + char strings[3][3] = { { s[0], s[1], '\0'} , + { s[2], s[3], '\0'} , + { s[4], s[5], '\0'} }; + uint8_t r = strtol(strings[0], NULL, 16); + uint8_t g = strtol(strings[1], NULL, 16); + uint8_t b = strtol(strings[2], NULL, 16); + return (r << 16 | g << 8 | b); } void handle_button(xcb_button_press_event_t *event) { - i3_ws *cur_ws; - i3_output *walk; - xcb_window_t bar = event->event; - SLIST_FOREACH(walk, outputs, slist) { - if (walk->bar == bar) { - break; - } - } - - if (walk == NULL) { - printf("Unknown Bar klicked!\n"); - return; - } - - TAILQ_FOREACH(cur_ws, walk->workspaces, tailq) { - if (cur_ws->visible) { - break; - } - } - - if (cur_ws == NULL) { - printf("No Workspace active?\n"); - return; - } - - int32_t x = event->event_x; - - printf("Got Button %d\n", event->detail); - - switch (event->detail) { - case 1: - TAILQ_FOREACH(cur_ws, walk->workspaces, tailq) { - printf("x = %d\n", x); - if (x < cur_ws->name_width + 10) { - break; - } - x -= cur_ws->name_width + 10; - } - if (cur_ws == NULL) { - return; - } - break; - case 4: - if (cur_ws == TAILQ_LAST(walk->workspaces, ws_head)) { - cur_ws = TAILQ_FIRST(walk->workspaces); - } else { - cur_ws = TAILQ_NEXT(cur_ws, tailq); - } - break; - case 5: - if (cur_ws == TAILQ_FIRST(walk->workspaces)) { - cur_ws = TAILQ_LAST(walk->workspaces, ws_head); - } else { - cur_ws = TAILQ_PREV(cur_ws, ws_head, tailq); - } - break; - } - - char buffer[50]; - snprintf(buffer, 50, "%d", cur_ws->num); - i3_send_msg(I3_IPC_MESSAGE_TYPE_COMMAND, buffer); + i3_ws *cur_ws; + i3_output *walk; + xcb_window_t bar = event->event; + SLIST_FOREACH(walk, outputs, slist) { + if (walk->bar == bar) { + break; + } + } + + if (walk == NULL) { + printf("Unknown Bar klicked!\n"); + return; + } + + TAILQ_FOREACH(cur_ws, walk->workspaces, tailq) { + if (cur_ws->visible) { + break; + } + } + + if (cur_ws == NULL) { + printf("No Workspace active?\n"); + return; + } + + int32_t x = event->event_x; + + printf("Got Button %d\n", event->detail); + + switch (event->detail) { + case 1: + TAILQ_FOREACH(cur_ws, walk->workspaces, tailq) { + printf("x = %d\n", x); + if (x < cur_ws->name_width + 10) { + break; + } + x -= cur_ws->name_width + 10; + } + if (cur_ws == NULL) { + return; + } + break; + case 4: + if (cur_ws == TAILQ_LAST(walk->workspaces, ws_head)) { + cur_ws = TAILQ_FIRST(walk->workspaces); + } else { + cur_ws = TAILQ_NEXT(cur_ws, tailq); + } + break; + case 5: + if (cur_ws == TAILQ_FIRST(walk->workspaces)) { + cur_ws = TAILQ_LAST(walk->workspaces, ws_head); + } else { + cur_ws = TAILQ_PREV(cur_ws, ws_head, tailq); + } + break; + } + + char buffer[50]; + snprintf(buffer, 50, "%d", cur_ws->num); + i3_send_msg(I3_IPC_MESSAGE_TYPE_COMMAND, buffer); } void handle_xcb_event(xcb_generic_event_t *event) { - switch (event->response_type & ~0x80) { - case XCB_EXPOSE: - draw_buttons(); - break; - case XCB_BUTTON_PRESS: - handle_button((xcb_button_press_event_t*) event); - break; - } + switch (event->response_type & ~0x80) { + case XCB_EXPOSE: + draw_buttons(); + break; + case XCB_BUTTON_PRESS: + handle_button((xcb_button_press_event_t*) event); + break; + } } int get_string_width(char *string) { - xcb_query_text_extents_cookie_t cookie; - xcb_query_text_extents_reply_t *reply; - xcb_generic_error_t *error; - int width; - - cookie = xcb_query_text_extents(xcb_connection, xcb_font, strlen(string), (xcb_char2b_t *)string); - if ((reply= xcb_query_text_extents_reply(xcb_connection, cookie, &error)) == NULL) { - printf("ERROR: Could not get text extents!"); - return 7; - } - - width = reply->overall_width; - free(reply); - return width; + xcb_query_text_extents_cookie_t cookie; + xcb_query_text_extents_reply_t *reply; + xcb_generic_error_t *error; + int width; + + cookie = xcb_query_text_extents(xcb_connection, xcb_font, strlen(string), (xcb_char2b_t*) string); + if ((reply= xcb_query_text_extents_reply(xcb_connection, cookie, &error)) == NULL) { + printf("ERROR: Could not get text extents!"); + return 7; + } + + width = reply->overall_width; + free(reply); + return width; } void init_xcb() { - /* FIXME: xcb_connect leaks Memory */ - xcb_connection = xcb_connect(NULL, NULL); - if (xcb_connection_has_error(xcb_connection)) { - printf("Cannot open display\n"); - exit(EXIT_FAILURE); - } - printf("Connected to xcb\n"); - - /* We have to request the atoms we need */ - #define ATOM_DO(name) atom_cookies[name] = xcb_intern_atom(xcb_connection, 0, strlen(#name), #name); + /* FIXME: xcb_connect leaks Memory */ + xcb_connection = xcb_connect(NULL, NULL); + if (xcb_connection_has_error(xcb_connection)) { + printf("Cannot open display\n"); + exit(EXIT_FAILURE); + } + printf("Connected to xcb\n"); + + /* We have to request the atoms we need */ + #define ATOM_DO(name) atom_cookies[name] = xcb_intern_atom(xcb_connection, 0, strlen(#name), #name); #include "xcb_atoms.def" - xcb_screens = xcb_setup_roots_iterator(xcb_get_setup(xcb_connection)).data; - xcb_root = xcb_screens->root; - - xcb_font = xcb_generate_id(xcb_connection); - char *fontname = "-misc-fixed-medium-r-semicondensed--12-110-75-75-c-60-iso10646-1"; - xcb_open_font(xcb_connection, - xcb_font, - strlen(fontname), - fontname); - - xcb_list_fonts_with_info_cookie_t cookie; - cookie = xcb_list_fonts_with_info(xcb_connection, - 1, - strlen(fontname), - fontname); - xcb_list_fonts_with_info_reply_t *reply; - reply = xcb_list_fonts_with_info_reply(xcb_connection, - cookie, - NULL); - font_height = reply->font_ascent + reply->font_descent; - printf("Calculated Font-height: %d\n", font_height); - - - /* FIXME: Maybe we can push that further backwards */ - get_atoms(); + xcb_screens = xcb_setup_roots_iterator(xcb_get_setup(xcb_connection)).data; + xcb_root = xcb_screens->root; + + xcb_font = xcb_generate_id(xcb_connection); + char *fontname = "-misc-fixed-medium-r-semicondensed--12-110-75-75-c-60-iso10646-1"; + xcb_open_font(xcb_connection, + xcb_font, + strlen(fontname), + fontname); + + xcb_list_fonts_with_info_cookie_t cookie; + cookie = xcb_list_fonts_with_info(xcb_connection, + 1, + strlen(fontname), + fontname); + xcb_list_fonts_with_info_reply_t *reply; + reply = xcb_list_fonts_with_info_reply(xcb_connection, + cookie, + NULL); + font_height = reply->font_ascent + reply->font_descent; + printf("Calculated Font-height: %d\n", font_height); + + + /* FIXME: Maybe we can push that further backwards */ + get_atoms(); } void clean_xcb() { - xcb_disconnect(xcb_connection); + xcb_disconnect(xcb_connection); } void get_atoms() { - xcb_intern_atom_reply_t* reply; - #define ATOM_DO(name) reply = xcb_intern_atom_reply(xcb_connection, atom_cookies[name], NULL); \ - atoms[name] = reply->atom; \ - free(reply); + xcb_intern_atom_reply_t *reply; + #define ATOM_DO(name) reply = xcb_intern_atom_reply(xcb_connection, atom_cookies[name], NULL); \ + atoms[name] = reply->atom; \ + free(reply); - #include "xcb_atoms.def" - printf("Got Atoms\n"); + #include "xcb_atoms.def" + printf("Got Atoms\n"); } void destroy_windows() { - i3_output *walk; - if (outputs == NULL) { - return; - } - SLIST_FOREACH(walk, outputs, slist) { - if (walk->bar == XCB_NONE) { - continue; - } - xcb_destroy_window(xcb_connection, walk->bar); - walk->bar = XCB_NONE; - } + i3_output *walk; + if (outputs == NULL) { + return; + } + SLIST_FOREACH(walk, outputs, slist) { + if (walk->bar == XCB_NONE) { + continue; + } + xcb_destroy_window(xcb_connection, walk->bar); + walk->bar = XCB_NONE; + } } void create_windows() { - uint32_t mask; - uint32_t values[2]; - - i3_output *walk; - SLIST_FOREACH(walk, outputs, slist) { - if (!walk->active) { - continue; - } - printf("Creating Window for output %s\n", walk->name); - - walk->bar = xcb_generate_id(xcb_connection); - mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; - values[0] = xcb_screens->black_pixel; - values[1] = XCB_EVENT_MASK_EXPOSURE | - XCB_EVENT_MASK_BUTTON_PRESS; - xcb_create_window(xcb_connection, - xcb_screens->root_depth, - walk->bar, - xcb_root, - walk->rect.x, walk->rect.y, - walk->rect.w, font_height + 6, - 1, - XCB_WINDOW_CLASS_INPUT_OUTPUT, - xcb_screens->root_visual, - mask, - values); - - xcb_change_property(xcb_connection, - XCB_PROP_MODE_REPLACE, - walk->bar, - atoms[_NET_WM_WINDOW_TYPE], - atoms[ATOM], - 32, - 1, - (unsigned char*) &atoms[_NET_WM_WINDOW_TYPE_DOCK]); - - walk->bargc = xcb_generate_id(xcb_connection); - mask = XCB_GC_FONT; - values[0] = xcb_font; - xcb_create_gc(xcb_connection, - walk->bargc, - walk->bar, - mask, - values); - - xcb_map_window(xcb_connection, walk->bar); - } - xcb_flush(xcb_connection); + uint32_t mask; + uint32_t values[2]; + + i3_output *walk; + SLIST_FOREACH(walk, outputs, slist) { + if (!walk->active) { + continue; + } + printf("Creating Window for output %s\n", walk->name); + + walk->bar = xcb_generate_id(xcb_connection); + mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; + values[0] = xcb_screens->black_pixel; + values[1] = XCB_EVENT_MASK_EXPOSURE | + XCB_EVENT_MASK_BUTTON_PRESS; + xcb_create_window(xcb_connection, + xcb_screens->root_depth, + walk->bar, + xcb_root, + walk->rect.x, walk->rect.y, + walk->rect.w, font_height + 6, + 1, + XCB_WINDOW_CLASS_INPUT_OUTPUT, + xcb_screens->root_visual, + mask, + values); + + xcb_change_property(xcb_connection, + XCB_PROP_MODE_REPLACE, + walk->bar, + atoms[_NET_WM_WINDOW_TYPE], + atoms[ATOM], + 32, + 1, + (unsigned char*) &atoms[_NET_WM_WINDOW_TYPE_DOCK]); + + walk->bargc = xcb_generate_id(xcb_connection); + mask = XCB_GC_FONT; + values[0] = xcb_font; + xcb_create_gc(xcb_connection, + walk->bargc, + walk->bar, + mask, + values); + + xcb_map_window(xcb_connection, walk->bar); + } + xcb_flush(xcb_connection); } void draw_buttons() { - printf("Drawing Buttons...\n"); - int i = 0; - i3_output *outputs_walk; - SLIST_FOREACH(outputs_walk, outputs, slist) { - if (!outputs_walk->active) { - printf("Output %s inactive, skipping...\n", outputs_walk->name); - continue; - } - if (outputs_walk->bar == XCB_NONE) { - create_windows(); - } - uint32_t color = get_colorpixel("000000"); - xcb_change_gc(xcb_connection, - outputs_walk->bargc, - XCB_GC_FOREGROUND, - &color); - xcb_rectangle_t rect = { 0, 0, outputs_walk->rect.w, font_height + 6 }; - xcb_poly_fill_rectangle(xcb_connection, - outputs_walk->bar, - outputs_walk->bargc, - 1, - &rect); - i3_ws *ws_walk; - TAILQ_FOREACH(ws_walk, outputs_walk->workspaces, tailq) { - printf("Drawing Button for WS %s at x = %d\n", ws_walk->name, i); - uint32_t color = get_colorpixel("240000"); - if (ws_walk->visible) { - color = get_colorpixel("480000"); - } - if (ws_walk->urgent) { - printf("WS %s is urgent!\n", ws_walk->name); - color = get_colorpixel("002400"); - } - xcb_change_gc(xcb_connection, - outputs_walk->bargc, - XCB_GC_FOREGROUND, - &color); - xcb_change_gc(xcb_connection, - outputs_walk->bargc, - XCB_GC_BACKGROUND, - &color); - xcb_rectangle_t rect = { i + 1, 1, ws_walk->name_width + 8, font_height + 4 }; - xcb_poly_fill_rectangle(xcb_connection, - outputs_walk->bar, - outputs_walk->bargc, - 1, - &rect); - color = get_colorpixel("FFFFFF"); - xcb_change_gc(xcb_connection, - outputs_walk->bargc, - XCB_GC_FOREGROUND, - &color); - xcb_image_text_8(xcb_connection, - strlen(ws_walk->name), - outputs_walk->bar, - outputs_walk->bargc, - i + 5, font_height + 1, - ws_walk->name); - i += 10 + ws_walk->name_width; - } - i = 0; - } - xcb_flush(xcb_connection); + printf("Drawing Buttons...\n"); + int i = 0; + i3_output *outputs_walk; + SLIST_FOREACH(outputs_walk, outputs, slist) { + if (!outputs_walk->active) { + printf("Output %s inactive, skipping...\n", outputs_walk->name); + continue; + } + if (outputs_walk->bar == XCB_NONE) { + create_windows(); + } + uint32_t color = get_colorpixel("000000"); + xcb_change_gc(xcb_connection, + outputs_walk->bargc, + XCB_GC_FOREGROUND, + &color); + xcb_rectangle_t rect = { 0, 0, outputs_walk->rect.w, font_height + 6 }; + xcb_poly_fill_rectangle(xcb_connection, + outputs_walk->bar, + outputs_walk->bargc, + 1, + &rect); + i3_ws *ws_walk; + TAILQ_FOREACH(ws_walk, outputs_walk->workspaces, tailq) { + printf("Drawing Button for WS %s at x = %d\n", ws_walk->name, i); + uint32_t color = get_colorpixel("240000"); + if (ws_walk->visible) { + color = get_colorpixel("480000"); + } + if (ws_walk->urgent) { + printf("WS %s is urgent!\n", ws_walk->name); + color = get_colorpixel("002400"); + } + xcb_change_gc(xcb_connection, + outputs_walk->bargc, + XCB_GC_FOREGROUND, + &color); + xcb_change_gc(xcb_connection, + outputs_walk->bargc, + XCB_GC_BACKGROUND, + &color); + xcb_rectangle_t rect = { i + 1, 1, ws_walk->name_width + 8, font_height + 4 }; + xcb_poly_fill_rectangle(xcb_connection, + outputs_walk->bar, + outputs_walk->bargc, + 1, + &rect); + color = get_colorpixel("FFFFFF"); + xcb_change_gc(xcb_connection, + outputs_walk->bargc, + XCB_GC_FOREGROUND, + &color); + xcb_image_text_8(xcb_connection, + strlen(ws_walk->name), + outputs_walk->bar, + outputs_walk->bargc, + i + 5, font_height + 1, + ws_walk->name); + i += 10 + ws_walk->name_width; + } + i = 0; + } + xcb_flush(xcb_connection); }