Commit 1cf22052 authored by Xaver Hugl's avatar Xaver Hugl
Browse files

move Activities singleton into Workspace

parent f2ad6bcc
......@@ -128,8 +128,8 @@ void ActivitiesTest::testSetOnActivitiesValidates()
QVERIFY(window->isDecorated());
// verify the test machine doesn't have the following activities used
QVERIFY(!Activities::self()->all().contains(QStringLiteral("foo")));
QVERIFY(!Activities::self()->all().contains(QStringLiteral("bar")));
QVERIFY(!Workspace::self()->activities()->all().contains(QStringLiteral("foo")));
QVERIFY(!Workspace::self()->activities()->all().contains(QStringLiteral("bar")));
window->setOnActivities(QStringList{QStringLiteral("foo"), QStringLiteral("bar")});
QVERIFY(!window->activities().contains(QLatin1String("foo")));
......
......@@ -297,7 +297,8 @@ void Workspace::activateWindow(Window *window, bool force)
if (!window->isOnCurrentActivity()) {
++block_focus;
// DBUS!
Activities::self()->setCurrent(window->activities().constFirst()); // first isn't necessarily best, but it's easiest
// first isn't necessarily best, but it's easiest
m_activities->setCurrent(window->activities().constFirst());
--block_focus;
}
#endif
......
......@@ -21,11 +21,8 @@
namespace KWin
{
KWIN_SINGLETON_FACTORY(Activities)
Activities::Activities(QObject *parent)
: QObject(parent)
, m_controller(new KActivities::Controller(this))
Activities::Activities()
: m_controller(new KActivities::Controller(this))
{
connect(m_controller, &KActivities::Controller::activityRemoved, this, &Activities::slotRemoved);
connect(m_controller, &KActivities::Controller::activityRemoved, this, &Activities::removed);
......@@ -33,11 +30,6 @@ Activities::Activities(QObject *parent)
connect(m_controller, &KActivities::Controller::currentActivityChanged, this, &Activities::slotCurrentChanged);
}
Activities::~Activities()
{
s_self = nullptr;
}
KActivities::Consumer::ServiceStatus Activities::serviceStatus() const
{
return m_controller->serviceStatus();
......
......@@ -30,7 +30,7 @@ class KWIN_EXPORT Activities : public QObject
Q_OBJECT
public:
~Activities() override;
explicit Activities();
bool stop(const QString &id);
bool start(const QString &id);
......@@ -79,8 +79,6 @@ private:
QString m_previous;
QString m_current;
KActivities::Controller *m_controller;
KWIN_SINGLETON(Activities)
};
inline QStringList Activities::all() const
......
......@@ -102,10 +102,10 @@ QString DBusInterface::activeOutputName()
bool DBusInterface::startActivity(const QString &in0)
{
#if KWIN_BUILD_ACTIVITIES
if (!Activities::self()) {
if (!Workspace::self()->activities()) {
return false;
}
return Activities::self()->start(in0);
return Workspace::self()->activities()->start(in0);
#else
Q_UNUSED(in0)
return false;
......@@ -115,10 +115,10 @@ bool DBusInterface::startActivity(const QString &in0)
bool DBusInterface::stopActivity(const QString &in0)
{
#if KWIN_BUILD_ACTIVITIES
if (!Activities::self()) {
if (!Workspace::self()->activities()) {
return false;
}
return Activities::self()->stop(in0);
return Workspace::self()->activities()->stop(in0);
#else
Q_UNUSED(in0)
return false;
......
......@@ -197,7 +197,7 @@ EffectsHandlerImpl::EffectsHandlerImpl(Compositor *compositor, Scene *scene)
connect(ws, &Workspace::geometryChanged, this, &EffectsHandler::virtualScreenSizeChanged);
connect(ws, &Workspace::geometryChanged, this, &EffectsHandler::virtualScreenGeometryChanged);
#if KWIN_BUILD_ACTIVITIES
if (Activities *activities = Activities::self()) {
if (Activities *activities = Workspace::self()->activities()) {
connect(activities, &Activities::added, this, &EffectsHandler::activityAdded);
connect(activities, &Activities::removed, this, &EffectsHandler::activityRemoved);
connect(activities, &Activities::currentChanged, this, &EffectsHandler::currentActivityChanged);
......@@ -979,10 +979,10 @@ void EffectsHandlerImpl::setShowingDesktop(bool showing)
QString EffectsHandlerImpl::currentActivity() const
{
#if KWIN_BUILD_ACTIVITIES
if (!Activities::self()) {
if (!Workspace::self()->activities()) {
return QString();
}
return Activities::self()->current();
return Workspace::self()->activities()->current();
#else
return QString();
#endif
......
......@@ -101,7 +101,7 @@ void DesktopBackgroundItem::updateWindow()
QString activity = m_activity;
if (activity.isEmpty()) {
#if KWIN_BUILD_ACTIVITIES
activity = Activities::self()->current();
activity = Workspace::self()->activities()->current();
#endif
}
......
......@@ -31,7 +31,7 @@ ClientLevel::ClientLevel(ClientModel *model, AbstractLevel *parent)
: AbstractLevel(model, parent)
{
#if KWIN_BUILD_ACTIVITIES
if (Activities *activities = Activities::self()) {
if (Activities *activities = Workspace::self()->activities()) {
connect(activities, &Activities::currentChanged, this, &ClientLevel::reInit);
}
#endif
......@@ -307,8 +307,8 @@ AbstractLevel *AbstractLevel::create(const QList<ClientModel::LevelRestriction>
switch (restriction) {
case ClientModel::ActivityRestriction: {
#if KWIN_BUILD_ACTIVITIES
if (Activities::self()) {
const QStringList &activities = Activities::self()->all();
if (Workspace::self()->activities()) {
const QStringList &activities = Workspace::self()->activities()->all();
for (QStringList::const_iterator it = activities.begin(); it != activities.end(); ++it) {
AbstractLevel *childLevel = create(childRestrictions, childrenRestrictions, model, currentLevel);
if (!childLevel) {
......@@ -400,7 +400,7 @@ ForkLevel::ForkLevel(const QList<ClientModel::LevelRestriction> &childRestrictio
connect(VirtualDesktopManager::self(), &VirtualDesktopManager::countChanged, this, &ForkLevel::desktopCountChanged);
connect(screens(), &Screens::countChanged, this, &ForkLevel::screenCountChanged);
#if KWIN_BUILD_ACTIVITIES
if (Activities *activities = Activities::self()) {
if (Activities *activities = Workspace::self()->activities()) {
connect(activities, &Activities::added, this, &ForkLevel::activityAdded);
connect(activities, &Activities::removed, this, &ForkLevel::activityRemoved);
}
......
......@@ -41,7 +41,7 @@ WorkspaceWrapper::WorkspaceWrapper(QObject *parent)
connect(vds, &VirtualDesktopManager::currentChanged, this, &WorkspaceWrapper::currentVirtualDesktopChanged);
connect(ws, &Workspace::windowDemandsAttentionChanged, this, &WorkspaceWrapper::clientDemandsAttentionChanged);
#if KWIN_BUILD_ACTIVITIES
if (KWin::Activities *activities = KWin::Activities::self()) {
if (KWin::Activities *activities = ws->activities()) {
connect(activities, &Activities::currentChanged, this, &WorkspaceWrapper::currentActivityChanged);
connect(activities, &Activities::added, this, &WorkspaceWrapper::activitiesChanged);
connect(activities, &Activities::added, this, &WorkspaceWrapper::activityAdded);
......@@ -104,10 +104,10 @@ Window *WorkspaceWrapper::activeClient() const
QString WorkspaceWrapper::currentActivity() const
{
#if KWIN_BUILD_ACTIVITIES
if (!Activities::self()) {
if (!Workspace::self()->activities()) {
return QString();
}
return Activities::self()->current();
return Workspace::self()->activities()->current();
#else
return QString();
#endif
......@@ -116,8 +116,8 @@ QString WorkspaceWrapper::currentActivity() const
void WorkspaceWrapper::setCurrentActivity(QString activity)
{
#if KWIN_BUILD_ACTIVITIES
if (Activities::self()) {
Activities::self()->setCurrent(activity);
if (Workspace::self()->activities()) {
Workspace::self()->activities()->setCurrent(activity);
}
#else
Q_UNUSED(activity)
......@@ -127,10 +127,10 @@ void WorkspaceWrapper::setCurrentActivity(QString activity)
QStringList WorkspaceWrapper::activityList() const
{
#if KWIN_BUILD_ACTIVITIES
if (!Activities::self()) {
if (!Workspace::self()->activities()) {
return QStringList();
}
return Activities::self()->all();
return Workspace::self()->activities()->all();
#else
return QStringList();
#endif
......
......@@ -70,8 +70,8 @@ TabBoxHandlerImpl::TabBoxHandlerImpl(TabBox *tabBox)
connect(vds, &VirtualDesktopManager::countChanged, m_desktopFocusChain, &DesktopChainManager::resize);
connect(vds, &VirtualDesktopManager::currentChanged, m_desktopFocusChain, &DesktopChainManager::addDesktop);
#if KWIN_BUILD_ACTIVITIES
if (Activities::self()) {
connect(Activities::self(), &Activities::currentChanged, m_desktopFocusChain, &DesktopChainManager::useChain);
if (Workspace::self()->activities()) {
connect(Workspace::self()->activities(), &Activities::currentChanged, m_desktopFocusChain, &DesktopChainManager::useChain);
}
#endif
}
......
......@@ -418,10 +418,10 @@ void UserActionsMenu::menuAboutToShow()
void UserActionsMenu::showHideActivityMenu()
{
#if KWIN_BUILD_ACTIVITIES
if (!Activities::self()) {
if (!Workspace::self()->activities()) {
return;
}
const QStringList &openActivities_ = Activities::self()->running();
const QStringList &openActivities_ = Workspace::self()->activities()->running();
qCDebug(KWIN_CORE) << "activities:" << openActivities_.size();
if (openActivities_.size() < 2) {
delete m_activityMenu;
......@@ -696,7 +696,7 @@ void UserActionsMenu::activityPopupAboutToShow()
}
#if KWIN_BUILD_ACTIVITIES
if (!Activities::self()) {
if (!Workspace::self()->activities()) {
return;
}
m_activityMenu->clear();
......@@ -717,7 +717,7 @@ void UserActionsMenu::activityPopupAboutToShow()
}
m_activityMenu->addSeparator();
const auto activities = Activities::self()->running();
const auto activities = Workspace::self()->activities()->running();
for (const QString &id : activities) {
KActivities::Info activity(id);
QString name = activity.name();
......@@ -776,7 +776,7 @@ void UserActionsMenu::slotWindowOperation(QAction *action)
void UserActionsMenu::slotToggleOnActivity(QAction *action)
{
#if KWIN_BUILD_ACTIVITIES
if (!Activities::self()) {
if (!Workspace::self()->activities()) {
return;
}
QString activity = action->data().toString();
......@@ -789,7 +789,7 @@ void UserActionsMenu::slotToggleOnActivity(QAction *action)
return;
}
Activities::self()->toggleWindowOnActivity(m_window, activity, false);
Workspace::self()->activities()->toggleWindowOnActivity(m_window, activity, false);
if (m_activityMenu && m_activityMenu->isVisible() && m_activityMenu->actions().count()) {
const bool isOnAll = m_window->isOnAllActivities();
m_activityMenu->actions().at(0)->setChecked(isOnAll);
......
......@@ -546,10 +546,10 @@ bool Window::isDeleted() const
bool Window::isOnCurrentActivity() const
{
#if KWIN_BUILD_ACTIVITIES
if (!Activities::self()) {
if (!Workspace::self()->activities()) {
return true;
}
return isOnActivity(Activities::self()->current());
return isOnActivity(Workspace::self()->activities()->current());
#else
return true;
#endif
......@@ -3464,7 +3464,7 @@ QStringList Window::activities() const
void Window::setOnActivity(const QString &activity, bool enable)
{
#if KWIN_BUILD_ACTIVITIES
if (!Activities::self()) {
if (!Workspace::self()->activities()) {
return;
}
QStringList newActivitiesList = activities();
......@@ -3473,7 +3473,7 @@ void Window::setOnActivity(const QString &activity, bool enable)
return;
}
if (enable) {
QStringList allActivities = Activities::self()->all();
QStringList allActivities = Workspace::self()->activities()->all();
if (!allActivities.contains(activity)) {
// bogus ID
return;
......@@ -3495,10 +3495,10 @@ void Window::setOnActivity(const QString &activity, bool enable)
void Window::setOnActivities(const QStringList &newActivitiesList)
{
#if KWIN_BUILD_ACTIVITIES
if (!Activities::self()) {
if (!Workspace::self()->activities()) {
return;
}
const auto allActivities = Activities::self()->all();
const auto allActivities = Workspace::self()->activities()->all();
const auto activityList = [&] {
auto result = rules()->checkActivity(newActivitiesList);
......@@ -3543,7 +3543,7 @@ void Window::setOnAllActivities(bool all)
if (all) {
setOnActivities(QStringList());
} else {
setOnActivity(Activities::self()->current(), true);
setOnActivity(Workspace::self()->activities()->current(), true);
}
#else
Q_UNUSED(all)
......
......@@ -135,12 +135,11 @@ Workspace::Workspace()
_self = this;
#if KWIN_BUILD_ACTIVITIES
Activities *activities = nullptr;
if (kwinApp()->usesKActivities()) {
activities = Activities::create(this);
m_activities = std::make_unique<Activities>();
}
if (activities) {
connect(activities, &Activities::currentChanged, this, &Workspace::updateCurrentActivity);
if (m_activities) {
connect(m_activities.get(), &Activities::currentChanged, this, &Workspace::updateCurrentActivity);
}
#endif
......@@ -1102,7 +1101,7 @@ Window *Workspace::findWindowToActivateOnDesktop(VirtualDesktop *desktop)
void Workspace::updateCurrentActivity(const QString &new_activity)
{
#if KWIN_BUILD_ACTIVITIES
if (!Activities::self()) {
if (!m_activities) {
return;
}
// closeActivePopup();
......@@ -2828,4 +2827,11 @@ FocusChain *Workspace::focusChain() const
return m_focusChain.get();
}
#if KWIN_BUILD_ACTIVITIES
Activities *Workspace::activities() const
{
return m_activities.get();
}
#endif
} // namespace
......@@ -56,6 +56,9 @@ class X11Window;
class X11EventFilter;
class FocusChain;
enum class Predicate;
#if KWIN_BUILD_ACTIVITIES
class Activities;
#endif
class KWIN_EXPORT Workspace : public QObject
{
......@@ -425,6 +428,9 @@ public:
return m_lastActiveWindow;
}
FocusChain *focusChain() const;
#if KWIN_BUILD_ACTIVITIES
Activities *activities() const;
#endif
public Q_SLOTS:
void performWindowOperation(KWin::Window *window, Options::WindowOperation op);
......@@ -694,6 +700,9 @@ private:
SessionManager *m_sessionManager;
std::unique_ptr<FocusChain> m_focusChain;
#if KWIN_BUILD_ACTIVITIES
std::unique_ptr<Activities> m_activities;
#endif
private:
friend bool performTransiencyCheck();
......
......@@ -571,7 +571,7 @@ bool X11Window::manage(xcb_window_t w, bool isMapped)
}
}
#if KWIN_BUILD_ACTIVITIES
if (Activities::self() && !isMapped && !skipTaskbar() && isNormalWindow() && !activitiesDefined) {
if (Workspace::self()->activities() && !isMapped && !skipTaskbar() && isNormalWindow() && !activitiesDefined) {
// a new, regular window, when we're not recovering from a crash,
// and it hasn't got an activity. let's try giving it the current one.
// TODO: decide whether to keep this before the 4.6 release
......@@ -579,7 +579,7 @@ bool X11Window::manage(xcb_window_t w, bool isMapped)
// with a public API for setting windows to be on all activities.
// something like KWindowSystem::setOnAllActivities or
// KActivityConsumer::setOnAllActivities
setOnActivity(Activities::self()->current(), true);
setOnActivity(Workspace::self()->activities()->current(), true);
}
#endif
}
......@@ -2504,8 +2504,8 @@ void X11Window::readActivities(Xcb::StringProperty &property)
// if the activities are not synced, and there are existing clients with
// activities specified, somebody has restarted kwin. we can not validate
// activities in this case. we need to trust the old values.
if (Activities::self() && Activities::self()->serviceStatus() != KActivities::Consumer::Unknown) {
QStringList allActivities = Activities::self()->all();
if (Workspace::self()->activities() && Workspace::self()->activities()->serviceStatus() != KActivities::Consumer::Unknown) {
QStringList allActivities = Workspace::self()->activities()->all();
if (allActivities.isEmpty()) {
qCDebug(KWIN_CORE) << "no activities!?!?";
// don't touch anything, there's probably something bad going on and we don't wanna make it worse
......
......@@ -562,7 +562,7 @@ XdgToplevelWindow::XdgToplevelWindow(XdgToplevelInterface *shellSurface)
{
setDesktops({VirtualDesktopManager::self()->currentDesktop()});
#if KWIN_BUILD_ACTIVITIES
if (auto a = Activities::self()) {
if (auto a = Workspace::self()->activities()) {
setOnActivities({a->current()});
}
#endif
......@@ -1771,7 +1771,7 @@ XdgPopupWindow::XdgPopupWindow(XdgPopupInterface *shellSurface)
m_windowType = NET::Unknown;
setDesktops({VirtualDesktopManager::self()->currentDesktop()});
#if KWIN_BUILD_ACTIVITIES
if (auto a = Activities::self()) {
if (auto a = Workspace::self()->activities()) {
setOnActivities({a->current()});
}
#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