]> icculus.org git repositories - mikachu/openbox.git/blob - plugins/placement/placement.c
the parsing shit changed but this didnt yet
[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     node = node->xmlChildrenNode;
17     if ((n = parse_find_node("remember", node)))
18         history = parse_bool(doc, n);
19 }
20
21 void plugin_setup_config()
22 {
23     history = TRUE;
24
25     parse_register("placement", parse_xml, NULL);
26 }
27
28 static void place_random(ObClient *c)
29 {
30     int l, r, t, b;
31     int x, y;
32     Rect *area;
33
34     if (ob_state() == OB_STATE_STARTING) return;
35
36     area = screen_area_monitor(c->desktop,
37                                g_random_int_range(0, screen_num_monitors));
38
39     l = area->x;
40     t = area->y;
41     r = area->x + area->width - c->frame->area.width;
42     b = area->y + area->height - c->frame->area.height;
43
44     if (r > l) x = g_random_int_range(l, r + 1);
45     else       x = 0;
46     if (b > t) y = g_random_int_range(t, b + 1);
47     else       y = 0;
48
49     frame_frame_gravity(c->frame, &x, &y); /* get where the client should be */
50     client_configure(c, OB_CORNER_TOPLEFT, x, y, c->area.width, c->area.height,
51                      TRUE, TRUE);
52 }
53
54 static void event(ObEvent *e, void *foo)
55 {
56     g_assert(e->type == Event_Client_New);
57
58     /* requested a position */
59     if (e->data.c.client->positioned) return;
60
61     if (!history || !place_history(e->data.c.client))
62         place_random(e->data.c.client);
63 }
64
65 void plugin_startup()
66 {
67     dispatch_register(Event_Client_New, (EventHandler)event, NULL);
68
69     history_startup();
70 }
71
72 void plugin_shutdown()
73 {
74     dispatch_register(0, (EventHandler)event, NULL);
75
76     history_shutdown();
77 }