Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Leap:42.3
plasma5-workspace
0012-Simplify-AppMenu-menu-management.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0012-Simplify-AppMenu-menu-management.patch of Package plasma5-workspace
From f5adedb6a756c45ffdadb88f31e76fe1f39a899e Mon Sep 17 00:00:00 2001 From: David Edmundson <kde@davidedmundson.co.uk> Date: Wed, 11 Jan 2017 14:00:51 +0000 Subject: [PATCH 12/44] Simplify AppMenu menu management Summary: Instead of having a menu from the importer and our custom vertical menu then syncing entries we can simply use the factory method in DBusMenuImporter to create our custom one from the start. This makes memory management easier as we only need to worry about the importer which implicitly owns the menu. Test Plan: Ran in-window menu, everything worked for me perfectly. Reviewers: #plasma, broulik Reviewed By: #plasma, broulik Subscribers: plasma-devel Tags: #plasma Differential Revision: https://phabricator.kde.org/D4062 --- appmenu/appmenu.cpp | 39 ++++++++++----------------------------- appmenu/appmenu.h | 5 +++-- appmenu/kdbusimporter.h | 4 ++++ 3 files changed, 17 insertions(+), 31 deletions(-) diff --git a/appmenu/appmenu.cpp b/appmenu/appmenu.cpp index e9d2ad18..52ce4839 100644 --- a/appmenu/appmenu.cpp +++ b/appmenu/appmenu.cpp @@ -119,8 +119,8 @@ void AppMenuModule::slotShowMenu(int x, int y, const QString &serviceName, const } // If menu visible, hide it - if (m_menu && m_menu->isVisible()) { - m_menu->hide(); + if (m_menu && m_menu.data()->isVisible()) { + m_menu.data()->hide(); return; } @@ -132,49 +132,32 @@ void AppMenuModule::slotShowMenu(int x, int y, const QString &serviceName, const } auto *importer = new KDBusMenuImporter(serviceName, menuObjectPath.path(), this); - // FIXME this causes a 4 second freeze in dbusmenu when the app times out in aboutToShow - // DBusMenuImporter::slotMenuAboutToShow(): Application did not answer to AboutToShow() before timeout - //QMetaObject::invokeMethod(importer, "updateMenu", Qt::DirectConnection); QMetaObject::invokeMethod(importer, "updateMenu", Qt::QueuedConnection); - - /*connect(importer, &DBusMenuImporter::actionActivationRequested, this, [=](QAction *action) { - // else send request to kwin or others dbus interface registrars - m_waitingAction = action; - emit showRequest(serviceName, menuObjectPath); - });*/ + disconnect(importer, 0, this, 0); // ensure we don't popup multiple times in case the menu updates again later connect(importer, &KDBusMenuImporter::menuUpdated, this, [=] { QMenu *menu = importer->menu(); if (!menu) { return; } + m_menu = qobject_cast<VerticalMenu*>(menu); - const auto &actions = menu->actions(); - if (actions.isEmpty()) { - return; - } - - m_menu = new VerticalMenu(); - m_menu->setServiceName(serviceName); - m_menu->setMenuObjectPath(menuObjectPath); - - for (QAction *action : actions) { - m_menu->addAction(action); - } + m_menu.data()->setServiceName(serviceName); + m_menu.data()->setMenuObjectPath(menuObjectPath); - connect(m_menu, &QMenu::aboutToHide, this, [this, importer] { + connect(m_menu.data(), &QMenu::aboutToHide, this, [this, importer] { hideMenu(); importer->deleteLater(); }); //m_menuImporter->fakeUnityAboutToShow(serviceName, menuObjectPath); - m_menu->popup(QPoint(x, y)); + m_menu.data()->popup(QPoint(x, y)); emit menuShown(serviceName, menuObjectPath); if (m_waitingAction) { - m_menu->setActiveAction(m_waitingAction); + m_menu.data()->setActiveAction(m_waitingAction); m_waitingAction = nullptr; } }); @@ -183,9 +166,7 @@ void AppMenuModule::slotShowMenu(int x, int y, const QString &serviceName, const void AppMenuModule::hideMenu() { if (m_menu) { - emit menuHidden(m_menu->serviceName(), m_menu->menuObjectPath()); - m_menu->deleteLater(); - m_menu = nullptr; + emit menuHidden(m_menu.data()->serviceName(), m_menu->menuObjectPath()); } } diff --git a/appmenu/appmenu.h b/appmenu/appmenu.h index dacfd7b6..6fd22bc4 100644 --- a/appmenu/appmenu.h +++ b/appmenu/appmenu.h @@ -28,6 +28,8 @@ #define APPMENUMODULE_H #include <kdedmodule.h> + +#include <QPointer> #include "menuimporter.h" class QDBusPendingCallWatcher; @@ -89,10 +91,9 @@ private: MenuImporter *m_menuImporter = nullptr; AppmenuDBus *m_appmenuDBus; + QPointer<VerticalMenu> m_menu; - VerticalMenu *m_menu = nullptr; QAction *m_waitingAction = nullptr; - }; #endif diff --git a/appmenu/kdbusimporter.h b/appmenu/kdbusimporter.h index d4246e10..ead7d65f 100644 --- a/appmenu/kdbusimporter.h +++ b/appmenu/kdbusimporter.h @@ -29,6 +29,7 @@ #include <dbusmenuimporter.h> #include <QIcon> +#include "verticalmenu.h" class KDBusMenuImporter : public DBusMenuImporter { @@ -45,6 +46,9 @@ protected: return QIcon::fromTheme(name); } + QMenu *createMenu(QWidget *parent) override { + return new VerticalMenu(parent); + } }; #endif //KDBUSMENUIMPORTER_H -- 2.12.0
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor