1 #include "openbox/actions.h"
2 #include "openbox/client.h"
3 #include "openbox/screen.h"
4 #include "openbox/frame.h"
5 #include <stdlib.h> /* for atoi */
19 static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node);
20 static void free_func(gpointer options);
21 static gboolean run_func(ObActionsData *data, gpointer options);
23 void action_moveresizeto_startup()
25 actions_register("MoveResizeTo",
32 static void parse_coord(xmlDocPtr doc, xmlNodePtr n, gint *pos,
33 gboolean *opposite, gboolean *center)
35 gchar *s = parse_string(doc, n);
36 if (g_ascii_strcasecmp(s, "current") != 0) {
37 if (!g_ascii_strcasecmp(s, "center"))
42 if (s[0] == '-' || s[0] == '+')
51 static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
56 o = g_new0(Options, 1);
63 if ((n = parse_find_node("x", node)))
64 parse_coord(doc, n, &o->x, &o->xopposite, &o->xcenter);
66 if ((n = parse_find_node("y", node)))
67 parse_coord(doc, n, &o->y, &o->yopposite, &o->ycenter);
69 if ((n = parse_find_node("width", node)))
70 o->w = parse_int(doc, n);
71 if ((n = parse_find_node("height", node)))
72 o->h = parse_int(doc, n);
74 if ((n = parse_find_node("monitor", node)))
75 o->monitor = parse_int(doc, n) - 1;
80 static void free_func(gpointer options)
87 /* Always return FALSE because its not interactive */
88 static gboolean run_func(ObActionsData *data, gpointer options)
96 gint x, y, lw, lh, w, h;
100 cmon = client_monitor(c);
101 if (mon < 0) mon = cmon;
102 area = screen_area(c->desktop, mon, NULL);
103 carea = screen_area(c->desktop, cmon, NULL);
106 if (w == G_MININT) w = c->area.width;
109 if (h == G_MININT) h = c->area.height;
111 /* it might not be able to resize how they requested, so find out what
112 it will actually be resized to */
115 client_try_configure(c, &x, &y, &w, &h, &lw, &lh, TRUE);
117 /* get the frame's size */
118 w += c->frame->size.left + c->frame->size.right;
119 h += c->frame->size.top + c->frame->size.bottom;
122 if (o->xcenter) x = (area->width - w) / 2;
123 else if (x == G_MININT) x = c->frame->area.x - carea->x;
124 else if (o->xopposite) x = area->width - w;
128 if (o->ycenter) y = (area->height - h) / 2;
129 else if (y == G_MININT) y = c->frame->area.y - carea->y;
130 else if (o->yopposite) y = area->height - h;
133 /* get the client's size back */
134 w -= c->frame->size.left + c->frame->size.right;
135 h -= c->frame->size.top + c->frame->size.bottom;
137 frame_frame_gravity(c->frame, &x, &y); /* get the client coords */
138 client_try_configure(c, &x, &y, &w, &h, &lw, &lh, TRUE);
139 /* force it on screen if its moving to another monitor */
140 client_find_onscreen(c, &x, &y, w, h, mon != cmon);
142 actions_client_move(data, TRUE);
143 client_configure(c, x, y, w, h, TRUE, TRUE, FALSE);
144 actions_client_move(data, FALSE);