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 */
26
static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node);
27
static gpointer setup_center_func(ObParseInst *i, xmlDocPtr doc,
29
static void free_func(gpointer options);
30
static gboolean run_func(ObActionsData *data, gpointer options);
32
void action_moveresizeto_startup(void)
34
actions_register("MoveResizeTo",
39
actions_register("MoveToCenter",
46
static void parse_coord(xmlDocPtr doc, xmlNodePtr n, gint *pos,
47
gboolean *opposite, gboolean *center)
49
gchar *s = parse_string(doc, n);
50
if (g_ascii_strcasecmp(s, "current") != 0) {
51
if (!g_ascii_strcasecmp(s, "center"))
56
if (s[0] == '-' || s[0] == '+')
65
static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
70
o = g_new0(Options, 1);
75
o->monitor = CURRENT_MONITOR;
77
if ((n = parse_find_node("x", node)))
78
parse_coord(doc, n, &o->x, &o->xopposite, &o->xcenter);
80
if ((n = parse_find_node("y", node)))
81
parse_coord(doc, n, &o->y, &o->yopposite, &o->ycenter);
83
if ((n = parse_find_node("width", node))) {
84
gchar *s = parse_string(doc, n);
85
if (g_ascii_strcasecmp(s, "current") != 0)
86
o->w = parse_int(doc, n);
89
if ((n = parse_find_node("height", node))) {
90
gchar *s = parse_string(doc, n);
91
if (g_ascii_strcasecmp(s, "current") != 0)
92
o->h = parse_int(doc, n);
96
if ((n = parse_find_node("monitor", node))) {
97
gchar *s = parse_string(doc, n);
98
if (g_ascii_strcasecmp(s, "current") != 0) {
99
if (!g_ascii_strcasecmp(s, "all"))
100
o->monitor = ALL_MONITORS;
101
else if(!g_ascii_strcasecmp(s, "next"))
102
o->monitor = NEXT_MONITOR;
103
else if(!g_ascii_strcasecmp(s, "prev"))
104
o->monitor = PREV_MONITOR;
106
o->monitor = parse_int(doc, n) - 1;
114
static gpointer setup_center_func(ObParseInst *i, xmlDocPtr doc,
119
o = g_new0(Options, 1);
130
static void free_func(gpointer options)
132
Options *o = options;
137
/* Always return FALSE because its not interactive */
138
static gboolean run_func(ObActionsData *data, gpointer options)
140
Options *o = options;
146
gint x, y, lw, lh, w, h;
150
cmon = client_monitor(c);
152
case CURRENT_MONITOR:
155
mon = SCREEN_AREA_ALL_MONITORS; break;
157
mon = (cmon + 1 > screen_num_monitors - 1) ? 0 : (cmon + 1); break;
159
mon = (cmon == 0) ? (screen_num_monitors - 1) : (cmon - 1); break;
161
g_assert_not_reached();
164
area = screen_area(c->desktop, mon, NULL);
165
carea = screen_area(c->desktop, cmon, NULL);
168
if (w == G_MININT) w = c->area.width;
171
if (h == G_MININT) h = c->area.height;
173
/* it might not be able to resize how they requested, so find out what
174
it will actually be resized to */
177
client_try_configure(c, &x, &y, &w, &h, &lw, &lh, TRUE);
179
/* get the frame's size */
180
w += c->frame->size.left + c->frame->size.right;
181
h += c->frame->size.top + c->frame->size.bottom;
184
if (o->xcenter) x = (area->width - w) / 2;
185
else if (x == G_MININT) x = c->frame->area.x - carea->x;
186
else if (o->xopposite) x = area->width - w - x;
190
if (o->ycenter) y = (area->height - h) / 2;
191
else if (y == G_MININT) y = c->frame->area.y - carea->y;
192
else if (o->yopposite) y = area->height - h - y;
195
/* get the client's size back */
196
w -= c->frame->size.left + c->frame->size.right;
197
h -= c->frame->size.top + c->frame->size.bottom;
199
frame_frame_gravity(c->frame, &x, &y); /* get the client coords */
200
client_try_configure(c, &x, &y, &w, &h, &lw, &lh, TRUE);
201
/* force it on screen if its moving to another monitor */
202
client_find_onscreen(c, &x, &y, w, h, mon != cmon);
204
actions_client_move(data, TRUE);
205
client_configure(c, x, y, w, h, TRUE, TRUE, FALSE);
206
actions_client_move(data, FALSE);