Change the indention-style

This commit is contained in:
Axel Wagner 2010-08-03 21:20:11 +02:00
parent 49eef0db3f
commit 8595d3bb48
9 changed files with 714 additions and 714 deletions

View File

@ -11,9 +11,9 @@ typedef struct i3_output i3_output;
SLIST_HEAD(outputs_head, i3_output); SLIST_HEAD(outputs_head, i3_output);
struct outputs_head *outputs; struct outputs_head *outputs;
void parse_outputs_json(char* json); void parse_outputs_json(char* json);
void free_outputs(); void free_outputs();
i3_output* get_output_by_name(char* name); i3_output* get_output_by_name(char* name);
struct i3_output { struct i3_output {
char* name; char* name;

View File

@ -5,30 +5,30 @@
/* Securely free p */ /* Securely free p */
#define FREE(p) do { \ #define FREE(p) do { \
if (p != NULL) { \ if (p != NULL) { \
free(p); \ free(p); \
p = NULL; \ p = NULL; \
} \ } \
} while (0) } while (0)
/* Securely fee single-linked list */ /* Securely fee single-linked list */
#define FREE_SLIST(l, type) do { \ #define FREE_SLIST(l, type) do { \
type *walk = SLIST_FIRST(l); \ type *walk = SLIST_FIRST(l); \
while (!SLIST_EMPTY(l)) { \ while (!SLIST_EMPTY(l)) { \
SLIST_REMOVE_HEAD(l, slist); \ SLIST_REMOVE_HEAD(l, slist); \
FREE(walk); \ FREE(walk); \
walk = SLIST_FIRST(l); \ walk = SLIST_FIRST(l); \
} \ } \
} while (0) } while (0)
#endif #endif
/* Securely fee tail-queues */ /* Securely fee tail-queues */
#define FREE_TAILQ(l, type) do { \ #define FREE_TAILQ(l, type) do { \
type *walk = TAILQ_FIRST(l); \ type *walk = TAILQ_FIRST(l); \
while (!TAILQ_EMPTY(l)) { \ while (!TAILQ_EMPTY(l)) { \
TAILQ_REMOVE(l, TAILQ_FIRST(l), tailq); \ TAILQ_REMOVE(l, TAILQ_FIRST(l), tailq); \
FREE(walk); \ FREE(walk); \
walk = TAILQ_FIRST(l); \ walk = TAILQ_FIRST(l); \
} \ } \
} while (0) } while (0)

View File

@ -12,16 +12,16 @@ void parse_workspaces_json();
void free_workspaces(); void free_workspaces();
struct i3_ws { struct i3_ws {
int num; int num;
char *name; char *name;
int name_width; int name_width;
bool visible; bool visible;
bool focused; bool focused;
bool urgent; bool urgent;
rect rect; rect rect;
struct i3_output *output; struct i3_output *output;
TAILQ_ENTRY(i3_ws) tailq; TAILQ_ENTRY(i3_ws) tailq;
}; };
#endif #endif

View File

