]> Dogcows Code - chaz/openbox/blob - openbox/engine.c
merge the C branch into HEAD
[chaz/openbox] / openbox / engine.c
1 #include "engine.h"
2
3 #include <glib.h>
4 #include <gmodule.h>
5 #ifdef HAVE_STDLIB_H
6 # include <stdlib.h>
7 #endif
8
9 static GModule *module;
10 static EngineStartup *estartup;
11 static EngineShutdown *eshutdown;
12
13 #define LOADSYM(name, var) \
14 if (!g_module_symbol(module, #name, (gpointer*)&var)) { \
15 g_warning("Failed to load symbol %s from engine", #name); \
16 return FALSE; \
17 }
18
19 static gboolean load(char *name)
20 {
21 char *path;
22
23 g_assert(module == NULL);
24
25 path = g_build_filename(ENGINEDIR, name, NULL);
26 module = g_module_open(path, G_MODULE_BIND_LAZY);
27 g_free(path);
28
29 if (module == NULL) {
30 path = g_build_filename(g_get_home_dir(), ".openbox", "engines", name,
31 NULL);
32 module = g_module_open(path, G_MODULE_BIND_LAZY);
33 g_free(path);
34 }
35
36 if (module == NULL)
37 return FALSE;
38
39 /* load the engine's symbols */
40 LOADSYM(startup, estartup);
41 LOADSYM(shutdown, eshutdown);
42 LOADSYM(frame_new, engine_frame_new);
43 LOADSYM(frame_grab_client, engine_frame_grab_client);
44 LOADSYM(frame_release_client, engine_frame_release_client);
45 LOADSYM(frame_adjust_size, engine_frame_adjust_size);
46 LOADSYM(frame_adjust_position, engine_frame_adjust_position);
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(char *engine)
63 {
64 module = NULL;
65
66 if (engine != NULL) {
67 if (load(engine))
68 return;
69 g_warning("Failed to load the engine '%s'", engine);
70 g_message("Falling back to the default: '%s'", DEFAULT_ENGINE);
71 }
72 if (!load(DEFAULT_ENGINE)) {
73 g_critical("Failed to load the engine '%s'. Aborting", DEFAULT_ENGINE);
74 exit(1);
75 }
76 }
77
78 void engine_shutdown()
79 {
80 if (module != NULL) {
81 eshutdown();
82 g_module_close(module);
83 }
84 }
This page took 0.038541 seconds and 4 git commands to generate.