2017-03-25 17:41:28 +00:00
|
|
|
/*
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2017 Martin Graesslin <mgraesslin@kde.org>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
|
|
|
|
|
|
|
*/
|
2017-03-25 17:41:28 +00:00
|
|
|
#include "popup_input_filter.h"
|
2020-03-04 07:55:26 +00:00
|
|
|
#include "abstract_client.h"
|
2017-03-25 17:41:28 +00:00
|
|
|
#include "deleted.h"
|
2020-07-22 18:35:41 +00:00
|
|
|
#include "workspace.h"
|
2017-03-25 17:41:28 +00:00
|
|
|
|
|
|
|
#include <QMouseEvent>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
PopupInputFilter::PopupInputFilter()
|
|
|
|
: QObject()
|
|
|
|
{
|
2020-07-22 18:35:41 +00:00
|
|
|
connect(workspace(), &Workspace::clientAdded, this, &PopupInputFilter::handleClientAdded);
|
2017-03-25 17:41:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PopupInputFilter::handleClientAdded(Toplevel *client)
|
|
|
|
{
|
|
|
|
if (m_popupClients.contains(client)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (client->hasPopupGrab()) {
|
|
|
|
// TODO: verify that the Toplevel is allowed as a popup
|
|
|
|
connect(client, &Toplevel::windowShown, this, &PopupInputFilter::handleClientAdded, Qt::UniqueConnection);
|
|
|
|
connect(client, &Toplevel::windowClosed, this, &PopupInputFilter::handleClientRemoved, Qt::UniqueConnection);
|
|
|
|
m_popupClients << client;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupInputFilter::handleClientRemoved(Toplevel *client)
|
|
|
|
{
|
|
|
|
m_popupClients.removeOne(client);
|
|
|
|
}
|
|
|
|
bool PopupInputFilter::pointerEvent(QMouseEvent *event, quint32 nativeButton)
|
|
|
|
{
|
|
|
|
Q_UNUSED(nativeButton)
|
|
|
|
if (m_popupClients.isEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (event->type() == QMouseEvent::MouseButtonPress) {
|
|
|
|
auto pointerFocus = qobject_cast<AbstractClient*>(input()->findToplevel(event->globalPos()));
|
|
|
|
if (!pointerFocus || !AbstractClient::belongToSameApplication(pointerFocus, qobject_cast<AbstractClient*>(m_popupClients.constLast()))) {
|
|
|
|
// a press on a window (or no window) not belonging to the popup window
|
|
|
|
cancelPopups();
|
|
|
|
// filter out this press
|
|
|
|
return true;
|
|
|
|
}
|
2017-04-10 16:19:45 +00:00
|
|
|
if (pointerFocus && pointerFocus->isDecorated()) {
|
|
|
|
// test whether it is on the decoration
|
|
|
|
const QRect clientRect = QRect(pointerFocus->clientPos(), pointerFocus->clientSize()).translated(pointerFocus->pos());
|
|
|
|
if (!clientRect.contains(event->globalPos())) {
|
|
|
|
cancelPopups();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2017-03-25 17:41:28 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupInputFilter::cancelPopups()
|
|
|
|
{
|
|
|
|
while (!m_popupClients.isEmpty()) {
|
|
|
|
auto c = m_popupClients.takeLast();
|
|
|
|
c->popupDone();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|