]> Dogcows Code - chaz/openbox/blob - openbox/engine.c
make the ~/.openbox dir on startup
[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, 0);
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, 0);
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_area, engine_frame_adjust_area);
46 LOADSYM(frame_adjust_shape, engine_frame_adjust_shape);
47 LOADSYM(frame_adjust_state, engine_frame_adjust_state);
48 LOADSYM(frame_adjust_focus, engine_frame_adjust_focus);
49 LOADSYM(frame_adjust_title, engine_frame_adjust_title);
50 LOADSYM(frame_adjust_icon, engine_frame_adjust_icon);
51 LOADSYM(frame_show, engine_frame_show);
52 LOADSYM(frame_hide, engine_frame_hide);
53 LOADSYM(get_context, engine_get_context);
54
55 if (!estartup())
56 return FALSE;
57
58 return TRUE;
59 }
60
61 void engine_startup(char *engine)
62 {
63 module = NULL;
64
65 if (engine != NULL) {
66 if (load(engine))
67 return;
68 g_warning("Failed to load the engine '%s'", engine);
69 g_message("Falling back to the default: '%s'", DEFAULT_ENGINE);
70 }
71 if (!load(DEFAULT_ENGINE)) {
72 g_critical("Failed to load the engine '%s'. Aborting", DEFAULT_ENGINE);
73 exit(1);
74 }
75 }
76
77 void engine_shutdown()
78 {
79 if (module != NULL) {
80 eshutdown();
81 g_module_close(module);
82 }
83 }
This page took 0.035119 seconds and 4 git commands to generate.