aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJavier <dev.git@javispedro.com>2014-05-24 15:52:37 +0200
committerJavier <dev.git@javispedro.com>2014-05-24 15:52:37 +0200
commitf823791f692e6aeca3f0a855c5e10c02bb48cbde (patch)
treee93b9f4663439b6d7217716c9b75305da55b8321
parent09e8212de806d76d9fdc468df8fa38ee2183eb1e (diff)
downloadtopmenu-qt-f823791f692e6aeca3f0a855c5e10c02bb48cbde.tar.gz
topmenu-qt-f823791f692e6aeca3f0a855c5e10c02bb48cbde.zip
fix a crash that happened when the server crashed
-rw-r--r--module/topmenumenubarimpl.cc27
-rw-r--r--module/topmenumenubarimpl.h2
2 files changed, 20 insertions, 9 deletions
diff --git a/module/topmenumenubarimpl.cc b/module/topmenumenubarimpl.cc
index 64934c1..641d748 100644
--- a/module/topmenumenubarimpl.cc
+++ b/module/topmenumenubarimpl.cc
@@ -69,6 +69,14 @@ static inline void set_menubarimpl_for_widget(QWidget *widget, TopMenuMenuBarImp
}
}
+static void handle_monitor_availability_changed(GObject *object, GParamSpec *pspec, gpointer user_data)
+{
+ TopMenuMenuBarImpl* self = static_cast<TopMenuMenuBarImpl*>(user_data);
+ Q_UNUSED(object);
+ Q_UNUSED(pspec);
+ self->updateServerAvailability();
+}
+
TopMenuMenuBarImpl::TopMenuMenuBarImpl(QObject *parent) :
MenuProxy(parent),
m_window(0), m_menubar(0), m_appmenubar(0), m_appmenu(0),
@@ -86,7 +94,8 @@ TopMenuMenuBarImpl::TopMenuMenuBarImpl(QObject *parent) :
}
m_monitor_connection_id = g_signal_connect(menuMonitor, "notify::available",
- G_CALLBACK(handleMonitorAvailabilityChanged), this);
+ G_CALLBACK(handle_monitor_availability_changed),
+ static_cast<void*>(this));
}
TopMenuMenuBarImpl::~TopMenuMenuBarImpl()
@@ -94,7 +103,6 @@ TopMenuMenuBarImpl::~TopMenuMenuBarImpl()
if (m_appmenubar) {
gtk_widget_destroy(GTK_WIDGET(m_appmenubar));
g_object_unref(m_appmenubar);
- m_appmenubar = 0;
}
if (m_window) {
if (get_menubarimpl_for_widget(m_window) == this) {
@@ -229,6 +237,14 @@ bool TopMenuMenuBarImpl::menuBarEventFilter(QObject *src, QEvent *event)
return false;
}
+void TopMenuMenuBarImpl::updateServerAvailability()
+{
+ if (m_menubar) {
+ // Hopefully the following causes Qt to "ask" isNativeMenuBar() again.
+ m_menubar->updateGeometry();
+ }
+}
+
GtkMenuItem * TopMenuMenuBarImpl::addAction(QAction* action, QAction* before, QMenu* parent)
{
if (!parent) {
@@ -296,13 +312,6 @@ QShortcut * TopMenuMenuBarImpl::createMnemonicShortcut(QAction *action, QWidget
return shortcut;
}
-void TopMenuMenuBarImpl::handleMonitorAvailabilityChanged(TopMenuMenuBarImpl *self)
-{
- if (self->m_menubar) {
- self->m_menubar->updateGeometry();
- }
-}
-
void TopMenuMenuBarImpl::handleShortcutActivated()
{
QShortcut *shortcut = static_cast<QShortcut*>(sender());
diff --git a/module/topmenumenubarimpl.h b/module/topmenumenubarimpl.h
index 49e8d83..4f7bff8 100644
--- a/module/topmenumenubarimpl.h
+++ b/module/topmenumenubarimpl.h
@@ -42,6 +42,8 @@ public:
bool shortcutsHandledByNativeMenuBar() const;
bool menuBarEventFilter(QObject *, QEvent *event);
+ void updateServerAvailability();
+
protected:
GtkMenuItem * addAction(QAction* action, QAction* before, QMenu* parent);
void removeAction(QAction* action);