]> icculus.org git repositories - mikachu/openbox.git/blob - plugins/placement/placement.c
xinerama support
[mikachu/openbox.git] / plugins / placement / placement.c
1 #include "kernel/dispatch.h"
2 #include "kernel/client.h"
3 #include "kernel/frame.h"
4 #include "kernel/screen.h"
5 #include "kernel/openbox.h"
6 #include "parser/parse.h"
7 #include "history.h"
8 #include <glib.h>
9
10 static gboolean history;
11
12 static void parse_xml(xmlDocPtr doc, xmlNodePtr node, void *d)
13 {
14     xmlNodePtr n;
15
16     if ((n = parse_find_node("remember", node)))
17         history = parse_bool(doc, n);
18 }
19
20 void plugin_setup_config()
21 {
22     history = TRUE;
23
24     parse_register("placement", parse_xml, NULL);
25 }
26
27 static void place_random(Client *c)
28 {
29     int l, r, t, b;
30     int x, y;
31     Rect *area;
32
33     if (ob_state == State_Starting) return;
34
35     area = screen_area_xinerama(c->desktop,
36                                 g_random_int_range(0, screen_num_xin_areas));
37
38     l = area->x;
39     t = area->y;
40     r = area->x + area->width - c->frame->area.width;
41     b = area->y + area->height - c->frame->area.height;
42
43     if (r > l) x = g_random_int_range(l, r + 1);
44     else       x = 0;
45     if (b > t) y = g_random_int_range(t, b + 1);
46     else       y = 0;
47
48     frame_frame_gravity(c->frame, &x, &y); /* get where the client should be */
49     client_configure(c, Corner_TopLeft, x, y, c->area.width, c->area.height,
50                      TRUE, TRUE);
51 }
52
53 static void event(ObEvent *e, void *foo)
54 {
55     g_assert(e->type == Event_Client_New);
56
57     /* requested a position */
58     if (e->data.c.client->positioned) return;
59
60     if (!history || !place_history(e->data.c.client))
61         place_random(e->data.c.client);
62 }
63
64 void plugin_startup()
65 {
66     dispatch_register(Event_Client_New, (EventHandler)event, NULL);
67
68     history_startup();
69 }
70
71 void plugin_shutdown()
72 {
73     dispatch_register(0, (EventHandler)event, NULL);
74
75     history_shutdown();
76 }