]> Dogcows Code - chaz/openbox/commitdiff
give actions a ref count
authorDana Jansens <danakj@orodu.net>
Fri, 26 Sep 2003 16:47:12 +0000 (16:47 +0000)
committerDana Jansens <danakj@orodu.net>
Fri, 26 Sep 2003 16:47:12 +0000 (16:47 +0000)
openbox/action.c
openbox/action.h
openbox/keytree.c
openbox/menu.c
openbox/mouse.c

index bef8768039d80488527029dfc92fcd833a0f008e..52a602ccf7071ba53818f0737a8307c4a5083d0c 100644 (file)
@@ -65,19 +65,26 @@ typedef struct
     void (*setup)(ObAction **, ObUserAction uact);
 } ActionString;
 
-static ObAction *action_new(void (*func)(union ActionData *data),
-                            ObUserAction uact)
+static ObAction *action_new(void (*func)(union ActionData *data))
 {
     ObAction *a = g_new0(ObAction, 1);
+    a->ref = 1;
     a->func = func;
 
     return a;
 }
 
-void action_free(ObAction *a)
+void action_ref(ObAction *a)
+{
+    ++a->ref;
+}
+
+void action_unref(ObAction *a)
 {
     if (a == NULL) return;
 
+    if (--a->ref > 0) return;
+
     /* deal with pointers */
     if (a->func == action_execute || a->func == action_restart)
         g_free(a->data.execute.path);
@@ -359,7 +366,7 @@ void setup_action_showmenu(ObAction **a, ObUserAction uact)
        assumptions that there is only one menu (and submenus) open at
        a time! */
     if (uact == OB_USER_ACTION_MENU_SELECTION) {
-        action_free(*a);
+        action_unref(*a);
         a = NULL;
     }
 }
@@ -772,7 +779,7 @@ ObAction *action_from_string(const gchar *name, ObUserAction uact)
     for (i = 0; actionstrings[i].name; i++)
         if (!g_ascii_strcasecmp(name, actionstrings[i].name)) {
             exist = TRUE;
-            a = action_new(actionstrings[i].func, uact);
+            a = action_new(actionstrings[i].func);
             if (actionstrings[i].setup)
                 actionstrings[i].setup(&a, uact);
             /* only key bindings can be interactive. thus saith the xor.
index 3edc96b90f7bbf04ae5998c12c064a4264921096..a2f941ed264240d91a76e9e9ffcc82620eea4346 100644 (file)
@@ -152,7 +152,8 @@ union ActionData {
 };
 
 struct _ObAction {
-    ObUserAction act;
+    guint ref;
+
     /* The func member acts like an enum to tell which one of the structs in
        the data union are valid.
     */
@@ -176,7 +177,8 @@ struct _ObAction {
 ObAction *action_from_string(const gchar *name, ObUserAction uact);
 ObAction *action_parse(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
                        ObUserAction uact);
-void action_free(ObAction *a);
+void action_ref(ObAction *a);
+void action_unref(ObAction *a);
 
 /*! Executes a list of actions.
   @param c The client associated with the action. Can be NULL.
index 960b0506053503a80f6181d13901e358a93ed767..02ad3cadd899298ee37b317c531980af49f81788 100644 (file)
@@ -34,7 +34,7 @@ void tree_destroy(KeyBindingTree *tree)
                g_free(it->data);
            g_list_free(tree->keylist);
            for (sit = tree->actions; sit != NULL; sit = sit->next)
-                action_free(sit->data);
+                action_unref(sit->data);
            g_slist_free(tree->actions);
        }
        g_free(tree);
index cf3fa5551b6c1661e887fb14e3cc708b37c7bb9d..2bd382cbab5227e3426ce803f44760a1225ee338 100644 (file)
@@ -326,7 +326,7 @@ void menu_entry_free(ObMenuEntry *self)
         case OB_MENU_ENTRY_TYPE_NORMAL:
             g_free(self->data.normal.label);
             while (self->data.normal.actions) {
-                action_free(self->data.normal.actions->data);
+                action_unref(self->data.normal.actions->data);
                 self->data.normal.actions =
                     g_slist_delete_link(self->data.normal.actions,
                                         self->data.normal.actions);
index 0fd2a8286e98548c16e53c97990c1bcd048634aa..414be04e47cdc3f256a7fa75023209d9549bb9d5 100644 (file)
@@ -142,7 +142,7 @@ void mouse_unbind_all()
                 GSList *it;
 
                 for (it = b->actions[j]; it; it = it->next)
-                    action_free(it->data);
+                    action_unref(it->data);
                 g_slist_free(b->actions[j]);
             }
             g_free(b);
This page took 0.032625 seconds and 4 git commands to generate.