@ -12,11 +12,11 @@ enum {
xcb_atom_t atoms[NUM_ATOMS]; xcb_atom_t atoms[NUM_ATOMS];
xcb_connection_t* xcb_connection; xcb_connection_t *xcb_connection;
xcb_screen_t* xcb_screens; xcb_screen_t *xcb_screens;
xcb_window_t xcb_root; xcb_window_t xcb_root;
xcb_font_t xcb_font; xcb_font_t xcb_font;
int font_height; int font_height;
void init_xcb(); void init_xcb();
void clean_xcb(); void clean_xcb();

View File

@ -12,193 +12,193 @@
#include "xcb.h" #include "xcb.h"
#include "ipc.h" #include "ipc.h"
ev_io* i3_connection; ev_io *i3_connection;
typedef void(*handler_t)(char*); typedef void(*handler_t)(char*);
int get_ipc_fd(const char* socket_path) { int get_ipc_fd(const char *socket_path) {
int sockfd = socket(AF_LOCAL, SOCK_STREAM, 0); int sockfd = socket(AF_LOCAL, SOCK_STREAM, 0);
if (sockfd == -1) { if (sockfd == -1) {
printf("ERROR: Could not create Socket!\n"); printf("ERROR: Could not create Socket!\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
struct sockaddr_un addr; struct sockaddr_un addr;
memset(&addr, 0, sizeof(struct sockaddr_un)); memset(&addr, 0, sizeof(struct sockaddr_un));
addr.sun_family = AF_LOCAL; addr.sun_family = AF_LOCAL;
strcpy(addr.sun_path, socket_path); strcpy(addr.sun_path, socket_path);
if (connect(sockfd, (const struct sockaddr*) &addr, sizeof(struct sockaddr_un)) < 0) { if (connect(sockfd, (const struct sockaddr*) &addr, sizeof(struct sockaddr_un)) < 0) {
printf("ERROR: Could not connct to i3\n"); printf("ERROR: Could not connct to i3\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
return sockfd; return sockfd;
} }
void got_command_reply(char *reply) { void got_command_reply(char *reply) {
/* FIXME: Error handling for command-replies */ /* FIXME: Error handling for command-replies */
} }
void got_workspace_reply(char *reply) { void got_workspace_reply(char *reply) {
printf("Got Workspace-Data!\n"); printf("Got Workspace-Data!\n");
parse_workspaces_json(reply); parse_workspaces_json(reply);
draw_buttons(); draw_buttons();
} }
void got_subscribe_reply(char *reply) { void got_subscribe_reply(char *reply) {
printf("Got Subscribe Reply: %s\n", reply); printf("Got Subscribe Reply: %s\n", reply);
/* FIXME: Error handling for subscribe-commands */ /* FIXME: Error handling for subscribe-commands */
} }
void got_output_reply(char *reply) { void got_output_reply(char *reply) {
printf("Got Outputs-Data!\nDestroying Windows...\n"); printf("Got Outputs-Data!\nDestroying Windows...\n");
destroy_windows(); destroy_windows();
printf("Parsing JSON...\n"); printf("Parsing JSON...\n");
parse_outputs_json(reply); parse_outputs_json(reply);
printf("Creating_Windows...\n"); printf("Creating_Windows...\n");
create_windows(); create_windows();
} }
handler_t reply_handlers[] = { handler_t reply_handlers[] = {
&got_command_reply, &got_command_reply,
&got_workspace_reply, &got_workspace_reply,
&got_subscribe_reply, &got_subscribe_reply,
&got_output_reply, &got_output_reply,
}; };
void got_workspace_event(char *event) { void got_workspace_event(char *event) {
printf("Got Workspace Event!\n"); printf("Got Workspace Event!\n");
i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_WORKSPACES, NULL); i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_WORKSPACES, NULL);
} }
void got_output_event(char *event) { void got_output_event(char *event) {
printf("Got Output Event!\n"); printf("Got Output Event!\n");
i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_OUTPUTS, NULL); i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_OUTPUTS, NULL);
} }
handler_t event_handlers[] = { handler_t event_handlers[] = {
&got_workspace_event, &got_workspace_event,
&got_output_event &got_output_event
}; };
void got_data(struct ev_loop *loop, ev_io *watcher, int events) { void got_data(struct ev_loop *loop, ev_io *watcher, int events) {
printf("Got data!\n"); printf("Got data!\n");
int fd = watcher->fd; int fd = watcher->fd;
uint32_t header_len = strlen(I3_IPC_MAGIC) + sizeof(uint32_t)*2; uint32_t header_len = strlen(I3_IPC_MAGIC) + sizeof(uint32_t)*2;
char *header = malloc(header_len); char *header = malloc(header_len);
if (header == NULL) { if (header == NULL) {
printf("ERROR: Could not allocate memory!\n"); printf("ERROR: Could not allocate memory!\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
uint32_t rec = 0; uint32_t rec = 0;
while (rec < header_len) { while (rec < header_len) {
int n = read(fd, header + rec, header_len - rec); int n = read(fd, header + rec, header_len - rec);
if (n == -1) { if (n == -1) {
printf("ERROR: read() failed!\n"); printf("ERROR: read() failed!\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (n == 0) { if (n == 0) {
printf("ERROR: Nothing to read!\n"); printf("ERROR: Nothing to read!\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
rec += n; 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); if (strncmp(header, I3_IPC_MAGIC, strlen(I3_IPC_MAGIC))) {
uint32_t size = *((uint32_t*) walk); printf("ERROR: Wrong magic code: %.*s\n Expected: %s\n",
walk += sizeof(uint32_t); (int) strlen(I3_IPC_MAGIC),
uint32_t type = *((uint32_t*) walk); header,
char *buffer = malloc(size + 1); I3_IPC_MAGIC);
if (buffer == NULL) { exit(EXIT_FAILURE);
printf("ERROR: Could not allocate memory!\n"); }
exit(EXIT_FAILURE);
}
rec = 0;
while (rec < size) { char *walk = header + strlen(I3_IPC_MAGIC);
int n = read(fd, buffer + rec, size - rec); uint32_t size = *((uint32_t*) walk);
if (n == -1) { walk += sizeof(uint32_t);
printf("ERROR: read() failed!\n"); uint32_t type = *((uint32_t*) walk);
exit(EXIT_FAILURE); char *buffer = malloc(size + 1);
} if (buffer == NULL) {
if (n == 0) { printf("ERROR: Could not allocate memory!\n");
printf("ERROR: Nothing to read!\n"); exit(EXIT_FAILURE);
exit(EXIT_FAILURE); }
} rec = 0;
rec += n;
}
buffer[size] = '\0';
if (type & (1 << 31)) {
type ^= 1 << 31;
event_handlers[type](buffer);
} else {
reply_handlers[type](buffer);
}
FREE(buffer); 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) { int i3_send_msg(uint32_t type, const char *payload) {
uint32_t len = 0; uint32_t len = 0;
if (payload != NULL) { if (payload != NULL) {
len = strlen(payload); len = strlen(payload);
} }
uint32_t to_write = strlen (I3_IPC_MAGIC) + sizeof(uint32_t)*2 + len; uint32_t to_write = strlen (I3_IPC_MAGIC) + sizeof(uint32_t)*2 + len;
char *buffer = malloc(to_write); char *buffer = malloc(to_write);
if (buffer == NULL) { if (buffer == NULL) {
printf("ERROR: Could not allocate memory\n"); printf("ERROR: Could not allocate memory\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
char *walk = buffer; char *walk = buffer;
strncpy(buffer, I3_IPC_MAGIC, strlen(I3_IPC_MAGIC)); strncpy(buffer, I3_IPC_MAGIC, strlen(I3_IPC_MAGIC));
walk += strlen(I3_IPC_MAGIC); walk += strlen(I3_IPC_MAGIC);
memcpy(walk, &len, sizeof(uint32_t)); memcpy(walk, &len, sizeof(uint32_t));
walk += sizeof(uint32_t); walk += sizeof(uint32_t);
memcpy(walk, &type, sizeof(uint32_t)); memcpy(walk, &type, sizeof(uint32_t));
walk += sizeof(uint32_t); walk += sizeof(uint32_t);
strncpy(walk, payload, len); strncpy(walk, payload, len);
uint32_t written = 0;
while (to_write > 0) { uint32_t written = 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; while (to_write > 0) {
written += n; int n = write(i3_connection->fd, buffer + written, to_write);
} if (n == -1) {
printf("ERROR: write() failed!\n");
exit(EXIT_FAILURE);
}
FREE(buffer); to_write -= n;
written += n;
}
return 1; FREE(buffer);
return 1;
} }
int init_connection(const char *socket_path) { 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)); i3_connection = malloc(sizeof(ev_io));
ev_io_init(i3_connection, &got_data, sockfd, EV_READ); ev_io_init(i3_connection, &got_data, sockfd, EV_READ);
ev_io_start(main_loop, i3_connection); ev_io_start(main_loop, i3_connection);
return 1; return 1;
} }
void subscribe_events() { void subscribe_events() {
i3_send_msg(I3_IPC_MESSAGE_TYPE_SUBSCRIBE, "[ \"workspace\", \"output\" ]"); i3_send_msg(I3_IPC_MESSAGE_TYPE_SUBSCRIBE, "[ \"workspace\", \"output\" ]");
} }

View File

@ -13,55 +13,55 @@
#include "xcb.h" #include "xcb.h"
void ev_prepare_cb(struct ev_loop *loop, ev_prepare *w, int revents) { 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) { void ev_check_cb(struct ev_loop *loop, ev_check *w, int revents) {
xcb_generic_event_t *event; xcb_generic_event_t *event;
if ((event = xcb_poll_for_event(xcb_connection)) != NULL) { if ((event = xcb_poll_for_event(xcb_connection)) != NULL) {
handle_xcb_event(event); handle_xcb_event(event);
} }
free(event); free(event);
} }
void xcb_io_cb(struct ev_loop *loop, ev_io *w, int revents) { void xcb_io_cb(struct ev_loop *loop, ev_io *w, int revents) {
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
main_loop = ev_default_loop(0); main_loop = ev_default_loop(0);
init_xcb(); init_xcb();
init_connection("/home/mero/.i3/ipc.sock"); init_connection("/home/mero/.i3/ipc.sock");
subscribe_events(); subscribe_events();
ev_io *xcb_io = malloc(sizeof(ev_io)); ev_io *xcb_io = malloc(sizeof(ev_io));
ev_prepare *ev_prep = malloc(sizeof(ev_prepare)); ev_prepare *ev_prep = malloc(sizeof(ev_prepare));
ev_check *ev_chk = malloc(sizeof(ev_check)); 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_io_init(xcb_io, &xcb_io_cb, xcb_get_file_descriptor(xcb_connection), EV_READ);
ev_prepare_init(ev_prep, &ev_prepare_cb); ev_prepare_init(ev_prep, &ev_prepare_cb);
ev_check_init(ev_chk, &ev_check_cb); ev_check_init(ev_chk, &ev_check_cb);
ev_io_start(main_loop, xcb_io); ev_io_start(main_loop, xcb_io);
ev_prepare_start(main_loop, ev_prep); ev_prepare_start(main_loop, ev_prep);
ev_check_start(main_loop, ev_chk); 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_OUTPUTS, NULL);
i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_WORKSPACES, 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_prepare_stop(main_loop, ev_prep);
ev_check_stop(main_loop, ev_chk); ev_check_stop(main_loop, ev_chk);
FREE(ev_prep); FREE(ev_prep);
FREE(ev_chk); FREE(ev_chk);
ev_default_destroy(); ev_default_destroy();
clean_xcb(); clean_xcb();
free_workspaces(); free_workspaces();
FREE_SLIST(outputs, i3_output); FREE_SLIST(outputs, i3_output);
return 0; return 0;
} }

View File

@ -10,187 +10,187 @@
#include "ipc.h" #include "ipc.h"
struct outputs_json_params { struct outputs_json_params {
struct outputs_head *outputs; struct outputs_head *outputs;
i3_output *outputs_walk; i3_output *outputs_walk;
char* cur_key; char *cur_key;
char* json; char *json;
}; };
static int outputs_null_cb(void* params_) { static int outputs_null_cb(void *params_) {
struct outputs_json_params* params = (struct outputs_json_params*) params_; struct outputs_json_params *params = (struct outputs_json_params*) params_;
if (strcmp(params->cur_key, "current_workspace")) { if (strcmp(params->cur_key, "current_workspace")) {
return 0; return 0;
} }
FREE(params->cur_key); FREE(params->cur_key);
return 1; return 1;
} }
static int outputs_boolean_cb(void* params_, bool val) { static int outputs_boolean_cb(void *params_, bool val) {
struct outputs_json_params* params = (struct outputs_json_params*) params_; struct outputs_json_params *params = (struct outputs_json_params*) params_;
if (strcmp(params->cur_key, "active")) { if (strcmp(params->cur_key, "active")) {
return 0; 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) { static int outputs_integer_cb(void *params_, long val) {
struct outputs_json_params* params = (struct outputs_json_params*) params_; struct outputs_json_params *params = (struct outputs_json_params*) params_;
if (!strcmp(params->cur_key, "current_workspace")) { if (!strcmp(params->cur_key, "current_workspace")) {
params->outputs_walk->ws = (int) val; params->outputs_walk->ws = (int) val;
FREE(params->cur_key); FREE(params->cur_key);
return 1; return 1;
} }
if (!strcmp(params->cur_key, "x")) { if (!strcmp(params->cur_key, "x")) {
params->outputs_walk->rect.x = (int) val; params->outputs_walk->rect.x = (int) val;
FREE(params->cur_key); FREE(params->cur_key);
return 1; return 1;
} }
if (!strcmp(params->cur_key, "y")) { if (!strcmp(params->cur_key, "y")) {
params->outputs_walk->rect.y = (int) val; params->outputs_walk->rect.y = (int) val;
FREE(params->cur_key); FREE(params->cur_key);
return 1; 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")) { if (!strcmp(params->cur_key, "width")) {
params->outputs_walk->rect.h = (int) val; params->outputs_walk->rect.w = (int) val;
FREE(params->cur_key); FREE(params->cur_key);
return 1; return 1;
} }
return 0; 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) { static int outputs_string_cb(void *params_, const unsigned char *val, unsigned int len) {
struct outputs_json_params* params = (struct outputs_json_params*) params_; struct outputs_json_params *params = (struct outputs_json_params*) params_;
if (strcmp(params->cur_key, "name")) {
return 0;
}
params->outputs_walk->name = malloc(sizeof(const unsigned char) * (len + 1)); if (strcmp(params->cur_key, "name")) {
strncpy(params->outputs_walk->name, (const char*) val, len); return 0;
params->outputs_walk->name[len] = '\0'; }
FREE(params->cur_key); params->outputs_walk->name = malloc(sizeof(const unsigned char) * (len + 1));
strncpy(params->outputs_walk->name, (const char*) val, len);
return 1; params->outputs_walk->name[len] = '\0';
FREE(params->cur_key);
return 1;
} }
static int outputs_start_map_cb(void* params_) { static int outputs_start_map_cb(void *params_) {
struct outputs_json_params* params = (struct outputs_json_params*) params_; struct outputs_json_params *params = (struct outputs_json_params*) params_;
i3_output *new_output = NULL; i3_output *new_output = NULL;
if (params->cur_key == NULL) { if (params->cur_key == NULL) {
new_output = malloc(sizeof(i3_output)); new_output = malloc(sizeof(i3_output));
new_output->name = NULL; new_output->name = NULL;
new_output->ws = 0, new_output->ws = 0,
memset(&new_output->rect, 0, sizeof(rect)); memset(&new_output->rect, 0, sizeof(rect));
new_output->bar = XCB_NONE; new_output->bar = XCB_NONE;
new_output->workspaces = malloc(sizeof(struct ws_head)); new_output->workspaces = malloc(sizeof(struct ws_head));
TAILQ_INIT(new_output->workspaces); 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) { 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_; struct outputs_json_params *params = (struct outputs_json_params*) params_;
FREE(params->cur_key); FREE(params->cur_key);
params->cur_key = malloc(sizeof(unsigned char) * (keyLen + 1)); params->cur_key = malloc(sizeof(unsigned char) * (keyLen + 1));
strncpy(params->cur_key, (const char*) keyVal, keyLen); strncpy(params->cur_key, (const char*) keyVal, keyLen);
params->cur_key[keyLen] = '\0'; params->cur_key[keyLen] = '\0';
return 1; return 1;
} }
yajl_callbacks outputs_callbacks = { yajl_callbacks outputs_callbacks = {
&outputs_null_cb, &outputs_null_cb,
&outputs_boolean_cb, &outputs_boolean_cb,
&outputs_integer_cb, &outputs_integer_cb,
NULL, NULL,
NULL, NULL,
&outputs_string_cb, &outputs_string_cb,
&outputs_start_map_cb, &outputs_start_map_cb,
&outputs_map_key_cb, &outputs_map_key_cb,
NULL, NULL,
NULL, NULL,
NULL NULL
}; };
void parse_outputs_json(char* json) { void parse_outputs_json(char *json) {
/* FIXME: Fasciliate stream-processing, i.e. allow starting to interpret /* FIXME: Fasciliate stream-processing, i.e. allow starting to interpret
* JSON in chunks */ * JSON in chunks */
struct outputs_json_params params; struct outputs_json_params params;
printf(json); printf(json);
params.outputs = malloc(sizeof(struct outputs_head)); params.outputs = malloc(sizeof(struct outputs_head));
SLIST_INIT(params.outputs); SLIST_INIT(params.outputs);
params.outputs_walk = NULL; params.outputs_walk = NULL;
params.cur_key = NULL; params.cur_key = NULL;
params.json = json; params.json = json;
yajl_handle handle; yajl_handle handle;
yajl_parser_config parse_conf = { 0, 0 }; yajl_parser_config parse_conf = { 0, 0 };
yajl_status state; yajl_status state;
handle = yajl_alloc(&outputs_callbacks, &parse_conf, NULL, (void*) &params);
state = yajl_parse(handle, (const unsigned char*) json, strlen(json)); handle = yajl_alloc(&outputs_callbacks, &parse_conf, NULL, (void*) &params);
/* FIXME: Propper errorhandling for JSON-parsing */ state = yajl_parse(handle, (const unsigned char*) json, strlen(json));
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) { /* FIXME: Propper errorhandling for JSON-parsing */
FREE_SLIST(outputs, i3_output); 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;
}
outputs = params.outputs; yajl_free(handle);
if (outputs != NULL) {
FREE_SLIST(outputs, i3_output);
}
outputs = params.outputs;
} }
i3_output* get_output_by_name(char* name) { i3_output *get_output_by_name(char *name) {
i3_output *walk; i3_output *walk;
SLIST_FOREACH(walk, outputs, slist) { SLIST_FOREACH(walk, outputs, slist) {
if (!strcmp(walk->name, name)) { if (!strcmp(walk->name, name)) {
break; break;
} }
} }
return walk; return walk;
} }

View File

@ -10,103 +10,103 @@
#include "ipc.h" #include "ipc.h"
struct workspaces_json_params { struct workspaces_json_params {
struct ws_head *workspaces; struct ws_head *workspaces;
i3_ws *workspaces_walk; i3_ws *workspaces_walk;
char *cur_key; char *cur_key;
char *json; char *json;
}; };
static int workspaces_null_cb(void* params_) { static int workspaces_null_cb(void *params_) {
struct workspaces_json_params* params = (struct workspaces_json_params*) params_; struct workspaces_json_params *params = (struct workspaces_json_params*) params_;
if (strcmp(params->cur_key, "current_workspace")) { if (strcmp(params->cur_key, "current_workspace")) {
return 0; return 0;
} }
FREE(params->cur_key); FREE(params->cur_key);
return 1; return 1;
} }
static int workspaces_boolean_cb(void* params_, bool val) { static int workspaces_boolean_cb(void *params_, bool val) {
struct workspaces_json_params* params = (struct workspaces_json_params*) params_; struct workspaces_json_params *params = (struct workspaces_json_params*) params_;
if (!strcmp(params->cur_key, "visible")) { if (!strcmp(params->cur_key, "visible")) {
params->workspaces_walk->visible = val; params->workspaces_walk->visible = val;
FREE(params->cur_key); FREE(params->cur_key);
return 1; return 1;
} }
if (!strcmp(params->cur_key, "focused")) { if (!strcmp(params->cur_key, "focused")) {
params->workspaces_walk->focused = val; params->workspaces_walk->focused = val;
FREE(params->cur_key); FREE(params->cur_key);
return 1; return 1;
} }
if (!strcmp(params->cur_key, "urgent")) { if (!strcmp(params->cur_key, "urgent")) {
params->workspaces_walk->urgent = val; params->workspaces_walk->urgent = val;
FREE(params->cur_key); FREE(params->cur_key);
return 1; return 1;
} }
FREE(params->cur_key); FREE(params->cur_key);
return 0; return 0;
} }
static int workspaces_integer_cb(void* params_, long val) { static int workspaces_integer_cb(void *params_, long val) {
struct workspaces_json_params* params = (struct workspaces_json_params*) params_; struct workspaces_json_params *params = (struct workspaces_json_params*) params_;
if (!strcmp(params->cur_key, "num")) { if (!strcmp(params->cur_key, "num")) {
params->workspaces_walk->num = (int) val; params->workspaces_walk->num = (int) val;
FREE(params->cur_key); FREE(params->cur_key);
return 1; return 1;
} }
if (!strcmp(params->cur_key, "x")) { if (!strcmp(params->cur_key, "x")) {
params->workspaces_walk->rect.x = (int) val; params->workspaces_walk->rect.x = (int) val;
FREE(params->cur_key); FREE(params->cur_key);
return 1; return 1;
} }
if (!strcmp(params->cur_key, "y")) { if (!strcmp(params->cur_key, "y")) {
params->workspaces_walk->rect.y = (int) val; params->workspaces_walk->rect.y = (int) val;
FREE(params->cur_key); FREE(params->cur_key);
return 1; 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")) { if (!strcmp(params->cur_key, "width")) {
params->workspaces_walk->rect.h = (int) val; params->workspaces_walk->rect.w = (int) val;
FREE(params->cur_key); FREE(params->cur_key);
return 1; return 1;
} }
FREE(params->cur_key); if (!strcmp(params->cur_key, "height")) {
return 0; 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")) { if (!strcmp(params->cur_key, "name")) {
params->workspaces_walk->name = malloc(sizeof(const unsigned char) * (len + 1)); params->workspaces_walk->name = malloc(sizeof(const unsigned char) * (len + 1));
strncpy(params->workspaces_walk->name, (const char*) val, len); 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", printf("Got Workspace %s, name_width: %d\n",
params->workspaces_walk->name, params->workspaces_walk->name,
params->workspaces_walk->name_width); params->workspaces_walk->name_width);
FREE(params->cur_key); FREE(params->cur_key);
return 1; return 1;
@ -115,12 +115,12 @@ static int workspaces_string_cb(void* params_, const unsigned char* val, unsigne
if (!strcmp(params->cur_key, "output")) { if (!strcmp(params->cur_key, "output")) {
output_name = malloc(sizeof(const unsigned char) * (len + 1)); output_name = malloc(sizeof(const unsigned char) * (len + 1));
strncpy(output_name, (const char*) val, len); 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); params->workspaces_walk->output = get_output_by_name(output_name);
TAILQ_INSERT_TAIL(params->workspaces_walk->output->workspaces, TAILQ_INSERT_TAIL(params->workspaces_walk->output->workspaces,
params->workspaces_walk, params->workspaces_walk,
tailq); tailq);
free(output_name); free(output_name);
return 1; return 1;
@ -129,98 +129,98 @@ static int workspaces_string_cb(void* params_, const unsigned char* val, unsigne
return 0; return 0;
} }
static int workspaces_start_map_cb(void* params_) { static int workspaces_start_map_cb(void *params_) {
struct workspaces_json_params* params = (struct workspaces_json_params*) 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) { if (params->cur_key == NULL) {
new_workspace = malloc(sizeof(i3_ws)); new_workspace = malloc(sizeof(i3_ws));
new_workspace->num = -1; new_workspace->num = -1;
new_workspace->name = NULL; new_workspace->name = NULL;
new_workspace->visible = 0; new_workspace->visible = 0;
new_workspace->focused = 0; new_workspace->focused = 0;
new_workspace->urgent = 0; new_workspace->urgent = 0;
memset(&new_workspace->rect, 0, sizeof(rect)); memset(&new_workspace->rect, 0, sizeof(rect));
new_workspace->output = NULL; new_workspace->output = NULL;
params->workspaces_walk = new_workspace; params->workspaces_walk = new_workspace;
return 1; return 1;
} }
return 1; return 1;
} }
static int workspaces_map_key_cb(void* params_, const unsigned char* keyVal, unsigned int keyLen) { 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_; struct workspaces_json_params *params = (struct workspaces_json_params*) params_;
FREE(params->cur_key); FREE(params->cur_key);
params->cur_key = malloc(sizeof(unsigned char) * (keyLen + 1)); params->cur_key = malloc(sizeof(unsigned char) * (keyLen + 1));
if (params->cur_key == NULL) { if (params->cur_key == NULL) {
printf("ERROR: Could not allocate memory!\n"); printf("ERROR: Could not allocate memory!\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
strncpy(params->cur_key, (const char*) keyVal, keyLen); strncpy(params->cur_key, (const char*) keyVal, keyLen);
params->cur_key[keyLen] = '\0'; params->cur_key[keyLen] = '\0';
return 1; return 1;
} }
yajl_callbacks workspaces_callbacks = { yajl_callbacks workspaces_callbacks = {
&workspaces_null_cb, &workspaces_null_cb,
&workspaces_boolean_cb, &workspaces_boolean_cb,
&workspaces_integer_cb, &workspaces_integer_cb,
NULL, NULL,
NULL, NULL,
&workspaces_string_cb, &workspaces_string_cb,
&workspaces_start_map_cb, &workspaces_start_map_cb,
&workspaces_map_key_cb, &workspaces_map_key_cb,
NULL, NULL,
NULL, NULL,
NULL NULL
}; };
void parse_workspaces_json(char* json) { void parse_workspaces_json(char *json) {
/* FIXME: Fasciliate stream-processing, i.e. allow starting to interpret /* FIXME: Fasciliate stream-processing, i.e. allow starting to interpret
* JSON in chunks */ * JSON in chunks */
struct workspaces_json_params params; struct workspaces_json_params params;
free_workspaces(); free_workspaces();
params.workspaces_walk = NULL; params.workspaces_walk = NULL;
params.cur_key = NULL; params.cur_key = NULL;
params.json = json; params.json = json;
yajl_handle handle; yajl_handle handle;
yajl_parser_config parse_conf = { 0, 0 }; yajl_parser_config parse_conf = { 0, 0 };
yajl_status state; yajl_status state;
handle = yajl_alloc(&workspaces_callbacks, &parse_conf, NULL, (void*) &params);
state = yajl_parse(handle, (const unsigned char*) json, strlen(json)); handle = yajl_alloc(&workspaces_callbacks, &parse_conf, NULL, (void*) &params);
/* FIXME: Propper errorhandling for JSON-parsing */ state = yajl_parse(handle, (const unsigned char*) json, strlen(json));
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); /* FIXME: Propper errorhandling for JSON-parsing */
switch (state) {
FREE(params.cur_key); 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() { void free_workspaces() {
i3_output *outputs_walk; i3_output *outputs_walk;
SLIST_FOREACH(outputs_walk, outputs, slist) { SLIST_FOREACH(outputs_walk, outputs, slist) {
if (outputs_walk->workspaces != NULL && !TAILQ_EMPTY(outputs_walk->workspaces)) { if (outputs_walk->workspaces != NULL && !TAILQ_EMPTY(outputs_walk->workspaces)) {
FREE_TAILQ(outputs_walk->workspaces, i3_ws); FREE_TAILQ(outputs_walk->workspaces, i3_ws);
} }
} }
} }

View File

@ -12,288 +12,288 @@
xcb_intern_atom_cookie_t atom_cookies[NUM_ATOMS]; xcb_intern_atom_cookie_t atom_cookies[NUM_ATOMS];
uint32_t get_colorpixel(const char *s) { uint32_t get_colorpixel(const char *s) {
char strings[3][3] = { { s[0], s[1], '\0'} , char strings[3][3] = { { s[0], s[1], '\0'} ,
{ s[2], s[3], '\0'} , { s[2], s[3], '\0'} ,
{ s[4], s[5], '\0'} }; { s[4], s[5], '\0'} };
uint8_t r = strtol(strings[0], NULL, 16); uint8_t r = strtol(strings[0], NULL, 16);
uint8_t g = strtol(strings[1], NULL, 16); uint8_t g = strtol(strings[1], NULL, 16);
uint8_t b = strtol(strings[2], NULL, 16); uint8_t b = strtol(strings[2], NULL, 16);
return (r << 16 | g << 8 | b); return (r << 16 | g << 8 | b);
} }
void handle_button(xcb_button_press_event_t *event) { void handle_button(xcb_button_press_event_t *event) {
i3_ws *cur_ws; i3_ws *cur_ws;
i3_output *walk; i3_output *walk;
xcb_window_t bar = event->event; xcb_window_t bar = event->event;
SLIST_FOREACH(walk, outputs, slist) { SLIST_FOREACH(walk, outputs, slist) {
if (walk->bar == bar) { if (walk->bar == bar) {
break; break;
} }
} }
if (walk == NULL) { if (walk == NULL) {
printf("Unknown Bar klicked!\n"); printf("Unknown Bar klicked!\n");
return; return;
} }
TAILQ_FOREACH(cur_ws, walk->workspaces, tailq) { TAILQ_FOREACH(cur_ws, walk->workspaces, tailq) {
if (cur_ws->visible) { if (cur_ws->visible) {
break; break;
} }
} }
if (cur_ws == NULL) { if (cur_ws == NULL) {
printf("No Workspace active?\n"); printf("No Workspace active?\n");
return; return;
} }
int32_t x = event->event_x; int32_t x = event->event_x;
printf("Got Button %d\n", event->detail); printf("Got Button %d\n", event->detail);
switch (event->detail) { switch (event->detail) {
case 1: case 1:
TAILQ_FOREACH(cur_ws, walk->workspaces, tailq) { TAILQ_FOREACH(cur_ws, walk->workspaces, tailq) {
printf("x = %d\n", x); printf("x = %d\n", x);
if (x < cur_ws->name_width + 10) { if (x < cur_ws->name_width + 10) {
break; break;
} }
x -= cur_ws->name_width + 10; x -= cur_ws->name_width + 10;
} }
if (cur_ws == NULL) { if (cur_ws == NULL) {
return; return;
} }
break; break;
case 4: case 4:
if (cur_ws == TAILQ_LAST(walk->workspaces, ws_head)) { if (cur_ws == TAILQ_LAST(walk->workspaces, ws_head)) {
cur_ws = TAILQ_FIRST(walk->workspaces); cur_ws = TAILQ_FIRST(walk->workspaces);
} else { } else {
cur_ws = TAILQ_NEXT(cur_ws, tailq); cur_ws = TAILQ_NEXT(cur_ws, tailq);
} }
break; break;
case 5: case 5:
if (cur_ws == TAILQ_FIRST(walk->workspaces)) { if (cur_ws == TAILQ_FIRST(walk->workspaces)) {
cur_ws = TAILQ_LAST(walk->workspaces, ws_head); cur_ws = TAILQ_LAST(walk->workspaces, ws_head);
} else { } else {
cur_ws = TAILQ_PREV(cur_ws, ws_head, tailq); cur_ws = TAILQ_PREV(cur_ws, ws_head, tailq);
} }
break; break;
} }
char buffer[50]; char buffer[50];
snprintf(buffer, 50, "%d", cur_ws->num); snprintf(buffer, 50, "%d", cur_ws->num);
i3_send_msg(I3_IPC_MESSAGE_TYPE_COMMAND, buffer); i3_send_msg(I3_IPC_MESSAGE_TYPE_COMMAND, buffer);
} }
void handle_xcb_event(xcb_generic_event_t *event) { void handle_xcb_event(xcb_generic_event_t *event) {
switch (event->response_type & ~0x80) { switch (event->response_type & ~0x80) {
case XCB_EXPOSE: case XCB_EXPOSE:
draw_buttons(); draw_buttons();
break; break;
case XCB_BUTTON_PRESS: case XCB_BUTTON_PRESS:
handle_button((xcb_button_press_event_t*) event); handle_button((xcb_button_press_event_t*) event);
break; break;
} }
} }
int get_string_width(char *string) { int get_string_width(char *string) {
xcb_query_text_extents_cookie_t cookie; xcb_query_text_extents_cookie_t cookie;
xcb_query_text_extents_reply_t *reply; xcb_query_text_extents_reply_t *reply;
xcb_generic_error_t *error; xcb_generic_error_t *error;
int width; int width;
cookie = xcb_query_text_extents(xcb_connection, xcb_font, strlen(string), (xcb_char2b_t *)string); 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) { if ((reply= xcb_query_text_extents_reply(xcb_connection, cookie, &error)) == NULL) {
printf("ERROR: Could not get text extents!"); printf("ERROR: Could not get text extents!");
return 7; return 7;
} }
width = reply->overall_width; width = reply->overall_width;
free(reply); free(reply);
return width; return width;
} }
void init_xcb() { void init_xcb() {
/* FIXME: xcb_connect leaks Memory */ /* FIXME: xcb_connect leaks Memory */
xcb_connection = xcb_connect(NULL, NULL); xcb_connection = xcb_connect(NULL, NULL);
if (xcb_connection_has_error(xcb_connection)) { if (xcb_connection_has_error(xcb_connection)) {
printf("Cannot open display\n"); printf("Cannot open display\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
printf("Connected to xcb\n"); printf("Connected to xcb\n");
/* We have to request the atoms we need */ /* We have to request the atoms we need */
#define ATOM_DO(name) atom_cookies[name] = xcb_intern_atom(xcb_connection, 0, strlen(#name), #name); #define ATOM_DO(name) atom_cookies[name] = xcb_intern_atom(xcb_connection, 0, strlen(#name), #name);
#include "xcb_atoms.def" #include "xcb_atoms.def"
xcb_screens = xcb_setup_roots_iterator(xcb_get_setup(xcb_connection)).data; xcb_screens = xcb_setup_roots_iterator(xcb_get_setup(xcb_connection)).data;
xcb_root = xcb_screens->root; xcb_root = xcb_screens->root;
xcb_font = xcb_generate_id(xcb_connection); xcb_font = xcb_generate_id(xcb_connection);
char *fontname = "-misc-fixed-medium-r-semicondensed--12-110-75-75-c-60-iso10646-1"; char *fontname = "-misc-fixed-medium-r-semicondensed--12-110-75-75-c-60-iso10646-1";
xcb_open_font(xcb_connection, xcb_open_font(xcb_connection,
xcb_font, xcb_font,
strlen(fontname), strlen(fontname),
fontname); fontname);
xcb_list_fonts_with_info_cookie_t cookie; xcb_list_fonts_with_info_cookie_t cookie;
cookie = xcb_list_fonts_with_info(xcb_connection, cookie = xcb_list_fonts_with_info(xcb_connection,
1, 1,
strlen(fontname), strlen(fontname),
fontname); fontname);
xcb_list_fonts_with_info_reply_t *reply; xcb_list_fonts_with_info_reply_t *reply;
reply = xcb_list_fonts_with_info_reply(xcb_connection, reply = xcb_list_fonts_with_info_reply(xcb_connection,
cookie, cookie,
NULL); NULL);
font_height = reply->font_ascent + reply->font_descent; font_height = reply->font_ascent + reply->font_descent;
printf("Calculated Font-height: %d\n", font_height); printf("Calculated Font-height: %d\n", font_height);
/* FIXME: Maybe we can push that further backwards */ /* FIXME: Maybe we can push that further backwards */
get_atoms(); get_atoms();
} }
void clean_xcb() { void clean_xcb() {
xcb_disconnect(xcb_connection); xcb_disconnect(xcb_connection);
} }
void get_atoms() { void get_atoms() {
xcb_intern_atom_reply_t* reply; xcb_intern_atom_reply_t *reply;
#define ATOM_DO(name) reply = xcb_intern_atom_reply(xcb_connection, atom_cookies[name], NULL); \ #define ATOM_DO(name) reply = xcb_intern_atom_reply(xcb_connection, atom_cookies[name], NULL); \
atoms[name] = reply->atom; \ atoms[name] = reply->atom; \
free(reply); free(reply);
#include "xcb_atoms.def" #include "xcb_atoms.def"
printf("Got Atoms\n"); printf("Got Atoms\n");
} }
void destroy_windows() { void destroy_windows() {
i3_output *walk; i3_output *walk;
if (outputs == NULL) { if (outputs == NULL) {
return; return;
} }
SLIST_FOREACH(walk, outputs, slist) { SLIST_FOREACH(walk, outputs, slist) {
if (walk->bar == XCB_NONE) { if (walk->bar == XCB_NONE) {
continue; continue;
} }
xcb_destroy_window(xcb_connection, walk->bar); xcb_destroy_window(xcb_connection, walk->bar);
walk->bar = XCB_NONE; walk->bar = XCB_NONE;
} }
} }
void create_windows() { void create_windows() {
uint32_t mask; uint32_t mask;
uint32_t values[2]; uint32_t values[2];
i3_output *walk; i3_output *walk;
SLIST_FOREACH(walk, outputs, slist) { SLIST_FOREACH(walk, outputs, slist) {
if (!walk->active) { if (!walk->active) {
continue; continue;
} }
printf("Creating Window for output %s\n", walk->name); printf("Creating Window for output %s\n", walk->name);
walk->bar = xcb_generate_id(xcb_connection); walk->bar = xcb_generate_id(xcb_connection);
mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
values[0] = xcb_screens->black_pixel; values[0] = xcb_screens->black_pixel;
values[1] = XCB_EVENT_MASK_EXPOSURE | values[1] = XCB_EVENT_MASK_EXPOSURE |
XCB_EVENT_MASK_BUTTON_PRESS; XCB_EVENT_MASK_BUTTON_PRESS;
xcb_create_window(xcb_connection, xcb_create_window(xcb_connection,
xcb_screens->root_depth, xcb_screens->root_depth,
walk->bar, walk->bar,
xcb_root, xcb_root,
walk->rect.x, walk->rect.y, walk->rect.x, walk->rect.y,
walk->rect.w, font_height + 6, walk->rect.w, font_height + 6,
1, 1,
XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_WINDOW_CLASS_INPUT_OUTPUT,
xcb_screens->root_visual, xcb_screens->root_visual,
mask, mask,
values); values);
xcb_change_property(xcb_connection, xcb_change_property(xcb_connection,
XCB_PROP_MODE_REPLACE, XCB_PROP_MODE_REPLACE,
walk->bar, walk->bar,
atoms[_NET_WM_WINDOW_TYPE], atoms[_NET_WM_WINDOW_TYPE],
atoms[ATOM], atoms[ATOM],
32, 32,
1, 1,
(unsigned char*) &atoms[_NET_WM_WINDOW_TYPE_DOCK]); (unsigned char*) &atoms[_NET_WM_WINDOW_TYPE_DOCK]);
walk->bargc = xcb_generate_id(xcb_connection); walk->bargc = xcb_generate_id(xcb_connection);
mask = XCB_GC_FONT; mask = XCB_GC_FONT;
values[0] = xcb_font; values[0] = xcb_font;
xcb_create_gc(xcb_connection, xcb_create_gc(xcb_connection,
walk->bargc, walk->bargc,
walk->bar, walk->bar,
mask, mask,
values); values);
xcb_map_window(xcb_connection, walk->bar); xcb_map_window(xcb_connection, walk->bar);
} }
xcb_flush(xcb_connection); xcb_flush(xcb_connection);
} }
void draw_buttons() { void draw_buttons() {
printf("Drawing Buttons...\n"); printf("Drawing Buttons...\n");
int i = 0; int i = 0;
i3_output *outputs_walk; i3_output *outputs_walk;
SLIST_FOREACH(outputs_walk, outputs, slist) { SLIST_FOREACH(outputs_walk, outputs, slist) {
if (!outputs_walk->active) { if (!outputs_walk->active) {
printf("Output %s inactive, skipping...\n", outputs_walk->name); printf("Output %s inactive, skipping...\n", outputs_walk->name);
continue; continue;
} }
if (outputs_walk->bar == XCB_NONE) { if (outputs_walk->bar == XCB_NONE) {
create_windows(); create_windows();
} }
uint32_t color = get_colorpixel("000000"); uint32_t color = get_colorpixel("000000");
xcb_change_gc(xcb_connection, xcb_change_gc(xcb_connection,
outputs_walk->bargc, outputs_walk->bargc,
XCB_GC_FOREGROUND, XCB_GC_FOREGROUND,
&color); &color);
xcb_rectangle_t rect = { 0, 0, outputs_walk->rect.w, font_height + 6 }; xcb_rectangle_t rect = { 0, 0, outputs_walk->rect.w, font_height + 6 };
xcb_poly_fill_rectangle(xcb_connection, xcb_poly_fill_rectangle(xcb_connection,
outputs_walk->bar, outputs_walk->bar,
outputs_walk->bargc, outputs_walk->bargc,
1, 1,
&rect); &rect);
i3_ws *ws_walk; i3_ws *ws_walk;
TAILQ_FOREACH(ws_walk, outputs_walk->workspaces, tailq) { TAILQ_FOREACH(ws_walk, outputs_walk->workspaces, tailq) {
printf("Drawing Button for WS %s at x = %d\n", ws_walk->name, i); printf("Drawing Button for WS %s at x = %d\n", ws_walk->name, i);
uint32_t color = get_colorpixel("240000"); uint32_t color = get_colorpixel("240000");
if (ws_walk->visible) { if (ws_walk->visible) {
color = get_colorpixel("480000"); color = get_colorpixel("480000");
} }
if (ws_walk->urgent) { if (ws_walk->urgent) {
printf("WS %s is urgent!\n", ws_walk->name); printf("WS %s is urgent!\n", ws_walk->name);
color = get_colorpixel("002400"); color = get_colorpixel("002400");
} }
xcb_change_gc(xcb_connection, xcb_change_gc(xcb_connection,
outputs_walk->bargc, outputs_walk->bargc,
XCB_GC_FOREGROUND, XCB_GC_FOREGROUND,
&color); &color);
xcb_change_gc(xcb_connection, xcb_change_gc(xcb_connection,
outputs_walk->bargc, outputs_walk->bargc,
XCB_GC_BACKGROUND, XCB_GC_BACKGROUND,
&color); &color);
xcb_rectangle_t rect = { i + 1, 1, ws_walk->name_width + 8, font_height + 4 }; xcb_rectangle_t rect = { i + 1, 1, ws_walk->name_width + 8, font_height + 4 };
xcb_poly_fill_rectangle(xcb_connection, xcb_poly_fill_rectangle(xcb_connection,
outputs_walk->bar, outputs_walk->bar,
outputs_walk->bargc, outputs_walk->bargc,
1, 1,
&rect); &rect);
color = get_colorpixel("FFFFFF"); color = get_colorpixel("FFFFFF");
xcb_change_gc(xcb_connection, xcb_change_gc(xcb_connection,
outputs_walk->bargc, outputs_walk->bargc,
XCB_GC_FOREGROUND, XCB_GC_FOREGROUND,
&color); &color);
xcb_image_text_8(xcb_connection, xcb_image_text_8(xcb_connection,
strlen(ws_walk->name), strlen(ws_walk->name),
outputs_walk->bar, outputs_walk->bar,
outputs_walk->bargc, outputs_walk->bargc,
i + 5, font_height + 1, i + 5, font_height + 1,
ws_walk->name); ws_walk->name);
i += 10 + ws_walk->name_width; i += 10 + ws_walk->name_width;
} }
i = 0; i = 0;
} }
xcb_flush(xcb_connection); xcb_flush(xcb_connection);
} }