1 #include "openbox/actions.h"
2 #include "openbox/client.h"
3 #include "openbox/screen.h"
4 #include "openbox/engine_interface.h"
5 #include "openbox/openbox.h"
7 #include <stdlib.h> /* for atoi */
26 static gpointer setup_func(xmlNodePtr node);
27 static gboolean run_func(ObActionsData *data, gpointer options);
29 void action_moveresizeto_startup(void)
31 actions_register("MoveResizeTo", setup_func, g_free, run_func, NULL, NULL);
34 static void parse_coord(xmlNodePtr n, gint *pos,
35 gboolean *opposite, gboolean *center)
37 gchar *s = obt_parse_node_string(n);
38 if (g_ascii_strcasecmp(s, "current") != 0) {
39 if (!g_ascii_strcasecmp(s, "center"))
44 if (s[0] == '-' || s[0] == '+')
53 static gpointer setup_func(xmlNodePtr node)
58 o = g_new0(Options, 1);
63 o->monitor = CURRENT_MONITOR;
65 if ((n = obt_parse_find_node(node, "x")))
66 parse_coord(n, &o->x, &o->xopposite, &o->xcenter);
68 if ((n = obt_parse_find_node(node, "y")))
69 parse_coord(n, &o->y, &o->yopposite, &o->ycenter);
71 if ((n = obt_parse_find_node(node, "width"))) {
72 gchar *s = obt_parse_node_string(n);
73 if (g_ascii_strcasecmp(s, "current") != 0)
74 o->w = obt_parse_node_int(n);
77 if ((n = obt_parse_find_node(node, "height"))) {
78 gchar *s = obt_parse_node_string(n);
79 if (g_ascii_strcasecmp(s, "current") != 0)
80 o->h = obt_parse_node_int(n);
84 if ((n = obt_parse_find_node(node, "monitor"))) {
85 gchar *s = obt_parse_node_string(n);
86 if (g_ascii_strcasecmp(s, "current") != 0) {
87 if (!g_ascii_strcasecmp(s, "all"))
88 o->monitor = ALL_MONITORS;
90 o->monitor = obt_parse_node_int(n) - 1;
98 /* Always return FALSE because its not interactive */
99 static gboolean run_func(ObActionsData *data, gpointer options)
101 Options *o = options;
107 gint x, y, lw, lh, w, h;
111 cmon = client_monitor(c);
112 if (mon == CURRENT_MONITOR) mon = cmon;
113 else if (mon == ALL_MONITORS) mon = SCREEN_AREA_ALL_MONITORS;
114 area = screen_area(c->desktop, mon, NULL);
115 carea = screen_area(c->desktop, cmon, NULL);
118 if (w == G_MININT) w = c->area.width;
121 if (h == G_MININT) h = c->area.height;
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 Strut c_size = render_plugin->frame_get_size(c->frame);
130 Rect c_area = render_plugin->frame_get_window_area(c->frame);
131 /* get the frame's size */
132 w += c_size.left + c_size.right;
133 h += c_size.top + c_size.bottom;
136 if (o->xcenter) x = (area->width - w) / 2;
137 else if (x == G_MININT) x = c_area.x - carea->x;
138 else if (o->xopposite) x = area->width - w;
142 if (o->ycenter) y = (area->height - h) / 2;
143 else if (y == G_MININT) y = c_area.y - carea->y;
144 else if (o->yopposite) y = area->height - h;
147 /* get the client's size back */
148 w -= c_size.left + c_size.right;
149 h -= c_size.top + c_size.bottom;
151 frame_frame_gravity(c, &x, &y); /* get the client coords */
152 client_try_configure(c, &x, &y, &w, &h, &lw, &lh, TRUE);
153 /* force it on screen if its moving to another monitor */
154 client_find_onscreen(c, &x, &y, w, h, mon != cmon);
156 actions_client_move(data, TRUE);
157 client_configure(c, x, y, w, h, TRUE, TRUE, FALSE);
158 actions_client_move(data, FALSE);