]> Dogcows Code - chaz/openbox/commitdiff
Menu data structures basically completed.
authorScott Moynes <smoynes@nexus.carleton.ca>
Sat, 29 Mar 2003 03:18:11 +0000 (03:18 +0000)
committerScott Moynes <smoynes@nexus.carleton.ca>
Sat, 29 Mar 2003 03:18:11 +0000 (03:18 +0000)
Need the engine support still, parser, and controllers.

openbox/Makefile.am
openbox/action.c
openbox/action.h
openbox/menu.c
openbox/menu.h

index f5b67f5007d50d9d5bd0d71c0d2f9a1d8996c940..d691cbcdcd5f8b08583360e677438e666af76965 100644 (file)
@@ -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 $^
index 521e3135637e4d7fe69d3f81a6429c1d4474e4f3..0242034635230cf328d890c29c09292d9dc79640 100644 (file)
@@ -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__);
+}
index fae5b6479bcee058073be89b7cae72db5eae00da..ff99af99dbad2e74cff235b7779c41a72967f5be 100644 (file)
@@ -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
index bd6cf065c2230a5d976423f3cbbfde5adc04dda9..a23cb29b7652f6df298e6ba527c167882e148fbd 100644 (file)
@@ -1,28 +1,81 @@
 #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
 
index 7c39760278a2f0be627dcec7c5cca41613fdfbcc..b3e712c3241479b9fd232b81f0e213f8e4379479 100644 (file)
@@ -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);
This page took 0.031639 seconds and 4 git commands to generate.