]> Dogcows Code - chaz/openbox/blob - openbox/actions/maximize.c
Merge branch 'backport' into work
[chaz/openbox] / 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_func(xmlNodePtr node);
16 static gboolean run_func_on(ObActionsData *data, gpointer options);
17 static gboolean run_func_off(ObActionsData *data, gpointer options);
18 static gboolean run_func_toggle(ObActionsData *data, gpointer options);
19 /* 3.4-compatibility */
20 static gpointer setup_both_func(xmlNodePtr node);
21 static gpointer setup_horz_func(xmlNodePtr node);
22 static gpointer setup_vert_func(xmlNodePtr node);
23
24 void action_maximize_startup(void)
25 {
26 actions_register("Maximize", setup_func, g_free, run_func_on,
27 NULL, NULL);
28 actions_register("Unmaximize", setup_func, g_free, run_func_off,
29 NULL, NULL);
30 actions_register("ToggleMaximize", setup_func, g_free, run_func_toggle,
31 NULL, NULL);
32 /* 3.4-compatibility */
33 actions_register("MaximizeFull", setup_both_func, g_free,
34 run_func_on, NULL, NULL);
35 actions_register("UnmaximizeFull", setup_both_func, g_free,
36 run_func_off, NULL, NULL);
37 actions_register("ToggleMaximizeFull", setup_both_func, g_free,
38 run_func_toggle, NULL, NULL);
39 actions_register("MaximizeHorz", setup_horz_func, g_free,
40 run_func_on, NULL, NULL);
41 actions_register("UnmaximizeHorz", setup_horz_func, g_free,
42 run_func_off, NULL, NULL);
43 actions_register("ToggleMaximizeHorz", setup_horz_func, g_free,
44 run_func_toggle, NULL, NULL);
45 actions_register("MaximizeVert", setup_vert_func, g_free,
46 run_func_on, NULL, NULL);
47 actions_register("UnmaximizeVert", setup_vert_func, g_free,
48 run_func_off, NULL, NULL);
49 actions_register("ToggleMaximizeVert", setup_vert_func, g_free,
50 run_func_toggle, NULL, NULL);
51 }
52
53 static gpointer setup_func(xmlNodePtr node)
54 {
55 xmlNodePtr n;
56 Options *o;
57
58 o = g_new0(Options, 1);
59 o->dir = BOTH;
60
61 if ((n = obt_parse_find_node(node, "direction"))) {
62 gchar *s = obt_parse_node_string(n);
63 if (!g_ascii_strcasecmp(s, "vertical") ||
64 !g_ascii_strcasecmp(s, "vert"))
65 o->dir = VERT;
66 else if (!g_ascii_strcasecmp(s, "horizontal") ||
67 !g_ascii_strcasecmp(s, "horz"))
68 o->dir = HORZ;
69 g_free(s);
70 }
71
72 return o;
73 }
74
75 /* Always return FALSE because its not interactive */
76 static gboolean run_func_on(ObActionsData *data, gpointer options)
77 {
78 Options *o = options;
79 if (data->client) {
80 actions_client_move(data, TRUE);
81 client_maximize(data->client, TRUE, o->dir);
82 actions_client_move(data, FALSE);
83 }
84 return FALSE;
85 }
86
87 /* Always return FALSE because its not interactive */
88 static gboolean run_func_off(ObActionsData *data, gpointer options)
89 {
90 Options *o = options;
91 if (data->client) {
92 actions_client_move(data, TRUE);
93 client_maximize(data->client, FALSE, o->dir);
94 actions_client_move(data, FALSE);
95 }
96 return FALSE;
97 }
98
99 /* Always return FALSE because its not interactive */
100 static gboolean run_func_toggle(ObActionsData *data, gpointer options)
101 {
102 Options *o = options;
103 if (data->client) {
104 gboolean toggle;
105 actions_client_move(data, TRUE);
106 toggle = ((o->dir == HORZ && !data->client->max_horz) ||
107 (o->dir == VERT && !data->client->max_vert) ||
108 (o->dir == BOTH &&
109 !(data->client->max_horz && data->client->max_vert)));
110 client_maximize(data->client, toggle, o->dir);
111 actions_client_move(data, FALSE);
112 }
113 return FALSE;
114 }
115
116 /* 3.4-compatibility */
117 static gpointer setup_both_func(xmlNodePtr node)
118 {
119 Options *o = g_new0(Options, 1);
120 o->dir = BOTH;
121 return o;
122 }
123
124 static gpointer setup_horz_func(xmlNodePtr node)
125 {
126 Options *o = g_new0(Options, 1);
127 o->dir = HORZ;
128 return o;
129 }
130
131 static gpointer setup_vert_func(xmlNodePtr node)
132 {
133 Options *o = g_new0(Options, 1);
134 o->dir = VERT;
135 return o;
136 }
137
This page took 0.04173 seconds and 4 git commands to generate.