]> icculus.org git repositories - mikachu/openbox.git/blob - openbox/actions/shade.c
changes for the 3.4 branch from master (svn trunk)
[mikachu/openbox.git] / openbox / actions / shade.c
1 #include "openbox/actions.h"
2 #include "openbox/client.h"
3
4 typedef struct {
5     gboolean toggle;
6     gboolean on;
7 } Options;
8
9 static gpointer setup_on_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node);
10 static gpointer setup_off_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node);
11 static gpointer setup_toggle_func(ObParseInst *i,
12                                   xmlDocPtr doc, xmlNodePtr node);
13 static void     free_func(gpointer options);
14 static gboolean run_func(ObActionsData *data, gpointer options);
15
16 void action_shade_startup()
17 {
18     actions_register("Shade",
19                      setup_on_func,
20                      free_func,
21                      run_func,
22                      NULL, NULL);
23     actions_register("Unshade",
24                      setup_off_func,
25                      free_func,
26                      run_func,
27                      NULL, NULL);
28     actions_register("ToggleShade",
29                      setup_toggle_func,
30                      free_func,
31                      run_func,
32                      NULL, NULL);
33 }
34
35 static gpointer setup_on_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
36 {
37     Options *o = g_new0(Options, 1);
38     o->on = TRUE;
39     return o;
40 }
41
42 static gpointer setup_off_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
43 {
44     Options *o = g_new0(Options, 1);
45     o->on = FALSE;
46     return o;
47 }
48
49 static gpointer setup_toggle_func(ObParseInst *i,
50                                   xmlDocPtr doc, xmlNodePtr node)
51 {
52     Options *o = g_new0(Options, 1);
53     o->toggle = TRUE;
54     return o;
55 }
56
57 static void free_func(gpointer options)
58 {
59     Options *o = options;
60
61     g_free(o);
62 }
63
64 /* Always return FALSE because its not interactive */
65 static gboolean run_func(ObActionsData *data, gpointer options)
66 {
67     Options *o = options;
68
69     if (data->client) {
70         actions_client_move(data, TRUE);
71         if (o->toggle)
72             client_shade(data->client, !data->client->shaded);
73         else
74             client_shade(data->client, o->on);
75         actions_client_move(data, FALSE);
76     }
77
78     return FALSE;
79 }