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 if (e->data.c.client->transient_for) {
60 if (e->data.c.client->transient_for != OB_TRAN_GROUP) {
61 ObClient *c = e->data.c.client;
62 ObClient *p = e->data.c.client->transient_for;
63 int x = (p->frame->area.width - c->frame->area.width) / 2 +
65 int y = (p->frame->area.height - c->frame->area.height) / 2 +
67 client_configure(c, OB_CORNER_TOPLEFT, x, y,
68 c->area.width, c->area.height,
73 ObClient *c = e->data.c.client;
74 gboolean first = TRUE;
76 for (it = c->group->members; it; it = it->next) {
77 ObClient *m = it->data;
78 if (!(m == c || m->transient_for)) {
82 r = m->frame->area.x + m->frame->area.width - 1;
83 b = m->frame->area.y + m->frame->area.height - 1;
86 l = MIN(l, m->frame->area.x);
87 t = MIN(t, m->frame->area.y);
88 r = MAX(r, m->frame->area.x +m->frame->area.width - 1);
89 b = MAX(b, m->frame->area.y +m->frame->area.height -1);
94 int x = ((r + 1 - l) - c->frame->area.width) / 2 + l;
95 int y = ((b + 1 - t) - c->frame->area.height) / 2 + t;
96 client_configure(c, OB_CORNER_TOPLEFT, x, y,
97 c->area.width, c->area.height,
104 /* requested a position */
105 if (e->data.c.client->positioned) return;
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);