]> icculus.org git repositories - mikachu/openbox.git/blob - openbox/actions/layer.c
Update Changelog and bump the version
[mikachu/openbox.git] / openbox / actions / layer.c
1 #include "openbox/actions.h"
2 #include "openbox/client.h"
3
4 typedef struct {
5     gint layer; /*!< -1 for below, 0 for normal, and 1 for above */
6     gboolean toggle;
7 } Options;
8
9 static gpointer setup_func_top(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node);
10 static gpointer setup_func_bottom(ObParseInst *i, xmlDocPtr doc,
11                                   xmlNodePtr node);
12 static gpointer setup_sendtop_func(ObParseInst *i,
13                                      xmlDocPtr doc, xmlNodePtr node);
14 static gpointer setup_sendbottom_func(ObParseInst *i,
15                                         xmlDocPtr doc, xmlNodePtr node);
16 static gpointer setup_sendnormal_func(ObParseInst *i,
17                                       xmlDocPtr doc, xmlNodePtr node);
18 static gboolean run_func(ObActionsData *data, gpointer options);
19
20 void action_layer_startup(void)
21 {
22     actions_register("ToggleAlwaysOnTop", setup_func_top, g_free,
23                      run_func, NULL, NULL);
24     actions_register("ToggleAlwaysOnBottom", setup_func_bottom, g_free,
25                      run_func, NULL, NULL);
26     actions_register("SendToTopLayer", setup_sendtop_func, g_free,
27                      run_func, NULL, NULL);
28     actions_register("SendToBottomLayer", setup_sendbottom_func, g_free,
29                      run_func, NULL, NULL);
30     actions_register("SendToNormalLayer", setup_sendnormal_func, g_free,
31                      run_func, NULL, NULL);
32 }
33
34 static gpointer setup_func_top(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
35 {
36     Options *o = g_new0(Options, 1);
37     o->layer = 1;
38     o->toggle = TRUE;
39     return o;
40 }
41
42 static gpointer setup_func_bottom(ObParseInst *i, xmlDocPtr doc,
43                                   xmlNodePtr node)
44 {
45     Options *o = g_new0(Options, 1);
46     o->layer = -1;
47     o->toggle = TRUE;
48     return o;
49 }
50
51 static gpointer setup_sendtop_func(ObParseInst *i,
52                                      xmlDocPtr doc, xmlNodePtr node)
53 {
54     Options *o = g_new0(Options, 1);
55     o->layer = 1;
56     o->toggle = FALSE;
57     return o;
58 }
59
60 static gpointer setup_sendbottom_func(ObParseInst *i,
61                                         xmlDocPtr doc, xmlNodePtr node)
62 {
63     Options *o = g_new0(Options, 1);
64     o->layer = -1;
65     o->toggle = FALSE;
66     return o;
67 }
68
69 static gpointer setup_sendnormal_func(ObParseInst *i,
70                                       xmlDocPtr doc, xmlNodePtr node)
71 {
72     Options *o = g_new0(Options, 1);
73     o->layer = 0;
74     o->toggle = FALSE;
75     return o;
76 }
77
78 /* Always return FALSE because its not interactive */
79 static gboolean run_func(ObActionsData *data, gpointer options)
80 {
81     Options *o = options;
82
83     if (data->client) {
84         ObClient *c = data->client;
85
86         actions_client_move(data, TRUE);
87
88         if (o->layer < 0) {
89             if (o->toggle || !c->below)
90                 client_set_layer(c, c->below ? 0 : -1);
91         }
92         else if (o->layer > 0) {
93             if (o->toggle || !c->above)
94                 client_set_layer(c, c->above ? 0 : 1);
95         }
96         else if (c->above || c->below)
97             client_set_layer(c, 0);
98
99         actions_client_move(data, FALSE);
100     }
101
102     return FALSE;
103 }