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. */
129 if (w == G_MININT) { /* not given, so no-op with current value */
130 if (o->w_sets_client_size)
133 w = c->frame->area.width;
135 else if (o->w_denom) /* used for eg. "1/3" or "55%" */
136 w = (w * area->width) / o->w_denom;
140 if (o->h_sets_client_size)
143 h = c->frame->area.height;
146 h = (h * area->height) / o->h_denom;
148 /* get back to the client's size. */
149 if (!o->w_sets_client_size)
150 w -= c->frame->size.left + c->frame->size.right;
151 if (!o->h_sets_client_size)
152 h -= c->frame->size.top + c->frame->size.bottom;
154 /* it might not be able to resize how they requested, so find out what
155 it will actually be resized to */
158 client_try_configure(c, &x, &y, &w, &h, &lw, &lh, TRUE);
160 /* get the frame's size */
161 w += c->frame->size.left + c->frame->size.right;
162 h += c->frame->size.top + c->frame->size.bottom;
164 /* get the position */
166 if (o->x.denom) /* relative positions */
167 x = (x * area->width) / o->x.denom;
168 if (o->x.center) x = (area->width - w) / 2;
169 else if (x == G_MININT) /* not specified */
170 x = c->frame->area.x - carea->x;
171 else if (o->x.opposite) /* value relative to right edge instead of left */
172 x = area->width - w - x;
177 y = (y * area->height) / o->y.denom;
178 if (o->y.center) y = (area->height - h) / 2;
179 else if (y == G_MININT)
180 y = c->frame->area.y - carea->y;
181 else if (o->y.opposite)
182 y = area->height - h - y;
185 /* get the client's size back */
186 w -= c->frame->size.left + c->frame->size.right;
187 h -= c->frame->size.top + c->frame->size.bottom;
189 frame_frame_gravity(c->frame, &x, &y); /* get the client coords */
190 client_try_configure(c, &x, &y, &w, &h, &lw, &lh, TRUE);
191 /* force it on screen if its moving to another monitor */
192 client_find_onscreen(c, &x, &y, w, h, mon != cmon);
194 actions_client_move(data, TRUE);
195 client_configure(c, x, y, w, h, TRUE, TRUE, FALSE);
196 actions_client_move(data, FALSE);
198 g_slice_free(Rect, area);
199 g_slice_free(Rect, carea);
205 /* 3.4-compatibility */
206 static gpointer setup_center_func(xmlNodePtr node)
210 o = g_slice_new0(Options);