]> git.sur5r.net Git - i3/i3/blobdiff - src/util.c
Don’t rely on libxcb-wm any longer, as it got removed in libxcb 0.3.4
[i3/i3] / src / util.c
index 880be2d6526d48d72c6db9ed0e8d11e2a504c68d..276f76f92be4cbd6fb6ac3321c19ea884e2c3376 100644 (file)
@@ -29,6 +29,8 @@
 #include "xcb.h"
 
 static iconv_t conversion_descriptor = 0;
+struct keyvalue_table_head by_parent = TAILQ_HEAD_INITIALIZER(by_parent);
+struct keyvalue_table_head by_child = TAILQ_HEAD_INITIALIZER(by_child);
 
 int min(int a, int b) {
         return (a < b ? a : b);
@@ -96,6 +98,44 @@ char *sstrdup(const char *str) {
         return result;
 }
 
+/*
+ * The table_* functions emulate the behaviour of libxcb-wm, which in libxcb 0.3.4 suddenly
+ * vanished. Great.
+ *
+ */
+bool table_put(struct keyvalue_table_head *head, uint32_t key, void *value) {
+        struct keyvalue_element *element = scalloc(sizeof(struct keyvalue_element));
+        element->key = key;
+        element->value = value;
+
+        TAILQ_INSERT_TAIL(head, element, elements);
+        return true;
+}
+
+void *table_remove(struct keyvalue_table_head *head, uint32_t key) {
+        struct keyvalue_element *element;
+
+        TAILQ_FOREACH(element, head, elements)
+                if (element->key == key) {
+                        void *value = element->value;
+                        TAILQ_REMOVE(head, element, elements);
+                        free(element);
+                        return value;
+                }
+
+        return NULL;
+}
+
+void *table_get(struct keyvalue_table_head *head, uint32_t key) {
+        struct keyvalue_element *element;
+
+        TAILQ_FOREACH(element, head, elements)
+                if (element->key == key)
+                        return element->value;
+
+        return NULL;
+}
+
 /*
  * Starts the given application by passing it through a shell. We use double fork
  * to avoid zombie processes. As the started application’s parent exits (immediately),