]> icculus.org git repositories - dana/openbox.git/blob - plugins/placement/placement.c
add the plugin_setup_config function
[dana/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 "history.h"
7 #include <glib.h>
8
9 gboolean history = TRUE;
10
11 void plugin_setup_config()
12 {
13 }
14
15 static void place_random(Client *c)
16 {
17     int l, r, t, b;
18     int x, y;
19     Rect *area;
20
21     if (ob_state == State_Starting) return;
22
23     area = screen_area(c->desktop);
24
25     l = area->x;
26     t = area->y;
27     r = area->x + area->width - c->frame->area.width;
28     b = area->y + area->height - c->frame->area.height;
29
30     if (r > l) x = g_random_int_range(l, r + 1);
31     else       x = 0;
32     if (b > t) y = g_random_int_range(t, b + 1);
33     else       y = 0;
34
35     frame_frame_gravity(c->frame, &x, &y); /* get where the client should be */
36     client_configure(c, Corner_TopLeft, x, y, c->area.width, c->area.height,
37                      TRUE, TRUE);
38 }
39
40 static void event(ObEvent *e, void *foo)
41 {
42     g_assert(e->type == Event_Client_New);
43
44     /* requested a position */
45     if (e->data.c.client->positioned) return;
46
47     if (!place_history(e->data.c.client))
48         place_random(e->data.c.client);
49 }
50
51 void plugin_startup()
52 {
53     dispatch_register(Event_Client_New, (EventHandler)event, NULL);
54
55     history_startup();
56 }
57
58 void plugin_shutdown()
59 {
60     dispatch_register(0, (EventHandler)event, NULL);
61
62     history_shutdown();
63 }