From 29e3748605eaf86635aed48273bddfdcdcae05c4 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Fri, 21 Mar 2003 07:33:07 +0000 Subject: [PATCH] add a window placement plugin --- .cvsignore | 1 + configure.ac | 1 + openbox/openbox.c | 1 + plugins/Makefile.am | 2 +- plugins/placement/.cvsignore | 6 +++++ plugins/placement/Makefile.am | 17 +++++++++++++ plugins/placement/placement.c | 46 +++++++++++++++++++++++++++++++++++ 7 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 plugins/placement/.cvsignore create mode 100644 plugins/placement/Makefile.am create mode 100644 plugins/placement/placement.c diff --git a/.cvsignore b/.cvsignore index 6e0a7615..a285411c 100644 --- a/.cvsignore +++ b/.cvsignore @@ -23,3 +23,4 @@ depcomp config.rpath py-compile ABOUT-NLS +compile diff --git a/configure.ac b/configure.ac index 1206cee5..79244a3c 100644 --- a/configure.ac +++ b/configure.ac @@ -64,6 +64,7 @@ AC_CONFIG_FILES([Makefile po/Makefile.in plugins/Makefile plugins/keyboard/Makefile plugins/mouse/Makefile + plugins/placement/Makefile doc/Makefile doc/doxygen/Makefile data/Makefile diff --git a/openbox/openbox.c b/openbox/openbox.c index 268d4e6d..e7fd7931 100644 --- a/openbox/openbox.c +++ b/openbox/openbox.c @@ -150,6 +150,7 @@ int main(int argc, char **argv) plugin_open("focus"); plugin_open("keyboard"); plugin_open("mouse"); + plugin_open("placement"); /* get all the existing windows */ client_manage_all(); diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 9e02e5fb..97d6d53f 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -1,6 +1,6 @@ plugindir=$(libdir)/openbox/plugins -SUBDIRS = keyboard mouse +SUBDIRS = keyboard mouse placement CPPFLAGS=$(XFT_CFLAGS) $(GLIB_CFLAGS) @CPPFLAGS@ \ -DPLUGINDIR=\"$(plugindir)\" diff --git a/plugins/placement/.cvsignore b/plugins/placement/.cvsignore new file mode 100644 index 00000000..75afa579 --- /dev/null +++ b/plugins/placement/.cvsignore @@ -0,0 +1,6 @@ +Makefile.in +Makefile +placement.la +placement.lo +.deps +.libs diff --git a/plugins/placement/Makefile.am b/plugins/placement/Makefile.am new file mode 100644 index 00000000..58993833 --- /dev/null +++ b/plugins/placement/Makefile.am @@ -0,0 +1,17 @@ +plugindir=$(libdir)/openbox/plugins + +CPPFLAGS=$(XFT_CFLAGS) $(GLIB_CFLAGS) @CPPFLAGS@ \ +-DPLUGINDIR=\"$(plugindir)\" \ +-DG_LOG_DOMAIN=\"Plugin-Placement\" + +plugin_LTLIBRARIES=placement.la + +placement_la_LDFLAGS=-module -avoid-version +placement_la_SOURCES=placement.c + +noinst_HEADERS= + +MAINTAINERCLEANFILES=Makefile.in + +distclean-local: + $(RM) *\~ *.orig *.rej .\#* diff --git a/plugins/placement/placement.c b/plugins/placement/placement.c new file mode 100644 index 00000000..f33e45de --- /dev/null +++ b/plugins/placement/placement.c @@ -0,0 +1,46 @@ +#include "../../kernel/dispatch.h" +#include "../../kernel/client.h" +#include "../../kernel/frame.h" +#include "../../kernel/screen.h" +#include "../../kernel/openbox.h" +#include + +void place_random(Client *c) +{ + int l, r, t, b; + int x, y; + Rect *area; + + area = screen_area(c->desktop); + + l = area->x; + t = area->y; + r = area->x + area->width - c->frame->area.width; + b = area->y + area->height - c->frame->area.height; + + x = g_random_int_range(l, r + 1); + y = g_random_int_range(t, b + 1); + + frame_frame_gravity(c->frame, &x, &y); /* get where the client should be */ + client_configure(c, Corner_TopLeft, x, y, c->area.width, c->area.height, + TRUE, TRUE); +} + +void event(ObEvent *e, void *foo) +{ + g_assert(e->type == Event_Client_New); + + if (ob_state == State_Starting) return; + + place_random(e->data.c.client); +} + +void plugin_startup() +{ + dispatch_register(Event_Client_New, (EventHandler)event, NULL); +} + +void plugin_shutdown() +{ + dispatch_register(0, (EventHandler)event, NULL); +} -- 2.45.2