]> Dogcows Code - chaz/openbox/commitdiff
make the execute action not segfault when using a prompt (bug #4543)
authorDana Jansens <danakj@orodu.net>
Thu, 11 Feb 2010 15:25:35 +0000 (10:25 -0500)
committerDana Jansens <danakj@orodu.net>
Thu, 11 Feb 2010 16:01:18 +0000 (11:01 -0500)
also save the client when using a prompt so it can be used if you choose "yes" from the prompt

openbox/actions/execute.c

index 0e9e7387e518cc19f55382c8ac937ac79367ad2f..ed205364bac4b192f8aacf70fc3e93c98908c75b 100644 (file)
@@ -18,22 +18,34 @@ typedef struct {
     gchar   *sn_icon;
     gchar   *sn_wmclass;
     gchar   *prompt;
+    ObActionsData *data;
 } Options;
 
 static gpointer setup_func(xmlNodePtr node);
 static void     free_func(gpointer options);
 static gboolean run_func(ObActionsData *data, gpointer options);
-/*
-static gboolean i_input_func(guint initial_state,
-                             XEvent *e,
-                             gpointer options,
-                             gboolean *used);
-static void     i_cancel_func(gpointer options);
-*/
+static void shutdown_func(void);
+static void client_dest(ObClient *client, gpointer data);
+
+static GSList *prompt_opts = NULL;
 
 void action_execute_startup(void)
 {
     actions_register("Execute", setup_func, free_func, run_func);
+    actions_set_shutdown("Execute", shutdown_func);
+
+    client_add_destroy_notify(client_dest, NULL);
+}
+
+static void client_dest(ObClient *client, gpointer data)
+{
+    GSList *it;
+
+    for (it = prompt_opts; it; it = g_slist_next(it)) {
+        Options *o = it->data;
+        if (o->data->client == client)
+            o->data->client = NULL;
+    }
 }
 
 static gpointer setup_func(xmlNodePtr node)
@@ -68,21 +80,29 @@ static gpointer setup_func(xmlNodePtr node)
     return o;
 }
 
+static void shutdown_func(void)
+{
+    client_remove_destroy_notify(client_dest);
+}
+
 static void free_func(gpointer options)
 {
     Options *o = options;
 
     if (o) {
+        prompt_opts = g_slist_remove(prompt_opts, o);
+
         g_free(o->cmd);
         g_free(o->sn_name);
         g_free(o->sn_icon);
         g_free(o->sn_wmclass);
         g_free(o->prompt);
+        if (o->data) g_free(o->data);
         g_free(o);
     }
 }
 
-static Options* dup_options(Options *in)
+static Options* dup_options(Options *in, ObActionsData *data)
 {
     Options *o = g_new(Options, 1);
     o->cmd = g_strdup(in->cmd);
@@ -91,15 +111,15 @@ static Options* dup_options(Options *in)
     o->sn_icon = g_strdup(in->sn_icon);
     o->sn_wmclass = g_strdup(in->sn_wmclass);
     o->prompt = NULL;
+    o->data = g_memdup(data, sizeof(ObActionsData));
     return o;
 }
 
-static gboolean run_func(ObActionsData *data, gpointer options);
-
 static gboolean prompt_cb(ObPrompt *p, gint result, gpointer options)
 {
+    Options *o = options;
     if (result)
-        run_func(NULL, options);
+        run_func(o->data, o);
     return TRUE; /* call the cleanup func */
 }
 
@@ -127,7 +147,7 @@ static gboolean run_func(ObActionsData *data, gpointer options)
             { _("Yes"), 1 }
         };
 
-        ocp = dup_options(options);
+        ocp = dup_options(options, data);
         p = prompt_new(o->prompt, _("Execute"), answers, 2, 0, 0,
                        prompt_cb, prompt_cleanup, ocp);
         prompt_show(p, NULL, FALSE);
This page took 0.031526 seconds and 4 git commands to generate.