diff --git a/appmenu/appmenu.cpp b/appmenu/appmenu.cpp index 14c3d2fe..e9d2ad18 100644 --- a/appmenu/appmenu.cpp +++ b/appmenu/appmenu.cpp @@ -1,227 +1,222 @@ /* This file is part of the KDE project. Copyright (c) 2011 Lionel Chauvin Copyright (c) 2011,2012 Cédric Bellegarde Copyright (c) 2016 Kai Uwe Broulik Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include #include "appmenu.h" #include "kdbusimporter.h" #include "menuimporteradaptor.h" #include "appmenuadaptor.h" #include "appmenu_dbus.h" #include "verticalmenu.h" #include #include #include #include #include #include #include #include #if HAVE_X11 #include #include #endif static const QByteArray s_x11AppMenuServiceNamePropertyName = QByteArrayLiteral("_KDE_NET_WM_APPMENU_SERVICE_NAME"); static const QByteArray s_x11AppMenuObjectPathPropertyName = QByteArrayLiteral("_KDE_NET_WM_APPMENU_OBJECT_PATH"); K_PLUGIN_FACTORY_WITH_JSON(AppMenuFactory, "appmenu.json", registerPlugin();) AppMenuModule::AppMenuModule(QObject* parent, const QList&) : KDEDModule(parent), m_appmenuDBus(new AppmenuDBus(this)) { reconfigure(); m_appmenuDBus->connectToBus(); connect(m_appmenuDBus, &AppmenuDBus::appShowMenu, this, &AppMenuModule::slotShowMenu); connect(m_appmenuDBus, &AppmenuDBus::reconfigured, this, &AppMenuModule::reconfigure); // transfer our signals to dbus connect(this, &AppMenuModule::showRequest, m_appmenuDBus, &AppmenuDBus::showRequest); connect(this, &AppMenuModule::menuHidden, m_appmenuDBus, &AppmenuDBus::menuHidden); connect(this, &AppMenuModule::menuShown, m_appmenuDBus, &AppmenuDBus::menuShown); QDBusConnection::sessionBus().connect({}, {}, QStringLiteral("com.canonical.dbusmenu"), QStringLiteral("ItemActivationRequested"), this, SLOT(itemActivationRequested(int,uint))); } AppMenuModule::~AppMenuModule() = default; void AppMenuModule::slotWindowRegistered(WId id, const QString &serviceName, const QDBusObjectPath &menuObjectPath) { #ifdef HAVE_X11 if (KWindowSystem::isPlatformX11()) { auto *c = QX11Info::connection(); static xcb_atom_t s_serviceNameAtom = XCB_ATOM_NONE; static xcb_atom_t s_objectPathAtom = XCB_ATOM_NONE; auto setWindowProperty = [c](WId id, xcb_atom_t &atom, const QByteArray &name, const QByteArray &value) { if (atom == XCB_ATOM_NONE) { const xcb_intern_atom_cookie_t cookie = xcb_intern_atom(c, false, name.length(), name.constData()); QScopedPointer reply(xcb_intern_atom_reply(c, cookie, Q_NULLPTR)); if (reply.isNull()) { return; } atom = reply->atom; if (atom == XCB_ATOM_NONE) { return; } } xcb_change_property(c, XCB_PROP_MODE_REPLACE, id, atom, XCB_ATOM_STRING, 8, value.length(), value.constData()); }; // TODO only set the property if it doesn't already exist setWindowProperty(id, s_serviceNameAtom, s_x11AppMenuServiceNamePropertyName, serviceName.toUtf8()); setWindowProperty(id, s_objectPathAtom, s_x11AppMenuObjectPathPropertyName, menuObjectPath.path().toUtf8()); } #endif } -void AppMenuModule::slotShowMenu(int x, int y, const QString &serviceName, const QDBusObjectPath &menuObjectPath) +void AppMenuModule::slotShowMenu(int x, int y, const QString &serviceName, const QDBusObjectPath &menuObjectPath, int actionId) { if (!m_menuImporter) { return; } // If menu visible, hide it if (m_menu && m_menu->isVisible()) { m_menu->hide(); return; } //dbus call by user (for khotkey shortcut) if (x == -1 || y == -1) { // We do not know kwin button position, so tell kwin to show menu - emit showRequest(serviceName, menuObjectPath); + emit showRequest(serviceName, menuObjectPath, actionId); return; } 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); });*/ connect(importer, &KDBusMenuImporter::menuUpdated, this, [=] { QMenu *menu = importer->menu(); if (!menu) { return; } 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); } connect(m_menu, &QMenu::aboutToHide, this, [this, importer] { hideMenu(); importer->deleteLater(); }); //m_menuImporter->fakeUnityAboutToShow(serviceName, menuObjectPath); m_menu->popup(QPoint(x, y)); emit menuShown(serviceName, menuObjectPath); if (m_waitingAction) { m_menu->setActiveAction(m_waitingAction); m_waitingAction = nullptr; } }); } void AppMenuModule::hideMenu() { if (m_menu) { emit menuHidden(m_menu->serviceName(), m_menu->menuObjectPath()); m_menu->deleteLater(); m_menu = nullptr; } } void AppMenuModule::itemActivationRequested(int winId, uint action) { - // our long-press Alt emits winid 0 and action 0 - // ignore "standard conforming" apps that send actual ids - if (winId != 0 || action != 0) { - return; - } - - emit showRequest(message().service(), QDBusObjectPath(message().path())); + Q_UNUSED(winId); + emit showRequest(message().service(), QDBusObjectPath(message().path()), action); } // reload settings void AppMenuModule::reconfigure() { m_waitingAction = nullptr; hideMenu(); // hide window decoration menu if exists KConfigGroup config(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), QStringLiteral("Appmenu Style")); const QString &menuStyle = config.readEntry("Style", "InApplication"); // TODO enum or Kconfigxt or what not? if (menuStyle == QLatin1String("InApplication")) { delete m_menuImporter; m_menuImporter = nullptr; return; } // Setup a menu importer if needed if (!m_menuImporter) { m_menuImporter = new MenuImporter(this); connect(m_menuImporter, &MenuImporter::WindowRegistered, this, &AppMenuModule::slotWindowRegistered); m_menuImporter->connectToBus(); } } #include "appmenu.moc" diff --git a/appmenu/appmenu.h b/appmenu/appmenu.h index 3dc93ff8..dacfd7b6 100644 --- a/appmenu/appmenu.h +++ b/appmenu/appmenu.h @@ -1,98 +1,98 @@ /* This file is part of the KDE project. Copyright (c) 2011 Lionel Chauvin Copyright (c) 2011,2012 Cédric Bellegarde Copyright (c) 2016 Kai Uwe Broulik Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef APPMENUMODULE_H #define APPMENUMODULE_H #include #include "menuimporter.h" class QDBusPendingCallWatcher; class KDBusMenuImporter; class AppmenuDBus; class TopMenuBar; class VerticalMenu; class AppMenuModule : public KDEDModule, protected QDBusContext { Q_OBJECT public: AppMenuModule(QObject* parent, const QList& list); ~AppMenuModule() override; Q_SIGNALS: /** * We do not know where is menu decoration button, so tell kwin to show menu */ - void showRequest(const QString &serviceName, const QDBusObjectPath &menuObjectPath); + void showRequest(const QString &serviceName, const QDBusObjectPath &menuObjectPath, int actionId); /** * This signal is emitted whenever popup menu/menubar is shown * Useful for decorations to know if menu button should look pressed */ void menuShown(const QString &service, const QDBusObjectPath &objectPath); /** * This signal is emitted whenever popup menu/menubar is hidden * Useful for decorations to know if menu button should be release */ void menuHidden(const QString &service, const QDBusObjectPath &objectPath); private Q_SLOTS: /** * A new window was registered to AppMenu * * For compatibility this will set the DBus service name and menu object path as properties * on the window so we keep working with clients that use the DBusMenu "properly". */ void slotWindowRegistered(WId id, const QString &serviceName, const QDBusObjectPath &menuObjectPath); /** * Show menu at QPoint(x,y) for DBus serviceName and menuObjectPath * if x or y == -1, show in application window */ - void slotShowMenu(int x, int y, const QString &serviceName, const QDBusObjectPath &menuObjectPath); + void slotShowMenu(int x, int y, const QString &serviceName, const QDBusObjectPath &menuObjectPath, int actionId); /** * Reconfigure module */ void reconfigure(); void itemActivationRequested(int winId, uint action); private: void hideMenu(); void fakeUnityAboutToShow(const QString &service, const QDBusObjectPath &menuObjectPath); KDBusMenuImporter *getImporter(const QString &service, const QString &path); MenuImporter *m_menuImporter = nullptr; AppmenuDBus *m_appmenuDBus; VerticalMenu *m_menu = nullptr; QAction *m_waitingAction = nullptr; }; #endif diff --git a/appmenu/appmenu_dbus.cpp b/appmenu/appmenu_dbus.cpp index b1420a70..1fe53431 100644 --- a/appmenu/appmenu_dbus.cpp +++ b/appmenu/appmenu_dbus.cpp @@ -1,69 +1,69 @@ /* This file is part of the KDE project. Copyright (c) 2011 Lionel Chauvin Copyright (c) 2011,2012 Cédric Bellegarde Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "appmenu_dbus.h" #include "kdbusimporter.h" #include "appmenuadaptor.h" #include #include #include #include static const char* DBUS_SERVICE = "org.kde.kappmenu"; static const char* DBUS_OBJECT_PATH = "/KAppMenu"; AppmenuDBus::AppmenuDBus(QObject* parent) : QObject(parent) { } AppmenuDBus::~AppmenuDBus() { } bool AppmenuDBus::connectToBus(const QString& service, const QString& path) { m_service = service.isEmpty() ? DBUS_SERVICE : service; QString newPath = path.isEmpty() ? DBUS_OBJECT_PATH : path; if (!QDBusConnection::sessionBus().registerService(m_service)) { return false; } new AppmenuAdaptor(this); QDBusConnection::sessionBus().registerObject(newPath, this); return true; } -void AppmenuDBus::showMenu(int x, int y, const QString &serviceName, const QDBusObjectPath &menuObjectPath) +void AppmenuDBus::showMenu(int x, int y, const QString &serviceName, const QDBusObjectPath &menuObjectPath, int actionId) { - emit appShowMenu(x, y, serviceName, menuObjectPath); + emit appShowMenu(x, y, serviceName, menuObjectPath, actionId); } void AppmenuDBus::reconfigure() { emit reconfigured(); } diff --git a/appmenu/appmenu_dbus.h b/appmenu/appmenu_dbus.h index 7102fc6a..e1456072 100644 --- a/appmenu/appmenu_dbus.h +++ b/appmenu/appmenu_dbus.h @@ -1,89 +1,89 @@ /* This file is part of the KDE project. Copyright (c) 2011 Lionel Chauvin Copyright (c) 2011,2012 Cédric Bellegarde Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef APPMENU_DBUS_H #define APPMENU_DBUS_H // Qt #include #include #include #include #include class KDBusMenuImporter; class AppmenuDBus : public QObject, protected QDBusContext { Q_OBJECT public: AppmenuDBus(QObject*); ~AppmenuDBus() override; bool connectToBus(const QString& service = QString(), const QString& path = QString()); /** * DBus method showing menu at QPoint(x,y) for given DBus service name and menuObjectPath * if x or y == -1, show in application window */ - void showMenu(int x, int y, const QString &serviceName, const QDBusObjectPath &menuObjectPath); + void showMenu(int x, int y, const QString &serviceName, const QDBusObjectPath &menuObjectPath, int actionId); /** * DBus method reconfiguring kded module */ void reconfigure(); Q_SIGNALS: /** * This signal is emitted on showMenu() request */ - void appShowMenu(int x, int y, const QString &serviceName, const QDBusObjectPath &menuObjectPath); + void appShowMenu(int x, int y, const QString &serviceName, const QDBusObjectPath &menuObjectPath, int actionId); /** * This signal is emitted on reconfigure() request */ void reconfigured(); // Dbus signals /** * This signal is emitted whenever kded want to show menu * We do not know where is menu decoration button, so tell kwin to show menu */ - void showRequest(const QString &serviceName, const QDBusObjectPath &menuObjectPath); + void showRequest(const QString &serviceName, const QDBusObjectPath &menuObjectPath, int actionId); /** * This signal is emitted whenever popup menu/menubar is shown * Useful for decorations to know if menu button should look pressed */ void menuShown(const QString &serviceName, const QDBusObjectPath &menuObjectPath); /** * This signal is emitted whenever popup menu/menubar is hidden * Useful for decorations to know if menu button should be release */ void menuHidden(const QString &serviceName, const QDBusObjectPath &menuObjectPath); private: QString m_service; }; #endif // APPMENU_DBUS_H diff --git a/appmenu/org.kde.kappmenu.xml b/appmenu/org.kde.kappmenu.xml index 3efdc111..d29d3ee8 100644 --- a/appmenu/org.kde.kappmenu.xml +++ b/appmenu/org.kde.kappmenu.xml @@ -1,26 +1,28 @@ + +