1 #include "openbox/action.h"
2 #include "openbox/action_list_run.h"
3 #include "openbox/action_value.h"
4 #include "openbox/client.h"
5 #include "openbox/client_set.h"
6 #include "openbox/screen.h"
7 #include "openbox/frame.h"
8 #include "openbox/config.h"
27 static gpointer setup_func(GHashTable *config);
28 static void free_func(gpointer o);
29 static gboolean run_func(const ObClientSet *set,
30 const ObActionListRun *data, gpointer options);
32 void action_moveresizeto_startup(void)
34 action_register("MoveResizeTo", OB_ACTION_DEFAULT_FILTER_SINGLE,
35 setup_func, free_func, run_func);
38 static gpointer setup_func(GHashTable *config)
43 o = g_slice_new0(Options);
48 o->monitor = CURRENT_MONITOR;
50 v = g_hash_table_lookup(config, "x");
51 if (v && action_value_is_string(v))
52 action_value_gravity_coord(v, &o->x);
53 v = g_hash_table_lookup(config, "y");
54 if (v && action_value_is_string(v))
55 action_value_gravity_coord(v, &o->y);
57 v = g_hash_table_lookup(config, "width");
58 if (v && action_value_is_string(v))
59 if (g_ascii_strcasecmp(action_value_string(v), "current") != 0)
60 action_value_fraction(v, &o->w, &o->w_denom);
61 v = g_hash_table_lookup(config, "height");
62 if (v && action_value_is_string(v))
63 if (g_ascii_strcasecmp(action_value_string(v), "current") != 0)
64 action_value_fraction(v, &o->h, &o->h_denom);
66 v = g_hash_table_lookup(config, "monitor");
67 if (v && action_value_is_string(v)) {
68 const gchar *s = action_value_string(v);
69 if (g_ascii_strcasecmp(s, "current") != 0) {
70 if (!g_ascii_strcasecmp(s, "all"))
71 o->monitor = ALL_MONITORS;
72 else if(!g_ascii_strcasecmp(s, "next"))
73 o->monitor = NEXT_MONITOR;
74 else if(!g_ascii_strcasecmp(s, "prev"))
75 o->monitor = PREV_MONITOR;
77 o->monitor = action_value_int(v) - 1;
84 static void free_func(gpointer o)
86 g_slice_free(Options, o);
89 static gboolean each_run(ObClient *c, const ObActionListRun *data,
95 gint x, y, lw, lh, w, h;
98 cmon = client_monitor(c);
100 case CURRENT_MONITOR:
103 mon = SCREEN_AREA_ALL_MONITORS; break;
105 mon = (cmon + 1 > screen_num_monitors - 1) ? 0 : (cmon + 1); break;
107 mon = (cmon == 0) ? (screen_num_monitors - 1) : (cmon - 1); break;
109 g_assert_not_reached();
112 area = screen_area(c->desktop, mon, NULL);
113 carea = screen_area(c->desktop, cmon, NULL);
116 if (w == G_MININT) w = c->area.width;
117 else if (o->w_denom) w = (w * area->width) / o->w_denom;
120 if (h == G_MININT) h = c->area.height;
121 else if (o->h_denom) h = (h * area->height) / o->h_denom;
123 /* it might not be able to resize how they requested, so find out what
124 it will actually be resized to */
127 client_try_configure(c, &x, &y, &w, &h, &lw, &lh, TRUE);
129 /* get the frame's size */
130 w += c->frame->size.left + c->frame->size.right;
131 h += c->frame->size.top + c->frame->size.bottom;
135 x = (x * area->width) / o->x.denom;
136 if (o->x.center) x = (area->width - w) / 2;
137 else if (x == G_MININT) x = c->frame->area.x - carea->x;
138 else if (o->x.opposite) x = area->width - w - x;
143 y = (y * area->height) / o->y.denom;
144 if (o->y.center) y = (area->height - h) / 2;
145 else if (y == G_MININT) y = c->frame->area.y - carea->y;
146 else if (o->y.opposite) y = area->height - h - y;
149 /* get the client's size back */
150 w -= c->frame->size.left + c->frame->size.right;
151 h -= c->frame->size.top + c->frame->size.bottom;
153 frame_frame_gravity(c->frame, &x, &y); /* get the client coords */
154 client_try_configure(c, &x, &y, &w, &h, &lw, &lh, TRUE);
155 /* force it on screen if its moving to another monitor */
156 client_find_onscreen(c, &x, &y, w, h, mon != cmon);
158 client_configure(c, x, y, w, h, TRUE, TRUE, FALSE);
160 g_slice_free(Rect, area);
161 g_slice_free(Rect, carea);
165 /* Always return FALSE because its not interactive */
166 static gboolean run_func(const ObClientSet *set,
167 const ObActionListRun *data, gpointer options)
169 if (!client_set_is_empty(set)) {
170 action_client_move(data, TRUE);
171 client_set_run(set, data, each_run, options);
172 action_client_move(data, FALSE);