+/*
+ * i3bar - an xcb-based status- and ws-bar for i3
+ *
+ * © 2010 Axel Wagner and contributors
+ *
+ * See file LICNSE for license information
+ *
+ * src/xcb.c: Communicating with X
+ *
+ */
#include <xcb/xcb.h>
#include <xcb/xproto.h>
#include <xcb/xcb_event.h>
break;
case 4:
/* Mouse wheel down. We select the next ws */
- if (cur_ws == TAILQ_FIRST(walk->workspaces, ws_head)) {
- cur_ws = TAILQ_LAST(walk->workspaces);
+ if (cur_ws == TAILQ_FIRST(walk->workspaces)) {
+ cur_ws = TAILQ_LAST(walk->workspaces, ws_head);
} else {
- cur_ws = TAILQ_PREV(cur_ws, tailq);
+ cur_ws = TAILQ_PREV(cur_ws, ws_head, tailq);
}
break;
case 5:
/* Mouse wheel up. We select the previos ws */
- if (cur_ws == TAILQ_LAST(walk->workspaces)) {
- cur_ws = TAILQ_FIRST(walk->workspaces, ws_head);
+ if (cur_ws == TAILQ_LAST(walk->workspaces, ws_head)) {
+ cur_ws = TAILQ_FIRST(walk->workspaces);
} else {
- cur_ws = TAILQ_NEXT(cur_ws, ws_head, tailq);
+ cur_ws = TAILQ_NEXT(cur_ws, tailq);
}
break;
}
i3_send_msg(I3_IPC_MESSAGE_TYPE_COMMAND, buffer);
}
-/*
- * An X-Event occured, we determine, what kind and call the appropriate handler
- *
- * FIXME: Merge this in ev_chk_cb(), the additional call is superflous
- *
- */
-void handle_xcb_event(xcb_generic_event_t *event) {
- switch (event->response_type & ~0x80) {
- case XCB_EXPOSE:
- /* Expose-events happen, when the window needs to be redrawn */
- draw_bars();
- break;
- case XCB_BUTTON_PRESS:
- /* Button-press-events are mouse-buttons clicked on one of our bars */
- handle_button((xcb_button_press_event_t*) event);
- break;
- }
-}
-
/*
* This function is called immediately bevor the main loop locks. We flush xcb
* then (and only then)
* of the watchers registered an event.
* We check wether an X-Event arrived and handle it.
*
- * FIXME: use a while-loop, to account for the xcb buffer
- *
*/
void xcb_chk_cb(struct ev_loop *loop, ev_check *watcher, int revents) {
xcb_generic_event_t *event;
- if ((event = xcb_poll_for_event(xcb_connection)) != NULL) {
- handle_xcb_event(event);
+ while ((event = xcb_poll_for_event(xcb_connection)) == NULL) {
+ return;
+ }
+
+ switch (event->response_type & ~0x80) {
+ case XCB_EXPOSE:
+ /* Expose-events happen, when the window needs to be redrawn */
+ draw_bars();
+ break;
+ case XCB_BUTTON_PRESS:
+ /* Button-press-events are mouse-buttons clicked on one of our bars */
+ handle_button((xcb_button_press_event_t*) event);
+ break;
}
FREE(event);
}
1,
strlen(fontname),
fontname);
- /* FIXME: push this to the end of init_xcb() */
- 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;
- FREE(reply);
-
- printf("Calculated Font-height: %d\n", font_height);
/* The varios Watchers to communicate with xcb */
xcb_io = malloc(sizeof(ev_io));
/* Now we get the atoms and save them in a nice data-structure */
get_atoms();
+
+ /* Now we calculate the font-height */
+ 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;
+ FREE(reply);
+
+ printf("Calculated Font-height: %d\n", font_height);
}
/*
*
*/
void clean_xcb() {
- /* FIXME: destroy() the bars first */
+ i3_output *walk;
+ SLIST_FOREACH(walk, outputs, slist) {
+ destroy_window(walk);
+ }
+ FREE_SLIST(outputs, i3_output);
+
xcb_disconnect(xcb_connection);
ev_check_stop(main_loop, xcb_chk);