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