ed4a0d0319
This provides a new protocol intended to be used by auto-hiding panels to make use of the centralized screen edges. To use it a Client can set an X11 property of type _KDE_NET_WM_SCREEN_EDGE_SHOW to KWin. As value it takes: * 0: top edge * 1: right edge * 2: bottom edge * 3: left edge KWin will hide the Client (hide because unmap or minimize would break it) and create an Edge. If that Edge gets triggered the Client is shown again and the property gets deleted. If the Client doesn't border the specified screen edge the Client gets shown immediately so that we never end in a situation that we cannot unhide the auto-hidden panel again. The exact process is described in the documentation of ScreenEdges. The Client can request to be shown again by deleting the property. If KWin gets restarted the state is read from the property and it is tried to create the edge as described. As this is a KWin specific extension we need to discuss what it means for Clients using this feature with other WMs: it does nothing. As the Client gets hidden by KWin and not by the Client, it just doesn't get hidden if the WM doesn't provide the feature. In case of an auto-hiding panel this seems like a good solution given that we don't want to hide it if we cannot unhide it. Of course there's the option for the Client to provide that feature itself and if that's wanted we would need to announce the feature in the _NET_SUPPORTED atom. At the moment that doesn't sound like being needed as Plasma doesn't want to provide an own implementation. The implementation comes with a small test application showing how the feature is intended to be used. REVIEW: 115910
98 lines
4.4 KiB
C++
98 lines
4.4 KiB
C++
/*
|
|
* Copyright 2014 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) version 3 or any later version
|
|
* accepted by the membership of KDE e.V. (or its successor approved
|
|
* by the membership of KDE e.V.), which shall act as a proxy
|
|
* defined in Section 14 of version 3 of the license.
|
|
*
|
|
* 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 <QApplication>
|
|
#include <QHBoxLayout>
|
|
#include <QMenu>
|
|
#include <QPushButton>
|
|
#include <QScreen>
|
|
#include <QTimer>
|
|
#include <QToolButton>
|
|
#include <QWidget>
|
|
#include "../xcbutils.h"
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
QApplication app(argc, argv);
|
|
QApplication::setApplicationDisplayName(QStringLiteral("Screen Edge Show Test App"));
|
|
|
|
QScopedPointer<QWidget> widget(new QWidget(nullptr, Qt::FramelessWindowHint));
|
|
|
|
KWin::Xcb::Atom atom(QByteArrayLiteral("_KDE_NET_WM_SCREEN_EDGE_SHOW"));
|
|
|
|
uint32_t value = 2;
|
|
QPushButton *hideWindowButton = new QPushButton(QStringLiteral("Hide"), widget.data());
|
|
QObject::connect(hideWindowButton, &QPushButton::clicked, [&widget, &atom, &value]() {
|
|
xcb_change_property(QX11Info::connection(), XCB_PROP_MODE_REPLACE, widget->winId(), atom, XCB_ATOM_CARDINAL, 32, 1, &value);
|
|
});
|
|
QPushButton *hideAndRestoreButton = new QPushButton(QStringLiteral("Hide and Restore after 10 sec"), widget.data());
|
|
QTimer *restoreTimer = new QTimer(hideAndRestoreButton);
|
|
restoreTimer->setSingleShot(true);
|
|
QObject::connect(hideAndRestoreButton, &QPushButton::clicked, [&widget, &atom, &value, restoreTimer]() {
|
|
xcb_change_property(QX11Info::connection(), XCB_PROP_MODE_REPLACE, widget->winId(), atom, XCB_ATOM_CARDINAL, 32, 1, &value);
|
|
restoreTimer->start(10000);
|
|
});
|
|
QObject::connect(restoreTimer, &QTimer::timeout, [&widget, &atom]() {
|
|
xcb_delete_property(QX11Info::connection(), widget->winId(), atom);
|
|
});
|
|
|
|
QToolButton *edgeButton = new QToolButton(widget.data());
|
|
edgeButton->setText(QStringLiteral("Edge"));
|
|
edgeButton->setPopupMode(QToolButton::MenuButtonPopup);
|
|
QMenu *edgeButtonMenu = new QMenu(edgeButton);
|
|
QObject::connect(edgeButtonMenu->addAction("Top"), &QAction::triggered, [&widget, &value]() {
|
|
const QRect geo = QGuiApplication::primaryScreen()->geometry();
|
|
widget->setGeometry(geo.x(), geo.y(), geo.width(), 100);
|
|
value = 0;
|
|
});
|
|
QObject::connect(edgeButtonMenu->addAction("Right"), &QAction::triggered, [&widget, &value]() {
|
|
const QRect geo = QGuiApplication::primaryScreen()->geometry();
|
|
widget->setGeometry(geo.x() + geo.width() - 100, geo.y(), 100, geo.height());
|
|
value = 1;
|
|
});
|
|
QObject::connect(edgeButtonMenu->addAction("Bottom"), &QAction::triggered, [&widget, &value]() {
|
|
const QRect geo = QGuiApplication::primaryScreen()->geometry();
|
|
widget->setGeometry(geo.x(), geo.y() + geo.height() - 100, geo.width(), 100);
|
|
value = 2;
|
|
});
|
|
QObject::connect(edgeButtonMenu->addAction("Left"), &QAction::triggered, [&widget, &value]() {
|
|
const QRect geo = QGuiApplication::primaryScreen()->geometry();
|
|
widget->setGeometry(geo.x(), geo.y(), 100, geo.height());
|
|
value = 3;
|
|
});
|
|
edgeButtonMenu->addSeparator();
|
|
QObject::connect(edgeButtonMenu->addAction("Floating"), &QAction::triggered, [&widget, &value]() {
|
|
const QRect geo = QGuiApplication::primaryScreen()->geometry();
|
|
widget->setGeometry(QRect(geo.center(), QSize(100, 100)));
|
|
value = 4;
|
|
});
|
|
edgeButton->setMenu(edgeButtonMenu);
|
|
|
|
QHBoxLayout *layout = new QHBoxLayout(widget.data());
|
|
layout->addWidget(hideWindowButton);
|
|
layout->addWidget(hideAndRestoreButton);
|
|
layout->addWidget(edgeButton);
|
|
widget->setLayout(layout);
|
|
|
|
const QRect geo = QGuiApplication::primaryScreen()->geometry();
|
|
widget->setGeometry(geo.x(), geo.y() + geo.height() - 100, geo.width(), 100);
|
|
widget->show();
|
|
|
|
return app.exec();
|
|
}
|