Need the engine support still, parser, and controllers.
openbox3_LDFLAGS=-export-dynamic
openbox3_SOURCES=client.c event.c extensions.c focus.c frame.c openbox.c \
prop.c screen.c stacking.c xerror.c timer.c dispatch.c \
- engine.c plugin.c action.c grab.c lex.cparse.c config.c
+ engine.c plugin.c action.c grab.c lex.cparse.c config.c menu.c
noinst_HEADERS=client.h event.h extensions.h focus.h frame.h geom.h gettext.h \
openbox.h prop.h screen.h stacking.h xerror.h dispatch.h \
- timer.h engine.h plugin.h action.h grab.h config.h
+ timer.h engine.h plugin.h action.h grab.h config.h menu.h
lex.cparse.c: cparse.l
$(FLEX) -Pcparse $^
} else if (!g_ascii_strcasecmp(name, "exit")) {
a = action_new(action_exit);
}
+ else if (!g_ascii_strcasecmp(name, "showmenu")) {
+ a = action_new(action_showmenu);
+ }
+
return a;
}
if (!c || !client_normal(c)) return;
+ /* XXX window snapping/struts */
+
dispatch_resize(c, &w, &h, data->resize.corner);
w -= c->frame->size.left + c->frame->size.right;
h -= c->frame->size.top + c->frame->size.bottom;
+
client_configure(c, data->resize.corner, c->area.x, c->area.y, w, h,
TRUE, data->resize.final);
}
{
ob_shutdown = TRUE;
}
+
+void action_showmenu(union ActionData *data)
+{
+ g_message(__FUNCTION__);
+}
Corner corner;
};
+struct ShowMenu {
+ Client *c;
+ char * menuName;
+};
+
union ActionData {
struct AnyAction any;
struct Execute execute;
struct NextPreviousDesktop nextprevdesktop;
struct Move move;
struct Resize resize;
+ struct ShowMenu showMenu;
};
typedef struct {
void action_restart(union ActionData *data);
/* Any */
void action_exit(union ActionData *data);
-
+/* ShowMenu */
+void action_showmenu(union ActionData *data);
#endif
#include <glib.h>
#include "menu.h"
+#include <assert.h>
-Menu *menu_new(char *label, Menu *parent)
+GHashTable *menu_hash = NULL;
+
+void menu_destroy_hash_key(const gpointer data)
+{
+ g_free(data);
+}
+
+void menu_free_entries(const Menu *menu)
+{
+ GList *it;
+
+ for (it = menu->entries; it; it = it->next)
+ menu_entry_free((MenuEntry *)it->data);
+
+ g_list_free(menu->entries);
+}
+
+void menu_destroy_hash_value(const gpointer data)
+{
+ const Menu *del_menu = (Menu *)data;
+
+ g_free(del_menu->label);
+ g_free(del_menu->name);
+
+ menu_free_entries(del_menu);
+}
+
+void menu_entry_free(const MenuEntry *entry)
+{
+ g_free(entry->label);
+ g_free(entry->render_data);
+}
+
+void menu_startup()
+{
+ menu_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+ menu_destroy_hash_key,
+ menu_destroy_hash_value);
+}
+
+void menu_shutdown()
{
- Menu *new_menu = g_new(Menu, 1);
- new_menu->label = g_strdup(lable);
+ g_hash_table_destroy(menu_hash);
+}
+
+Menu *menu_new(const char *label, const char *name, Menu *parent)
+{
+ Menu *new_menu = g_new0(Menu, 1);
+ new_menu->label = g_strdup(label);
+ new_menu->name = g_strdup(name);
new_menu->parent = parent;
new_menu->entries = NULL;
- new_menu->tail = NULL;
new_menu->shown = FALSE;
new_menu->invalid = FALSE;
/* default controllers? */
+ g_hash_table_insert(menu_hash, g_strdup(name), new_menu);
return new_menu;
}
-MenuEntry *menu_entry_new_full(char *label, Action *action,
- MenuEntryRenderType render_type,
+void menu_free(const char *name)
+{
+ g_hash_table_remove(menu_hash, name);
+}
+
+MenuEntry *menu_entry_new_full(const char *label, Action *action,
+ const MenuEntryRenderType render_type,
gpointer render_data, gpointer submenu)
{
MenuEntry *menu_entry = g_new(MenuEntry, 1);
menu_entry->label = g_strdup(label);
+ menu_entry->render_type = render_type;
menu_entry->action.func = action->func;
menu_entry->action.data = action->data; //watch out. copying Client * ptr
typedef struct Menu {
char *label;
+ char *name;
GList *entries;
/* GList *tail; */
typedef enum MenuEntryRenderType {
MenuEntryRenderType_None = 0,
- MenuEntryRenderType_Submenu 1 << 0,
- MenuEntryRenderType_Boolean 1 << 1,
- MenuEntryRenderType_Separator 1 << 2,
+ MenuEntryRenderType_Submenu = 1 << 0,
+ MenuEntryRenderType_Boolean = 1 << 1,
+ MenuEntryRenderType_Separator = 1 << 2,
- MenuEntryRenderType_Other 1 << 7
-} MenuEntryType;
+ MenuEntryRenderType_Other = 1 << 7
+} MenuEntryRenderType;
typedef struct {
MenuEntryRenderType render_type;
gboolean enabled;
gboolean boolean_value;
- gpointer render_data;
+ gpointer render_data; /* where the engine can store anything it likes */
Menu *submenu;
} MenuEntry;
-Menu *menu_new(char *label, Menu *parent);
-MenuEntry *menu_entry_new_full(char *label, Action *action,
- MenuEntryRenderType render_type,
- gpointer render_data, gpointer submenu);
+Menu *menu_new(const char *label, const char *name, Menu *parent);
+void menu_free(const char *name);
+
+MenuEntry *menu_entry_new_full(const char *label, Action *action,
+ const MenuEntryRenderType render_type,
+ gpointer render_data, gpointer submenu);
#define menu_entry_new(label, action) \
menu_entry_new(label, action, MenuEntryRenderType_None, NULL, NULL)
+void menu_entry_free(const MenuEntry *entry);
+
void menu_entry_set_submenu(MenuEntry *entry, Menu *submenu);
void menu_add_entry(Menu *menu, MenuEntry *entry);