From f8a47de5ec444c452093371e3db16857eb39a490 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Sun, 16 Mar 2003 21:11:39 +0000 Subject: merge the C branch into HEAD --- openbox/engine.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 openbox/engine.c (limited to 'openbox/engine.c') diff --git a/openbox/engine.c b/openbox/engine.c new file mode 100644 index 00000000..3457da18 --- /dev/null +++ b/openbox/engine.c @@ -0,0 +1,84 @@ +#include "engine.h" + +#include +#include +#ifdef HAVE_STDLIB_H +# include +#endif + +static GModule *module; +static EngineStartup *estartup; +static EngineShutdown *eshutdown; + +#define LOADSYM(name, var) \ + if (!g_module_symbol(module, #name, (gpointer*)&var)) { \ + g_warning("Failed to load symbol %s from engine", #name); \ + return FALSE; \ + } + +static gboolean load(char *name) +{ + char *path; + + g_assert(module == NULL); + + path = g_build_filename(ENGINEDIR, name, NULL); + module = g_module_open(path, G_MODULE_BIND_LAZY); + g_free(path); + + if (module == NULL) { + path = g_build_filename(g_get_home_dir(), ".openbox", "engines", name, + NULL); + module = g_module_open(path, G_MODULE_BIND_LAZY); + g_free(path); + } + + if (module == NULL) + return FALSE; + + /* load the engine's symbols */ + LOADSYM(startup, estartup); + LOADSYM(shutdown, eshutdown); + LOADSYM(frame_new, engine_frame_new); + LOADSYM(frame_grab_client, engine_frame_grab_client); + LOADSYM(frame_release_client, engine_frame_release_client); + LOADSYM(frame_adjust_size, engine_frame_adjust_size); + LOADSYM(frame_adjust_position, engine_frame_adjust_position); + LOADSYM(frame_adjust_shape, engine_frame_adjust_shape); + LOADSYM(frame_adjust_state, engine_frame_adjust_state); + LOADSYM(frame_adjust_focus, engine_frame_adjust_focus); + LOADSYM(frame_adjust_title, engine_frame_adjust_title); + LOADSYM(frame_adjust_icon, engine_frame_adjust_icon); + LOADSYM(frame_show, engine_frame_show); + LOADSYM(frame_hide, engine_frame_hide); + LOADSYM(get_context, engine_get_context); + + if (!estartup()) + return FALSE; + + return TRUE; +} + +void engine_startup(char *engine) +{ + module = NULL; + + if (engine != NULL) { + if (load(engine)) + return; + g_warning("Failed to load the engine '%s'", engine); + g_message("Falling back to the default: '%s'", DEFAULT_ENGINE); + } + if (!load(DEFAULT_ENGINE)) { + g_critical("Failed to load the engine '%s'. Aborting", DEFAULT_ENGINE); + exit(1); + } +} + +void engine_shutdown() +{ + if (module != NULL) { + eshutdown(); + g_module_close(module); + } +} -- cgit v1.2.3