]> icculus.org git repositories - dana/openbox.git/blob - openbox/engine.c
change how rc parsing will work. a=b will be parsed in any [section] and given to...
[dana/openbox.git] / 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 char *engine_name = NULL;
10 char *engine_theme = NULL;
11 char *engine_layout = "NDSLIMC";
12 char *engine_font = "Sans-7";
13 gboolean engine_shadow = FALSE;
14 int engine_shadow_offset = 1;
15 int engine_shadow_tint = 25;
16
17 static GModule *module = NULL;
18 static EngineStartup *estartup = NULL;
19 static EngineShutdown *eshutdown = NULL;
20
21 #define LOADSYM(name, var) \
22     if (!g_module_symbol(module, #name, (gpointer*)&var)) { \
23         g_warning("Failed to load symbol %s from engine", #name); \
24         return FALSE; \
25     }
26
27 static gboolean load(char *name)
28 {
29     char *path;
30
31     g_assert(module == NULL);
32
33     path = g_build_filename(ENGINEDIR, name, NULL);
34     module = g_module_open(path, 0);
35     g_free(path);
36
37     if (module == NULL) {
38         path = g_build_filename(g_get_home_dir(), ".openbox", "engines", name,
39                                 NULL);
40         module = g_module_open(path, 0);
41         g_free(path);
42     }
43
44     if (module == NULL)
45         return FALSE;
46
47     /* load the engine's symbols */
48     LOADSYM(startup, estartup);
49     LOADSYM(shutdown, eshutdown);
50     LOADSYM(frame_new, engine_frame_new);
51     LOADSYM(frame_grab_client, engine_frame_grab_client);
52     LOADSYM(frame_release_client, engine_frame_release_client);
53     LOADSYM(frame_adjust_area, engine_frame_adjust_area);
54     LOADSYM(frame_adjust_shape, engine_frame_adjust_shape);
55     LOADSYM(frame_adjust_state, engine_frame_adjust_state);
56     LOADSYM(frame_adjust_focus, engine_frame_adjust_focus);
57     LOADSYM(frame_adjust_title, engine_frame_adjust_title);
58     LOADSYM(frame_adjust_icon, engine_frame_adjust_icon);
59     LOADSYM(frame_show, engine_frame_show);
60     LOADSYM(frame_hide, engine_frame_hide);
61     LOADSYM(get_context, engine_get_context);
62
63     if (!estartup())
64         return FALSE;
65
66     return TRUE;
67 }
68
69 void engine_startup()
70 {
71     module = NULL;
72 }
73
74 void engine_load()
75 {
76     if (load(engine_name))
77         return;
78     g_warning("Failed to load the engine '%s'", engine_name);
79     g_message("Falling back to the default: '%s'", DEFAULT_ENGINE);
80     if (!load(DEFAULT_ENGINE)) {
81         g_critical("Failed to load the engine '%s'. Aborting", DEFAULT_ENGINE);
82         exit(1);
83     }
84 }
85
86 void engine_shutdown()
87 {
88     g_free(engine_name);
89     if (module != NULL) {
90         eshutdown();
91         g_module_close(module);
92     }
93 }