1 #include "openbox/actions.h"
2 #include "openbox/client.h"
3 #include "openbox/screen.h"
4 #include "openbox/frame.h"
5 #include "openbox/config.h"
22 gboolean w_sets_client_size;
23 gboolean h_sets_client_size;
26 static gpointer setup_func(xmlNodePtr node);
27 static void free_func(gpointer o);
28 static gboolean run_func(ObActionsData *data, gpointer options);
29 /* 3.4-compatibility */
30 static gpointer setup_center_func(xmlNodePtr node);
32 void action_moveresizeto_startup(void)
34 actions_register("MoveResizeTo", setup_func, free_func, run_func);
35 /* 3.4-compatibility */
36 actions_register("MoveToCenter", setup_center_func, free_func, run_func);
39 static gpointer setup_func(xmlNodePtr node)
44 o = g_slice_new0(Options);
49 o->monitor = CURRENT_MONITOR;
51 if ((n = obt_xml_find_node(node, "x")))
52 config_parse_gravity_coord(n, &o->x);
54 if ((n = obt_xml_find_node(node, "y")))
55 config_parse_gravity_coord(n, &o->y);
57 if ((n = obt_xml_find_node(node, "width"))) {
58 gchar *s = obt_xml_node_string(n);
59 if (g_ascii_strcasecmp(s, "current") != 0)
60 config_parse_relative_number(s, &o->w, &o->w_denom);
63 obt_xml_attr_bool(n, "client", &o->w_sets_client_size);
65 if ((n = obt_xml_find_node(node, "height"))) {
66 gchar *s = obt_xml_node_string(n);
67 if (g_ascii_strcasecmp(s, "current") != 0)
68 config_parse_relative_number(s, &o->h, &o->h_denom);
71 obt_xml_attr_bool(n, "client", &o->h_sets_client_size);
74 if ((n = obt_xml_find_node(node, "monitor"))) {
75 gchar *s = obt_xml_node_string(n);
76 if (g_ascii_strcasecmp(s, "current") != 0) {
77 if (!g_ascii_strcasecmp(s, "all"))
78 o->monitor = ALL_MONITORS;
79 else if(!g_ascii_strcasecmp(s, "next"))
80 o->monitor = NEXT_MONITOR;
81 else if(!g_ascii_strcasecmp(s, "prev"))
82 o->monitor = PREV_MONITOR;
84 o->monitor = obt_xml_node_int(n) - 1;
92 static void free_func(gpointer o)
94 g_slice_free(Options, o);
97 /* Always return FALSE because its not interactive */
98 static gboolean run_func(ObActionsData *data, gpointer options)
100 Options *o = options;
106 gint x, y, lw, lh, w, h;
110 cmon = client_monitor(c);
112 case CURRENT_MONITOR:
115 mon = SCREEN_AREA_ALL_MONITORS; break;
117 mon = (cmon + 1 > screen_num_monitors - 1) ? 0 : (cmon + 1); break;
119 mon = (cmon == 0) ? (screen_num_monitors - 1) : (cmon - 1); break;
121 g_assert_not_reached();
124 area = screen_area(c->desktop, mon, NULL);
125 carea = screen_area(c->desktop, cmon, NULL);
127 /* find a target size for the client/frame. */
130 if (o->w_sets_client_size)
133 w = c->frame->area.width;
135 else if (o->w_denom) w = (w * area->width) / o->w_denom;
139 if (o->h_sets_client_size)
142 h = c->frame->area.height;
144 else if (o->h_denom) h = (h * area->height) / o->h_denom;
146 /* get back to the client's size. */
147 if (!o->w_sets_client_size)
148 w -= c->frame->size.left + c->frame->size.right;
149 if (!o->h_sets_client_size)
150 h -= c->frame->size.top + c->frame->size.bottom;
152 /* it might not be able to resize how they requested, so find out what
153 it will actually be resized to */
156 client_try_configure(c, &x, &y, &w, &h, &lw, &lh, TRUE);
158 /* get the frame's size */
159 w += c->frame->size.left + c->frame->size.right;
160 h += c->frame->size.top + c->frame->size.bottom;
164 x = (x * area->width) / o->x.denom;
165 if (o->x.center) x = (area->width - w) / 2;
166 else if (x == G_MININT) x = c->frame->area.x - carea->x;
167 else if (o->x.opposite) x = area->width - w - x;
172 y = (y * area->height) / o->y.denom;
173 if (o->y.center) y = (area->height - h) / 2;
174 else if (y == G_MININT) y = c->frame->area.y - carea->y;
175 else if (o->y.opposite) y = area->height - h - y;
178 /* get the client's size back */
179 w -= c->frame->size.left + c->frame->size.right;
180 h -= c->frame->size.top + c->frame->size.bottom;
182 frame_frame_gravity(c->frame, &x, &y); /* get the client coords */
183 client_try_configure(c, &x, &y, &w, &h, &lw, &lh, TRUE);
184 /* force it on screen if its moving to another monitor */
185 client_find_onscreen(c, &x, &y, w, h, mon != cmon);
187 actions_client_move(data, TRUE);
188 client_configure(c, x, y, w, h, TRUE, TRUE, FALSE);
189 actions_client_move(data, FALSE);
191 g_slice_free(Rect, area);
192 g_slice_free(Rect, carea);
198 /* 3.4-compatibility */
199 static gpointer setup_center_func(xmlNodePtr node)
203 o = g_slice_new0(Options);