Merge branch 'backport' into 3.4
[mikachu/openbox.git] / openbox / actions / maximize.c
1 #include "openbox/actions.h"
2 #include "openbox/client.h"
3
4 /* These match the values for client_maximize */
5 typedef enum {
6     BOTH = 0,
7     HORZ = 1,
8     VERT = 2
9 } MaxDirection;
10
11 typedef struct {
12     MaxDirection dir;
13 } Options;
14
15 static gpointer setup_both_func(ObParseInst *i, xmlDocPtr doc,
16                               xmlNodePtr node);
17 static gpointer setup_horz_func(ObParseInst *i, xmlDocPtr doc,
18                                xmlNodePtr node);
19 static gpointer setup_vert_func(ObParseInst *i,
20                                   xmlDocPtr doc, xmlNodePtr node);
21 static gboolean run_func_on(ObActionsData *data, gpointer options);
22 static gboolean run_func_off(ObActionsData *data, gpointer options);
23 static gboolean run_func_toggle(ObActionsData *data, gpointer options);
24
25 void action_maximize_startup(void)
26 {
27     actions_register("MaximizeFull", setup_both_func, g_free,
28                      run_func_on, NULL, NULL);
29     actions_register("UnmaximizeFull", setup_both_func, g_free,
30                      run_func_off, NULL, NULL);
31     actions_register("ToggleMaximizeFull", setup_both_func, g_free,
32                      run_func_toggle, NULL, NULL);
33     actions_register("MaximizeHorz", setup_horz_func, g_free,
34                      run_func_on, NULL, NULL);
35     actions_register("UnmaximizeHorz", setup_horz_func, g_free,
36                      run_func_off, NULL, NULL);
37     actions_register("ToggleMaximizeHorz", setup_horz_func, g_free,
38                      run_func_toggle, NULL, NULL);
39     actions_register("MaximizeVert", setup_vert_func, g_free,
40                      run_func_on, NULL, NULL);
41     actions_register("UnmaximizeVert", setup_vert_func, g_free,
42                      run_func_off, NULL, NULL);
43     actions_register("ToggleMaximizeVert", setup_vert_func, g_free,
44                      run_func_toggle, NULL, NULL);
45 }
46
47 static gpointer setup_both_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
48 {
49     Options *o = g_new0(Options, 1);
50     o->dir = BOTH;
51     return o;
52 }
53
54 static gpointer setup_horz_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
55 {
56     Options *o = g_new0(Options, 1);
57     o->dir = HORZ;
58     return o;
59 }
60
61 static gpointer setup_vert_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
62 {
63     Options *o = g_new0(Options, 1);
64     o->dir = VERT;
65     return o;
66 }
67
68 /* Always return FALSE because its not interactive */
69 static gboolean run_func_on(ObActionsData *data, gpointer options)
70 {
71     Options *o = options;
72     if (data->client) {
73         actions_client_move(data, TRUE);
74         client_maximize(data->client, TRUE, o->dir);
75         actions_client_move(data, FALSE);
76     }
77     return FALSE;
78 }
79
80 /* Always return FALSE because its not interactive */
81 static gboolean run_func_off(ObActionsData *data, gpointer options)
82 {
83     Options *o = options;
84     if (data->client) {
85         actions_client_move(data, TRUE);
86         client_maximize(data->client, FALSE, o->dir);
87         actions_client_move(data, FALSE);
88     }
89     return FALSE;
90 }
91
92 /* Always return FALSE because its not interactive */
93 static gboolean run_func_toggle(ObActionsData *data, gpointer options)
94 {
95     Options *o = options;
96     if (data->client) {
97         gboolean toggle;
98         actions_client_move(data, TRUE);
99         toggle = ((o->dir == HORZ && !data->client->max_horz) ||
100                   (o->dir == VERT && !data->client->max_vert) ||
101                   (o->dir == BOTH &&
102                    !(data->client->max_horz && data->client->max_vert)));
103         client_maximize(data->client, toggle, o->dir);
104         actions_client_move(data, FALSE);
105     }
106     return FALSE;
107 }