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"
7 /* These match the values for client_maximize */
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);
27 void action_maximize_startup(void)
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);
37 static gpointer setup_func(GHashTable *config)
42 o = g_slice_new0(Options);
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"))
51 else if (!g_ascii_strcasecmp(s, "horizontal") ||
52 !g_ascii_strcasecmp(s, "horz"))
59 static void free_func(gpointer o)
61 g_slice_free(Options, o);
64 static gboolean each_on(ObClient *c, const ObActionListRun *data,
69 action_client_move(data, TRUE);
70 client_maximize(data->target, TRUE, o->dir);
71 action_client_move(data, FALSE);
76 /* Always return FALSE because its not interactive */
77 static gboolean run_func_on(const ObClientSet *set,
78 const ObActionListRun *data, gpointer options)
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);
88 static gboolean each_off(ObClient *c, const ObActionListRun *data,
93 action_client_move(data, TRUE);
94 client_maximize(data->target, FALSE, o->dir);
95 action_client_move(data, FALSE);
100 /* Always return FALSE because its not interactive */
101 static gboolean run_func_off(const ObClientSet *set,
102 const ObActionListRun *data, gpointer options)
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);
112 static gboolean each_toggle(ObClient *c, const ObActionListRun *data,
115 Options *o = options;
117 toggle = ((o->dir == HORZ && !data->target->max_horz) ||
118 (o->dir == VERT && !data->target->max_vert) ||
120 !(data->target->max_horz && data->target->max_vert)));
121 client_maximize(data->target, toggle, o->dir);
125 /* Always return FALSE because its not interactive */
126 static gboolean run_func_toggle(const ObClientSet *set,
127 const ObActionListRun *data, gpointer options)
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);