start a focus plugin.
/* get_context */
typedef GQuark EngineGetContext(Client *client, Window win);
-/* frame_mouse_enter */
-typedef void EngineMouseEnter(Frame *self, Window win);
-/* frame_mouse_leave */
-typedef void EngineMouseLeave(Frame *self, Window win);
-/* frame_mouse_press */
-typedef void EngineMousePress(Frame *self, Window win, int x, int y);
-/* frame_mouse_release */
-typedef void EngineMouseRelease(Frame *self, Window win, int x, int y);
-
#endif
ob3_LDFLAGS=-export-dynamic
ob3_SOURCES=client.c event.c extensions.c focus.c frame.c openbox.c prop.c \
screen.c stacking.c xerror.c themerc.c timer.c dispatch.c \
- engine.c
+ engine.c plugin.c
noinst_HEADERS=client.h event.h extensions.h focus.h frame.h geom.h gettext.h \
openbox.h prop.h screen.h stacking.h xerror.h themerc.h dispatch.h \
- timer.h engine.h
+ timer.h engine.h plugin.h
MAINTAINERCLEANFILES= Makefile.in
#include <glib.h>
+typedef struct {
+ EventHandler h;
+ void *data;
+} Func;
+
static GSList **funcs;
void dispatch_startup()
{
guint i;
EventType j;
+ GSList *it;
for (i = 0, j = 1; j < EVENT_RANGE; ++i, j <<= 1) {
+ for (it = funcs[i]; it != NULL; it = it->next)
+ g_free(it->data);
g_slist_free(funcs[i]);
funcs[i] = NULL;
}
g_free(funcs);
}
-void dispatch_register(EventHandler h, EventMask mask)
+void dispatch_register(EventMask mask, EventHandler h, void *data)
{
guint i;
EventType j;
+ GSList *it, *next;
+ EventMask m;
+ Func *f;
- while (mask) {
+ /* add to masks it needs to be registered for */
+ m = mask;
+ while (m) {
for (i = 0, j = 1; j < EVENT_RANGE; ++i, j <<= 1)
- if (mask & j) {
- funcs[i] = g_slist_append(funcs[i], h);
- mask ^= j; /* remove from the mask */
+ if (m & j) {
+ for (it = funcs[i]; it != NULL; it = it->next) {
+ f = it->data;
+ if (f->h == h && f->data == data)
+ break;
+ }
+ if (it == NULL) { /* wasn't already regged */
+ f = g_new(Func, 1);
+ f->h = h;
+ f->data = data;
+ funcs[i] = g_slist_append(funcs[i], f);
+ }
+ m ^= j; /* remove from the mask */
}
g_assert(j >= EVENT_RANGE); /* an invalid event is in the mask */
}
+
+ /* remove from masks its not registered for anymore */
+ for (i = 0, j = 1; j < EVENT_RANGE; ++i, j <<= 1) {
+ if (!(j & mask))
+ for (it = funcs[i]; it != NULL; it = next) {
+ next = it->next;
+ f = it->data;
+ if (f->h == h && f->data == data) {
+ g_free(f);
+ funcs[i] = g_slist_delete_link(funcs[i], it);
+ }
+ }
+ }
}
void dispatch_x(XEvent *xe, Client *c)
++i;
}
- for (it = funcs[i]; it != NULL; it = it->next)
- ((EventHandler)it->data)(&obe);
+ for (it = funcs[i]; it != NULL; it = it->next) {
+ Func *f = it->data;
+ f->h(&obe, f->data);
+ }
}
void dispatch_client(EventType e, Client *c)
++i;
}
- for (it = funcs[i]; it != NULL; it = it->next)
- ((EventHandler)it->data)(&obe);
+ for (it = funcs[i]; it != NULL; it = it->next) {
+ Func *f = it->data;
+ f->h(&obe, f->data);
+ }
}
void dispatch_ob(EventType e)
++i;
}
- for (it = funcs[i]; it != NULL; it = it->next)
- ((EventHandler)it->data)(&obe);
+ for (it = funcs[i]; it != NULL; it = it->next) {
+ Func *f = it->data;
+ f->h(&obe, f->data);
+ }
}
void dispatch_signal(int signal)
++i;
}
- for (it = funcs[i]; it != NULL; it = it->next)
- ((EventHandler)it->data)(&obe);
+ for (it = funcs[i]; it != NULL; it = it->next) {
+ Func *f = it->data;
+ f->h(&obe, f->data);
+ }
}
Event_Ob_Desktop = 1 << 15, /* changed desktops */
Event_Ob_NumDesktops = 1 << 16, /* changed the number of desktops */
Event_Ob_ShowDesktop = 1 << 17, /* entered/left show-the-desktop mode */
- Event_Ob_Startup = 1 << 18, /* startup under way */
- Event_Ob_Shutdown = 1 << 19, /* shutdown under way */
- Event_Signal = 1 << 20, /* a signal from the OS */
+ Event_Signal = 1 << 18, /* a signal from the OS */
- EVENT_RANGE = 1 << 21
+ EVENT_RANGE = 1 << 19
} EventType;
typedef struct {
EventData data;
} ObEvent;
-typedef void (*EventHandler)(const ObEvent *e);
+typedef void (*EventHandler)(const ObEvent *e, void *data);
typedef unsigned int EventMask;
-void dispatch_register(EventHandler h, EventMask mask);
+void dispatch_register(EventMask mask, EventHandler h, void *data);
void dispatch_x(XEvent *e, Client *c);
void dispatch_client(EventType e, Client *c);
LOADSYM(frame_show, engine_frame_show);
LOADSYM(frame_hide, engine_frame_hide);
LOADSYM(get_context, engine_get_context);
- LOADSYM(frame_mouse_enter, engine_mouse_enter);
- LOADSYM(frame_mouse_leave, engine_mouse_leave);
- LOADSYM(frame_mouse_press, engine_mouse_press);
- LOADSYM(frame_mouse_release, engine_mouse_release);
if (!estartup())
return FALSE;
EngineGetContext *engine_get_context;
-EngineMouseEnter *engine_mouse_enter;
-EngineMouseLeave *engine_mouse_leave;
-EngineMousePress *engine_mouse_press;
-EngineMouseRelease *engine_mouse_release;
-
#endif
#include "gettext.h"
#include "engine.h"
#include "themerc.h"
+#include "plugin.h"
#include "timer.h"
#include "../render/render.h"
#include "../render/font.h"
gboolean ob_sync = TRUE;
Cursors ob_cursors;
-void signal_handler(const ObEvent *e);
+void signal_handler(const ObEvent *e, void *data);
int main(int argc, char **argv)
{
/* start our event dispatcher and register for signals */
dispatch_startup();
- dispatch_register(signal_handler, Event_Signal);
+ dispatch_register(Event_Signal, signal_handler, NULL);
/* set up signal handler */
sigemptyset(&sigset);
screen_startup();
focus_startup();
client_startup();
+ plugin_startup();
- dispatch_ob(Event_Ob_Startup);
+ /* XXX load all plugins!! */
+ plugin_open("foo");
/* get all the existing windows */
client_manage_all();
client_unmanage_all();
- dispatch_ob(Event_Ob_Shutdown);
-
+ plugin_shutdown();
client_shutdown();
screen_shutdown();
event_shutdown();
return 0;
}
-void signal_handler(const ObEvent *e)
+void signal_handler(const ObEvent *e, void *data)
{
switch (e->data.signal) {
case SIGUSR1:
--- /dev/null
+#include <glib.h>
+#include <gmodule.h>
+
+typedef void (*PluginStartup)();
+typedef void (*PluginShutdown)();
+
+typedef struct {
+ GModule *module;
+ char *name;
+
+ PluginStartup startup;
+ PluginShutdown shutdown;
+} Plugin;
+
+static gpointer load_sym(GModule *module, char *name, char *symbol)
+{
+ gpointer var = NULL;
+ if (!g_module_symbol(module, symbol, &var))
+ g_warning("Failed to load symbol '%s' from plugin '%s'", symbol, name);
+ return var;
+}
+
+static Plugin *plugin_new(char *name)
+{
+ Plugin *p;
+ char *path;
+
+ p = g_new(Plugin, 1);
+
+ path = g_build_filename(PLUGINDIR, name, NULL);
+ p->module = g_module_open(path, G_MODULE_BIND_LAZY);
+ g_free(path);
+
+ if (p->module == NULL) {
+ path = g_build_filename(g_get_home_dir(), ".openbox", "plugins", name,
+ NULL);
+ p->module = g_module_open(path, G_MODULE_BIND_LAZY);
+ g_free(path);
+ }
+
+ if (p->module == NULL) {
+ g_free(p);
+ return NULL;
+ }
+
+ p->startup = load_sym(p->module, name, "startup");
+ p->shutdown = load_sym(p->module, name, "shutdown");
+
+ if (p->startup == NULL || p->shutdown == NULL) {
+ g_module_close(p->module);
+ g_free(p);
+ return NULL;
+ }
+
+ p->name = g_strdup(name);
+ return p;
+}
+
+static void plugin_free(Plugin *p)
+{
+ p->shutdown();
+
+ g_free(p->name);
+ g_module_close(p->module);
+}
+
+
+static GData *plugins = NULL;
+
+void plugin_startup()
+{
+ g_datalist_init(&plugins);
+}
+
+void plugin_shutdown()
+{
+ g_datalist_clear(&plugins);
+}
+
+gboolean plugin_open(char *name)
+{
+ Plugin *p;
+
+ if (g_datalist_get_data(&plugins, name) != NULL) {
+ g_warning("plugin '%s' already loaded, can't load again", name);
+ return TRUE;
+ }
+
+ p = plugin_new(name);
+ if (p == NULL) {
+ g_warning("failed to load plugin '%s'", name);
+ return FALSE;
+ }
+
+ g_datalist_set_data_full(&plugins, name, p, (GDestroyNotify) plugin_free);
+ p->startup();
+ return TRUE;
+}
+
+void plugin_close(char *name)
+{
+ g_datalist_remove_data(&plugins, name);
+}
--- /dev/null
+#ifndef __plugin_h
+#define __plugin_h
+
+void plugin_startup();
+void plugin_shutdown();
+
+gboolean plugin_open(char *name);
+void plugin_close(char *name);
+
+#endif
-DPLUGINDIR=\"$(plugindir)\" \
-DG_LOG_DOMAIN=\"Openbox-Plugin\"
-#engine_LTLIBRARIES=openbox.la
+plugin_LTLIBRARIES=focus.la
-#openbox_la_LDFLAGS=-module -avoid-version
-#openbox_la_SOURCES=openbox.c theme.c
+focus_la_LDFLAGS=-module -avoid-version
+focus_la_SOURCES=focus.c
noinst_HEADERS=
--- /dev/null
+#include "../kernel/dispatch.h"
+
+void startup()
+{
+}
+
+void shutdown()
+{
+}