]> icculus.org git repositories - mikachu/openbox.git/blob - openbox/actions/shade.c
add the desktop action
[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_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node);
10 static void     free_func(gpointer options);
11 static gboolean run_func(ObActionsData *data, gpointer options);
12
13 void action_shade_startup()
14 {
15     actions_register("Shade",
16                      setup_func,
17                      free_func,
18                      run_func,
19                      NULL, NULL);
20 }
21
22 static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
23 {
24     xmlNodePtr n;
25     Options *o;
26
27     o = g_new0(Options, 1);
28     o->toggle = TRUE;
29
30     if ((n = parse_find_node("shade", node))) {
31         gchar *s = parse_string(doc, n);
32         if (g_ascii_strcasecmp(s, "toggle")) {
33             o->toggle = FALSE;
34             o->on = parse_bool(doc, n);
35         }
36         g_free(s);
37     }
38
39     return o;
40 }
41
42 static void free_func(gpointer options)
43 {
44     Options *o = options;
45
46     g_free(o);
47 }
48
49 /* Always return FALSE because its not interactive */
50 static gboolean run_func(ObActionsData *data, gpointer options)
51 {
52     Options *o = options;
53
54     if (data->client) {
55         actions_client_move(data, TRUE);
56         if (o->toggle)
57             client_shade(data->client, !data->client->shaded);
58         else
59             client_shade(data->client, o->on);
60         actions_client_move(data, FALSE);
61     }
62
63     return FALSE;
64 }