Commit 0977109d authored by Graeme Gott's avatar Graeme Gott

Fix unable to hide menu with shortcut.

The remote event happens after the loss of focus from the shortcut has
already hidden the menu. This means that unless a delay is used, you
cannot toggle the menu and it will be shown every time.
parent cfb69fac
......@@ -93,7 +93,8 @@ Plugin::Plugin(XfcePanelPlugin* plugin) :
m_plugin(plugin),
m_window(nullptr),
m_opacity(100),
m_file_icon(false)
m_file_icon(false),
m_focus_out_time(0)
{
// Load settings
wm_settings = new Settings;
......@@ -377,6 +378,18 @@ gboolean Plugin::remote_event(XfcePanelPlugin*, gchar* name, GValue* value)
return false;
}
// Ignore event if menu lost focus and hid within last 1/4 second;
// needed for toggling as remote event happens after focus is lost
if (m_focus_out_time)
{
if ((g_get_monotonic_time() - m_focus_out_time) < 250000)
{
m_focus_out_time = 0;
return true;
}
m_focus_out_time = 0;
}
if (gtk_widget_get_visible(m_window->get_widget()))
{
m_window->hide();
......@@ -554,6 +567,7 @@ void Plugin::show_menu(bool at_cursor)
m_opacity = wm_settings->menu_opacity;
}
m_window->show(at_cursor ? Window::PositionAtCursor : Window::Position(xfce_panel_plugin_get_orientation(m_plugin)));
m_focus_out_time = 0;
}
//-----------------------------------------------------------------------------
......@@ -58,6 +58,11 @@ public:
static std::string get_button_title_default();
std::string get_button_icon_name() const;
void focus_lost()
{
m_focus_out_time = g_get_monotonic_time();
}
void reload();
void set_button_style(ButtonStyle style);
void set_button_title(const std::string& title);
......@@ -89,6 +94,7 @@ private:
int m_opacity;
bool m_file_icon;
gint64 m_focus_out_time;
};
}
......
......@@ -591,6 +591,7 @@ gboolean WhiskerMenu::Window::on_focus_out_event(GtkWidget* widget, GdkEvent*)
if (!m_child_has_focus && gtk_widget_get_visible(widget))
{
hide();
m_plugin->focus_lost();
}
return GDK_EVENT_PROPAGATE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment