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"
24 static gpointer setup_func(xmlNodePtr node);
25 static void free_func(gpointer o);
26 static gboolean run_func(ObActionsData *data, gpointer options);
27 /* 3.4-compatibility */
28 static gpointer setup_center_func(xmlNodePtr node);
30 void action_moveresizeto_startup(void)
32 actions_register("MoveResizeTo", setup_func, free_func, run_func);
33 /* 3.4-compatibility */
34 actions_register("MoveToCenter", setup_center_func, free_func, run_func);
37 static gpointer setup_func(xmlNodePtr node)
42 o = g_slice_new0(Options);
47 o->monitor = CURRENT_MONITOR;
49 if ((n = obt_xml_find_node(node, "x")))
50 config_parse_gravity_coord(n, &o->x);
52 if ((n = obt_xml_find_node(node, "y")))
53 config_parse_gravity_coord(n, &o->y);
55 if ((n = obt_xml_find_node(node, "width"))) {
56 gchar *s = obt_xml_node_string(n);
57 if (g_ascii_strcasecmp(s, "current") != 0)
58 config_parse_relative_number(s, &o->w, &o->w_denom);
61 if ((n = obt_xml_find_node(node, "height"))) {
62 gchar *s = obt_xml_node_string(n);
63 if (g_ascii_strcasecmp(s, "current") != 0)
64 config_parse_relative_number(s, &o->h, &o->h_denom);
68 if ((n = obt_xml_find_node(node, "monitor"))) {
69 gchar *s = obt_xml_node_string(n);
70 if (g_ascii_strcasecmp(s, "current") != 0) {
71 if (!g_ascii_strcasecmp(s, "all"))
72 o->monitor = ALL_MONITORS;
73 else if(!g_ascii_strcasecmp(s, "next"))
74 o->monitor = NEXT_MONITOR;
75 else if(!g_ascii_strcasecmp(s, "prev"))
76 o->monitor = PREV_MONITOR;
78 o->monitor = obt_xml_node_int(n) - 1;
86 static void free_func(gpointer o)
88 g_slice_free(Options, o);
91 /* Always return FALSE because its not interactive */
92 static gboolean run_func(ObActionsData *data, gpointer options)
100 gint x, y, lw, lh, w, h;
104 cmon = client_monitor(c);
106 case CURRENT_MONITOR:
109 mon = SCREEN_AREA_ALL_MONITORS; break;
111 mon = (cmon + 1 > screen_num_monitors - 1) ? 0 : (cmon + 1); break;
113 mon = (cmon == 0) ? (screen_num_monitors - 1) : (cmon - 1); break;
115 g_assert_not_reached();
118 area = screen_area(c->desktop, mon, NULL);
119 carea = screen_area(c->desktop, cmon, NULL);
122 if (w == G_MININT) w = c->area.width;
123 else if (o->w_denom) w = (w * area->width) / o->w_denom;
126 if (h == G_MININT) h = c->area.height;
127 else if (o->h_denom) h = (h * area->height) / o->h_denom;
129 /* it might not be able to resize how they requested, so find out what
130 it will actually be resized to */
133 client_try_configure(c, &x, &y, &w, &h, &lw, &lh, TRUE);
135 /* get the frame's size */
136 w += c->frame->size.left + c->frame->size.right;
137 h += c->frame->size.top + c->frame->size.bottom;
141 x = (x * area->width) / o->x.denom;
142 if (o->x.center) x = (area->width - w) / 2;
143 else if (x == G_MININT) x = c->frame->area.x - carea->x;
144 else if (o->x.opposite) x = area->width - w - x;
149 y = (y * area->height) / o->y.denom;
150 if (o->y.center) y = (area->height - h) / 2;
151 else if (y == G_MININT) y = c->frame->area.y - carea->y;
152 else if (o->y.opposite) y = area->height - h - y;
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);
168 g_slice_free(Rect, area);
169 g_slice_free(Rect, carea);
175 /* 3.4-compatibility */
176 static gpointer setup_center_func(xmlNodePtr node)
180 o = g_slice_new0(Options);