]> git.sur5r.net Git - i3/i3/blobdiff - i3bar/src/xcb.c
Add licensing information
[i3/i3] / i3bar / src / xcb.c
index 21d7df39baff21e1a6720c7fec530302a881a1d3..ae1c8278ad1500298c6bec02c95ea2aca80479f5 100644 (file)
@@ -1,3 +1,13 @@
+/*
+ * 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>
@@ -102,18 +112,18 @@ void handle_button(xcb_button_press_event_t *event) {
             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;
     }
@@ -123,25 +133,6 @@ void handle_button(xcb_button_press_event_t *event) {
     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)
@@ -156,13 +147,22 @@ void xcb_prep_cb(struct ev_loop *loop, ev_prepare *watcher, int revenst) {
  * 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);
 }
@@ -232,15 +232,6 @@ void init_xcb(char *fontname) {
                                       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));
@@ -257,6 +248,16 @@ void init_xcb(char *fontname) {
 
     /* Now we get the atoms and save them in a nice data-structure */
     get_atoms();
+
+    /* Now we calculate the font-height */
+    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);
 }
 
 /*
@@ -265,7 +266,12 @@ void init_xcb(char *fontname) {
  *
  */
 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);