Fix shadowed variables
[mikachu/openbox.git] / openbox / menuframe.c
index c6dd02f..944fa2e 100644 (file)
@@ -21,6 +21,7 @@
 #include "client.h"
 #include "menu.h"
 #include "screen.h"
+#include "actions.h"
 #include "grab.h"
 #include "openbox.h"
 #include "mainloop.h"
@@ -45,6 +46,7 @@ static ObMenuEntryFrame* menu_entry_frame_new(ObMenuEntry *entry,
 static void menu_entry_frame_free(ObMenuEntryFrame *self);
 static void menu_frame_update(ObMenuFrame *self);
 static gboolean menu_entry_frame_submenu_timeout(gpointer data);
+static void menu_frame_hide(ObMenuFrame *self);
 
 static Window createWindow(Window parent, gulong mask,
                            XSetWindowAttributes *attrib)
@@ -342,6 +344,8 @@ void menu_frame_move_on_screen(ObMenuFrame *self, gint x, gint y,
         *dx = MAX(*dx, a->x - x);
         *dy = MAX(*dy, a->y - y);
     }
+
+    g_free(a);
 }
 
 static void menu_entry_frame_render(ObMenuEntryFrame *self)
@@ -397,6 +401,7 @@ static void menu_entry_frame_render(ObMenuEntryFrame *self)
         text_a->texture[0].data.text.string = self->entry->data.normal.label;
         if (self->entry->data.normal.shortcut &&
             (self->frame->menu->show_all_shortcuts ||
+             self->entry->data.normal.shortcut_always_show ||
              self->entry->data.normal.shortcut_position > 0))
         {
             text_a->texture[0].data.text.shortcut = TRUE;
@@ -412,6 +417,7 @@ static void menu_entry_frame_render(ObMenuEntryFrame *self)
         sub = self->entry->data.submenu.submenu;
         text_a->texture[0].data.text.string = sub ? sub->title : "";
         if (sub->shortcut && (self->frame->menu->show_all_shortcuts ||
+                              sub->shortcut_always_show ||
                               sub->shortcut_position > 0))
         {
             text_a->texture[0].data.text.shortcut = TRUE;
@@ -498,6 +504,8 @@ static void menu_entry_frame_render(ObMenuEntryFrame *self)
             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.alpha =
+            self->entry->data.normal.icon_alpha;
         self->a_icon->texture[0].data.rgba.data =
             self->entry->data.normal.icon_data;
         self->a_icon->surface.parent = item_a;
@@ -597,7 +605,7 @@ static gint menu_entry_frame_get_height(ObMenuEntryFrame *self,
         if (self->entry->data.separator.label != NULL) {
             h += ob_rr_theme->menu_title_height +
                 (ob_rr_theme->mbwidth - PADDING) * 2;
+
             /* if the first entry is a labeled separator, then make its border
                overlap with the menu's outside border */
             if (first_entry)
@@ -629,9 +637,9 @@ void menu_frame_render(ObMenuFrame *self)
     STRUT_SET(self->item_margin, 0, 0, 0, 0);
 
     if (self->entries) {
-        ObMenuEntryFrame *e = self->entries->data;
         gint l, t, r, b;
 
+        e = self->entries->data;
         e->a_text_normal->texture[0].data.text.string = "";
         tw = RrMinWidth(e->a_text_normal);
         tw += 2*PADDING;
@@ -686,7 +694,8 @@ void menu_frame_render(ObMenuFrame *self)
         }
 
         RECT_SET_POINT(e->area, 0, h+e->border);
-        XMoveWindow(ob_display, e->window, e->area.x-e->border, e->area.y-e->border);
+        XMoveWindow(ob_display, e->window,
+                    e->area.x-e->border, e->area.y-e->border);
         XSetWindowBorderWidth(ob_display, e->window, e->border);
         XSetWindowBorder(ob_display, e->window,
                          RrColorPixel(ob_rr_theme->menu_border_color));
@@ -728,7 +737,7 @@ void menu_frame_render(ObMenuFrame *self)
             if (e->entry->data.separator.label != NULL) {
                 e->a_text_title->texture[0].data.text.string =
                     e->entry->data.separator.label;
-                tw = RrMinWidth(e->a_text_title);
+                tw = RrMinWidth(e->a_text_title) + 2*ob_rr_theme->paddingx;
                 tw = MIN(tw, MAX_MENU_WIDTH);
                 th = ob_rr_theme->menu_title_height +
                     (ob_rr_theme->mbwidth - PADDING) *2;
@@ -879,12 +888,14 @@ static void menu_frame_update(ObMenuFrame *self)
             more_frame = menu_entry_frame_new(more_entry, self);
             /* make it get deleted when the menu frame goes away */
             menu_entry_unref(more_entry);
-                                       
+
             /* add our More... entry to the frame */
             self->entries = g_list_append(self->entries, more_frame);
         }
     }
 
+    g_free(a);
+
     menu_frame_render(self);
 }
 
@@ -914,10 +925,10 @@ static gboolean menu_frame_show(ObMenuFrame *self)
 
         /* grab the pointer in such a way as to pass through "owner events"
            so that we can get enter/leave notifies in the menu. */
-        if (!grab_pointer(TRUE, TRUE, OB_CURSOR_POINTER))
+        if (!grab_pointer(TRUE, FALSE, OB_CURSOR_POINTER))
             return FALSE;
-        if (!grab_keyboard(TRUE)) {
-            grab_pointer(FALSE, TRUE, OB_CURSOR_POINTER);
+        if (!grab_keyboard()) {
+            ungrab_pointer();
             return FALSE;
         }
     }
@@ -933,7 +944,7 @@ static gboolean menu_frame_show(ObMenuFrame *self)
 }
 
 gboolean menu_frame_show_topmenu(ObMenuFrame *self, gint x, gint y,
-                                 gint button)
+                                 gboolean mouse)
 {
     gint px, py;
     guint i;
@@ -946,14 +957,16 @@ gboolean menu_frame_show_topmenu(ObMenuFrame *self, gint x, gint y,
     /* find the monitor the menu is on */
     for (i = 0; i < screen_num_monitors; ++i) {
         Rect *a = screen_physical_area_monitor(i);
-        if (RECT_CONTAINS(*a, x, y)) {
+        gboolean contains = RECT_CONTAINS(*a, x, y);
+        g_free(a);
+        if (contains) {
             self->monitor = i;
             break;
         }
     }
 
     if (self->menu->place_func)
-        self->menu->place_func(self, &x, &y, button, self->menu->data);
+        self->menu->place_func(self, &x, &y, mouse, self->menu->data);
     else
         menu_frame_place_topmenu(self, &x, &y);
 
@@ -1013,7 +1026,7 @@ gboolean menu_frame_show_submenu(ObMenuFrame *self, ObMenuFrame *parent,
     return TRUE;
 }
 
-void menu_frame_hide(ObMenuFrame *self)
+static void menu_frame_hide(ObMenuFrame *self)
 {
     GList *it = g_list_find(menu_frame_visible, self);
 
@@ -1035,8 +1048,8 @@ void menu_frame_hide(ObMenuFrame *self)
 
     if (menu_frame_visible == NULL) {
         /* last menu shown */
-        grab_pointer(FALSE, TRUE, OB_CURSOR_NONE);
-        grab_keyboard(FALSE);
+        ungrab_pointer();
+        ungrab_keyboard();
     }
 
     XUnmapWindow(ob_display, self->window);
@@ -1062,8 +1075,14 @@ void menu_frame_hide_all_client(ObClient *client)
     GList *it = g_list_last(menu_frame_visible);
     if (it) {
         ObMenuFrame *f = it->data;
-        if (f->client == client)
+        if (f->client == client) {
+            if (config_submenu_show_delay) {
+                /* remove any submenu open requests */
+                ob_main_loop_timeout_remove(ob_main_loop,
+                                            menu_entry_frame_submenu_timeout);
+            }
             menu_frame_hide(f);
+        }
     }
 }
 
@@ -1108,6 +1127,7 @@ ObMenuEntryFrame* menu_entry_frame_under(gint x, gint y)
 
 static gboolean menu_entry_frame_submenu_timeout(gpointer data)
 {
+    g_assert(menu_frame_visible);
     menu_entry_frame_show_submenu((ObMenuEntryFrame*)data);
     return FALSE;
 }
@@ -1122,8 +1142,8 @@ void menu_frame_select(ObMenuFrame *self, ObMenuEntryFrame *entry,
         entry = old;
 
     if (old == entry) return;
-   
-    if (config_submenu_show_delay) { 
+
+    if (config_submenu_show_delay) {
         /* remove any submenu open requests */
         ob_main_loop_timeout_remove(ob_main_loop,
                                     menu_entry_frame_submenu_timeout);
@@ -1169,7 +1189,7 @@ void menu_entry_frame_show_submenu(ObMenuEntryFrame *self)
     menu_frame_show_submenu(f, self->frame, self);
 }
 
-void menu_entry_frame_execute(ObMenuEntryFrame *self, guint state, Time time)
+void menu_entry_frame_execute(ObMenuEntryFrame *self, guint state)
 {
     if (self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
         self->entry->data.normal.enabled)
@@ -1190,9 +1210,10 @@ void menu_entry_frame_execute(ObMenuEntryFrame *self, guint state, Time time)
         }
 
         if (func)
-            func(entry, frame, client, state, data, time);
+            func(entry, frame, client, state, data);
         else
-            action_run(acts, client, state, time);
+            actions_run_acts(acts, OB_USER_ACTION_MENU_SELECTION,
+                             state, -1, -1, 0, OB_FRAME_CONTEXT_NONE, client);
     }
 }