From a116f2c6310db702e377e9cd1a95c9a980aba5ae Mon Sep 17 00:00:00 2001 From: Scott Moynes Date: Sat, 29 Mar 2003 03:18:11 +0000 Subject: [PATCH] Menu data structures basically completed. Need the engine support still, parser, and controllers. --- openbox/Makefile.am | 4 +-- openbox/action.c | 12 +++++++++ openbox/action.h | 9 ++++++- openbox/menu.c | 65 ++++++++++++++++++++++++++++++++++++++++----- openbox/menu.h | 25 ++++++++++------- 5 files changed, 96 insertions(+), 19 deletions(-) diff --git a/openbox/Makefile.am b/openbox/Makefile.am index f5b67f50..d691cbcd 100644 --- a/openbox/Makefile.am +++ b/openbox/Makefile.am @@ -27,11 +27,11 @@ openbox3_LDADD=@LIBINTL@ ../render/librender.a 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 $^ diff --git a/openbox/action.c b/openbox/action.c index 521e3135..02420346 100644 --- a/openbox/action.c +++ b/openbox/action.c @@ -155,6 +155,10 @@ Action *action_from_string(char *name) } 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; } @@ -623,10 +627,13 @@ void action_resize(union ActionData *data) 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); } @@ -641,3 +648,8 @@ void action_exit(union ActionData *data) { ob_shutdown = TRUE; } + +void action_showmenu(union ActionData *data) +{ + g_message(__FUNCTION__); +} diff --git a/openbox/action.h b/openbox/action.h index fae5b647..ff99af99 100644 --- a/openbox/action.h +++ b/openbox/action.h @@ -62,6 +62,11 @@ struct Resize { Corner corner; }; +struct ShowMenu { + Client *c; + char * menuName; +}; + union ActionData { struct AnyAction any; struct Execute execute; @@ -73,6 +78,7 @@ union ActionData { struct NextPreviousDesktop nextprevdesktop; struct Move move; struct Resize resize; + struct ShowMenu showMenu; }; typedef struct { @@ -185,5 +191,6 @@ void action_resize(union ActionData *data); void action_restart(union ActionData *data); /* Any */ void action_exit(union ActionData *data); - +/* ShowMenu */ +void action_showmenu(union ActionData *data); #endif diff --git a/openbox/menu.c b/openbox/menu.c index bd6cf065..a23cb29b 100644 --- a/openbox/menu.c +++ b/openbox/menu.c @@ -1,28 +1,81 @@ #include #include "menu.h" +#include -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 diff --git a/openbox/menu.h b/openbox/menu.h index 7c397602..b3e712c3 100644 --- a/openbox/menu.h +++ b/openbox/menu.h @@ -6,6 +6,7 @@ typedef struct Menu { char *label; + char *name; GList *entries; /* GList *tail; */ @@ -26,12 +27,12 @@ typedef struct Menu { 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 { @@ -43,19 +44,23 @@ 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); -- 2.39.2