]> Dogcows Code - chaz/openbox/blob - plugins/placement/placement.c
add a window placement plugin
[chaz/openbox] / 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 <glib.h>
7
8 void place_random(Client *c)
9 {
10 int l, r, t, b;
11 int x, y;
12 Rect *area;
13
14 area = screen_area(c->desktop);
15
16 l = area->x;
17 t = area->y;
18 r = area->x + area->width - c->frame->area.width;
19 b = area->y + area->height - c->frame->area.height;
20
21 x = g_random_int_range(l, r + 1);
22 y = g_random_int_range(t, b + 1);
23
24 frame_frame_gravity(c->frame, &x, &y); /* get where the client should be */
25 client_configure(c, Corner_TopLeft, x, y, c->area.width, c->area.height,
26 TRUE, TRUE);
27 }
28
29 void event(ObEvent *e, void *foo)
30 {
31 g_assert(e->type == Event_Client_New);
32
33 if (ob_state == State_Starting) return;
34
35 place_random(e->data.c.client);
36 }
37
38 void plugin_startup()
39 {
40 dispatch_register(Event_Client_New, (EventHandler)event, NULL);
41 }
42
43 void plugin_shutdown()
44 {
45 dispatch_register(0, (EventHandler)event, NULL);
46 }
This page took 0.037213 seconds and 5 git commands to generate.