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 */
24 static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node);
25 static gpointer setup_center_func(ObParseInst *i, xmlDocPtr doc,
27 static void free_func(gpointer options);
28 static gboolean run_func(ObActionsData *data, gpointer options);
30 void action_moveresizeto_startup(void)
32 actions_register("MoveResizeTo",
37 actions_register("MoveToCenter",
44 static void parse_coord(xmlDocPtr doc, xmlNodePtr n, gint *pos,
45 gboolean *opposite, gboolean *center)
47 gchar *s = parse_string(doc, n);
48 if (g_ascii_strcasecmp(s, "current") != 0) {
49 if (!g_ascii_strcasecmp(s, "center"))
54 if (s[0] == '-' || s[0] == '+')
63 static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
68 o = g_new0(Options, 1);
73 o->monitor = CURRENT_MONITOR;
75 if ((n = parse_find_node("x", node)))
76 parse_coord(doc, n, &o->x, &o->xopposite, &o->xcenter);
78 if ((n = parse_find_node("y", node)))
79 parse_coord(doc, n, &o->y, &o->yopposite, &o->ycenter);
81 if ((n = parse_find_node("width", node))) {
82 gchar *s = parse_string(doc, n);
83 if (g_ascii_strcasecmp(s, "current") != 0)
84 o->w = parse_int(doc, n);
87 if ((n = parse_find_node("height", node))) {
88 gchar *s = parse_string(doc, n);
89 if (g_ascii_strcasecmp(s, "current") != 0)
90 o->h = parse_int(doc, n);
94 if ((n = parse_find_node("monitor", node))) {
95 gchar *s = parse_string(doc, n);
96 if (g_ascii_strcasecmp(s, "current") != 0) {
97 if (!g_ascii_strcasecmp(s, "all"))
98 o->monitor = ALL_MONITORS;
100 o->monitor = parse_int(doc, n) - 1;
108 static gpointer setup_center_func(ObParseInst *i, xmlDocPtr doc,
113 o = g_new0(Options, 1);
124 static void free_func(gpointer options)
126 Options *o = options;
131 /* Always return FALSE because its not interactive */
132 static gboolean run_func(ObActionsData *data, gpointer options)
134 Options *o = options;
140 gint x, y, lw, lh, w, h;
144 cmon = client_monitor(c);
145 if (mon == CURRENT_MONITOR) mon = cmon;
146 else if (mon == ALL_MONITORS) mon = SCREEN_AREA_ALL_MONITORS;
147 area = screen_area(c->desktop, mon, NULL);
148 carea = screen_area(c->desktop, cmon, NULL);
151 if (w == G_MININT) w = c->area.width;
154 if (h == G_MININT) h = c->area.height;
156 /* it might not be able to resize how they requested, so find out what
157 it will actually be resized to */
160 client_try_configure(c, &x, &y, &w, &h, &lw, &lh, TRUE);
162 /* get the frame's size */
163 w += c->frame->size.left + c->frame->size.right;
164 h += c->frame->size.top + c->frame->size.bottom;
167 if (o->xcenter) x = (area->width - w) / 2;
168 else if (x == G_MININT) x = c->frame->area.x - carea->x;
169 else if (o->xopposite) x = area->width - w - x;
173 if (o->ycenter) y = (area->height - h) / 2;
174 else if (y == G_MININT) y = c->frame->area.y - carea->y;
175 else if (o->yopposite) 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);