Allow moving fullscreen windows between monitors
[openbox.git] / openbox / actions / exit.c
blob2d9fc63312dc9c73b196474db71fb0f79bd99f83
1 #include "openbox/actions.h"
2 #include "openbox/openbox.h"
3 #include "openbox/prompt.h"
4 #include "openbox/session.h"
5 #include "gettext.h"
7 typedef struct {
8 gboolean prompt;
9 } Options;
11 static gpointer setup_func(xmlNodePtr node);
12 static void free_func(gpointer o);
13 static gboolean run_func(ObActionsData *data, gpointer options);
15 void action_exit_startup(void)
17 actions_register("Exit", setup_func, free_func, run_func);
18 actions_register("SessionLogout", setup_func, free_func, run_func);
21 static gpointer setup_func(xmlNodePtr node)
23 xmlNodePtr n;
24 Options *o;
26 o = g_slice_new0(Options);
27 o->prompt = TRUE;
29 if ((n = obt_xml_find_node(node, "prompt")))
30 o->prompt = obt_xml_node_bool(n);
32 return o;
35 static void free_func(gpointer o)
37 g_slice_free(Options, o);
40 static void do_exit(void)
42 if (session_connected())
43 session_request_logout(FALSE);
44 else
45 ob_exit(0);
48 static gboolean prompt_cb(ObPrompt *p, gint result, gpointer data)
50 if (result)
51 do_exit();
52 return TRUE; /* call the cleanup func */
55 static void prompt_cleanup(ObPrompt *p, gpointer data)
57 prompt_unref(p);
61 /* Always return FALSE because its not interactive */
62 static gboolean run_func(ObActionsData *data, gpointer options)
64 Options *o = options;
66 if (o->prompt) {
67 ObPrompt *p;
68 ObPromptAnswer answers[] = {
69 { _("Cancel"), 0 },
70 { _("Exit"), 1 }
73 if (session_connected())
74 p = prompt_new(_("Are you sure you want to log out?"),
75 _("Log Out"),
76 answers, 2, 0, 0, prompt_cb, prompt_cleanup, NULL);
77 else
78 p = prompt_new(_("Are you sure you want to exit Openbox?"),
79 _("Exit Openbox"),
80 answers, 2, 0, 0, prompt_cb, prompt_cleanup, NULL);
82 prompt_show(p, NULL, FALSE);
84 else
85 do_exit();
87 return FALSE;