summaryrefslogtreecommitdiff
path: root/openbox
diff options
context:
space:
mode:
authorDana Jansens <danakj@orodu.net>2003-08-28 06:32:27 +0000
committerDana Jansens <danakj@orodu.net>2003-08-28 06:32:27 +0000
commitffba11aeb059bef0b4876eb6aad2a8a24e2db6f1 (patch)
treebc66e6ef487984bae5f3697aaa766b029358bbaf /openbox
parent615cbd96075905d75533f9b615c4ee6a75f4f9a4 (diff)
load menu plugins automatically from whats in the menu file
menu fixups move enabled into the 'normal menu item' specific data stuff
Diffstat (limited to 'openbox')
-rw-r--r--openbox/menu.c38
-rw-r--r--openbox/menu.h6
-rw-r--r--openbox/menuframe.c9
-rw-r--r--openbox/plugin.c56
-rw-r--r--openbox/plugin.h5
-rw-r--r--openbox/screen.c2
-rw-r--r--openbox/session.c2
7 files changed, 68 insertions, 50 deletions
diff --git a/openbox/menu.c b/openbox/menu.c
index 3e38c0f9..5efb0c35 100644
--- a/openbox/menu.c
+++ b/openbox/menu.c
@@ -68,19 +68,29 @@ static void parse_menu(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
gpointer data)
{
ObMenuParseState *state = data;
- gchar *name = NULL, *title = NULL;
+ gchar *name = NULL, *title = NULL, *plugin = NULL;
if (!parse_attr_string("id", node, &name))
goto parse_menu_fail;
if (!g_hash_table_lookup(menu_hash, name)) {
- if (!parse_attr_string("label", node, &title))
- goto parse_menu_fail;
-
- if (menu_new(name, title, NULL)) {
- state->menus = g_slist_prepend(state->menus, name);
- parse_tree(i, doc, node->xmlChildrenNode);
- state->menus = g_slist_delete_link(state->menus, state->menus);
+ if (parse_attr_string("plugin", node, &plugin)) {
+ if (!plugin_open(plugin, i))
+ goto parse_menu_fail;
+ plugin_start(plugin);
+ if (!g_hash_table_lookup(menu_hash, name))
+ g_warning("Specified plugin '%s' did not provide the "
+ "menu '%s'", plugin, name);
+ goto parse_menu_fail;
+ } else {
+ if (!parse_attr_string("label", node, &title))
+ goto parse_menu_fail;
+
+ if (menu_new(name, title, NULL)) {
+ state->menus = g_slist_prepend(state->menus, name);
+ parse_tree(i, doc, node->xmlChildrenNode);
+ state->menus = g_slist_delete_link(state->menus, state->menus);
+ }
}
}
@@ -90,6 +100,7 @@ static void parse_menu(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
parse_menu_fail:
g_free(name);
g_free(title);
+ g_free(plugin);
}
@@ -202,7 +213,16 @@ static ObMenuEntry* menu_entry_new(ObMenu *menu, ObMenuEntryType type, gint id)
self->type = type;
self->menu = menu;
self->id = id;
- self->enabled = TRUE;
+
+ switch (type) {
+ case OB_MENU_ENTRY_TYPE_NORMAL:
+ self->data.normal.enabled = TRUE;
+ break;
+ case OB_MENU_ENTRY_TYPE_SUBMENU:
+ case OB_MENU_ENTRY_TYPE_SEPARATOR:
+ break;
+ }
+
return self;
}
diff --git a/openbox/menu.h b/openbox/menu.h
index 66390e75..a3332280 100644
--- a/openbox/menu.h
+++ b/openbox/menu.h
@@ -47,6 +47,9 @@ typedef enum
struct _ObNormalMenuEntry {
gchar *label;
+ /* state */
+ gboolean enabled;
+
/* List of ObActions */
GSList *actions;
};
@@ -66,9 +69,6 @@ struct _ObMenuEntry
gint id;
- /* state */
- gboolean enabled;
-
union u {
ObNormalMenuEntry normal;
ObSubmenuMenuEntry submenu;
diff --git a/openbox/menuframe.c b/openbox/menuframe.c
index daecd6c4..832f49af 100644
--- a/openbox/menuframe.c
+++ b/openbox/menuframe.c
@@ -171,7 +171,8 @@ static void menu_entry_frame_render(ObMenuEntryFrame *self)
RrAppearance *item_a, *text_a;
gint th; /* temp */
- item_a = (!self->entry->enabled ?
+ item_a = ((self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
+ !self->entry->data.normal.enabled) ?
self->a_disabled :
(self == self->frame->selected ?
self->a_selected :
@@ -193,7 +194,8 @@ static void menu_entry_frame_render(ObMenuEntryFrame *self)
item_a->surface.parenty = self->area.y;
RrPaint(item_a, self->window, self->area.width, self->area.height);
- text_a = (!self->entry->enabled ?
+ text_a = ((self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
+ !self->entry->data.normal.enabled) ?
self->a_text_disabled :
(self == self->frame->selected ?
self->a_text_selected :
@@ -299,7 +301,8 @@ static void menu_frame_render(ObMenuFrame *self)
RECT_SET_POINT(e->area, 0, allitems_h);
XMoveWindow(ob_display, e->window, 0, e->area.y);
- text_a = (!e->entry->enabled ?
+ text_a = ((e->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
+ !e->entry->data.normal.enabled) ?
e->a_text_disabled :
(e == self->selected ?
e->a_text_selected :
diff --git a/openbox/plugin.c b/openbox/plugin.c
index b8d9be4b..300cd82d 100644
--- a/openbox/plugin.c
+++ b/openbox/plugin.c
@@ -6,14 +6,16 @@
typedef struct {
GModule *module;
- char *name;
+ gchar *name;
+
+ gboolean started;
PluginSetupConfig config;
PluginStartup startup;
PluginShutdown shutdown;
} Plugin;
-static gpointer load_sym(GModule *module, char *name, char *symbol,
+static gpointer load_sym(GModule *module, gchar *name, gchar *symbol,
gboolean allow_fail)
{
gpointer var;
@@ -26,12 +28,13 @@ static gpointer load_sym(GModule *module, char *name, char *symbol,
return var;
}
-static Plugin *plugin_new(char *name)
+static Plugin *plugin_new(gchar *name)
{
Plugin *p;
- char *path;
+ gchar *path;
p = g_new(Plugin, 1);
+ p->started = FALSE;
path = g_build_filename(g_get_home_dir(), ".openbox", "plugins", name,
NULL);
@@ -88,15 +91,12 @@ void plugin_shutdown()
g_datalist_clear(&plugins);
}
-gboolean plugin_open_full(char *name, gboolean reopen, ObParseInst *i)
+gboolean plugin_open(gchar *name, ObParseInst *i)
{
Plugin *p;
- if (g_datalist_get_data(&plugins, name) != NULL) {
- if (!reopen)
- g_warning("plugin '%s' already loaded, can't load again", name);
+ if (g_datalist_get_data(&plugins, name) != NULL)
return TRUE;
- }
p = plugin_new(name);
if (p == NULL) {
@@ -109,22 +109,12 @@ gboolean plugin_open_full(char *name, gboolean reopen, ObParseInst *i)
return TRUE;
}
-gboolean plugin_open(char *name, ObParseInst *i) {
- return plugin_open_full(name, FALSE, i);
-}
-
-gboolean plugin_open_reopen(char *name, ObParseInst *i) {
- return plugin_open_full(name, TRUE, i);
-}
-
-void plugin_close(char *name)
-{
- g_datalist_remove_data(&plugins, name);
-}
-
static void foreach_start(GQuark key, Plugin *p, gpointer *foo)
{
- p->startup();
+ if (!p->started) {
+ p->startup();
+ p->started = TRUE;
+ }
}
void plugin_startall()
@@ -132,11 +122,25 @@ void plugin_startall()
g_datalist_foreach(&plugins, (GDataForeachFunc)foreach_start, NULL);
}
+void plugin_start(gchar *name)
+{
+ Plugin *p;
+
+ if (!(p = g_datalist_get_data(&plugins, name))) {
+ g_warning("Tried to start plugin '%s' but it is not loaded", name);
+ return;
+ }
+ if (!p->started) {
+ p->startup();
+ p->started = TRUE;
+ }
+}
+
void plugin_loadall(ObParseInst *i)
{
GIOChannel *io;
GError *err;
- char *path, *name;
+ gchar *path, *name;
path = g_build_filename(g_get_home_dir(), ".openbox", "pluginrc", NULL);
err = NULL;
@@ -153,10 +157,6 @@ void plugin_loadall(ObParseInst *i)
if (io == NULL) {
/* load the default plugins */
plugin_open("placement", i);
-
- /* XXX rm me when the parser loads me magically */
- plugin_open("client_menu", i);
- plugin_open("client_list_menu", i);
} else {
/* load the plugins in the rc file */
while (g_io_channel_read_line(io, &name, NULL, NULL, &err) ==
diff --git a/openbox/plugin.h b/openbox/plugin.h
index 7ef004bf..989e48f7 100644
--- a/openbox/plugin.h
+++ b/openbox/plugin.h
@@ -10,9 +10,8 @@ void plugin_loadall(struct _ObParseInst *i);
void plugin_startall();
/* default plugin */
-gboolean plugin_open(char *name, struct _ObParseInst *i);
/* load a plugin, but don't warn about reopens. for menus */
-gboolean plugin_open_reopen(char *name, struct _ObParseInst *i);
-void plugin_close(char *name);
+gboolean plugin_open(gchar *name, struct _ObParseInst *i);
+void plugin_start(gchar *name);
#endif
diff --git a/openbox/screen.c b/openbox/screen.c
index 936ad624..ac0889bf 100644
--- a/openbox/screen.c
+++ b/openbox/screen.c
@@ -179,8 +179,6 @@ gboolean screen_annex()
}
- ob_debug("Managing screen %d\n", ob_screen);
-
set_root_cursor();
/* set the OPENBOX_PID hint */
diff --git a/openbox/session.c b/openbox/session.c
index 1343c85f..4cf6f1cd 100644
--- a/openbox/session.c
+++ b/openbox/session.c
@@ -194,8 +194,6 @@ void session_startup(int argc, char **argv)
g_free(val_uid.value);
save_commands();
-
- ob_debug("Connected to session manager with id %s\n", ob_sm_id);
}
}