]> icculus.org git repositories - dana/openbox.git/blob - openbox/actions/maximize.c
Add action_list_run.c/h with action_list_run() and struct ObActionListRun.
[dana/openbox.git] / openbox / actions / maximize.c
1 #include "openbox/action.h"
2 #include "openbox/action_list_run.h"
3 #include "openbox/action_value.h"
4 #include "openbox/client.h"
5
6 /* These match the values for client_maximize */
7 typedef enum {
8     BOTH = 0,
9     HORZ = 1,
10     VERT = 2
11 } MaxDirection;
12
13 typedef struct {
14     MaxDirection dir;
15 } Options;
16
17 static gpointer setup_func(GHashTable *config);
18 static void free_func(gpointer o);
19 static gboolean run_func_on(const ObActionListRun *data, gpointer options);
20 static gboolean run_func_off(const ObActionListRun *data, gpointer options);
21 static gboolean run_func_toggle(const ObActionListRun *data, gpointer options);
22
23 void action_maximize_startup(void)
24 {
25     action_register("Maximize", OB_ACTION_DEFAULT_FILTER_SINGLE,
26                     setup_func, free_func, run_func_on);
27     action_register("Unmaximize", OB_ACTION_DEFAULT_FILTER_SINGLE,
28                     setup_func, free_func, run_func_off);
29     action_register("ToggleMaximize", OB_ACTION_DEFAULT_FILTER_SINGLE,
30                     setup_func, free_func, run_func_toggle);
31 }
32
33 static gpointer setup_func(GHashTable *config)
34 {
35     ObActionValue *v;
36     Options *o;
37
38     o = g_slice_new0(Options);
39     o->dir = BOTH;
40
41     v = g_hash_table_lookup(config, "dir");
42     if (v && action_value_is_string(v)) {
43         const gchar *s = action_value_string(v);
44         if (!g_ascii_strcasecmp(s, "vertical") ||
45             !g_ascii_strcasecmp(s, "vert"))
46             o->dir = VERT;
47         else if (!g_ascii_strcasecmp(s, "horizontal") ||
48                  !g_ascii_strcasecmp(s, "horz"))
49             o->dir = HORZ;
50     }
51
52     return o;
53 }
54
55 static void free_func(gpointer o)
56 {
57     g_slice_free(Options, o);
58 }
59
60 /* Always return FALSE because its not interactive */
61 static gboolean run_func_on(const ObActionListRun *data, gpointer options)
62 {
63     Options *o = options;
64     if (data->client) {
65         action_client_move(data, TRUE);
66         client_maximize(data->client, TRUE, o->dir);
67         action_client_move(data, FALSE);
68     }
69     return FALSE;
70 }
71
72 /* Always return FALSE because its not interactive */
73 static gboolean run_func_off(const ObActionListRun *data, gpointer options)
74 {
75     Options *o = options;
76     if (data->client) {
77         action_client_move(data, TRUE);
78         client_maximize(data->client, FALSE, o->dir);
79         action_client_move(data, FALSE);
80     }
81     return FALSE;
82 }
83
84 /* Always return FALSE because its not interactive */
85 static gboolean run_func_toggle(const ObActionListRun *data, gpointer options)
86 {
87     Options *o = options;
88     if (data->client) {
89         gboolean toggle;
90         action_client_move(data, TRUE);
91         toggle = ((o->dir == HORZ && !data->client->max_horz) ||
92                   (o->dir == VERT && !data->client->max_vert) ||
93                   (o->dir == BOTH &&
94                    !(data->client->max_horz && data->client->max_vert)));
95         client_maximize(data->client, toggle, o->dir);
96         action_client_move(data, FALSE);
97     }
98     return FALSE;
99 }