kwin/activities.h
Martin Gräßlin da85b5fdc7 Split out Activities related code from Workspace
All activities related code moves into new singleton class Activities.
This class gets only included into the build if the build option is
enabled which means there are less ifdefs all over the code and it also
handles better the moc doesn't like ifdef case.

The class holds the list of open and all activites, the current and the
previous activity and the KActivities::Controller. It also emits the
signals for any activities related changes.

Workspace still contains some activities related code. That is the
adjustment on change of current activity. Nevertheless the code looks
much cleaner now and does not contain the confusing naming conflict with
takeActivity() which existed before.

In all the places where Activities got used the code got adjusted and
quite often the ifdef got added with a fallback for the disabled case.
2013-04-11 13:01:36 +02:00

129 lines
3.1 KiB
C++

/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
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_ACTIVITIES_H
#define KWIN_ACTIVITIES_H
#include <QObject>
#include <QStringList>
namespace KActivities {
class Controller;
}
namespace KWin
{
class Client;
class Activities : public QObject
{
Q_OBJECT
public:
~Activities();
bool stop(const QString &id);
bool start(const QString &id);
void update(bool running, bool updateCurrent, QObject *target = NULL, QString slot = QString());
void setCurrent(const QString &activity);
/**
* Adds/removes client \a c to/from \a activity.
*
* Takes care of transients as well.
*/
void toggleClientOnActivity(Client* c, const QString &activity, bool dont_activate);
const QStringList &running() const;
const QStringList &all() const;
const QString &current() const;
const QString &previous() const;
static Activities *self();
static Activities *create(QObject *parent);
Q_SIGNALS:
/**
* This signal is emitted when the global
* activity is changed
* @param id id of the new current activity
*/
void currentChanged(const QString &id);
/**
* This signal is emitted when a new activity is added
* @param id id of the new activity
*/
void added(const QString &id);
/**
* This signal is emitted when the activity
* is removed
* @param id id of the removed activity
*/
void removed(const QString &id);
private Q_SLOTS:
void slotRemoved(const QString &activity);
void slotAdded(const QString &activity);
void slotCurrentChanged(const QString &newActivity);
void reallyStop(const QString &id); //dbus deadlocks suck
void handleReply();
private:
explicit Activities(QObject *parent);
QStringList m_running;
QStringList m_all;
QString m_current;
QString m_previous;
KActivities::Controller *m_controller;
static Activities *s_self;
};
inline
Activities *Activities::self()
{
return s_self;
}
inline
const QStringList &Activities::all() const
{
return m_all;
}
inline
const QString &Activities::current() const
{
return m_current;
}
inline
const QString &Activities::previous() const
{
return m_previous;
}
inline
const QStringList &Activities::running() const
{
return m_running;
}
}
#endif // KWIN_ACTIVITIES_H