]> Dogcows Code - chaz/openbox/blob - openbox/actions/moveresizeto.c
remove trailing whitespace
[chaz/openbox] / openbox / actions / moveresizeto.c
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 */
6
7 typedef struct {
8 gboolean xcenter;
9 gboolean ycenter;
10 gboolean xopposite;
11 gboolean yopposite;
12 gint x;
13 gint y;
14 gint w;
15 gint h;
16 gint monitor;
17 } Options;
18
19 static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node);
20 static void free_func(gpointer options);
21 static gboolean run_func(ObActionsData *data, gpointer options);
22
23 void action_moveresizeto_startup()
24 {
25 actions_register("MoveResizeTo",
26 setup_func,
27 free_func,
28 run_func,
29 NULL, NULL);
30 }
31
32 static void parse_coord(xmlDocPtr doc, xmlNodePtr n, gint *pos,
33 gboolean *opposite, gboolean *center)
34 {
35 gchar *s = parse_string(doc, n);
36 if (!g_ascii_strcasecmp(s, "center"))
37 *center = TRUE;
38 else {
39 if (s[0] == '-')
40 *opposite = TRUE;
41 if (s[0] == '-' || s[0] == '+')
42 *pos = atoi(s+1);
43 else
44 *pos = atoi(s);
45 }
46 g_free(s);
47 }
48
49 static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
50 {
51 xmlNodePtr n;
52 Options *o;
53
54 o = g_new0(Options, 1);
55 o->x = G_MININT;
56 o->y = G_MININT;
57 o->w = G_MININT;
58 o->h = G_MININT;
59 o->monitor = -1;
60
61 if ((n = parse_find_node("x", node)))
62 parse_coord(doc, n, &o->x, &o->xopposite, &o->xcenter);
63
64 if ((n = parse_find_node("y", node)))
65 parse_coord(doc, n, &o->y, &o->yopposite, &o->ycenter);
66
67 if ((n = parse_find_node("width", node)))
68 o->w = parse_int(doc, n) - 1;
69 if ((n = parse_find_node("height", node)))
70 o->h = parse_int(doc, n) - 1;
71
72 if ((n = parse_find_node("monitor", node)))
73 o->monitor = parse_int(doc, n) - 1;
74
75 return o;
76 }
77
78 static void free_func(gpointer options)
79 {
80 Options *o = options;
81
82 g_free(o);
83 }
84
85 /* Always return FALSE because its not interactive */
86 static gboolean run_func(ObActionsData *data, gpointer options)
87 {
88 Options *o = options;
89
90 if (data->client) {
91 Rect *area, *carea;
92 ObClient *c;
93 gint mon, cmon;
94 gint x, y, lw, lh, w, h;
95
96 c = data->client;
97 mon = o->monitor;
98 cmon = client_monitor(c);
99 if (mon < 0) mon = cmon;
100 area = screen_area(c->desktop, mon, NULL);
101 carea = screen_area(c->desktop, cmon, NULL);
102
103 w = o->w;
104 if (w == G_MININT) w = c->area.width;
105
106 h = o->h;
107 if (h == G_MININT) h = c->area.height;
108
109 /* it might not be able to resize how they requested, so find out what
110 it will actually be resized to */
111 x = c->area.x;
112 y = c->area.y;
113 client_try_configure(c, &x, &y, &w, &h, &lw, &lh, TRUE);
114
115 /* get the frame's size */
116 w += c->frame->size.left + c->frame->size.right;
117 h += c->frame->size.top + c->frame->size.bottom;
118
119 x = o->x;
120 if (o->xcenter) x = (area->width - w) / 2;
121 else if (x == G_MININT) x = c->frame->area.x - carea->x;
122 else if (o->xopposite) x = area->width - w;
123 x += area->x;
124
125 y = o->y;
126 if (o->ycenter) y = (area->height - h) / 2;
127 else if (y == G_MININT) y = c->frame->area.y - carea->y;
128 else if (o->yopposite) y = area->height - h;
129 y += area->y;
130
131 /* get the client's size back */
132 w -= c->frame->size.left + c->frame->size.right;
133 h -= c->frame->size.top + c->frame->size.bottom;
134
135 frame_frame_gravity(c->frame, &x, &y); /* get the client coords */
136 client_try_configure(c, &x, &y, &w, &h, &lw, &lh, TRUE);
137 /* force it on screen if its moving to another monitor */
138 client_find_onscreen(c, &x, &y, w, h, mon != cmon);
139
140 actions_client_move(data, TRUE);
141 client_configure(c, x, y, w, h, TRUE, TRUE, FALSE);
142 actions_client_move(data, FALSE);
143
144 g_free(area);
145 g_free(carea);
146 }
147
148 return FALSE;
149 }
This page took 0.038744 seconds and 5 git commands to generate.