]> icculus.org git repositories - dana/openbox.git/blob - openbox/actions/exit.c
Pass a client set to all actions, and make focus cycling use a client set.
[dana/openbox.git] / openbox / actions / exit.c
1 #include "openbox/action.h"
2 #include "openbox/action_list_run.h"
3 #include "openbox/action_value.h"
4 #include "openbox/client_set.h"
5 #include "openbox/openbox.h"
6 #include "openbox/prompt.h"
7 #include "openbox/session.h"
8 #include "gettext.h"
9
10 typedef struct {
11     gboolean prompt;
12 } Options;
13
14 static gpointer setup_func(GHashTable *config);
15 static void free_func(gpointer o);
16 static gboolean run_func(const ObClientSet *set,
17                          const ObActionListRun *data, gpointer options);
18
19 void action_exit_startup(void)
20 {
21     action_register("Exit", OB_ACTION_DEFAULT_FILTER_EMPTY,
22                     setup_func, free_func, run_func);
23 }
24
25 static gpointer setup_func(GHashTable *config)
26 {
27     ObActionValue *v;
28     Options *o;
29
30     o = g_slice_new0(Options);
31     o->prompt = TRUE;
32
33     v = g_hash_table_lookup(config, "prompt");
34     if (v && action_value_is_string(v))
35         o->prompt = action_value_bool(v);
36
37     return o;
38 }
39
40 static void free_func(gpointer o)
41 {
42     g_slice_free(Options, o);
43 }
44
45 static void do_exit(void)
46 {
47     if (session_connected())
48         session_request_logout(FALSE);
49     else
50         ob_exit(0);
51 }
52
53 static gboolean prompt_cb(ObPrompt *p, gint result, gpointer data)
54 {
55     if (result)
56         do_exit();
57     return TRUE; /* call the cleanup func */
58 }
59
60 static void prompt_cleanup(ObPrompt *p, gpointer data)
61 {
62     prompt_unref(p);
63 }
64
65
66 /* Always return FALSE because its not interactive */
67 static gboolean run_func(const ObClientSet *set,
68                          const ObActionListRun *data, gpointer options)
69 {
70     Options *o = options;
71
72     if (o->prompt) {
73         ObPrompt *p;
74         ObPromptAnswer answers[] = {
75             { _("Cancel"), 0 },
76             { _("Exit"), 1 }
77         };
78
79         if (session_connected())
80             p = prompt_new(_("Are you sure you want to log out?"),
81                            _("Log Out"),
82                            answers, 2, 0, 0, prompt_cb, prompt_cleanup, NULL);
83         else
84             p = prompt_new(_("Are you sure you want to exit Openbox?"),
85                            _("Exit Openbox"),
86                            answers, 2, 0, 0, prompt_cb, prompt_cleanup, NULL);
87
88         prompt_show(p, NULL, FALSE);
89     }
90     else
91         do_exit();
92
93     return FALSE;
94 }