[scripting] ScriptingClientModel operates on AbstractClient
This commit is contained in:
parent
86e0fc4dde
commit
c4c637db92
2 changed files with 40 additions and 43 deletions
|
@ -37,7 +37,7 @@ static quint32 nextId() {
|
||||||
ClientLevel::ClientLevel(ClientModel *model, AbstractLevel *parent)
|
ClientLevel::ClientLevel(ClientModel *model, AbstractLevel *parent)
|
||||||
: AbstractLevel(model, parent)
|
: AbstractLevel(model, parent)
|
||||||
{
|
{
|
||||||
connect(Workspace::self(), SIGNAL(clientAdded(KWin::Client*)), SLOT(clientAdded(KWin::Client*)));
|
connect(Workspace::self(), &Workspace::clientAdded, this, &ClientLevel::clientAdded);
|
||||||
connect(Workspace::self(), &Workspace::clientRemoved, this, &ClientLevel::clientRemoved);
|
connect(Workspace::self(), &Workspace::clientRemoved, this, &ClientLevel::clientRemoved);
|
||||||
connect(model, SIGNAL(exclusionsChanged()), SLOT(reInit()));
|
connect(model, SIGNAL(exclusionsChanged()), SLOT(reInit()));
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ ClientLevel::~ClientLevel()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientLevel::clientAdded(Client *client)
|
void ClientLevel::clientAdded(AbstractClient *client)
|
||||||
{
|
{
|
||||||
setupClientConnections(client);
|
setupClientConnections(client);
|
||||||
checkClient(client);
|
checkClient(client);
|
||||||
|
@ -54,24 +54,20 @@ void ClientLevel::clientAdded(Client *client)
|
||||||
|
|
||||||
void ClientLevel::clientRemoved(AbstractClient *client)
|
void ClientLevel::clientRemoved(AbstractClient *client)
|
||||||
{
|
{
|
||||||
if (Client *c = qobject_cast<Client*>(client)) {
|
removeClient(client);
|
||||||
removeClient(c);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientLevel::setupClientConnections(Client *client)
|
void ClientLevel::setupClientConnections(AbstractClient *client)
|
||||||
{
|
{
|
||||||
connect(client, SIGNAL(desktopChanged()), SLOT(checkClient()));
|
auto check = [this, client] {
|
||||||
connect(client, SIGNAL(screenChanged()), SLOT(checkClient()));
|
checkClient(client);
|
||||||
connect(client, SIGNAL(activitiesChanged(KWin::Toplevel*)), SLOT(checkClient()));
|
};
|
||||||
|
connect(client, &AbstractClient::desktopChanged, this, check);
|
||||||
|
connect(client, &AbstractClient::screenChanged, this, check);
|
||||||
|
connect(client, &AbstractClient::activitiesChanged, this, check);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientLevel::checkClient()
|
void ClientLevel::checkClient(AbstractClient *client)
|
||||||
{
|
|
||||||
checkClient(static_cast<Client*>(sender()));
|
|
||||||
}
|
|
||||||
|
|
||||||
void ClientLevel::checkClient(Client *client)
|
|
||||||
{
|
{
|
||||||
const bool shouldInclude = !exclude(client) && shouldAdd(client);
|
const bool shouldInclude = !exclude(client) && shouldAdd(client);
|
||||||
const bool contains = containsClient(client);
|
const bool contains = containsClient(client);
|
||||||
|
@ -83,7 +79,7 @@ void ClientLevel::checkClient(Client *client)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ClientLevel::exclude(Client *client) const
|
bool ClientLevel::exclude(AbstractClient *client) const
|
||||||
{
|
{
|
||||||
ClientModel::Exclusions exclusions = model()->exclusions();
|
ClientModel::Exclusions exclusions = model()->exclusions();
|
||||||
if (exclusions == ClientModel::NoExclusion) {
|
if (exclusions == ClientModel::NoExclusion) {
|
||||||
|
@ -109,6 +105,7 @@ bool ClientLevel::exclude(Client *client) const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#if 0
|
||||||
if (exclusions & ClientModel::SkipTaskbarExclusion) {
|
if (exclusions & ClientModel::SkipTaskbarExclusion) {
|
||||||
if (client->skipTaskbar()) {
|
if (client->skipTaskbar()) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -119,6 +116,7 @@ bool ClientLevel::exclude(Client *client) const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
if (exclusions & ClientModel::SwitchSwitcherExclusion) {
|
if (exclusions & ClientModel::SwitchSwitcherExclusion) {
|
||||||
if (client->skipSwitcher()) {
|
if (client->skipSwitcher()) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -152,7 +150,7 @@ bool ClientLevel::exclude(Client *client) const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ClientLevel::shouldAdd(Client *client) const
|
bool ClientLevel::shouldAdd(AbstractClient *client) const
|
||||||
{
|
{
|
||||||
if (restrictions() == ClientModel::NoRestriction) {
|
if (restrictions() == ClientModel::NoRestriction) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -175,7 +173,7 @@ bool ClientLevel::shouldAdd(Client *client) const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientLevel::addClient(Client *client)
|
void ClientLevel::addClient(AbstractClient *client)
|
||||||
{
|
{
|
||||||
if (containsClient(client)) {
|
if (containsClient(client)) {
|
||||||
return;
|
return;
|
||||||
|
@ -185,10 +183,10 @@ void ClientLevel::addClient(Client *client)
|
||||||
emit endInsert();
|
emit endInsert();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientLevel::removeClient(Client *client)
|
void ClientLevel::removeClient(AbstractClient *client)
|
||||||
{
|
{
|
||||||
int index = 0;
|
int index = 0;
|
||||||
QMap<quint32, Client*>::iterator it = m_clients.begin();
|
auto it = m_clients.begin();
|
||||||
for (; it != m_clients.end(); ++it, ++index) {
|
for (; it != m_clients.end(); ++it, ++index) {
|
||||||
if (it.value() == client) {
|
if (it.value() == client) {
|
||||||
break;
|
break;
|
||||||
|
@ -227,7 +225,7 @@ quint32 ClientLevel::idForRow(int row) const
|
||||||
if (row >= m_clients.size()) {
|
if (row >= m_clients.size()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
QMap<quint32, Client*>::const_iterator it = m_clients.constBegin();
|
auto it = m_clients.constBegin();
|
||||||
for (int i=0; i<row; ++i) {
|
for (int i=0; i<row; ++i) {
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
@ -242,7 +240,7 @@ bool ClientLevel::containsId(quint32 id) const
|
||||||
int ClientLevel::rowForId(quint32 id) const
|
int ClientLevel::rowForId(quint32 id) const
|
||||||
{
|
{
|
||||||
int row = 0;
|
int row = 0;
|
||||||
for (QMap<quint32, Client*>::const_iterator it = m_clients.constBegin();
|
for (auto it = m_clients.constBegin();
|
||||||
it != m_clients.constEnd();
|
it != m_clients.constEnd();
|
||||||
++it, ++row) {
|
++it, ++row) {
|
||||||
if (it.key() == id) {
|
if (it.key() == id) {
|
||||||
|
@ -252,18 +250,18 @@ int ClientLevel::rowForId(quint32 id) const
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Client *ClientLevel::clientForId(quint32 child) const
|
AbstractClient *ClientLevel::clientForId(quint32 child) const
|
||||||
{
|
{
|
||||||
QMap<quint32, Client*>::const_iterator it = m_clients.constFind(child);
|
auto it = m_clients.constFind(child);
|
||||||
if (it == m_clients.constEnd()) {
|
if (it == m_clients.constEnd()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return it.value();
|
return it.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ClientLevel::containsClient(Client *client) const
|
bool ClientLevel::containsClient(AbstractClient *client) const
|
||||||
{
|
{
|
||||||
for (QMap<quint32, Client*>::const_iterator it = m_clients.constBegin();
|
for (auto it = m_clients.constBegin();
|
||||||
it != m_clients.constEnd();
|
it != m_clients.constEnd();
|
||||||
++it) {
|
++it) {
|
||||||
if (it.value() == client) {
|
if (it.value() == client) {
|
||||||
|
@ -627,10 +625,10 @@ int ForkLevel::rowForId(quint32 child) const
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Client *ForkLevel::clientForId(quint32 child) const
|
AbstractClient *ForkLevel::clientForId(quint32 child) const
|
||||||
{
|
{
|
||||||
for (QList<AbstractLevel*>::const_iterator it = m_children.constBegin(); it != m_children.constEnd(); ++it) {
|
for (QList<AbstractLevel*>::const_iterator it = m_children.constBegin(); it != m_children.constEnd(); ++it) {
|
||||||
if (Client *client = (*it)->clientForId(child)) {
|
if (AbstractClient *client = (*it)->clientForId(child)) {
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -698,7 +696,7 @@ QVariant ClientModel::data(const QModelIndex &index, int role) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (role == Qt::DisplayRole || role == ClientRole) {
|
if (role == Qt::DisplayRole || role == ClientRole) {
|
||||||
if (Client *client = m_root->clientForId(index.internalId())) {
|
if (AbstractClient *client = m_root->clientForId(index.internalId())) {
|
||||||
return qVariantFromValue(client);
|
return qVariantFromValue(client);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,7 +147,7 @@ public:
|
||||||
virtual const AbstractLevel *levelForId(quint32 id) const = 0;
|
virtual const AbstractLevel *levelForId(quint32 id) const = 0;
|
||||||
virtual AbstractLevel *parentForId(quint32 child) const = 0;
|
virtual AbstractLevel *parentForId(quint32 child) const = 0;
|
||||||
virtual int rowForId(quint32 child) const = 0;
|
virtual int rowForId(quint32 child) const = 0;
|
||||||
virtual Client *clientForId(quint32 child) const = 0;
|
virtual AbstractClient *clientForId(quint32 child) const = 0;
|
||||||
|
|
||||||
virtual void setScreen(uint screen);
|
virtual void setScreen(uint screen);
|
||||||
virtual void setVirtualDesktop(uint virtualDesktop);
|
virtual void setVirtualDesktop(uint virtualDesktop);
|
||||||
|
@ -190,7 +190,7 @@ public:
|
||||||
virtual const AbstractLevel *levelForId(quint32 id) const;
|
virtual const AbstractLevel *levelForId(quint32 id) const;
|
||||||
virtual AbstractLevel *parentForId(quint32 child) const;
|
virtual AbstractLevel *parentForId(quint32 child) const;
|
||||||
virtual int rowForId(quint32 child) const;
|
virtual int rowForId(quint32 child) const;
|
||||||
virtual Client *clientForId(quint32 child) const;
|
virtual AbstractClient *clientForId(quint32 child) const override;
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void desktopCountChanged(uint previousCount, uint newCount);
|
void desktopCountChanged(uint previousCount, uint newCount);
|
||||||
void screenCountChanged(int previousCount, int newCount);
|
void screenCountChanged(int previousCount, int newCount);
|
||||||
|
@ -224,25 +224,24 @@ public:
|
||||||
quint32 idForRow(int row) const;
|
quint32 idForRow(int row) const;
|
||||||
bool containsId(quint32 id) const;
|
bool containsId(quint32 id) const;
|
||||||
int rowForId(quint32 row) const;
|
int rowForId(quint32 row) const;
|
||||||
Client *clientForId(quint32 child) const;
|
AbstractClient *clientForId(quint32 child) const;
|
||||||
virtual const AbstractLevel *levelForId(quint32 id) const;
|
virtual const AbstractLevel *levelForId(quint32 id) const;
|
||||||
virtual AbstractLevel *parentForId(quint32 child) const;
|
virtual AbstractLevel *parentForId(quint32 child) const override;
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void clientAdded(KWin::Client *client);
|
void clientAdded(KWin::AbstractClient *client);
|
||||||
void clientRemoved(KWin::AbstractClient *client);
|
void clientRemoved(KWin::AbstractClient *client);
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
// uses sender()
|
// uses sender()
|
||||||
void checkClient();
|
|
||||||
void reInit();
|
void reInit();
|
||||||
private:
|
private:
|
||||||
void checkClient(KWin::Client *client);
|
void checkClient(KWin::AbstractClient *client);
|
||||||
void setupClientConnections(Client *client);
|
void setupClientConnections(AbstractClient *client);
|
||||||
void addClient(Client *client);
|
void addClient(AbstractClient *client);
|
||||||
void removeClient(Client *client);
|
void removeClient(AbstractClient *client);
|
||||||
bool shouldAdd(Client *client) const;
|
bool shouldAdd(AbstractClient *client) const;
|
||||||
bool exclude(Client *client) const;
|
bool exclude(AbstractClient *client) const;
|
||||||
bool containsClient(Client *client) const;
|
bool containsClient(AbstractClient *client) const;
|
||||||
QMap<quint32, Client*> m_clients;
|
QMap<quint32, AbstractClient*> m_clients;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SimpleClientModel : public ClientModel
|
class SimpleClientModel : public ClientModel
|
||||||
|
|
Loading…
Reference in a new issue