]> git.sur5r.net Git - i3/i3/blobdiff - i3bar/src/workspaces.c
Remove yajl major version conditionals
[i3/i3] / i3bar / src / workspaces.c
index 5df1899f33a408f4a8429a52acaa3a2b060c8f7a..4e6854cf7a79fab06ef80e191fdf03b615344d1a 100644 (file)
@@ -2,7 +2,7 @@
  * vim:ts=4:sw=4:expandtab
  *
  * i3bar - an xcb-based status- and ws-bar for i3
- * © 2010-2011 Axel Wagner and contributors (see also: LICENSE)
+ * © 2010-2012 Axel Wagner and contributors (see also: LICENSE)
  *
  * workspaces.c: Maintaining the workspace-lists
  *
@@ -58,11 +58,7 @@ static int workspaces_boolean_cb(void *params_, int val) {
  * Parse an integer (num or the rect)
  *
  */
-#if YAJL_MAJOR >= 2
 static int workspaces_integer_cb(void *params_, long long val) {
-#else
-static int workspaces_integer_cb(void *params_, long val) {
-#endif
     struct workspaces_json_params *params = (struct workspaces_json_params*) params_;
 
     if (!strcmp(params->cur_key, "num")) {
@@ -103,34 +99,23 @@ static int workspaces_integer_cb(void *params_, long val) {
  * Parse a string (name, output)
  *
  */
-#if YAJL_MAJOR >= 2
 static int workspaces_string_cb(void *params_, const unsigned char *val, size_t len) {
-#else
-static int workspaces_string_cb(void *params_, const unsigned char *val, unsigned int len) {
-#endif
         struct workspaces_json_params *params = (struct workspaces_json_params*) params_;
 
         char *output_name;
 
         if (!strcmp(params->cur_key, "name")) {
             /* Save the name */
-            params->workspaces_walk->name = smalloc(sizeof(const unsigned char) * (len + 1));
-            strncpy(params->workspaces_walk->name, (const char*) val, len);
-            params->workspaces_walk->name[len] = '\0';
-
-            /* Convert the name to ucs2, save its length in glyphs and calculate its rendered width */
-            size_t ucs2_len;
-            xcb_char2b_t *ucs2_name = (xcb_char2b_t*) convert_utf8_to_ucs2(params->workspaces_walk->name, &ucs2_len);
-            params->workspaces_walk->ucs2_name = ucs2_name;
-            params->workspaces_walk->name_glyphs = ucs2_len;
+            params->workspaces_walk->name = i3string_from_utf8_with_length((const char *)val, len);
+
+            /* Save its rendered width */
             params->workspaces_walk->name_width =
-                predict_text_width((char *)params->workspaces_walk->ucs2_name,
-                params->workspaces_walk->name_glyphs, true);
+                predict_text_width(params->workspaces_walk->name);
 
-            DLOG("Got Workspace %s, name_width: %d, glyphs: %d\n",
-                 params->workspaces_walk->name,
+            DLOG("Got Workspace %s, name_width: %d, glyphs: %zu\n",
+                 i3string_as_utf8(params->workspaces_walk->name),
                  params->workspaces_walk->name_width,
-                 params->workspaces_walk->name_glyphs);
+                 i3string_get_num_glyphs(params->workspaces_walk->name));
             FREE(params->cur_key);
 
             return 1;
@@ -189,11 +174,7 @@ static int workspaces_start_map_cb(void *params_) {
  * Essentially we just save it in the parsing-state
  *
  */
-#if YAJL_MAJOR >= 2
 static int workspaces_map_key_cb(void *params_, const unsigned char *keyVal, size_t keyLen) {
-#else
-static int workspaces_map_key_cb(void *params_, const unsigned char *keyVal, unsigned int keyLen) {
-#endif
     struct workspaces_json_params *params = (struct workspaces_json_params*) params_;
     FREE(params->cur_key);
 
@@ -205,18 +186,12 @@ static int workspaces_map_key_cb(void *params_, const unsigned char *keyVal, uns
 }
 
 /* A datastructure to pass all these callbacks to yajl */
-yajl_callbacks workspaces_callbacks = {
-    NULL,
-    &workspaces_boolean_cb,
-    &workspaces_integer_cb,
-    NULL,
-    NULL,
-    &workspaces_string_cb,
-    &workspaces_start_map_cb,
-    &workspaces_map_key_cb,
-    NULL,
-    NULL,
-    NULL
+static yajl_callbacks workspaces_callbacks = {
+    .yajl_boolean = workspaces_boolean_cb,
+    .yajl_integer = workspaces_integer_cb,
+    .yajl_string = workspaces_string_cb,
+    .yajl_start_map = workspaces_start_map_cb,
+    .yajl_map_key = workspaces_map_key_cb,
 };
 
 /*
@@ -236,13 +211,7 @@ void parse_workspaces_json(char *json) {
 
     yajl_handle handle;
     yajl_status state;
-#if YAJL_MAJOR < 2
-    yajl_parser_config parse_conf = { 0, 0 };
-
-    handle = yajl_alloc(&workspaces_callbacks, &parse_conf, NULL, (void*) &params);
-#else
     handle = yajl_alloc(&workspaces_callbacks, NULL, (void*) &params);
-#endif
 
     state = yajl_parse(handle, (const unsigned char*) json, strlen(json));
 
@@ -251,9 +220,6 @@ void parse_workspaces_json(char *json) {
         case yajl_status_ok:
             break;
         case yajl_status_client_canceled:
-#if YAJL_MAJOR < 2
-        case yajl_status_insufficient_data:
-#endif
         case yajl_status_error:
             ELOG("Could not parse workspaces-reply!\n");
             exit(EXIT_FAILURE);
@@ -269,7 +235,7 @@ void parse_workspaces_json(char *json) {
  * free() all workspace data-structures. Does not free() the heads of the tailqueues.
  *
  */
-void free_workspaces() {
+void free_workspaces(void) {
     i3_output *outputs_walk;
     if (outputs == NULL) {
         return;
@@ -279,8 +245,7 @@ void free_workspaces() {
     SLIST_FOREACH(outputs_walk, outputs, slist) {
         if (outputs_walk->workspaces != NULL && !TAILQ_EMPTY(outputs_walk->workspaces)) {
             TAILQ_FOREACH(ws_walk, outputs_walk->workspaces, tailq) {
-                FREE(ws_walk->name);
-                FREE(ws_walk->ucs2_name);
+                I3STRING_FREE(ws_walk->name);
             }
             FREE_TAILQ(outputs_walk->workspaces, i3_ws);
         }