2003-04-05 20:27:03 +00:00
|
|
|
#include "kernel/dispatch.h"
|
|
|
|
#include "kernel/client.h"
|
|
|
|
#include "kernel/frame.h"
|
|
|
|
#include "kernel/screen.h"
|
|
|
|
#include "kernel/openbox.h"
|
2003-05-24 21:47:06 +00:00
|
|
|
#include "parser/parse.h"
|
2003-03-21 07:53:29 +00:00
|
|
|
#include "history.h"
|
2003-03-21 07:33:07 +00:00
|
|
|
#include <glib.h>
|
|
|
|
|
2003-04-05 20:27:03 +00:00
|
|
|
static gboolean history;
|
|
|
|
|
2003-05-24 15:35:26 +00:00
|
|
|
static void parse_xml(xmlDocPtr doc, xmlNodePtr node, void *d)
|
2003-04-05 20:27:03 +00:00
|
|
|
{
|
2003-05-24 15:35:26 +00:00
|
|
|
xmlNodePtr n;
|
|
|
|
|
|
|
|
if ((n = parse_find_node("remember", node)))
|
|
|
|
history = parse_bool(doc, n);
|
2003-04-05 20:27:03 +00:00
|
|
|
}
|
2003-03-21 07:53:29 +00:00
|
|
|
|
2003-03-23 19:42:47 +00:00
|
|
|
void plugin_setup_config()
|
|
|
|
{
|
2003-04-05 20:27:03 +00:00
|
|
|
history = TRUE;
|
|
|
|
|
2003-05-24 15:35:26 +00:00
|
|
|
parse_register("placement", parse_xml, NULL);
|
2003-03-23 19:42:47 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 06:38:42 +00:00
|
|
|
static void place_random(ObClient *c)
|
2003-03-21 07:33:07 +00:00
|
|
|
{
|
|
|
|
int l, r, t, b;
|
|
|
|
int x, y;
|
|
|
|
Rect *area;
|
|
|
|
|
2003-07-10 19:06:00 +00:00
|
|
|
if (ob_state() == OB_STATE_STARTING) return;
|
2003-03-22 05:56:32 +00:00
|
|
|
|
2003-07-10 05:44:23 +00:00
|
|
|
area = screen_area_monitor(c->desktop,
|
|
|
|
g_random_int_range(0, screen_num_monitors));
|
2003-03-21 07:33:07 +00:00
|
|
|
|
|
|
|
l = area->x;
|
|
|
|
t = area->y;
|
|
|
|
r = area->x + area->width - c->frame->area.width;
|
|
|
|
b = area->y + area->height - c->frame->area.height;
|
|
|
|
|
2003-03-21 07:53:29 +00:00
|
|
|
if (r > l) x = g_random_int_range(l, r + 1);
|
|
|
|
else x = 0;
|
|
|
|
if (b > t) y = g_random_int_range(t, b + 1);
|
|
|
|
else y = 0;
|
2003-03-21 07:33:07 +00:00
|
|
|
|
|
|
|
frame_frame_gravity(c->frame, &x, &y); /* get where the client should be */
|
2003-07-10 06:18:47 +00:00
|
|
|
client_configure(c, OB_CORNER_TOPLEFT, x, y, c->area.width, c->area.height,
|
2003-03-21 07:33:07 +00:00
|
|
|
TRUE, TRUE);
|
|
|
|
}
|
|
|
|
|
2003-03-21 09:31:36 +00:00
|
|
|
static void event(ObEvent *e, void *foo)
|
2003-03-21 07:33:07 +00:00
|
|
|
{
|
|
|
|
g_assert(e->type == Event_Client_New);
|
|
|
|
|
2003-03-21 10:29:30 +00:00
|
|
|
/* requested a position */
|
|
|
|
if (e->data.c.client->positioned) return;
|
|
|
|
|
2003-04-05 20:27:03 +00:00
|
|
|
if (!history || !place_history(e->data.c.client))
|
2003-03-21 07:53:29 +00:00
|
|
|
place_random(e->data.c.client);
|
2003-03-21 07:33:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void plugin_startup()
|
|
|
|
{
|
2003-03-21 09:31:36 +00:00
|
|
|
dispatch_register(Event_Client_New, (EventHandler)event, NULL);
|
2003-03-21 07:53:29 +00:00
|
|
|
|
|
|
|
history_startup();
|
2003-03-21 07:33:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void plugin_shutdown()
|
|
|
|
{
|
2003-03-21 09:31:36 +00:00
|
|
|
dispatch_register(0, (EventHandler)event, NULL);
|
2003-03-21 07:53:29 +00:00
|
|
|
|
|
|
|
history_shutdown();
|
2003-03-21 07:33:07 +00:00
|
|
|
}
|