all repos — openbox @ 556eb7b7fb20b3b0db03b6d92259ad3bb16dccde

openbox fork - make it a bit more like ryudo

openbox/actions/layer.c (raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "openbox/actions.h"
#include "openbox/client.h"

typedef struct {
    gint layer; /*!< -1 for below, 0 for normal, and 1 for above */
    gboolean toggle;
} Options;

static gpointer setup_func_top(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node);
static gpointer setup_func_bottom(ObParseInst *i, xmlDocPtr doc,
                                  xmlNodePtr node);
static gpointer setup_func_send(ObParseInst *i, xmlDocPtr doc,
                                xmlNodePtr node);
static gboolean run_func(ObActionsData *data, gpointer options);

void action_layer_startup(void)
{
    actions_register("ToggleAlwaysOnTop", setup_func_top, g_free,
                     run_func, NULL, NULL);
    actions_register("ToggleAlwaysOnBottom", setup_func_bottom, g_free,
                     run_func, NULL, NULL);
    actions_register("SendToLayer", setup_func_send, g_free,
                     run_func, NULL, NULL);
}

static gpointer setup_func_top(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
{
    Options *o = g_new0(Options, 1);
    o->layer = 1;
    o->toggle = TRUE;
    return o;
}

static gpointer setup_func_bottom(ObParseInst *i, xmlDocPtr doc,
                                  xmlNodePtr node)
{
    Options *o = g_new0(Options, 1);
    o->layer = -1;
    o->toggle = TRUE;
    return o;
}

static gpointer setup_func_send(ObParseInst *i, xmlDocPtr doc,
                                xmlNodePtr node)
{
    xmlNodePtr n;
    Options *o;

    o = g_new0(Options, 1);

    if ((n = parse_find_node("layer", node))) {
        gchar *s = parse_string(doc, n);
        if (!g_ascii_strcasecmp(s, "above") ||
            !g_ascii_strcasecmp(s, "top"))
            o->layer = 1;
        else if (!g_ascii_strcasecmp(s, "below") ||
                 !g_ascii_strcasecmp(s, "bottom"))
            o->layer = -1;
        else if (!g_ascii_strcasecmp(s, "normal") ||
                 !g_ascii_strcasecmp(s, "middle"))
            o->layer = 0;
        g_free(s);
    }

    return o;
}

/* Always return FALSE because its not interactive */
static gboolean run_func(ObActionsData *data, gpointer options)
{
    Options *o = options;

    if (data->client) {
        ObClient *c = data->client;

        actions_client_move(data, TRUE);

        if (o->layer < 0) {
            if (o->toggle || !c->below)
                client_set_layer(c, c->below ? 0 : -1);
        }
        else if (o->layer > 0) {
            if (o->toggle || !c->above)
                client_set_layer(c, c->above ? 0 : 1);
        }
        else if (c->above || c->below)
            client_set_layer(c, 0);

        actions_client_move(data, FALSE);
    }

    return FALSE;
}