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 Rect* pick_head(ObClient *c)
31 /* more than one guy in his group (more than just him) */
32 if (c->group && c->group->members->next) {
35 /* try on the client's desktop */
36 for (it = c->group->members; it; it = g_slist_next(it)) {
37 ObClient *itc = it->data;
39 (itc->desktop == c->desktop ||
40 itc->desktop == DESKTOP_ALL || c->desktop == DESKTOP_ALL))
41 return screen_area_monitor(c->desktop,
42 client_monitor(it->data));
45 /* try on all desktops */
46 for (it = c->group->members; it; it = g_slist_next(it)) {
47 ObClient *itc = it->data;
49 return screen_area_monitor(c->desktop,
50 client_monitor(it->data));
57 static void place_random(ObClient *c)
63 if (ob_state() == OB_STATE_STARTING) return;
67 area = screen_area_monitor(c->desktop,
68 g_random_int_range(0, screen_num_monitors));
72 r = area->x + area->width - c->frame->area.width;
73 b = area->y + area->height - c->frame->area.height;
75 if (r > l) x = g_random_int_range(l, r + 1);
77 if (b > t) y = g_random_int_range(t, b + 1);
80 frame_frame_gravity(c->frame, &x, &y); /* get where the client should be */
81 client_configure(c, OB_CORNER_TOPLEFT, x, y, c->area.width, c->area.height,
85 static void event(ObEvent *e, void *foo)
87 g_assert(e->type == Event_Client_New);
89 /* requested a position */
90 if (e->data.c.client->positioned) return;
92 if (e->data.c.client->transient_for) {
93 if (e->data.c.client->transient_for != OB_TRAN_GROUP) {
94 ObClient *c = e->data.c.client;
95 ObClient *p = e->data.c.client->transient_for;
96 int x = (p->frame->area.width - c->frame->area.width) / 2 +
98 int y = (p->frame->area.height - c->frame->area.height) / 2 +
100 client_configure(c, OB_CORNER_TOPLEFT, x, y,
101 c->area.width, c->area.height,
106 ObClient *c = e->data.c.client;
107 gboolean first = TRUE;
109 for (it = c->group->members; it; it = it->next) {
110 ObClient *m = it->data;
111 if (!(m == c || m->transient_for)) {
113 l = m->frame->area.x;
114 t = m->frame->area.y;
115 r = m->frame->area.x + m->frame->area.width - 1;
116 b = m->frame->area.y + m->frame->area.height - 1;
119 l = MIN(l, m->frame->area.x);
120 t = MIN(t, m->frame->area.y);
121 r = MAX(r, m->frame->area.x +m->frame->area.width - 1);
122 b = MAX(b, m->frame->area.y +m->frame->area.height -1);
127 int x = ((r + 1 - l) - c->frame->area.width) / 2 + l;
128 int y = ((b + 1 - t) - c->frame->area.height) / 2 + t;
129 client_configure(c, OB_CORNER_TOPLEFT, x, y,
130 c->area.width, c->area.height,
137 /* center parentless dialogs on the screen */
138 if (e->data.c.client->type == OB_CLIENT_TYPE_DIALOG) {
140 ObClient *c = e->data.c.client;
145 area = screen_area_monitor(c->desktop, 0);
147 x = (area->width - c->frame->area.width) / 2 + area->x;
148 y = (area->height - c->frame->area.height) / 2 + area->y;
149 client_configure(c, OB_CORNER_TOPLEFT, x, y,
150 c->area.width, c->area.height,
155 if (!history || !place_history(e->data.c.client))
156 place_random(e->data.c.client);
159 void plugin_startup()
161 dispatch_register(Event_Client_New, (EventHandler)event, NULL);
166 void plugin_shutdown()
168 dispatch_register(0, (EventHandler)event, NULL);