]> icculus.org git repositories - mikachu/openbox.git/blob - openbox/engine.c
move config option loading for the kernel into config.c/h
[mikachu/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 EngineFrameNew *engine_frame_new;
11 EngineFrameGrabClient *engine_frame_grab_client;
12 EngineFrameReleaseClient *engine_frame_release_client;
13 EngineFrameAdjustArea *engine_frame_adjust_area;
14 EngineFrameAdjustShape *engine_frame_adjust_shape;
15 EngineFrameAdjustState *engine_frame_adjust_state;
16 EngineFrameAdjustFocus *engine_frame_adjust_focus;
17 EngineFrameAdjustTitle *engine_frame_adjust_title;
18 EngineFrameAdjustIcon *engine_frame_adjust_icon;
19 EngineFrameShow *engine_frame_show;
20 EngineFrameHide *engine_frame_hide;
21 EngineGetContext *engine_get_context;
22 EngineRenderLabel *engine_render_label;
23 EngineSizeLabel *engine_size_label;
24
25 static GModule *module = NULL;
26 static EngineStartup *estartup = NULL;
27 static EngineShutdown *eshutdown = NULL;
28
29 #define LOADSYM(name, var) \
30     if (!g_module_symbol(module, #name, (gpointer*)&var)) { \
31         g_warning("Failed to load symbol %s from engine", #name); \
32         return FALSE; \
33     }
34
35 static gboolean load(char *name)
36 {
37     char *path;
38
39     g_assert(module == NULL);
40
41     path = g_build_filename(g_get_home_dir(), ".openbox", "engines", name,
42                             NULL);
43     module = g_module_open(path, 0);
44     g_free(path);
45
46     if (module == NULL) {
47         path = g_build_filename(ENGINEDIR, name, NULL);
48         module = g_module_open(path, 0);
49         g_free(path);
50     }
51
52     if (module == NULL) {
53         g_warning(g_module_error());
54         return FALSE;
55     }
56
57     /* load the engine's symbols */
58     LOADSYM(startup, estartup);
59     LOADSYM(shutdown, eshutdown);
60     LOADSYM(frame_new, engine_frame_new);
61     LOADSYM(frame_grab_client, engine_frame_grab_client);
62     LOADSYM(frame_release_client, engine_frame_release_client);
63     LOADSYM(frame_adjust_area, engine_frame_adjust_area);
64     LOADSYM(frame_adjust_shape, engine_frame_adjust_shape);
65     LOADSYM(frame_adjust_state, engine_frame_adjust_state);
66     LOADSYM(frame_adjust_focus, engine_frame_adjust_focus);
67     LOADSYM(frame_adjust_title, engine_frame_adjust_title);
68     LOADSYM(frame_adjust_icon, engine_frame_adjust_icon);
69     LOADSYM(frame_show, engine_frame_show);
70     LOADSYM(frame_hide, engine_frame_hide);
71     LOADSYM(get_context, engine_get_context);
72     LOADSYM(render_label, engine_render_label);
73     LOADSYM(size_label, engine_size_label);
74
75     if (!estartup())
76         return FALSE;
77
78     return TRUE;
79 }
80
81 void engine_startup()
82 {
83     module = NULL;
84 }
85
86 void engine_load()
87 {
88     if (load(config_engine_name))
89         return;
90     g_warning("Failed to load the engine '%s'", config_engine_name);
91     g_message("Falling back to the default: '%s'", DEFAULT_ENGINE);
92     if (module != NULL) {
93         g_module_close(module);
94         module = NULL;
95     }
96     if (!load(DEFAULT_ENGINE)) {
97         g_critical("Failed to load the engine '%s'. Aborting", DEFAULT_ENGINE);
98         exit(1);
99     }
100 }
101
102 void engine_shutdown()
103 {
104     if (module != NULL) {
105         eshutdown();
106         g_module_close(module);
107     }
108 }