all repos — openbox @ d179d6428ae585a3b8a13479bfe4586e41de2ff9

openbox fork - make it a bit more like ryudo

openbox/actions/maximize.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include "openbox/actions.h"
#include "openbox/client.h"

/* These match the values for client_maximize */
typedef enum {
    BOTH = 0,
    HORZ = 1,
    VERT = 2
} MaxDirection;

typedef struct {
    MaxDirection dir;
} Options;

static gpointer setup_func(xmlNodePtr node);
static void free_func(gpointer o);
static gboolean run_func_on(ObActionsData *data, gpointer options);
static gboolean run_func_off(ObActionsData *data, gpointer options);
static gboolean run_func_toggle(ObActionsData *data, gpointer options);
/* 3.4-compatibility */
static gpointer setup_both_func(xmlNodePtr node);
static gpointer setup_horz_func(xmlNodePtr node);
static gpointer setup_vert_func(xmlNodePtr node);

void action_maximize_startup(void)
{
    actions_register("Maximize", setup_func, free_func, run_func_on);
    actions_register("Unmaximize", setup_func, free_func, run_func_off);
    actions_register("ToggleMaximize", setup_func, free_func, run_func_toggle);
    /* 3.4-compatibility */
    actions_register("MaximizeFull", setup_both_func, free_func,
                     run_func_on);
    actions_register("UnmaximizeFull", setup_both_func, free_func,
                     run_func_off);
    actions_register("ToggleMaximizeFull", setup_both_func, free_func,
                     run_func_toggle);
    actions_register("MaximizeHorz", setup_horz_func, free_func,
                     run_func_on);
    actions_register("UnmaximizeHorz", setup_horz_func, free_func,
                     run_func_off);
    actions_register("ToggleMaximizeHorz", setup_horz_func, free_func,
                     run_func_toggle);
    actions_register("MaximizeVert", setup_vert_func, free_func,
                     run_func_on);
    actions_register("UnmaximizeVert", setup_vert_func, free_func,
                     run_func_off);
    actions_register("ToggleMaximizeVert", setup_vert_func, free_func,
                     run_func_toggle);
}

static gpointer setup_func(xmlNodePtr node)
{
    xmlNodePtr n;
    Options *o;

    o = g_slice_new0(Options);
    o->dir = BOTH;

    if ((n = obt_xml_find_node(node, "direction"))) {
        gchar *s = obt_xml_node_string(n);
        if (!g_ascii_strcasecmp(s, "vertical") ||
            !g_ascii_strcasecmp(s, "vert"))
            o->dir = VERT;
        else if (!g_ascii_strcasecmp(s, "horizontal") ||
                 !g_ascii_strcasecmp(s, "horz"))
            o->dir = HORZ;
        g_free(s);
    }

    return o;
}

static void free_func(gpointer o)
{
    g_slice_free(Options, o);
}

/* Always return FALSE because its not interactive */
static gboolean run_func_on(ObActionsData *data, gpointer options)
{
    Options *o = options;
    if (data->client) {
        actions_client_move(data, TRUE);
        client_maximize(data->client, TRUE, o->dir);
        actions_client_move(data, FALSE);
    }
    return FALSE;
}

/* Always return FALSE because its not interactive */
static gboolean run_func_off(ObActionsData *data, gpointer options)
{
    Options *o = options;
    if (data->client) {
        actions_client_move(data, TRUE);
        client_maximize(data->client, FALSE, o->dir);
        actions_client_move(data, FALSE);
    }
    return FALSE;
}

/* Always return FALSE because its not interactive */
static gboolean run_func_toggle(ObActionsData *data, gpointer options)
{
    Options *o = options;
    if (data->client) {
        gboolean toggle;
        actions_client_move(data, TRUE);
        toggle = ((o->dir == HORZ && !data->client->max_horz) ||
                  (o->dir == VERT && !data->client->max_vert) ||
                  (o->dir == BOTH &&
                   !(data->client->max_horz && data->client->max_vert)));
        client_maximize(data->client, toggle, o->dir);
        actions_client_move(data, FALSE);
    }
    return FALSE;
}

/* 3.4-compatibility */
static gpointer setup_both_func(xmlNodePtr node)
{
    Options *o = g_slice_new0(Options);
    o->dir = BOTH;
    return o;
}

static gpointer setup_horz_func(xmlNodePtr node)
{
    Options *o = g_slice_new0(Options);
    o->dir = HORZ;
    return o;
}

static gpointer setup_vert_func(xmlNodePtr node)
{
    Options *o = g_slice_new0(Options);
    o->dir = VERT;
    return o;
}