[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Add id objects for tags.



<nullie> is there way to get tag name by id, easier than parsing tag_status ?
<The-Compiler> heh, why does the tags object only have a by-name, and no by-id? :P
<The-Compiler> if it had, it'd be easy \o/

And so this was born.

-- 
() ascii ribbon campaign - stop html mail    www.asciiribbon.org
/\ www.the-compiler.org  | I love long mails http://email.is-not-s.ms/
I just thought of something funny...your mother. - Cheech Marin 
From 52638a947d708032c464e729bb18d52d6f418483 Mon Sep 17 00:00:00 2001
From: Florian Bruhin <git _at_ the _minus_ compiler _dot_ org>
Date: Mon, 21 Apr 2014 18:44:43 +0200
Subject: [PATCH] Add tag id objects.

---
 src/tag.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/src/tag.c b/src/tag.c
index 483495b..831abde 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -205,6 +205,20 @@ static int tag_attr_index(void* data) {
     return tag_index_of(tag);
 }
 
+static void tag_unlink_id_object(HSTag* tag, void* data) {
+    (void)data;
+    hsobject_unlink(g_tag_object, tag->object);
+}
+
+static void tag_link_id_object(HSTag* tag, void* data) {
+    (void)data;
+    GString* index_str = g_string_new("");
+    int index = tag_index_of(tag);
+    g_string_printf(index_str, "%d", index);
+    hsobject_link(g_tag_object, tag->object, index_str->str);
+    g_string_free(index_str, true);
+}
+
 HSTag* add_tag(char* name) {
     HSTag* find_result = find_tag(name);
     if (find_result) {
@@ -233,6 +247,7 @@ HSTag* add_tag(char* name) {
         ATTRIBUTE_LAST,
     };
     hsobject_set_attributes(tag->object, attributes);
+    tag_link_id_object(tag, NULL);
 
     ewmh_update_desktops();
     ewmh_update_desktop_names();
@@ -332,6 +347,7 @@ int tag_remove_command(int argc, char** argv, GString* 
output) {
         }
     }
     g_free(buf);
+    tag_foreach(tag_unlink_id_object, NULL);
     // remove tag
     char* oldname = g_strdup(tag->name->str);
     tag_free(tag);
@@ -347,6 +363,7 @@ int tag_remove_command(int argc, char** argv, GString* 
output) {
     tag_set_flags_dirty();
     hook_emit_list("tag_removed", oldname, target->name->str, NULL);
     g_free(oldname);
+    tag_foreach(tag_link_id_object, NULL);
     return 0;
 }
 
-- 
1.9.2

Attachment: pgpmbDAd9y61P.pgp
Description: PGP signature