1 #include "kernel/dispatch.h"
2 #include "kernel/client.h"
3 #include "kernel/group.h"
4 #include "kernel/frame.h"
5 #include "kernel/screen.h"
6 #include "kernel/openbox.h"
7 #include "parser/parse.h"
11 static gboolean history;
13 static void parse_xml(xmlDocPtr doc, xmlNodePtr node, void *d)
17 node = node->xmlChildrenNode;
18 if ((n = parse_find_node("remember", node)))
19 history = parse_bool(doc, n);
22 void plugin_setup_config()
26 parse_register("placement", parse_xml, NULL);
29 static void place_random(ObClient *c)
35 if (ob_state() == OB_STATE_STARTING) return;
37 area = screen_area_monitor(c->desktop,
38 g_random_int_range(0, screen_num_monitors));
42 r = area->x + area->width - c->frame->area.width;
43 b = area->y + area->height - c->frame->area.height;
45 if (r > l) x = g_random_int_range(l, r + 1);
47 if (b > t) y = g_random_int_range(t, b + 1);
50 frame_frame_gravity(c->frame, &x, &y); /* get where the client should be */
51 client_configure(c, OB_CORNER_TOPLEFT, x, y, c->area.width, c->area.height,
55 static void event(ObEvent *e, void *foo)
57 g_assert(e->type == Event_Client_New);
59 /* requested a position */
60 if (e->data.c.client->positioned) return;
62 if (e->data.c.client->transient_for) {
63 if (e->data.c.client->transient_for != OB_TRAN_GROUP) {
64 ObClient *c = e->data.c.client;
65 ObClient *p = e->data.c.client->transient_for;
66 int x = (p->frame->area.width - c->frame->area.width) / 2 +
68 int y = (p->frame->area.height - c->frame->area.height) / 2 +
70 client_configure(c, OB_CORNER_TOPLEFT, x, y,
71 c->area.width, c->area.height,
76 ObClient *c = e->data.c.client;
77 gboolean first = TRUE;
79 for (it = c->group->members; it; it = it->next) {
80 ObClient *m = it->data;
81 if (!(m == c || m->transient_for)) {
85 r = m->frame->area.x + m->frame->area.width - 1;
86 b = m->frame->area.y + m->frame->area.height - 1;
89 l = MIN(l, m->frame->area.x);
90 t = MIN(t, m->frame->area.y);
91 r = MAX(r, m->frame->area.x +m->frame->area.width - 1);
92 b = MAX(b, m->frame->area.y +m->frame->area.height -1);
97 int x = ((r + 1 - l) - c->frame->area.width) / 2 + l;
98 int y = ((b + 1 - t) - c->frame->area.height) / 2 + t;
99 client_configure(c, OB_CORNER_TOPLEFT, x, y,
100 c->area.width, c->area.height,
107 if (!history || !place_history(e->data.c.client))
108 place_random(e->data.c.client);
111 void plugin_startup()
113 dispatch_register(Event_Client_New, (EventHandler)event, NULL);
118 void plugin_shutdown()
120 dispatch_register(0, (EventHandler)event, NULL);