]> icculus.org git repositories - mikachu/openbox.git/blob - openbox/engine.c
make client_showhide a static function
[mikachu/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 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     LOADSYM(frame_mouse_enter, engine_mouse_enter);
56     LOADSYM(frame_mouse_leave, engine_mouse_leave);
57     LOADSYM(frame_mouse_press, engine_mouse_press);
58     LOADSYM(frame_mouse_release, engine_mouse_release);
59
60     if (!estartup())
61         return FALSE;
62
63     return TRUE;
64 }
65
66 void engine_startup(char *engine)
67 {
68     module = NULL;
69
70     if (engine != NULL) {
71         if (load(engine))
72             return;
73         g_warning("Failed to load the engine '%s'", engine);
74         g_message("Falling back to the default: '%s'", DEFAULT_ENGINE);
75     }
76     if (!load(DEFAULT_ENGINE)) {
77         g_critical("Failed to load the engine '%s'. Aborting", DEFAULT_ENGINE);
78         exit(1);
79     }
80 }
81
82 void engine_shutdown()
83 {
84     if (module != NULL) {
85         eshutdown();
86         g_module_close(module);
87     }
88 }