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
This commit is contained in:
Martin Gräßlin 2013-03-15 16:49:20 +01:00
parent 76cd9e6174
commit 7e3809a3ca
7 changed files with 187 additions and 81 deletions

View file

@ -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()

103
appmenu.cpp Normal file
View file

@ -0,0 +1,103 @@
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (c) 2011 Lionel Chauvin <megabigbug@yahoo.fr>
Copyright (c) 2011,2012 Cédric Bellegarde <gnumdk@gmail.com>
Copyright (C) 2013 Martin Gräßlin <mgraesslin@kde.org>
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 <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "appmenu.h"
#include "client.h"
// Qt
#include <QtDBus/QDBusConnection>
#include <QtDBus/QDBusMessage>
#include <QtDBus/QDBusPendingCall>
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<QVariant> args = QList<QVariant>() << 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

68
appmenu.h Normal file
View file

@ -0,0 +1,68 @@
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (c) 2011 Lionel Chauvin <megabigbug@yahoo.fr>
Copyright (c) 2011,2012 Cédric Bellegarde <gnumdk@gmail.com>
Copyright (C) 2013 Martin Gräßlin <mgraesslin@kde.org>
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 <http://www.gnu.org/licenses/>.
*********************************************************************/
#ifndef KWIN_APPLICATIONMENU_H
#define KWIN_APPLICATIONMENU_H
// Qt
#include <QObject>
// xcb
#include <xcb/xcb.h>
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<xcb_window_t> m_windowsMenu;
static ApplicationMenu *s_self;
};
inline
ApplicationMenu *ApplicationMenu::self()
{
return s_self;
}
}
#endif // KWIN_APPLICATIONMENU_H

View file

@ -57,6 +57,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifdef KWIN_BUILD_TABBOX
#include "tabbox.h"
#endif
#ifdef KWIN_BUILD_KAPPMENU
#include "appmenu.h"
#endif
#include <X11/extensions/shape.h>
@ -2460,7 +2463,7 @@ void Client::setAppMenuUnavailable()
void Client::showApplicationMenu(const QPoint &p)
{
workspace()->showApplicationMenu(p, window());
ApplicationMenu::self()->showApplicationMenu(p, window());
}
#endif

View file

@ -77,21 +77,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "tabbox.h"
#endif
#ifdef KWIN_BUILD_KAPPMENU
#include <QDBusMessage>
#include <QDBusConnection>
#include <QDBusPendingCall>
#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<QVariant> args = QList<QVariant>() << 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)

View file

@ -74,6 +74,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifdef KWIN_BUILD_SCRIPTING
#include "scripting/scripting.h"
#endif
#ifdef KWIN_BUILD_KAPPMENU
#include "appmenu.h"
#endif
#include <X11/extensions/shape.h>
#include <X11/keysym.h>
@ -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<void> 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);

View file

@ -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<WId> m_windowsMenu;
#endif
Scripting *m_scripting;
QScopedPointer<KillWindow> m_windowKiller;