]> Dogcows Code - chaz/openbox/blob - plugins/placement/placement.c
dd818970b0fef6b498be005a507bbb549607fe90
[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 "kernel/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(c->desktop);
36
37 l = area->x;
38 t = area->y;
39 r = area->x + area->width - c->frame->area.width;
40 b = area->y + area->height - c->frame->area.height;
41
42 if (r > l) x = g_random_int_range(l, r + 1);
43 else x = 0;
44 if (b > t) y = g_random_int_range(t, b + 1);
45 else y = 0;
46
47 frame_frame_gravity(c->frame, &x, &y); /* get where the client should be */
48 client_configure(c, Corner_TopLeft, x, y, c->area.width, c->area.height,
49 TRUE, TRUE);
50 }
51
52 static void event(ObEvent *e, void *foo)
53 {
54 g_assert(e->type == Event_Client_New);
55
56 /* requested a position */
57 if (e->data.c.client->positioned) return;
58
59 if (!history || !place_history(e->data.c.client))
60 place_random(e->data.c.client);
61 }
62
63 void plugin_startup()
64 {
65 dispatch_register(Event_Client_New, (EventHandler)event, NULL);
66
67 history_startup();
68 }
69
70 void plugin_shutdown()
71 {
72 dispatch_register(0, (EventHandler)event, NULL);
73
74 history_shutdown();
75 }
This page took 0.040458 seconds and 3 git commands to generate.