mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-28 14:43:09 +00:00
Use KWayland protocol to close the active window
As a nice side-effect this allows us to enable/disable the close button depending on whether we have a window to close.
This commit is contained in:
parent
bf4959d63e
commit
8f7f23321f
4 changed files with 34 additions and 42 deletions
|
|
@ -1,2 +0,0 @@
|
|||
|
||||
workspace.activeClient.closeWindow();
|
||||
|
|
@ -73,7 +73,8 @@ PlasmaCore.ColorScope {
|
|||
width: parent.width/3
|
||||
anchors.right: parent.right
|
||||
iconSource: "window-close"
|
||||
onClicked: plasmoid.nativeInterface.executeScript("close");
|
||||
enabled: plasmoid.nativeInterface.hasCloseableActiveWindow;
|
||||
onClicked: plasmoid.nativeInterface.closeActiveWindow();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,10 +21,6 @@
|
|||
|
||||
#include <QtQml>
|
||||
#include <QDebug>
|
||||
#include <QDBusMessage>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusPendingCallWatcher>
|
||||
#include <QDBusPendingReply>
|
||||
|
||||
#include <Plasma/Package>
|
||||
|
||||
|
|
@ -47,35 +43,6 @@ TaskPanel::~TaskPanel()
|
|||
{
|
||||
}
|
||||
|
||||
void TaskPanel::executeScript(const QString &script)
|
||||
{
|
||||
//Plasma::Package p =
|
||||
QDBusMessage message = QDBusMessage::createMethodCall(s_kwinService, "/Scripting", QString(), "loadScript");
|
||||
QList<QVariant> arguments;
|
||||
arguments << QVariant(package().filePath("scripts", script + ".js"));
|
||||
message.setArguments(arguments);
|
||||
QDBusPendingReply<void> asyncCall = QDBusConnection::sessionBus().asyncCall(message);
|
||||
|
||||
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(asyncCall, this);
|
||||
QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
|
||||
this, SLOT(loadScriptFinishedSlot(QDBusPendingCallWatcher*)));
|
||||
}
|
||||
|
||||
void TaskPanel::loadScriptFinishedSlot(QDBusPendingCallWatcher *watcher)
|
||||
{
|
||||
QDBusMessage reply = watcher->reply();
|
||||
if (reply.type() == QDBusMessage::ErrorMessage) {
|
||||
qWarning() << reply.errorMessage();
|
||||
} else {
|
||||
const int id = reply.arguments().first().toInt();
|
||||
QDBusConnection::sessionBus().connect(s_kwinService, "/" + QString::number(id), QString(), "print", this, SLOT(print(QString)));
|
||||
QDBusConnection::sessionBus().connect(s_kwinService, "/" + QString::number(id), QString(), "printError", this, SLOT(print(QString)));
|
||||
QDBusMessage message = QDBusMessage::createMethodCall(s_kwinService, "/" + QString::number(id), QString(), "run");
|
||||
//fire blindly the call for now
|
||||
QDBusConnection::sessionBus().asyncCall(message);
|
||||
}
|
||||
}
|
||||
|
||||
void TaskPanel::requestShowingDesktop(bool showingDesktop)
|
||||
{
|
||||
if (!m_windowManagement) {
|
||||
|
|
@ -108,11 +75,35 @@ void TaskPanel::initWayland()
|
|||
emit showingDesktopChanged(m_showingDesktop);
|
||||
}
|
||||
);
|
||||
connect(m_windowManagement, &PlasmaWindowManagement::activeWindowChanged, this, &TaskPanel::updateActiveWindow);
|
||||
updateActiveWindow();
|
||||
}
|
||||
);
|
||||
registry->setup();
|
||||
}
|
||||
|
||||
void TaskPanel::updateActiveWindow()
|
||||
{
|
||||
if (!m_windowManagement) {
|
||||
return;
|
||||
}
|
||||
m_activeWindow = m_windowManagement->activeWindow();
|
||||
// TODO: connect to closeableChanged, not needed right now as KWin doesn't provide this changeable
|
||||
emit hasCloseableActiveWindowChanged();
|
||||
}
|
||||
|
||||
bool TaskPanel::hasCloseableActiveWindow() const
|
||||
{
|
||||
return m_activeWindow && m_activeWindow->isCloseable();
|
||||
}
|
||||
|
||||
void TaskPanel::closeActiveWindow()
|
||||
{
|
||||
if (m_activeWindow) {
|
||||
m_activeWindow->requestClose();
|
||||
}
|
||||
}
|
||||
|
||||
K_EXPORT_PLASMA_APPLET_WITH_JSON(taskpanel, TaskPanel, "metadata.json")
|
||||
|
||||
#include "taskpanel.moc"
|
||||
|
|
|
|||
|
|
@ -24,13 +24,12 @@
|
|||
|
||||
#include <Plasma/Containment>
|
||||
|
||||
class QDBusPendingCallWatcher;
|
||||
|
||||
namespace KWayland
|
||||
{
|
||||
namespace Client
|
||||
{
|
||||
class PlasmaWindowManagement;
|
||||
class PlasmaWindow;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -38,28 +37,31 @@ class TaskPanel : public Plasma::Containment
|
|||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool showDesktop READ isShowingDesktop WRITE requestShowingDesktop NOTIFY showingDesktopChanged)
|
||||
Q_PROPERTY(bool hasCloseableActiveWindow READ hasCloseableActiveWindow NOTIFY hasCloseableActiveWindowChanged)
|
||||
|
||||
public:
|
||||
TaskPanel( QObject *parent, const QVariantList &args );
|
||||
~TaskPanel();
|
||||
|
||||
Q_INVOKABLE void executeScript(const QString &script);
|
||||
Q_INVOKABLE void closeActiveWindow();
|
||||
|
||||
bool isShowingDesktop() const {
|
||||
return m_showingDesktop;
|
||||
}
|
||||
void requestShowingDesktop(bool showingDesktop);
|
||||
|
||||
bool hasCloseableActiveWindow() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void showingDesktopChanged(bool);
|
||||
|
||||
private Q_SLOTS:
|
||||
void loadScriptFinishedSlot(QDBusPendingCallWatcher *watcher);
|
||||
void hasCloseableActiveWindowChanged();
|
||||
|
||||
private:
|
||||
void initWayland();
|
||||
void updateActiveWindow();
|
||||
bool m_showingDesktop;
|
||||
KWayland::Client::PlasmaWindowManagement *m_windowManagement;
|
||||
KWayland::Client::PlasmaWindow *m_activeWindow = nullptr;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue