]> Dogcows Code - chaz/openbox/blob - openbox/actions/session.c
add a SessionLogout action
[chaz/openbox] / openbox / actions / session.c
1 #include "openbox/actions.h"
2 #include "openbox/prompt.h"
3 #include "openbox/session.h"
4 #include "gettext.h"
5
6 #ifndef USE_SM
7 void action_logout_startup(void) {}
8 #else
9
10 typedef struct {
11 gboolean prompt;
12 gboolean silent;
13 } Options;
14
15 static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node);
16 static gboolean logout_func(ObActionsData *data, gpointer options);
17
18 void action_session_startup(void)
19 {
20 actions_register("SessionLogout", setup_func, NULL, logout_func,
21 NULL, NULL);
22 }
23
24 static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
25 {
26 xmlNodePtr n;
27 Options *o;
28
29 o = g_new0(Options, 1);
30
31 if ((n = parse_find_node("prompt", node)))
32 o->prompt = parse_bool(doc, n);
33
34 return o;
35 }
36
37 static void prompt_cb(ObPrompt *p, gint result, gpointer data)
38 {
39 Options *o = data;
40 if (result)
41 session_request_logout(o->silent);
42 g_free(o);
43 prompt_unref(p);
44 }
45
46 /* Always return FALSE because its not interactive */
47 static gboolean logout_func(ObActionsData *data, gpointer options)
48 {
49 Options *o = options;
50
51 if (o->prompt) {
52 Options *o2;
53 ObPrompt *p;
54 ObPromptAnswer answers[] = {
55 { _("Cancel"), 0 },
56 { _("Log out"), 1 }
57 };
58
59 o2 = g_memdup(o, sizeof(Options));
60 p = prompt_new(_("Are you sure you want to log out?"),
61 answers, 2, 0, 0, prompt_cb, o2);
62 prompt_show(p, NULL, FALSE);
63 }
64 else
65 prompt_cb(NULL, 1, NULL);
66
67 return FALSE;
68 }
69
70 #endif
This page took 0.035362 seconds and 4 git commands to generate.