From 7e3809a3cafacb5fca7613f85c43a388eff3df9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Fri, 15 Mar 2013 16:49:20 +0100 Subject: [PATCH] Split out Application Menu related code into own class Following the approach to move out of Workspace what doesn't belong into Workspace Appmenu support goes into an own class. This also has the advantage of better compilation with Qt 5 as moc seems to dislike ifdefs in the slot definitions. REVIEW: 109497 --- CMakeLists.txt | 7 ++++ appmenu.cpp | 103 ++++++++++++++++++++++++++++++++++++++++++++++++ appmenu.h | 68 ++++++++++++++++++++++++++++++++ client.cpp | 5 ++- useractions.cpp | 22 ----------- workspace.cpp | 48 +++------------------- workspace.h | 15 ------- 7 files changed, 187 insertions(+), 81 deletions(-) create mode 100644 appmenu.cpp create mode 100644 appmenu.h diff --git a/CMakeLists.txt b/CMakeLists.txt index ecddc55ed8..f0795b4873 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -172,6 +172,13 @@ if(KWIN_BUILD_SCREENEDGES) ) endif() +if(KWIN_BUILD_KAPPMENU) + set( + kwin_KDEINIT_SRCS ${kwin_KDEINIT_SRCS} + appmenu.cpp + ) +endif() + if(KWIN_HAVE_EGL) set(kwin_KDEINIT_SRCS ${kwin_KDEINIT_SRCS} eglonxbackend.cpp) endif() diff --git a/appmenu.cpp b/appmenu.cpp new file mode 100644 index 0000000000..ffdffea87e --- /dev/null +++ b/appmenu.cpp @@ -0,0 +1,103 @@ +/******************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (c) 2011 Lionel Chauvin +Copyright (c) 2011,2012 Cédric Bellegarde +Copyright (C) 2013 Martin Gräßlin + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*********************************************************************/ +#include "appmenu.h" +#include "client.h" +// Qt +#include +#include +#include + +namespace KWin { + +static const char *KDED_SERVICE = "org.kde.kded"; +static const char *KDED_APPMENU_PATH = "/modules/appmenu"; +static const char *KDED_INTERFACE = "org.kde.kded"; + +ApplicationMenu *ApplicationMenu::s_self = NULL; + +ApplicationMenu *ApplicationMenu::create(QObject *parent) +{ + Q_ASSERT(!s_self); + s_self = new ApplicationMenu(parent); + return s_self; +} + +ApplicationMenu::ApplicationMenu(QObject *parent) + : QObject(parent) +{ + QDBusConnection dbus = QDBusConnection::sessionBus(); + dbus.connect(KDED_SERVICE, KDED_APPMENU_PATH, KDED_INTERFACE, "showRequest", + this, SLOT(slotShowRequest(qulonglong))); + dbus.connect(KDED_SERVICE, KDED_APPMENU_PATH, KDED_INTERFACE, "menuAvailable", + this, SLOT(slotMenuAvailable(qulonglong))); + dbus.connect(KDED_SERVICE, KDED_APPMENU_PATH, KDED_INTERFACE, "menuHidden", + this, SLOT(slotMenuHidden(qulonglong))); + dbus.connect(KDED_SERVICE, KDED_APPMENU_PATH, KDED_INTERFACE, "clearMenus", + this, SLOT(slotClearMenus())); +} + +ApplicationMenu::~ApplicationMenu() +{ + s_self = NULL; +} + +bool ApplicationMenu::hasMenu(xcb_window_t window) +{ + return m_windowsMenu.removeOne(window); +} + +void ApplicationMenu::slotShowRequest(qulonglong wid) +{ + if (Client *c = Workspace::self()->findClient(WindowMatchPredicate(wid))) + c->emitShowRequest(); +} + +void ApplicationMenu::slotMenuAvailable(qulonglong wid) +{ + if (Client *c = Workspace::self()->findClient(WindowMatchPredicate(wid))) + c->setAppMenuAvailable(); + else + m_windowsMenu.append(wid); +} + +void ApplicationMenu::slotMenuHidden(qulonglong wid) +{ + if (Client *c = Workspace::self()->findClient(WindowMatchPredicate(wid))) + c->emitMenuHidden(); +} + +void ApplicationMenu::slotClearMenus() +{ + foreach (Client *c, Workspace::self()->clientList()) { + c->setAppMenuUnavailable(); + } +} + +void ApplicationMenu::showApplicationMenu(const QPoint &p, const xcb_window_t id) +{ + QList args = QList() << p.x() << p.y() << qulonglong(id); + QDBusMessage method = QDBusMessage::createMethodCall(KDED_SERVICE, KDED_APPMENU_PATH, KDED_INTERFACE, "showMenu"); + method.setArguments(args); + QDBusConnection::sessionBus().asyncCall(method); +} + +} // namespace diff --git a/appmenu.h b/appmenu.h new file mode 100644 index 0000000000..868dfc35e3 --- /dev/null +++ b/appmenu.h @@ -0,0 +1,68 @@ +/******************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (c) 2011 Lionel Chauvin +Copyright (c) 2011,2012 Cédric Bellegarde +Copyright (C) 2013 Martin Gräßlin + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*********************************************************************/ +#ifndef KWIN_APPLICATIONMENU_H +#define KWIN_APPLICATIONMENU_H +// Qt +#include +// xcb +#include + +class QPoint; + +namespace KWin +{ + +class ApplicationMenu : public QObject +{ + Q_OBJECT + +public: + virtual ~ApplicationMenu(); + + bool hasMenu(xcb_window_t window); + void showApplicationMenu(const QPoint &pos, const xcb_window_t window); + + static ApplicationMenu *self(); + static ApplicationMenu *create(QObject *parent); + +private Q_SLOTS: + void slotShowRequest(qulonglong wid); + void slotMenuAvailable(qulonglong wid); + void slotMenuHidden(qulonglong wid); + void slotClearMenus(); + +private: + ApplicationMenu(QObject *parent); + QList m_windowsMenu; + + static ApplicationMenu *s_self; +}; + +inline +ApplicationMenu *ApplicationMenu::self() +{ + return s_self; +} + +} + +#endif // KWIN_APPLICATIONMENU_H diff --git a/client.cpp b/client.cpp index aab9dedd8a..f596fb5265 100644 --- a/client.cpp +++ b/client.cpp @@ -57,6 +57,9 @@ along with this program. If not, see . #ifdef KWIN_BUILD_TABBOX #include "tabbox.h" #endif +#ifdef KWIN_BUILD_KAPPMENU +#include "appmenu.h" +#endif #include @@ -2460,7 +2463,7 @@ void Client::setAppMenuUnavailable() void Client::showApplicationMenu(const QPoint &p) { - workspace()->showApplicationMenu(p, window()); + ApplicationMenu::self()->showApplicationMenu(p, window()); } #endif diff --git a/useractions.cpp b/useractions.cpp index 93f0402c5b..9f21ce14f8 100755 --- a/useractions.cpp +++ b/useractions.cpp @@ -77,21 +77,9 @@ along with this program. If not, see . #include "tabbox.h" #endif -#ifdef KWIN_BUILD_KAPPMENU -#include -#include -#include -#endif - namespace KWin { -#ifdef KWIN_BUILD_KAPPMENU -static const char *KDED_SERVICE = "org.kde.kded"; -static const char *KDED_APPMENU_PATH = "/modules/appmenu"; -static const char *KDED_INTERFACE = "org.kde.kded"; -#endif - UserActionsMenu::UserActionsMenu(QObject *parent) : QObject(parent) , m_menu(NULL) @@ -1254,16 +1242,6 @@ void Workspace::showWindowMenuAt(unsigned long, int, int) slotWindowOperations(); } -#ifdef KWIN_BUILD_KAPPMENU -void Workspace::showApplicationMenu(const QPoint &p, const WId id) -{ - QList args = QList() << p.x() << p.y() << qulonglong(id); - QDBusMessage method = QDBusMessage::createMethodCall(KDED_SERVICE, KDED_APPMENU_PATH, KDED_INTERFACE, "showMenu"); - method.setArguments(args); - QDBusConnection::sessionBus().asyncCall(method); -} -#endif - void Workspace::slotActivateAttentionWindow() { if (attention_chain.count() > 0) diff --git a/workspace.cpp b/workspace.cpp index 11b76cc273..c32da3155e 100644 --- a/workspace.cpp +++ b/workspace.cpp @@ -74,6 +74,9 @@ along with this program. If not, see . #ifdef KWIN_BUILD_SCRIPTING #include "scripting/scripting.h" #endif +#ifdef KWIN_BUILD_KAPPMENU +#include "appmenu.h" +#endif #include #include @@ -90,12 +93,6 @@ namespace KWin extern int screen_number; extern bool is_multihead; -#ifdef KWIN_BUILD_KAPPMENU -static const char *KDED_SERVICE = "org.kde.kded"; -static const char *KDED_APPMENU_PATH = "/modules/appmenu"; -static const char *KDED_INTERFACE = "org.kde.kded"; -#endif - Workspace* Workspace::_self = 0; Workspace::Workspace(bool restore) @@ -142,15 +139,7 @@ Workspace::Workspace(bool restore) QFuture reparseConfigFuture = QtConcurrent::run(options, &Options::reparseConfiguration); #ifdef KWIN_BUILD_KAPPMENU - QDBusConnection dbus = QDBusConnection::sessionBus(); - dbus.connect(KDED_SERVICE, KDED_APPMENU_PATH, KDED_INTERFACE, "showRequest", - this, SLOT(slotShowRequest(qulonglong))); - dbus.connect(KDED_SERVICE, KDED_APPMENU_PATH, KDED_INTERFACE, "menuAvailable", - this, SLOT(slotMenuAvailable(qulonglong))); - dbus.connect(KDED_SERVICE, KDED_APPMENU_PATH, KDED_INTERFACE, "menuHidden", - this, SLOT(slotMenuHidden(qulonglong))); - dbus.connect(KDED_SERVICE, KDED_APPMENU_PATH, KDED_INTERFACE, "clearMenus", - this, SLOT(slotClearMenus())); + ApplicationMenu::create(this); #endif _self = this; @@ -647,7 +636,7 @@ void Workspace::addClient(Client* c, allowed_t) tab_box->reset(true); #endif #ifdef KWIN_BUILD_KAPPMENU - if (m_windowsMenu.removeOne(c->window())) + if (ApplicationMenu::self()->hasMenu(c->window())) c->setAppMenuAvailable(); #endif } @@ -878,34 +867,7 @@ void Workspace::slotReloadConfig() { reconfigure(); } -#ifdef KWIN_BUILD_KAPPMENU -void Workspace::slotShowRequest(qulonglong wid) -{ - if (Client *c = findClient(WindowMatchPredicate(wid))) - c->emitShowRequest(); -} -void Workspace::slotMenuAvailable(qulonglong wid) -{ - if (Client *c = findClient(WindowMatchPredicate(wid))) - c->setAppMenuAvailable(); - else - m_windowsMenu.append(wid); -} - -void Workspace::slotMenuHidden(qulonglong wid) -{ - if (Client *c = findClient(WindowMatchPredicate(wid))) - c->emitMenuHidden(); -} - -void Workspace::slotClearMenus() -{ - foreach (Client *c, clients) { - c->setAppMenuUnavailable(); - } -} -#endif void Workspace::reconfigure() { reconfigureTimer.start(200); diff --git a/workspace.h b/workspace.h index b5411278c8..ab187bbc7f 100644 --- a/workspace.h +++ b/workspace.h @@ -305,10 +305,6 @@ public: return m_userActionsMenu; } -#ifdef KWIN_BUILD_KAPPMENU - void showApplicationMenu(const QPoint &, const WId); -#endif - void updateMinimizedOfTransients(Client*); void updateOnAllDesktopsOfTransients(Client*); void updateOnAllActivitiesOfTransients(Client*); @@ -497,12 +493,6 @@ private slots: void writeWindowRules(); void slotBlockShortcuts(int data); void slotReloadConfig(); -#ifdef KWIN_BUILD_KAPPMENU - void slotShowRequest(qulonglong wid); - void slotMenuAvailable(qulonglong wid); - void slotMenuHidden(qulonglong wid); - void slotClearMenus(); -#endif void updateCurrentActivity(const QString &new_activity); void slotActivityRemoved(const QString &activity); void slotActivityAdded(const QString &activity); @@ -714,11 +704,6 @@ private: bool forced_global_mouse_grab; friend class StackingUpdatesBlocker; -#ifdef KWIN_BUILD_KAPPMENU - //used for menu available before window is mapped - QList m_windowsMenu; -#endif - Scripting *m_scripting; QScopedPointer m_windowKiller;