]> Dogcows Code - chaz/openbox/blobdiff - openbox/menuframe.c
fix for using freed memory to exec stuff
[chaz/openbox] / openbox / menuframe.c
index ea7f254c6ef95007e38ded3addb6ee2c3e3b98d9..725b1a18b732047284a392a1e436cab57a8dbc90 100644 (file)
@@ -16,6 +16,9 @@
 
 GList *menu_frame_visible;
 
+static ObMenuEntryFrame* menu_entry_frame_new(ObMenuEntry *entry,
+                                              ObMenuFrame *frame);
+static void menu_entry_frame_free(ObMenuEntryFrame *self);
 static void menu_frame_render(ObMenuFrame *self);
 static void menu_frame_update(ObMenuFrame *self);
 
@@ -60,6 +63,11 @@ ObMenuFrame* menu_frame_new(ObMenu *menu, ObClient *client)
 void menu_frame_free(ObMenuFrame *self)
 {
     if (self) {
+        while (self->entries) {
+            menu_entry_frame_free(self->entries->data);
+            self->entries = g_list_delete_link(self->entries, self->entries);
+        }
+
         stacking_remove(MENU_AS_WINDOW(self));
 
         XDestroyWindow(ob_display, self->items);
@@ -73,7 +81,8 @@ void menu_frame_free(ObMenuFrame *self)
     }
 }
 
-ObMenuEntryFrame* menu_entry_frame_new(ObMenuEntry *entry, ObMenuFrame *frame)
+static ObMenuEntryFrame* menu_entry_frame_new(ObMenuEntry *entry,
+                                              ObMenuFrame *frame)
 {
     ObMenuEntryFrame *self;
     XSetWindowAttributes attr;
@@ -110,7 +119,7 @@ ObMenuEntryFrame* menu_entry_frame_new(ObMenuEntry *entry, ObMenuFrame *frame)
     return self;
 }
 
-void menu_entry_frame_free(ObMenuEntryFrame *self)
+static void menu_entry_frame_free(ObMenuEntryFrame *self)
 {
     if (self) {
         XDestroyWindow(ob_display, self->icon);
@@ -134,7 +143,6 @@ void menu_entry_frame_free(ObMenuEntryFrame *self)
 
 void menu_frame_move(ObMenuFrame *self, gint x, gint y)
 {
-    /* XXX screen constraints */
     RECT_SET_POINT(self->area, x, y);
     XMoveWindow(ob_display, self->window, self->area.x, self->area.y);
 }
@@ -170,6 +178,7 @@ static void menu_entry_frame_render(ObMenuEntryFrame *self)
 {
     RrAppearance *item_a, *text_a;
     gint th; /* temp */
+    ObMenu *sub;
 
     item_a = ((self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
                !self->entry->data.normal.enabled) ?
@@ -205,8 +214,8 @@ static void menu_entry_frame_render(ObMenuEntryFrame *self)
         text_a->texture[0].data.text.string = self->entry->data.normal.label;
         break;
     case OB_MENU_ENTRY_TYPE_SUBMENU:
-        text_a->texture[0].data.text.string =
-            self->entry->data.submenu.submenu->title;
+        sub = self->entry->data.submenu.submenu;
+        text_a->texture[0].data.text.string = sub ? sub->title : "";
         break;
     case OB_MENU_ENTRY_TYPE_SEPARATOR:
         break;
@@ -229,11 +238,17 @@ static void menu_entry_frame_render(ObMenuEntryFrame *self)
         break;
     }
 
-    /* XXX draw icons */
-    if (0) {
+    if (self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
+        self->entry->data.normal.icon_data)
+    {
         XMoveResizeWindow(ob_display, self->icon, 0, 0,
                           self->frame->item_h, self->frame->item_h);
-        /* XXX set the RGBA surface stuff */
+        self->a_icon->texture[0].data.rgba.width =
+            self->entry->data.normal.icon_width;
+        self->a_icon->texture[0].data.rgba.height =
+            self->entry->data.normal.icon_height;
+        self->a_icon->texture[0].data.rgba.data =
+            self->entry->data.normal.icon_data;
         self->a_icon->surface.parent = item_a;
         self->a_icon->surface.parentx = 0;
         self->a_icon->surface.parenty = 0;
@@ -265,6 +280,7 @@ static void menu_frame_render(ObMenuFrame *self)
     gint tw, th; /* temps */
     GList *it;
     gboolean has_icon = FALSE, has_bullet = FALSE;
+    ObMenu *sub;
 
     XSetWindowBorderWidth(ob_display, self->window, ob_rr_theme->bwidth);
     XSetWindowBorder(ob_display, self->window,
@@ -312,11 +328,12 @@ static void menu_frame_render(ObMenuFrame *self)
             text_a->texture[0].data.text.string = e->entry->data.normal.label;
             RrMinsize(text_a, &tw, &th);
 
-            /* XXX has_icon = TRUE; */
+            if (e->entry->data.normal.icon_data)
+                has_icon = TRUE;
             break;
         case OB_MENU_ENTRY_TYPE_SUBMENU:
-            text_a->texture[0].data.text.string =
-                e->entry->data.submenu.submenu->title;
+            sub = e->entry->data.submenu.submenu;
+            text_a->texture[0].data.text.string = sub ? sub->title : "";
             RrMinsize(text_a, &tw, &th);
 
             has_bullet = TRUE;
@@ -378,6 +395,8 @@ static void menu_frame_update(ObMenuFrame *self)
 {
     GList *mit, *fit;
 
+    menu_find_submenus(self->menu);
+
     self->selected = NULL;
 
     for (mit = self->menu->entries, fit = self->entries; mit && fit;
@@ -538,6 +557,8 @@ void menu_entry_frame_show_submenu(ObMenuEntryFrame *self)
 {
     ObMenuFrame *f;
 
+    if (!self->entry->data.submenu.submenu) return;
+
     f = menu_frame_new(self->entry->data.submenu.submenu,
                        self->frame->client);
     menu_frame_move(f,
@@ -551,16 +572,22 @@ void menu_entry_frame_show_submenu(ObMenuEntryFrame *self)
 void menu_entry_frame_execute(ObMenuEntryFrame *self, gboolean hide)
 {
     if (self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL) {
+        /* grab all this shizzle, cuz when the menu gets hidden, 'self'
+           gets freed */
+        ObMenuEntry *entry = self->entry;
+        ObMenuExecuteFunc func = self->frame->menu->execute_func;
+        gpointer data = self->frame->menu->data;
+        GSList *acts = self->entry->data.normal.actions;
+
         /* release grabs before executing the shit */
         menu_frame_hide_all();
 
-        if (self->frame->menu->execute_func)
-            self->frame->menu->execute_func(self, self->frame->menu->data);
+        if (func)
+            func(entry, data);
         else {
             GSList *it;
 
-            for (it = self->entry->data.normal.actions; it;
-                 it = g_slist_next(it))
+            for (it = acts; it; it = g_slist_next(it))
             {
                 ObAction *act = it->data;
                 act->data.any.c = self->frame->client;
This page took 0.027969 seconds and 4 git commands to generate.