Commit 7f1923cc authored by Xaver Hugl's avatar Xaver Hugl
Browse files

move ApplicationMenu singleton into Workspace

parent 1cf22052
......@@ -22,13 +22,10 @@
namespace KWin
{
KWIN_SINGLETON_FACTORY(ApplicationMenu)
static const QString s_viewService(QStringLiteral("org.kde.kappmenuview"));
ApplicationMenu::ApplicationMenu(QObject *parent)
: QObject(parent)
, m_appmenuInterface(new OrgKdeKappmenuInterface(QStringLiteral("org.kde.kappmenu"), QStringLiteral("/KAppMenu"), QDBusConnection::sessionBus(), this))
ApplicationMenu::ApplicationMenu()
: m_appmenuInterface(new OrgKdeKappmenuInterface(QStringLiteral("org.kde.kappmenu"), QStringLiteral("/KAppMenu"), QDBusConnection::sessionBus(), this))
{
connect(m_appmenuInterface, &OrgKdeKappmenuInterface::showRequest, this, &ApplicationMenu::slotShowRequest);
connect(m_appmenuInterface, &OrgKdeKappmenuInterface::menuShown, this, &ApplicationMenu::slotMenuShown);
......@@ -49,11 +46,6 @@ ApplicationMenu::ApplicationMenu(QObject *parent)
m_applicationMenuEnabled = QDBusConnection::sessionBus().interface()->isServiceRegistered(QStringLiteral("org.kde.kappmenu"));
}
ApplicationMenu::~ApplicationMenu()
{
s_self = nullptr;
}
bool ApplicationMenu::applicationMenuEnabled() const
{
return m_applicationMenuEnabled;
......
......@@ -32,7 +32,7 @@ class ApplicationMenu : public QObject
Q_OBJECT
public:
~ApplicationMenu() override;
explicit ApplicationMenu();
void showApplicationMenu(const QPoint &pos, Window *c, int actionId);
......@@ -55,8 +55,6 @@ private:
Window *findWindowWithApplicationMenu(const QString &serviceName, const QDBusObjectPath &menuObjectPath);
bool m_applicationMenuEnabled = false;
KWIN_SINGLETON(ApplicationMenu)
};
}
......
......@@ -149,7 +149,7 @@ void SettingsImpl::readSettings()
m_rightButtons = right;
Q_EMIT decorationSettings()->decorationButtonsRightChanged(m_rightButtons);
}
ApplicationMenu::self()->setViewEnabled(left.contains(KDecoration2::DecorationButtonType::ApplicationMenu) || right.contains(KDecoration2::DecorationButtonType::ApplicationMenu));
Workspace::self()->applicationMenu()->setViewEnabled(left.contains(KDecoration2::DecorationButtonType::ApplicationMenu) || right.contains(KDecoration2::DecorationButtonType::ApplicationMenu));
const bool close = config.readEntry("CloseOnDoubleClickOnMenu", false);
if (close != m_closeDoubleClickMenu) {
m_closeDoubleClickMenu = close;
......
......@@ -1744,7 +1744,7 @@ void Workspace::showWindowMenu(const QRect &pos, Window *window)
void Workspace::showApplicationMenu(const QRect &pos, Window *window, int actionId)
{
ApplicationMenu::self()->showApplicationMenu(window->pos().toPoint() + pos.bottomLeft(), window, actionId);
Workspace::self()->applicationMenu()->showApplicationMenu(window->pos().toPoint() + pos.bottomLeft(), window, actionId);
}
/**
......
......@@ -115,7 +115,7 @@ Window::Window()
}
});
connect(ApplicationMenu::self(), &ApplicationMenu::applicationMenuEnabledChanged, this, [this] {
connect(Workspace::self()->applicationMenu(), &ApplicationMenu::applicationMenuEnabledChanged, this, [this] {
Q_EMIT hasApplicationMenuChanged(hasApplicationMenu());
});
}
......@@ -3339,7 +3339,7 @@ QString Window::findDesktopFile(const QString &desktopFileName)
bool Window::hasApplicationMenu() const
{
return ApplicationMenu::self()->applicationMenuEnabled() && !m_applicationMenuServiceName.isEmpty() && !m_applicationMenuObjectPath.isEmpty();
return Workspace::self()->applicationMenu()->applicationMenuEnabled() && !m_applicationMenuServiceName.isEmpty() && !m_applicationMenuObjectPath.isEmpty();
}
void Window::updateApplicationMenuServiceName(const QString &serviceName)
......
......@@ -122,6 +122,7 @@ Workspace::Workspace()
, workspaceInit(true)
, m_sessionManager(new SessionManager(this))
, m_focusChain(std::make_unique<FocusChain>())
, m_applicationMenu(std::make_unique<ApplicationMenu>())
{
// If KWin was already running it saved its configuration after loosing the selection -> Reread
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
......@@ -130,8 +131,6 @@ Workspace::Workspace()
QFuture<void> reparseConfigFuture = QtConcurrent::run(&Options::reparseConfiguration, options);
#endif
ApplicationMenu::create(this);
_self = this;
#if KWIN_BUILD_ACTIVITIES
......@@ -2827,6 +2826,11 @@ FocusChain *Workspace::focusChain() const
return m_focusChain.get();
}
ApplicationMenu *Workspace::applicationMenu() const
{
return m_applicationMenu.get();
}
#if KWIN_BUILD_ACTIVITIES
Activities *Workspace::activities() const
{
......
......@@ -55,6 +55,7 @@ class VirtualDesktop;
class X11Window;
class X11EventFilter;
class FocusChain;
class ApplicationMenu;
enum class Predicate;
#if KWIN_BUILD_ACTIVITIES
class Activities;
......@@ -428,6 +429,7 @@ public:
return m_lastActiveWindow;
}
FocusChain *focusChain() const;
ApplicationMenu *applicationMenu() const;
#if KWIN_BUILD_ACTIVITIES
Activities *activities() const;
#endif
......@@ -700,6 +702,7 @@ private:
SessionManager *m_sessionManager;
std::unique_ptr<FocusChain> m_focusChain;
std::unique_ptr<ApplicationMenu> m_applicationMenu;
#if KWIN_BUILD_ACTIVITIES
std::unique_ptr<Activities> m_activities;
#endif
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment