]> Dogcows Code - chaz/openbox/blob - openbox/actions/layer.c
4a1cf651901d6023d3e3c745e9409b1f8cbea804
[chaz/openbox] / 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_func_send(ObParseInst *i, xmlDocPtr doc,
13 xmlNodePtr node);
14 static gboolean run_func(ObActionsData *data, gpointer options);
15
16 void action_layer_startup()
17 {
18 actions_register("ToggleAlwaysOnTop", setup_func_top, g_free,
19 run_func_toggle, NULL, NULL);
20 actions_register("ToggleAlwaysOnBottom", setup_func_bottom, g_free,
21 run_func_toggle, NULL, NULL);
22 actions_register("SendToLayer", setup_func_send, g_free,
23 run_func_send, NULL, NULL);
24 }
25
26 static gpointer setup_func_top(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
27 {
28 Options *o = g_new0(Options, 1);
29 o->layer = 1;
30 return o;
31 }
32
33 static gpointer setup_func_bottom(ObParseInst *i, xmlDocPtr doc,
34 xmlNodePtr node)
35 {
36 Options *o = g_new0(Options, 1);
37 o->layer = -1;
38 return o;
39 }
40
41 static gpointer setup_func_send(ObParseInst *i, xmlDocPtr doc,
42 xmlNodePtr node)
43 {
44 xmlNodePtr n;
45 Options *o;
46
47 o = g_new0(Options, 1);
48 o->toggle = TRUE;
49
50 if ((n = parse_find_node("layer", node))) {
51 gchar *s = parse_string(doc, n);
52 if (!g_ascii_strcasecmp(s, "above") ||
53 !g_ascii_strcasecmp(s, "top"))
54 o->layer = 1;
55 else if (!g_ascii_strcasecmp(s, "below") ||
56 !g_ascii_strcasecmp(s, "bottom"))
57 o->layer = -1;
58 else if (!g_ascii_strcasecmp(s, "normal") ||
59 !g_ascii_strcasecmp(s, "middle"))
60 o->layer = 0;
61 g_free(s);
62 }
63
64 return o;
65 }
66
67 /* Always return FALSE because its not interactive */
68 static gboolean run_func(ObActionsData *data, gpointer options)
69 {
70 Options *o = options;
71
72 if (data->client) {
73 ObClient *c = data->client;
74
75 actions_client_move(data, TRUE);
76
77 if (o->layer < 0) {
78 if (o->toggle || !c->below)
79 client_set_layer(c, c->below ? 0 : -1);
80 }
81 else if (o->layer > 0) {
82 if (o->toggle || !c->above)
83 client_set_layer(c, c->above ? 0 : 1);
84 }
85 else if (c->above || c->below)
86 client_set_layer(c, 0);
87
88 actions_client_move(data, FALSE);
89 }
90
91 return FALSE;
92 }
This page took 0.040089 seconds and 4 git commands to generate.