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 void free_func(gpointer options);
26 static gboolean run_func(ObActionsData *data, gpointer options);
28 void action_moveresizeto_startup(void)
30 actions_register("MoveResizeTo",
37 static void parse_coord(xmlDocPtr doc, xmlNodePtr n, gint *pos,
38 gboolean *opposite, gboolean *center)
40 gchar *s = parse_string(doc, n);
41 if (g_ascii_strcasecmp(s, "current") != 0) {
42 if (!g_ascii_strcasecmp(s, "center"))
47 if (s[0] == '-' || s[0] == '+')
56 static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
61 o = g_new0(Options, 1);
66 o->monitor = CURRENT_MONITOR;
68 if ((n = parse_find_node("x", node)))
69 parse_coord(doc, n, &o->x, &o->xopposite, &o->xcenter);
71 if ((n = parse_find_node("y", node)))
72 parse_coord(doc, n, &o->y, &o->yopposite, &o->ycenter);
74 if ((n = parse_find_node("width", node))) {
75 gchar *s = parse_string(doc, n);
76 if (g_ascii_strcasecmp(s, "current") != 0)
77 o->w = parse_int(doc, n);
80 if ((n = parse_find_node("height", node))) {
81 gchar *s = parse_string(doc, n);
82 if (g_ascii_strcasecmp(s, "current") != 0)
83 o->h = parse_int(doc, n);
87 if ((n = parse_find_node("monitor", node))) {
88 gchar *s = parse_string(doc, n);
89 if (g_ascii_strcasecmp(s, "current") != 0) {
90 if (!g_ascii_strcasecmp(s, "all"))
91 o->monitor = ALL_MONITORS;
93 o->monitor = parse_int(doc, n) - 1;
101 static void free_func(gpointer options)
103 Options *o = options;
108 /* Always return FALSE because its not interactive */
109 static gboolean run_func(ObActionsData *data, gpointer options)
111 Options *o = options;
117 gint x, y, lw, lh, w, h;
121 cmon = client_monitor(c);
122 if (mon == CURRENT_MONITOR) mon = cmon;
123 else if (mon == ALL_MONITORS) mon = SCREEN_AREA_ALL_MONITORS;
124 area = screen_area(c->desktop, mon, NULL);
125 carea = screen_area(c->desktop, cmon, NULL);
128 if (w == G_MININT) w = c->area.width;
131 if (h == G_MININT) h = c->area.height;
133 /* it might not be able to resize how they requested, so find out what
134 it will actually be resized to */
137 client_try_configure(c, &x, &y, &w, &h, &lw, &lh, TRUE);
139 /* get the frame's size */
140 w += c->frame->size.left + c->frame->size.right;
141 h += c->frame->size.top + c->frame->size.bottom;
144 if (o->xcenter) x = (area->width - w) / 2;
145 else if (x == G_MININT) x = c->frame->area.x - carea->x;
146 else if (o->xopposite) x = area->width - w;
150 if (o->ycenter) y = (area->height - h) / 2;
151 else if (y == G_MININT) y = c->frame->area.y - carea->y;
152 else if (o->yopposite) y = area->height - h;
155 /* get the client's size back */
156 w -= c->frame->size.left + c->frame->size.right;
157 h -= c->frame->size.top + c->frame->size.bottom;
159 frame_frame_gravity(c->frame, &x, &y); /* get the client coords */
160 client_try_configure(c, &x, &y, &w, &h, &lw, &lh, TRUE);
161 /* force it on screen if its moving to another monitor */
162 client_find_onscreen(c, &x, &y, w, h, mon != cmon);
164 actions_client_move(data, TRUE);
165 client_configure(c, x, y, w, h, TRUE, TRUE, FALSE);
166 actions_client_move(data, FALSE);