]> icculus.org git repositories - dana/openbox.git/blob - openbox/engine.c
add a var to track errors
[dana/openbox.git] / openbox / engine.c
1 #include "engine.h"
2 #include "config.h"
3
4 #include <glib.h>
5 #include <gmodule.h>
6 #ifdef HAVE_STDLIB_H
7 #  include <stdlib.h>
8 #endif
9
10 static GModule *module;
11 static EngineStartup *estartup;
12 static EngineShutdown *eshutdown;
13
14 #define LOADSYM(name, var) \
15     if (!g_module_symbol(module, #name, (gpointer*)&var)) { \
16         g_warning("Failed to load symbol %s from engine", #name); \
17         return FALSE; \
18     }
19
20 static gboolean load(char *name)
21 {
22     char *path;
23
24     g_assert(module == NULL);
25
26     path = g_build_filename(ENGINEDIR, name, NULL);
27     module = g_module_open(path, 0);
28     g_free(path);
29
30     if (module == NULL) {
31         path = g_build_filename(g_get_home_dir(), ".openbox", "engines", name,
32                                 NULL);
33         module = g_module_open(path, 0);
34         g_free(path);
35     }
36
37     if (module == NULL)
38         return FALSE;
39
40     /* load the engine's symbols */
41     LOADSYM(startup, estartup);
42     LOADSYM(shutdown, eshutdown);
43     LOADSYM(frame_new, engine_frame_new);
44     LOADSYM(frame_grab_client, engine_frame_grab_client);
45     LOADSYM(frame_release_client, engine_frame_release_client);
46     LOADSYM(frame_adjust_area, engine_frame_adjust_area);
47     LOADSYM(frame_adjust_shape, engine_frame_adjust_shape);
48     LOADSYM(frame_adjust_state, engine_frame_adjust_state);
49     LOADSYM(frame_adjust_focus, engine_frame_adjust_focus);
50     LOADSYM(frame_adjust_title, engine_frame_adjust_title);
51     LOADSYM(frame_adjust_icon, engine_frame_adjust_icon);
52     LOADSYM(frame_show, engine_frame_show);
53     LOADSYM(frame_hide, engine_frame_hide);
54     LOADSYM(get_context, engine_get_context);
55
56     if (!estartup())
57         return FALSE;
58
59     return TRUE;
60 }
61
62 void engine_startup()
63 {
64     ConfigValue engine;
65
66     module = NULL;
67
68     if (config_get("engine", Config_String, &engine)) {
69         if (load(engine.string))
70             return;
71         g_warning("Failed to load the engine '%s'", engine.string);
72         g_message("Falling back to the default: '%s'", DEFAULT_ENGINE);
73     }
74     if (!load(DEFAULT_ENGINE)) {
75         g_critical("Failed to load the engine '%s'. Aborting", DEFAULT_ENGINE);
76         exit(1);
77     }
78 }
79
80 void engine_shutdown()
81 {
82     if (module != NULL) {
83         eshutdown();
84         g_module_close(module);
85     }
86 }