]> icculus.org git repositories - dana/openbox.git/blob - openbox/actions/maximize.c
Use ObConfigValue to parse gravity coords, remove parse special functions from config...
[dana/openbox.git] / openbox / actions / maximize.c
1 #include "openbox/action.h"
2 #include "openbox/action_list_run.h"
3 #include "openbox/config_value.h"
4 #include "openbox/client.h"
5 #include "openbox/client_set.h"
6
7 /* These match the values for client_maximize */
8 typedef enum {
9     BOTH = 0,
10     HORZ = 1,
11     VERT = 2
12 } MaxDirection;
13
14 typedef struct {
15     MaxDirection dir;
16 } Options;
17
18 static gpointer setup_func(GHashTable *config);
19 static void free_func(gpointer o);
20 static gboolean run_func_on(const ObClientSet *set,
21                             const ObActionListRun *data, gpointer options);
22 static gboolean run_func_off(const ObClientSet *set,
23                              const ObActionListRun *data, gpointer options);
24 static gboolean run_func_toggle(const ObClientSet *set,
25                                 const ObActionListRun *data, gpointer options);
26
27 void action_maximize_startup(void)
28 {
29     action_register("Maximize", OB_ACTION_DEFAULT_FILTER_SINGLE,
30                     setup_func, free_func, run_func_on);
31     action_register("Unmaximize", OB_ACTION_DEFAULT_FILTER_SINGLE,
32                     setup_func, free_func, run_func_off);
33     action_register("ToggleMaximize", OB_ACTION_DEFAULT_FILTER_SINGLE,
34                     setup_func, free_func, run_func_toggle);
35 }
36
37 static gpointer setup_func(GHashTable *config)
38 {
39     ObConfigValue *v;
40     Options *o;
41
42     o = g_slice_new0(Options);
43     o->dir = BOTH;
44
45     v = g_hash_table_lookup(config, "dir");
46     if (v && config_value_is_string(v)) {
47         const gchar *s = config_value_string(v);
48         if (!g_ascii_strcasecmp(s, "vertical") ||
49             !g_ascii_strcasecmp(s, "vert"))
50             o->dir = VERT;
51         else if (!g_ascii_strcasecmp(s, "horizontal") ||
52                  !g_ascii_strcasecmp(s, "horz"))
53             o->dir = HORZ;
54     }
55
56     return o;
57 }
58
59 static void free_func(gpointer o)
60 {
61     g_slice_free(Options, o);
62 }
63
64 static gboolean each_on(ObClient *c, const ObActionListRun *data,
65                         gpointer options)
66 {
67     Options *o = options;
68     if (data->target) {
69         action_client_move(data, TRUE);
70         client_maximize(data->target, TRUE, o->dir);
71         action_client_move(data, FALSE);
72     }
73     return TRUE;
74 }
75
76 /* Always return FALSE because its not interactive */
77 static gboolean run_func_on(const ObClientSet *set,
78                             const ObActionListRun *data, gpointer options)
79 {
80     if (!client_set_is_empty(set)) {
81         action_client_move(data, TRUE);
82         client_set_run(set, data, each_on, options);
83         action_client_move(data, FALSE);
84     }
85     return FALSE;
86 }
87
88 static gboolean each_off(ObClient *c, const ObActionListRun *data,
89                          gpointer options)
90 {
91     Options *o = options;
92     if (data->target) {
93         action_client_move(data, TRUE);
94         client_maximize(data->target, FALSE, o->dir);
95         action_client_move(data, FALSE);
96     }
97     return TRUE;
98 }
99
100 /* Always return FALSE because its not interactive */
101 static gboolean run_func_off(const ObClientSet *set,
102                              const ObActionListRun *data, gpointer options)
103 {
104     if (!client_set_is_empty(set)) {
105         action_client_move(data, TRUE);
106         client_set_run(set, data, each_off, options);
107         action_client_move(data, FALSE);
108     }
109     return FALSE;
110 }
111
112 static gboolean each_toggle(ObClient *c, const ObActionListRun *data,
113                             gpointer options)
114 {
115     Options *o = options;
116     gboolean toggle;
117     toggle = ((o->dir == HORZ && !data->target->max_horz) ||
118               (o->dir == VERT && !data->target->max_vert) ||
119               (o->dir == BOTH &&
120                !(data->target->max_horz && data->target->max_vert)));
121     client_maximize(data->target, toggle, o->dir);
122     return TRUE;
123 }
124
125 /* Always return FALSE because its not interactive */
126 static gboolean run_func_toggle(const ObClientSet *set,
127                                 const ObActionListRun *data, gpointer options)
128 {
129     if (!client_set_is_empty(set)) {
130         action_client_move(data, TRUE);
131         client_set_run(set, data, each_toggle, options);
132         action_client_move(data, FALSE);
133     }
134     return FALSE;
135 }