mirror of https://github.com/cutefishos/statusbar
Add activity info to item on the left
parent
6738de37d1
commit
d764b5fccd
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (C) 2021 CutefishOS Team.
|
||||
*
|
||||
* Author: cutefishos <cutefishos@foxmail.com>
|
||||
*
|
||||
* 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 3 of the License, or
|
||||
* 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 "activity.h"
|
||||
|
||||
#include <QX11Info>
|
||||
#include <NETWM>
|
||||
#include <KWindowSystem>
|
||||
|
||||
Activity::Activity(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
onActiveWindowChanged();
|
||||
|
||||
connect(KWindowSystem::self(), &KWindowSystem::activeWindowChanged, this, &Activity::onActiveWindowChanged);
|
||||
connect(KWindowSystem::self(), static_cast<void (KWindowSystem::*)(WId)>(&KWindowSystem::windowChanged),
|
||||
this, &Activity::onActiveWindowChanged);
|
||||
}
|
||||
|
||||
QString Activity::title() const
|
||||
{
|
||||
return m_title;
|
||||
}
|
||||
|
||||
void Activity::close()
|
||||
{
|
||||
NETRootInfo(QX11Info::connection(), NET::CloseWindow).closeWindowRequest(KWindowSystem::activeWindow());
|
||||
}
|
||||
|
||||
void Activity::onActiveWindowChanged()
|
||||
{
|
||||
KWindowInfo info(KWindowSystem::activeWindow(), NET::WMState | NET::WMVisibleName);
|
||||
|
||||
QString title = info.visibleName();
|
||||
if (title != m_title) {
|
||||
m_title = title;
|
||||
emit titleChanged();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (C) 2021 CutefishOS Team.
|
||||
*
|
||||
* Author: cutefishos <cutefishos@foxmail.com>
|
||||
*
|
||||
* 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 3 of the License, or
|
||||
* 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 ACTIVITY_H
|
||||
#define ACTIVITY_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class Activity : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString title READ title NOTIFY titleChanged)
|
||||
|
||||
public:
|
||||
explicit Activity(QObject *parent = nullptr);
|
||||
|
||||
QString title() const;
|
||||
|
||||
Q_INVOKABLE void close();
|
||||
|
||||
private slots:
|
||||
void onActiveWindowChanged();
|
||||
|
||||
signals:
|
||||
void titleChanged();
|
||||
|
||||
private:
|
||||
QString m_title;
|
||||
};
|
||||
|
||||
#endif // ACTIVITY_H
|
||||
@ -1,25 +0,0 @@
|
||||
#include "statusnotifieritemjob.h"
|
||||
|
||||
StatusNotifierItemJob::StatusNotifierItemJob(StatusNotifierItemSource *source, QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_source(source)
|
||||
{
|
||||
// Queue connection, so that all 'deleteLater' are performed before we use updated menu.
|
||||
connect(source, SIGNAL(contextMenuReady(QMenu *)), this, SLOT(contextMenuReady(QMenu *)), Qt::QueuedConnection);
|
||||
connect(source, &StatusNotifierItemSource::activateResult, this, &StatusNotifierItemJob::activateCallback);
|
||||
}
|
||||
|
||||
void StatusNotifierItemJob::start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void StatusNotifierItemJob::activateCallback(bool success)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void StatusNotifierItemJob::contextMenuReady(QMenu *menu)
|
||||
{
|
||||
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
#ifndef STATUSNOTIFIERITEMJOB_H
|
||||
#define STATUSNOTIFIERITEMJOB_H
|
||||
|
||||
#include <QThread>
|
||||
#include <QMenu>
|
||||
|
||||
#include "statusnotifieritemsource.h"
|
||||
|
||||
class StatusNotifierItemJob : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit StatusNotifierItemJob(StatusNotifierItemSource *source, QObject *parent = nullptr);
|
||||
|
||||
protected:
|
||||
void start();
|
||||
|
||||
private Q_SLOTS:
|
||||
void activateCallback(bool success);
|
||||
void contextMenuReady(QMenu *menu);
|
||||
|
||||
private:
|
||||
StatusNotifierItemSource *m_source;
|
||||
};
|
||||
|
||||
#endif // STATUSNOTIFIERITEMJOB_H
|
||||
Loading…
Reference in New Issue