2015-03-04 11:21:10 +03:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2015 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) 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 "shell_client.h"
|
2015-05-27 11:16:46 +03:00
|
|
|
#include "composite.h"
|
2015-10-29 12:41:25 +03:00
|
|
|
#include "cursor.h"
|
2015-03-04 11:21:10 +03:00
|
|
|
#include "deleted.h"
|
2016-08-30 14:16:52 +03:00
|
|
|
#include "placement.h"
|
2016-09-15 22:03:40 +03:00
|
|
|
#include "screenedge.h"
|
2015-05-27 11:16:46 +03:00
|
|
|
#include "screens.h"
|
2015-03-04 11:21:10 +03:00
|
|
|
#include "wayland_server.h"
|
2015-05-27 11:16:46 +03:00
|
|
|
#include "workspace.h"
|
2015-03-16 11:14:04 +03:00
|
|
|
#include "virtualdesktops.h"
|
2015-05-19 13:03:53 +03:00
|
|
|
#include "workspace.h"
|
2015-12-17 17:47:36 +03:00
|
|
|
#include "decorations/decorationbridge.h"
|
|
|
|
#include "decorations/decoratedclient.h"
|
|
|
|
#include <KDecoration2/Decoration>
|
|
|
|
#include <KDecoration2/DecoratedClient>
|
2015-03-04 11:21:10 +03:00
|
|
|
|
2015-05-18 15:51:40 +03:00
|
|
|
#include <KWayland/Client/surface.h>
|
2016-11-15 18:48:20 +03:00
|
|
|
#include <KWayland/Server/clientconnection.h>
|
2015-10-29 12:41:25 +03:00
|
|
|
#include <KWayland/Server/seat_interface.h>
|
2015-03-04 11:21:10 +03:00
|
|
|
#include <KWayland/Server/shell_interface.h>
|
|
|
|
#include <KWayland/Server/surface_interface.h>
|
|
|
|
#include <KWayland/Server/buffer_interface.h>
|
2015-06-09 20:10:56 +03:00
|
|
|
#include <KWayland/Server/plasmashell_interface.h>
|
2015-07-15 12:24:19 +03:00
|
|
|
#include <KWayland/Server/shadow_interface.h>
|
2015-12-17 13:14:54 +03:00
|
|
|
#include <KWayland/Server/server_decoration_interface.h>
|
2015-06-10 01:59:53 +03:00
|
|
|
#include <KWayland/Server/qtsurfaceextension_interface.h>
|
2015-11-05 13:30:02 +03:00
|
|
|
#include <KWayland/Server/plasmawindowmanagement_interface.h>
|
2015-06-20 02:11:42 +03:00
|
|
|
#include <KDesktopFile>
|
|
|
|
|
2015-08-18 15:40:26 +03:00
|
|
|
#include <QOpenGLFramebufferObject>
|
2015-05-18 15:51:40 +03:00
|
|
|
#include <QWindow>
|
|
|
|
|
2016-11-15 18:48:20 +03:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <signal.h>
|
|
|
|
|
2015-03-04 11:21:10 +03:00
|
|
|
using namespace KWayland::Server;
|
|
|
|
|
2016-10-13 10:35:32 +03:00
|
|
|
static const QByteArray s_schemePropertyName = QByteArrayLiteral("KDE_COLOR_SCHEME_PATH");
|
2017-01-11 12:21:03 +03:00
|
|
|
static const QByteArray s_appMenuServiceNamePropertyName = QByteArrayLiteral("KDE_APPMENU_SERVICE_NAME");
|
|
|
|
static const QByteArray s_appMenuObjectPathPropertyName = QByteArrayLiteral("KDE_APPMENU_OBJECT_PATH");
|
2017-01-11 22:00:40 +03:00
|
|
|
static const QByteArray s_skipClosePropertyName = QByteArrayLiteral("KWIN_SKIP_CLOSE_ANIMATION");
|
2016-10-13 10:35:32 +03:00
|
|
|
|
2015-03-04 11:21:10 +03:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
ShellClient::ShellClient(ShellSurfaceInterface *surface)
|
2015-03-16 11:14:04 +03:00
|
|
|
: AbstractClient()
|
2015-03-04 11:21:10 +03:00
|
|
|
, m_shellSurface(surface)
|
2016-04-22 15:13:37 +03:00
|
|
|
, m_xdgShellSurface(nullptr)
|
|
|
|
, m_xdgShellPopup(nullptr)
|
|
|
|
, m_internal(surface->client() == waylandServer()->internalConnection())
|
|
|
|
{
|
|
|
|
setSurface(surface->surface());
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
ShellClient::ShellClient(XdgShellSurfaceInterface *surface)
|
|
|
|
: AbstractClient()
|
|
|
|
, m_shellSurface(nullptr)
|
|
|
|
, m_xdgShellSurface(surface)
|
|
|
|
, m_xdgShellPopup(nullptr)
|
|
|
|
, m_internal(surface->client() == waylandServer()->internalConnection())
|
|
|
|
{
|
|
|
|
setSurface(surface->surface());
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
ShellClient::ShellClient(XdgShellPopupInterface *surface)
|
|
|
|
: AbstractClient()
|
|
|
|
, m_shellSurface(nullptr)
|
|
|
|
, m_xdgShellSurface(nullptr)
|
|
|
|
, m_xdgShellPopup(surface)
|
2015-12-18 19:26:21 +03:00
|
|
|
, m_internal(surface->client() == waylandServer()->internalConnection())
|
2015-03-04 11:21:10 +03:00
|
|
|
{
|
|
|
|
setSurface(surface->surface());
|
2016-04-18 12:55:40 +03:00
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
ShellClient::~ShellClient() = default;
|
|
|
|
|
2016-04-22 15:13:37 +03:00
|
|
|
template <class T>
|
|
|
|
void ShellClient::initSurface(T *shellSurface)
|
|
|
|
{
|
2016-10-31 17:56:01 +03:00
|
|
|
m_caption = shellSurface->title().simplified();
|
2016-04-22 15:13:37 +03:00
|
|
|
connect(shellSurface, &T::titleChanged, this, &ShellClient::captionChanged);
|
|
|
|
connect(shellSurface, &T::destroyed, this, &ShellClient::destroyClient);
|
|
|
|
connect(shellSurface, &T::titleChanged, this,
|
|
|
|
[this] (const QString &s) {
|
2016-10-31 17:56:01 +03:00
|
|
|
m_caption = s.simplified();
|
2016-04-22 15:13:37 +03:00
|
|
|
emit captionChanged();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(shellSurface, &T::moveRequested, this,
|
|
|
|
[this] {
|
|
|
|
// TODO: check the seat and serial
|
|
|
|
performMouseCommand(Options::MouseMove, Cursor::pos());
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
setResourceClass(shellSurface->windowClass());
|
2016-10-27 16:59:08 +03:00
|
|
|
setDesktopFileName(shellSurface->windowClass());
|
2016-04-22 15:13:37 +03:00
|
|
|
connect(shellSurface, &T::windowClassChanged, this,
|
|
|
|
[this] (const QByteArray &windowClass) {
|
|
|
|
setResourceClass(windowClass);
|
2016-10-27 16:59:08 +03:00
|
|
|
setDesktopFileName(windowClass);
|
2016-04-22 15:13:37 +03:00
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(shellSurface, &T::resizeRequested, this,
|
|
|
|
[this] (SeatInterface *seat, quint32 serial, Qt::Edges edges) {
|
|
|
|
// TODO: check the seat and serial
|
|
|
|
Q_UNUSED(seat)
|
|
|
|
Q_UNUSED(serial)
|
|
|
|
if (!isResizable() || isShade()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (isMoveResize()) {
|
|
|
|
finishMoveResize(false);
|
|
|
|
}
|
|
|
|
setMoveResizePointerButtonDown(true);
|
|
|
|
setMoveOffset(Cursor::pos() - pos()); // map from global
|
|
|
|
setInvertedMoveOffset(rect().bottomRight() - moveOffset());
|
|
|
|
setUnrestrictedMoveResize(false);
|
|
|
|
auto toPosition = [edges] {
|
|
|
|
Position pos = PositionCenter;
|
|
|
|
if (edges.testFlag(Qt::TopEdge)) {
|
|
|
|
pos = PositionTop;
|
|
|
|
} else if (edges.testFlag(Qt::BottomEdge)) {
|
|
|
|
pos = PositionBottom;
|
|
|
|
}
|
|
|
|
if (edges.testFlag(Qt::LeftEdge)) {
|
|
|
|
pos = Position(pos | PositionLeft);
|
|
|
|
} else if (edges.testFlag(Qt::RightEdge)) {
|
|
|
|
pos = Position(pos | PositionRight);
|
|
|
|
}
|
|
|
|
return pos;
|
|
|
|
};
|
|
|
|
setMoveResizePointerMode(toPosition());
|
|
|
|
if (!startMoveResize())
|
|
|
|
setMoveResizePointerButtonDown(false);
|
|
|
|
updateCursor();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(shellSurface, &T::maximizedChanged, this,
|
|
|
|
[this] (bool maximized) {
|
2016-09-12 15:41:03 +03:00
|
|
|
if (m_shellSurface && isFullScreen()) {
|
|
|
|
// ignore for wl_shell - there it is mutual exclusive and messes with the geometry
|
|
|
|
return;
|
|
|
|
}
|
2016-04-22 15:13:37 +03:00
|
|
|
maximize(maximized ? MaximizeFull : MaximizeRestore);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
// TODO: consider output!
|
|
|
|
connect(shellSurface, &T::fullscreenChanged, this, &ShellClient::clientFullScreenChanged);
|
|
|
|
|
|
|
|
connect(shellSurface, &T::transientForChanged, this, &ShellClient::setTransient);
|
|
|
|
}
|
|
|
|
|
2016-04-18 12:55:40 +03:00
|
|
|
void ShellClient::init()
|
|
|
|
{
|
2016-10-27 16:59:08 +03:00
|
|
|
connect(this, &ShellClient::desktopFileNameChanged, this, &ShellClient::updateIcon);
|
2015-05-18 15:51:40 +03:00
|
|
|
findInternalWindow();
|
|
|
|
createWindowId();
|
2015-03-04 11:21:10 +03:00
|
|
|
setupCompositing();
|
2016-04-18 12:55:40 +03:00
|
|
|
SurfaceInterface *s = surface();
|
|
|
|
Q_ASSERT(s);
|
|
|
|
if (s->buffer()) {
|
2015-03-04 11:21:10 +03:00
|
|
|
setReadyForPainting();
|
2016-06-03 14:37:24 +03:00
|
|
|
if (shouldExposeToWindowManagement()) {
|
|
|
|
setupWindowManagementInterface();
|
|
|
|
}
|
2015-06-03 22:19:00 +03:00
|
|
|
m_unmapped = false;
|
2016-11-04 19:52:49 +03:00
|
|
|
m_clientSize = s->size();
|
2015-03-04 11:21:10 +03:00
|
|
|
} else {
|
|
|
|
ready_for_painting = false;
|
|
|
|
}
|
2015-05-18 15:51:40 +03:00
|
|
|
if (m_internalWindow) {
|
2015-05-20 09:27:48 +03:00
|
|
|
updateInternalWindowGeometry();
|
2015-06-08 21:18:40 +03:00
|
|
|
setOnAllDesktops(true);
|
2016-05-09 15:48:10 +03:00
|
|
|
updateDecoration(true);
|
2015-05-18 15:51:40 +03:00
|
|
|
} else {
|
2015-10-13 11:52:01 +03:00
|
|
|
doSetGeometry(QRect(QPoint(0, 0), m_clientSize));
|
2015-06-08 21:18:40 +03:00
|
|
|
setDesktop(VirtualDesktopManager::self()->current());
|
2015-05-18 15:51:40 +03:00
|
|
|
}
|
2016-04-18 12:55:40 +03:00
|
|
|
if (waylandServer()->inputMethodConnection() == s->client()) {
|
2015-06-13 05:06:12 +03:00
|
|
|
m_windowType = NET::OnScreenDisplay;
|
|
|
|
}
|
2015-03-04 11:21:10 +03:00
|
|
|
|
2016-04-18 12:55:40 +03:00
|
|
|
connect(s, &SurfaceInterface::sizeChanged, this,
|
2015-03-04 11:21:10 +03:00
|
|
|
[this] {
|
2016-11-04 19:52:49 +03:00
|
|
|
m_clientSize = surface()->size();
|
2015-12-17 17:47:36 +03:00
|
|
|
doSetGeometry(QRect(geom.topLeft(), m_clientSize + QSize(borderLeft() + borderRight(), borderTop() + borderBottom())));
|
2015-03-04 11:21:10 +03:00
|
|
|
}
|
|
|
|
);
|
2016-04-18 12:55:40 +03:00
|
|
|
connect(s, &SurfaceInterface::unmapped, this, &ShellClient::unmap);
|
2016-08-24 16:43:02 +03:00
|
|
|
connect(s, &SurfaceInterface::unbound, this, &ShellClient::destroyClient);
|
2016-05-23 09:54:28 +03:00
|
|
|
connect(s, &SurfaceInterface::destroyed, this, &ShellClient::destroyClient);
|
2016-04-18 12:55:40 +03:00
|
|
|
if (m_shellSurface) {
|
2016-04-22 15:13:37 +03:00
|
|
|
initSurface(m_shellSurface);
|
|
|
|
} else if (m_xdgShellSurface) {
|
|
|
|
initSurface(m_xdgShellSurface);
|
|
|
|
connect(m_xdgShellSurface, &XdgShellSurfaceInterface::windowMenuRequested, this,
|
|
|
|
[this] (SeatInterface *seat, quint32 serial, const QPoint &surfacePos) {
|
|
|
|
// TODO: check serial on seat
|
|
|
|
Q_UNUSED(seat)
|
|
|
|
Q_UNUSED(serial)
|
|
|
|
performMouseCommand(Options::MouseOperationsMenu, pos() + surfacePos);
|
2016-04-18 12:55:40 +03:00
|
|
|
}
|
|
|
|
);
|
2016-04-22 15:13:37 +03:00
|
|
|
connect(m_xdgShellSurface, &XdgShellSurfaceInterface::minimizeRequested, this,
|
2016-04-18 12:55:40 +03:00
|
|
|
[this] {
|
2016-04-22 15:13:37 +03:00
|
|
|
performMouseCommand(Options::MouseMinimize, Cursor::pos());
|
2016-04-18 12:55:40 +03:00
|
|
|
}
|
|
|
|
);
|
2016-04-22 15:13:37 +03:00
|
|
|
auto configure = [this] {
|
|
|
|
if (m_closing) {
|
|
|
|
return;
|
2016-04-18 12:55:40 +03:00
|
|
|
}
|
2016-04-22 15:13:37 +03:00
|
|
|
m_xdgShellSurface->configure(xdgSurfaceStates());
|
|
|
|
};
|
|
|
|
connect(this, &AbstractClient::activeChanged, this, configure);
|
|
|
|
connect(this, &AbstractClient::clientStartUserMovedResized, this, configure);
|
|
|
|
connect(this, &AbstractClient::clientFinishUserMovedResized, this, configure);
|
|
|
|
} else if (m_xdgShellPopup) {
|
|
|
|
connect(m_xdgShellPopup, &XdgShellPopupInterface::destroyed, this, &ShellClient::destroyClient);
|
2016-04-18 12:55:40 +03:00
|
|
|
}
|
2015-07-15 12:24:19 +03:00
|
|
|
|
|
|
|
// setup shadow integration
|
|
|
|
getShadow();
|
2016-04-18 12:55:40 +03:00
|
|
|
connect(s, &SurfaceInterface::shadowChanged, this, &Toplevel::getShadow);
|
2015-09-11 13:11:01 +03:00
|
|
|
|
|
|
|
setTransient();
|
2015-12-17 13:14:54 +03:00
|
|
|
// check whether we have a ServerSideDecoration
|
2016-04-18 12:55:40 +03:00
|
|
|
if (ServerSideDecorationInterface *deco = ServerSideDecorationInterface::get(s)) {
|
2015-12-17 13:14:54 +03:00
|
|
|
installServerSideDecoration(deco);
|
|
|
|
}
|
2015-12-17 17:47:36 +03:00
|
|
|
|
|
|
|
updateColorScheme(QString());
|
2017-01-11 12:21:03 +03:00
|
|
|
updateApplicationMenu();
|
2015-03-04 11:21:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShellClient::destroyClient()
|
|
|
|
{
|
2015-04-30 14:48:59 +03:00
|
|
|
m_closing = true;
|
2015-11-10 16:27:03 +03:00
|
|
|
Deleted *del = nullptr;
|
|
|
|
if (workspace()) {
|
|
|
|
del = Deleted::create(this);
|
|
|
|
}
|
2015-03-04 11:21:10 +03:00
|
|
|
emit windowClosed(this, del);
|
2016-06-03 17:53:23 +03:00
|
|
|
destroyWindowManagementInterface();
|
2015-12-17 17:47:36 +03:00
|
|
|
destroyDecoration();
|
2015-10-01 15:12:46 +03:00
|
|
|
|
2015-11-10 16:27:03 +03:00
|
|
|
if (workspace()) {
|
|
|
|
StackingUpdatesBlocker blocker(workspace());
|
|
|
|
if (transientFor()) {
|
|
|
|
transientFor()->removeTransient(this);
|
|
|
|
}
|
|
|
|
for (auto it = transients().constBegin(); it != transients().constEnd();) {
|
|
|
|
if ((*it)->transientFor() == this) {
|
|
|
|
removeTransient(*it);
|
|
|
|
it = transients().constBegin(); // restart, just in case something more has changed with the list
|
|
|
|
} else {
|
|
|
|
++it;
|
|
|
|
}
|
2015-10-01 15:12:46 +03:00
|
|
|
}
|
|
|
|
}
|
2015-03-04 11:21:10 +03:00
|
|
|
waylandServer()->removeClient(this);
|
|
|
|
|
2015-11-10 16:27:03 +03:00
|
|
|
if (del) {
|
|
|
|
del->unrefWindow();
|
|
|
|
}
|
2015-03-04 11:21:10 +03:00
|
|
|
m_shellSurface = nullptr;
|
2016-04-22 15:13:37 +03:00
|
|
|
m_xdgShellSurface = nullptr;
|
|
|
|
m_xdgShellPopup = nullptr;
|
2015-03-04 11:21:10 +03:00
|
|
|
deleteClient(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShellClient::deleteClient(ShellClient *c)
|
|
|
|
{
|
|
|
|
delete c;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList ShellClient::activities() const
|
|
|
|
{
|
|
|
|
// TODO: implement
|
|
|
|
return QStringList();
|
|
|
|
}
|
|
|
|
|
2015-12-08 12:11:26 +03:00
|
|
|
QPoint ShellClient::clientContentPos() const
|
|
|
|
{
|
|
|
|
return -1 * clientPos();
|
|
|
|
}
|
|
|
|
|
2015-03-04 11:21:10 +03:00
|
|
|
QSize ShellClient::clientSize() const
|
|
|
|
{
|
|
|
|
// TODO: connect for changes
|
|
|
|
return m_clientSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShellClient::debug(QDebug &stream) const
|
|
|
|
{
|
|
|
|
// TODO: implement
|
|
|
|
Q_UNUSED(stream)
|
|
|
|
}
|
|
|
|
|
2015-09-17 12:06:59 +03:00
|
|
|
Layer ShellClient::layerForDock() const
|
2015-03-04 11:21:10 +03:00
|
|
|
{
|
2015-09-17 12:06:59 +03:00
|
|
|
if (m_plasmaShellSurface) {
|
|
|
|
switch (m_plasmaShellSurface->panelBehavior()) {
|
|
|
|
case PlasmaShellSurfaceInterface::PanelBehavior::WindowsCanCover:
|
2015-06-09 20:10:56 +03:00
|
|
|
return NormalLayer;
|
2015-09-17 12:06:59 +03:00
|
|
|
case PlasmaShellSurfaceInterface::PanelBehavior::AutoHide:
|
2015-06-09 20:10:56 +03:00
|
|
|
return AboveLayer;
|
2015-09-17 12:06:59 +03:00
|
|
|
case PlasmaShellSurfaceInterface::PanelBehavior::WindowsGoBelow:
|
|
|
|
case PlasmaShellSurfaceInterface::PanelBehavior::AlwaysVisible:
|
|
|
|
return DockLayer;
|
|
|
|
default:
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
break;
|
|
|
|
}
|
2015-06-09 20:10:56 +03:00
|
|
|
}
|
2015-09-17 12:06:59 +03:00
|
|
|
return AbstractClient::layerForDock();
|
2015-03-04 11:21:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QRect ShellClient::transparentRect() const
|
|
|
|
{
|
|
|
|
// TODO: implement
|
|
|
|
return QRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
NET::WindowType ShellClient::windowType(bool direct, int supported_types) const
|
|
|
|
{
|
|
|
|
// TODO: implement
|
|
|
|
Q_UNUSED(direct)
|
|
|
|
Q_UNUSED(supported_types)
|
2015-06-08 22:27:55 +03:00
|
|
|
return m_windowType;
|
2015-03-04 11:21:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
double ShellClient::opacity() const
|
|
|
|
{
|
2016-02-18 10:27:02 +03:00
|
|
|
return m_opacity;
|
2015-03-04 11:21:10 +03:00
|
|
|
}
|
|
|
|
|
2015-03-16 11:13:19 +03:00
|
|
|
void ShellClient::setOpacity(double opacity)
|
|
|
|
{
|
2016-02-18 10:27:02 +03:00
|
|
|
const qreal newOpacity = qBound(0.0, opacity, 1.0);
|
|
|
|
if (newOpacity == m_opacity) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const qreal oldOpacity = m_opacity;
|
|
|
|
m_opacity = newOpacity;
|
|
|
|
addRepaintFull();
|
|
|
|
emit opacityChanged(this, oldOpacity);
|
2015-03-16 11:13:19 +03:00
|
|
|
}
|
|
|
|
|
2015-03-04 11:21:10 +03:00
|
|
|
void ShellClient::addDamage(const QRegion &damage)
|
|
|
|
{
|
2016-04-18 14:33:23 +03:00
|
|
|
auto s = surface();
|
2016-11-04 19:52:49 +03:00
|
|
|
if (s->size().isValid()) {
|
|
|
|
m_clientSize = s->size();
|
2015-05-19 13:03:53 +03:00
|
|
|
QPoint position = geom.topLeft();
|
|
|
|
if (m_positionAfterResize.isValid()) {
|
2015-06-07 03:38:53 +03:00
|
|
|
addLayerRepaint(geometry());
|
2015-05-19 13:03:53 +03:00
|
|
|
position = m_positionAfterResize.point();
|
|
|
|
m_positionAfterResize.clear();
|
|
|
|
}
|
2015-12-17 17:47:36 +03:00
|
|
|
doSetGeometry(QRect(position, m_clientSize + QSize(borderLeft() + borderRight(), borderTop() + borderBottom())));
|
2015-03-04 11:21:10 +03:00
|
|
|
}
|
2015-07-22 09:38:00 +03:00
|
|
|
markAsMapped();
|
2016-08-09 14:50:29 +03:00
|
|
|
setDepth((s->buffer()->hasAlphaChannel() && !isDesktop()) ? 32 : 24);
|
2016-03-04 18:33:09 +03:00
|
|
|
repaints_region += damage.translated(clientPos());
|
2015-03-04 11:21:10 +03:00
|
|
|
Toplevel::addDamage(damage);
|
|
|
|
}
|
|
|
|
|
2015-08-18 15:40:26 +03:00
|
|
|
void ShellClient::setInternalFramebufferObject(const QSharedPointer<QOpenGLFramebufferObject> &fbo)
|
|
|
|
{
|
|
|
|
if (fbo.isNull()) {
|
|
|
|
unmap();
|
|
|
|
return;
|
|
|
|
}
|
2016-11-04 19:52:49 +03:00
|
|
|
|
|
|
|
//Kwin currently scales internal windows to 1, so this is currently always correct
|
|
|
|
//when that changes, this needs adjusting
|
2015-08-18 15:40:26 +03:00
|
|
|
m_clientSize = fbo->size();
|
2016-11-04 19:52:49 +03:00
|
|
|
markAsMapped();
|
2015-10-13 11:52:01 +03:00
|
|
|
doSetGeometry(QRect(geom.topLeft(), m_clientSize));
|
2015-08-18 15:40:26 +03:00
|
|
|
Toplevel::setInternalFramebufferObject(fbo);
|
|
|
|
Toplevel::addDamage(QRegion(0, 0, width(), height()));
|
|
|
|
}
|
|
|
|
|
2015-07-22 09:38:00 +03:00
|
|
|
void ShellClient::markAsMapped()
|
2015-07-09 10:10:33 +03:00
|
|
|
{
|
|
|
|
if (!m_unmapped) {
|
|
|
|
return;
|
|
|
|
}
|
2015-12-17 17:47:36 +03:00
|
|
|
|
2015-07-09 10:10:33 +03:00
|
|
|
m_unmapped = false;
|
2016-07-04 16:06:20 +03:00
|
|
|
if (!ready_for_painting) {
|
|
|
|
setReadyForPainting();
|
|
|
|
} else {
|
|
|
|
addRepaintFull();
|
|
|
|
emit windowShown(this);
|
|
|
|
}
|
2016-06-03 14:37:24 +03:00
|
|
|
if (shouldExposeToWindowManagement()) {
|
|
|
|
setupWindowManagementInterface();
|
|
|
|
}
|
2016-09-15 22:03:40 +03:00
|
|
|
updateShowOnScreenEdge();
|
2015-07-09 10:10:33 +03:00
|
|
|
}
|
|
|
|
|
2015-12-17 17:47:36 +03:00
|
|
|
void ShellClient::createDecoration(const QRect &oldGeom)
|
|
|
|
{
|
|
|
|
KDecoration2::Decoration *decoration = Decoration::DecorationBridge::self()->createDecoration(this);
|
|
|
|
if (decoration) {
|
|
|
|
QMetaObject::invokeMethod(decoration, "update", Qt::QueuedConnection);
|
|
|
|
connect(decoration, &KDecoration2::Decoration::shadowChanged, this, &Toplevel::getShadow);
|
|
|
|
connect(decoration, &KDecoration2::Decoration::bordersChanged, this,
|
|
|
|
[this]() {
|
|
|
|
GeometryUpdatesBlocker blocker(this);
|
2016-06-09 17:54:06 +03:00
|
|
|
RequestGeometryBlocker requestBlocker(this);
|
2015-12-17 17:47:36 +03:00
|
|
|
QRect oldgeom = geometry();
|
|
|
|
if (!isShade())
|
|
|
|
checkWorkspacePosition(oldgeom);
|
|
|
|
emit geometryShapeChanged(this, oldgeom);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
setDecoration(decoration);
|
2016-06-10 11:52:41 +03:00
|
|
|
// TODO: ensure the new geometry still fits into the client area (e.g. maximized windows)
|
2016-06-23 12:26:31 +03:00
|
|
|
doSetGeometry(QRect(oldGeom.topLeft(), m_clientSize + (decoration ? QSize(decoration->borderLeft() + decoration->borderRight(),
|
|
|
|
decoration->borderBottom() + decoration->borderTop()) : QSize())));
|
2015-12-17 17:47:36 +03:00
|
|
|
|
|
|
|
emit geometryShapeChanged(this, oldGeom);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShellClient::updateDecoration(bool check_workspace_pos, bool force)
|
|
|
|
{
|
|
|
|
if (!force &&
|
|
|
|
((!isDecorated() && noBorder()) || (isDecorated() && !noBorder())))
|
|
|
|
return;
|
|
|
|
QRect oldgeom = geometry();
|
|
|
|
QRect oldClientGeom = oldgeom.adjusted(borderLeft(), borderTop(), -borderRight(), -borderBottom());
|
|
|
|
blockGeometryUpdates(true);
|
|
|
|
if (force)
|
|
|
|
destroyDecoration();
|
|
|
|
if (!noBorder()) {
|
|
|
|
createDecoration(oldgeom);
|
|
|
|
} else
|
|
|
|
destroyDecoration();
|
|
|
|
if (m_serverDecoration && isDecorated()) {
|
|
|
|
m_serverDecoration->setMode(KWayland::Server::ServerSideDecorationManagerInterface::Mode::Server);
|
|
|
|
}
|
|
|
|
getShadow();
|
|
|
|
if (check_workspace_pos)
|
|
|
|
checkWorkspacePosition(oldgeom, -2, oldClientGeom);
|
|
|
|
blockGeometryUpdates(false);
|
|
|
|
}
|
|
|
|
|
2015-10-13 11:52:01 +03:00
|
|
|
void ShellClient::setGeometry(int x, int y, int w, int h, ForceGeometry_t force)
|
|
|
|
{
|
|
|
|
Q_UNUSED(force)
|
|
|
|
// TODO: better merge with Client's implementation
|
2015-10-14 17:34:19 +03:00
|
|
|
if (QSize(w, h) == geom.size()) {
|
|
|
|
// size didn't change, update directly
|
|
|
|
doSetGeometry(QRect(x, y, w, h));
|
|
|
|
} else {
|
|
|
|
// size did change, Client needs to provide a new buffer
|
|
|
|
requestGeometry(QRect(x, y, w, h));
|
|
|
|
}
|
2015-10-13 11:52:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShellClient::doSetGeometry(const QRect &rect)
|
2015-03-04 11:21:10 +03:00
|
|
|
{
|
2017-01-04 19:53:46 +03:00
|
|
|
if (geom == rect && pendingGeometryUpdate() == PendingGeometryNone) {
|
2015-03-04 11:21:10 +03:00
|
|
|
return;
|
|
|
|
}
|
2015-08-20 10:38:19 +03:00
|
|
|
if (!m_unmapped) {
|
|
|
|
addWorkspaceRepaint(visibleRect());
|
|
|
|
}
|
2015-03-04 11:21:10 +03:00
|
|
|
const QRect old = geom;
|
|
|
|
geom = rect;
|
2015-10-14 13:11:56 +03:00
|
|
|
|
|
|
|
if (m_unmapped && m_geomMaximizeRestore.isEmpty() && !geom.isEmpty()) {
|
|
|
|
// use first valid geometry as restore geometry
|
|
|
|
m_geomMaximizeRestore = geom;
|
|
|
|
}
|
|
|
|
|
2015-08-20 10:38:19 +03:00
|
|
|
if (!m_unmapped) {
|
|
|
|
addWorkspaceRepaint(visibleRect());
|
|
|
|
}
|
2017-01-04 19:53:46 +03:00
|
|
|
syncGeometryToInternalWindow();
|
2016-06-10 11:50:02 +03:00
|
|
|
if (hasStrut()) {
|
|
|
|
workspace()->updateClientArea();
|
|
|
|
}
|
2015-03-04 11:21:10 +03:00
|
|
|
emit geometryShapeChanged(this, old);
|
2017-01-29 16:30:43 +03:00
|
|
|
|
|
|
|
if (isResize()) {
|
|
|
|
performMoveResize();
|
|
|
|
}
|
2015-03-04 11:21:10 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 19:53:46 +03:00
|
|
|
void ShellClient::doMove(int x, int y)
|
|
|
|
{
|
|
|
|
Q_UNUSED(x)
|
|
|
|
Q_UNUSED(y)
|
|
|
|
syncGeometryToInternalWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShellClient::syncGeometryToInternalWindow()
|
|
|
|
{
|
|
|
|
if (!m_internalWindow) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const QRect windowRect = QRect(geom.topLeft() + QPoint(borderLeft(), borderTop()),
|
|
|
|
geom.size() - QSize(borderLeft() + borderRight(), borderTop() + borderBottom()));
|
|
|
|
if (m_internalWindow->geometry() != windowRect) {
|
|
|
|
m_internalWindow->setGeometry(windowRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-04 11:21:10 +03:00
|
|
|
QByteArray ShellClient::windowRole() const
|
|
|
|
{
|
|
|
|
return QByteArray();
|
|
|
|
}
|
|
|
|
|
2015-03-16 11:14:04 +03:00
|
|
|
bool ShellClient::belongsToSameApplication(const AbstractClient *other, bool active_hack) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(active_hack)
|
|
|
|
if (auto s = other->surface()) {
|
|
|
|
return s->client() == surface()->client();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShellClient::blockActivityUpdates(bool b)
|
|
|
|
{
|
|
|
|
Q_UNUSED(b)
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ShellClient::caption(bool full, bool stripped) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(full)
|
|
|
|
Q_UNUSED(stripped)
|
2016-06-16 14:30:32 +03:00
|
|
|
return m_caption;
|
2015-03-16 11:14:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShellClient::closeWindow()
|
|
|
|
{
|
2016-04-22 15:13:37 +03:00
|
|
|
if (m_xdgShellSurface && isCloseable()) {
|
|
|
|
m_xdgShellSurface->close();
|
|
|
|
return;
|
|
|
|
}
|
2015-06-12 02:20:31 +03:00
|
|
|
if (m_qtExtendedSurface && isCloseable()) {
|
2015-06-10 01:59:53 +03:00
|
|
|
m_qtExtendedSurface->close();
|
|
|
|
}
|
2016-05-09 15:48:10 +03:00
|
|
|
if (m_internalWindow) {
|
|
|
|
m_internalWindow->hide();
|
|
|
|
}
|
2015-03-16 11:14:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
AbstractClient *ShellClient::findModal(bool allow_itself)
|
|
|
|
{
|
|
|
|
Q_UNUSED(allow_itself)
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ShellClient::isCloseable() const
|
|
|
|
{
|
2015-06-12 02:20:31 +03:00
|
|
|
if (m_windowType == NET::Desktop || m_windowType == NET::Dock) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-04-22 15:13:37 +03:00
|
|
|
if (m_xdgShellSurface) {
|
|
|
|
return true;
|
|
|
|
}
|
2016-05-09 15:48:10 +03:00
|
|
|
if (m_internal) {
|
|
|
|
return true;
|
|
|
|
}
|
2015-06-10 01:59:53 +03:00
|
|
|
return m_qtExtendedSurface ? true : false;
|
2015-03-16 11:14:04 +03:00
|
|
|
}
|
|
|
|
|
2015-05-21 16:59:27 +03:00
|
|
|
bool ShellClient::isFullScreenable() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-16 11:14:04 +03:00
|
|
|
bool ShellClient::isFullScreen() const
|
|
|
|
{
|
2015-10-08 11:05:40 +03:00
|
|
|
return m_fullScreen;
|
2015-03-16 11:14:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ShellClient::isMaximizable() const
|
|
|
|
{
|
2016-05-09 15:48:10 +03:00
|
|
|
if (m_internal) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-06-07 04:28:38 +03:00
|
|
|
return true;
|
2015-03-16 11:14:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ShellClient::isMinimizable() const
|
|
|
|
{
|
2016-11-03 13:32:51 +03:00
|
|
|
if (m_internal) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-10-29 12:31:23 +03:00
|
|
|
return (!m_plasmaShellSurface || m_plasmaShellSurface->role() == PlasmaShellSurfaceInterface::Role::Normal);
|
2015-11-05 13:30:02 +03:00
|
|
|
}
|
|
|
|
|
2015-03-16 11:14:04 +03:00
|
|
|
bool ShellClient::isMovable() const
|
|
|
|
{
|
2016-03-16 17:35:24 +03:00
|
|
|
if (m_plasmaShellSurface) {
|
|
|
|
return m_plasmaShellSurface->role() == PlasmaShellSurfaceInterface::Role::Normal;
|
|
|
|
}
|
2016-04-22 15:13:37 +03:00
|
|
|
if (m_xdgShellPopup) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-10-26 11:17:46 +03:00
|
|
|
return true;
|
2015-03-16 11:14:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ShellClient::isMovableAcrossScreens() const
|
|
|
|
{
|
2016-03-16 17:35:24 +03:00
|
|
|
if (m_plasmaShellSurface) {
|
|
|
|
return m_plasmaShellSurface->role() == PlasmaShellSurfaceInterface::Role::Normal;
|
|
|
|
}
|
2016-04-22 15:13:37 +03:00
|
|
|
if (m_xdgShellPopup) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-10-26 11:17:46 +03:00
|
|
|
return true;
|
2015-03-16 11:14:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ShellClient::isResizable() const
|
|
|
|
{
|
2016-03-16 17:35:24 +03:00
|
|
|
if (m_plasmaShellSurface) {
|
|
|
|
return m_plasmaShellSurface->role() == PlasmaShellSurfaceInterface::Role::Normal;
|
|
|
|
}
|
2016-04-22 15:13:37 +03:00
|
|
|
if (m_xdgShellPopup) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-10-13 17:26:45 +03:00
|
|
|
return true;
|
2015-03-16 11:14:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ShellClient::isShown(bool shaded_is_shown) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(shaded_is_shown)
|
2016-10-11 17:24:10 +03:00
|
|
|
return !m_closing && !m_unmapped && !isMinimized() && !m_hidden;
|
2015-03-16 11:14:04 +03:00
|
|
|
}
|
|
|
|
|
2015-05-23 10:02:11 +03:00
|
|
|
void ShellClient::hideClient(bool hide)
|
|
|
|
{
|
2016-10-11 17:24:10 +03:00
|
|
|
if (m_hidden == hide) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_hidden = hide;
|
|
|
|
if (hide) {
|
|
|
|
addWorkspaceRepaint(visibleRect());
|
|
|
|
workspace()->clientHidden(this);
|
|
|
|
emit windowHidden(this);
|
|
|
|
} else {
|
|
|
|
emit windowShown(this);
|
|
|
|
}
|
2015-05-23 10:02:11 +03:00
|
|
|
}
|
|
|
|
|
2016-06-09 15:37:32 +03:00
|
|
|
static bool changeMaximizeRecursion = false;
|
2015-10-13 11:22:18 +03:00
|
|
|
void ShellClient::changeMaximize(bool horizontal, bool vertical, bool adjust)
|
2015-03-16 11:14:04 +03:00
|
|
|
{
|
2016-06-09 15:37:32 +03:00
|
|
|
if (changeMaximizeRecursion) {
|
|
|
|
return;
|
|
|
|
}
|
2016-09-16 15:27:50 +03:00
|
|
|
|
|
|
|
if (!isResizable()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QRect clientArea = isElectricBorderMaximizing() ?
|
|
|
|
workspace()->clientArea(MaximizeArea, Cursor::pos(), desktop()) :
|
|
|
|
workspace()->clientArea(MaximizeArea, this);
|
|
|
|
|
2016-06-09 15:37:32 +03:00
|
|
|
MaximizeMode oldMode = m_maximizeMode;
|
2015-06-07 04:28:38 +03:00
|
|
|
StackingUpdatesBlocker blocker(workspace());
|
2016-06-09 17:54:06 +03:00
|
|
|
RequestGeometryBlocker geometryBlocker(this);
|
2015-10-13 11:22:18 +03:00
|
|
|
// 'adjust == true' means to update the size only, e.g. after changing workspace size
|
|
|
|
if (!adjust) {
|
|
|
|
if (vertical)
|
|
|
|
m_maximizeMode = MaximizeMode(m_maximizeMode ^ MaximizeVertical);
|
|
|
|
if (horizontal)
|
|
|
|
m_maximizeMode = MaximizeMode(m_maximizeMode ^ MaximizeHorizontal);
|
|
|
|
}
|
|
|
|
// TODO: add more checks as in Client
|
2016-06-09 15:37:32 +03:00
|
|
|
|
|
|
|
// call into decoration update borders
|
|
|
|
if (isDecorated() && decoration()->client() && !(options->borderlessMaximizedWindows() && m_maximizeMode == KWin::MaximizeFull)) {
|
|
|
|
changeMaximizeRecursion = true;
|
|
|
|
const auto c = decoration()->client().data();
|
|
|
|
if ((m_maximizeMode & MaximizeVertical) != (oldMode & MaximizeVertical)) {
|
|
|
|
emit c->maximizedVerticallyChanged(m_maximizeMode & MaximizeVertical);
|
|
|
|
}
|
|
|
|
if ((m_maximizeMode & MaximizeHorizontal) != (oldMode & MaximizeHorizontal)) {
|
|
|
|
emit c->maximizedHorizontallyChanged(m_maximizeMode & MaximizeHorizontal);
|
|
|
|
}
|
|
|
|
if ((m_maximizeMode == MaximizeFull) != (oldMode == MaximizeFull)) {
|
|
|
|
emit c->maximizedChanged(m_maximizeMode & MaximizeFull);
|
|
|
|
}
|
|
|
|
changeMaximizeRecursion = false;
|
|
|
|
}
|
2016-06-09 17:50:48 +03:00
|
|
|
|
2016-11-25 18:45:40 +03:00
|
|
|
if (options->borderlessMaximizedWindows()) {
|
|
|
|
// triggers a maximize change.
|
|
|
|
// The next setNoBorder interation will exit since there's no change but the first recursion pullutes the restore geometry
|
|
|
|
changeMaximizeRecursion = true;
|
|
|
|
setNoBorder(rules()->checkNoBorder(m_maximizeMode == MaximizeFull));
|
|
|
|
changeMaximizeRecursion = false;
|
|
|
|
}
|
2016-09-16 15:27:50 +03:00
|
|
|
|
|
|
|
// Conditional quick tiling exit points
|
|
|
|
const auto oldQuickTileMode = quickTileMode();
|
|
|
|
if (quickTileMode() != QuickTileNone) {
|
|
|
|
if (oldMode == MaximizeFull &&
|
|
|
|
!clientArea.contains(m_geomMaximizeRestore.center())) {
|
|
|
|
// Not restoring on the same screen
|
|
|
|
// TODO: The following doesn't work for some reason
|
|
|
|
//quick_tile_mode = QuickTileNone; // And exit quick tile mode manually
|
|
|
|
} else if ((oldMode == MaximizeVertical && m_maximizeMode == MaximizeRestore) ||
|
|
|
|
(oldMode == MaximizeFull && m_maximizeMode == MaximizeHorizontal)) {
|
|
|
|
// Modifying geometry of a tiled window
|
|
|
|
updateQuickTileMode(QuickTileNone); // Exit quick tile mode without restoring geometry
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-09 17:50:48 +03:00
|
|
|
// TODO: check rules
|
|
|
|
if (m_maximizeMode == MaximizeFull) {
|
|
|
|
m_geomMaximizeRestore = geometry();
|
2016-09-16 15:27:50 +03:00
|
|
|
// TODO: Client has more checks
|
|
|
|
if (options->electricBorderMaximize()) {
|
|
|
|
updateQuickTileMode(QuickTileMaximize);
|
|
|
|
} else {
|
|
|
|
updateQuickTileMode(QuickTileNone);
|
|
|
|
}
|
|
|
|
if (quickTileMode() != oldQuickTileMode) {
|
|
|
|
emit quickTileModeChanged();
|
|
|
|
}
|
2016-06-09 17:50:48 +03:00
|
|
|
requestGeometry(workspace()->clientArea(MaximizeArea, this));
|
|
|
|
workspace()->raiseClient(this);
|
|
|
|
} else {
|
2016-09-16 15:27:50 +03:00
|
|
|
if (m_maximizeMode == MaximizeRestore) {
|
|
|
|
updateQuickTileMode(QuickTileNone);
|
|
|
|
}
|
|
|
|
if (quickTileMode() != oldQuickTileMode) {
|
|
|
|
emit quickTileModeChanged();
|
|
|
|
}
|
|
|
|
|
2016-06-09 17:50:48 +03:00
|
|
|
if (m_geomMaximizeRestore.isValid()) {
|
|
|
|
requestGeometry(m_geomMaximizeRestore);
|
|
|
|
} else {
|
|
|
|
requestGeometry(workspace()->clientArea(PlacementArea, this));
|
|
|
|
}
|
|
|
|
}
|
2015-03-16 11:14:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
MaximizeMode ShellClient::maximizeMode() const
|
|
|
|
{
|
2015-06-07 04:28:38 +03:00
|
|
|
return m_maximizeMode;
|
2015-03-16 11:14:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ShellClient::noBorder() const
|
|
|
|
{
|
2015-12-17 17:47:36 +03:00
|
|
|
if (isInternal()) {
|
2016-05-09 15:48:10 +03:00
|
|
|
return m_internalWindowFlags.testFlag(Qt::FramelessWindowHint) || m_internalWindowFlags.testFlag(Qt::Popup);
|
2015-12-17 17:47:36 +03:00
|
|
|
}
|
|
|
|
if (m_serverDecoration) {
|
|
|
|
if (m_serverDecoration->mode() == ServerSideDecorationManagerInterface::Mode::Server) {
|
2016-09-12 15:41:03 +03:00
|
|
|
return m_userNoBorder || isFullScreen();
|
2015-12-17 17:47:36 +03:00
|
|
|
}
|
|
|
|
}
|
2015-03-16 11:14:04 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const WindowRules *ShellClient::rules() const
|
|
|
|
{
|
|
|
|
static WindowRules s_rules;
|
|
|
|
return &s_rules;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShellClient::setFullScreen(bool set, bool user)
|
|
|
|
{
|
|
|
|
Q_UNUSED(set)
|
|
|
|
Q_UNUSED(user)
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShellClient::setNoBorder(bool set)
|
|
|
|
{
|
2015-12-17 17:47:36 +03:00
|
|
|
if (!userCanSetNoBorder()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
set = rules()->checkNoBorder(set);
|
|
|
|
if (m_userNoBorder == set) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_userNoBorder = set;
|
|
|
|
updateDecoration(true, false);
|
|
|
|
updateWindowRules(Rules::NoBorder);
|
2015-03-16 11:14:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShellClient::setOnAllActivities(bool set)
|
|
|
|
{
|
|
|
|
Q_UNUSED(set)
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShellClient::setShortcut(const QString &cut)
|
|
|
|
{
|
|
|
|
Q_UNUSED(cut)
|
|
|
|
}
|
|
|
|
|
|
|
|
const QKeySequence &ShellClient::shortcut() const
|
|
|
|
{
|
|
|
|
static QKeySequence seq;
|
|
|
|
return seq;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShellClient::takeFocus()
|
|
|
|
{
|
2015-07-09 21:43:41 +03:00
|
|
|
if (rules()->checkAcceptFocus(wantsInput())) {
|
|
|
|
setActive(true);
|
|
|
|
}
|
2015-06-23 12:08:28 +03:00
|
|
|
|
|
|
|
bool breakShowingDesktop = !keepAbove() && !isOnScreenDisplay();
|
|
|
|
if (breakShowingDesktop) {
|
|
|
|
// check that it doesn't belong to the desktop
|
|
|
|
const auto &clients = waylandServer()->clients();
|
|
|
|
for (auto c: clients) {
|
|
|
|
if (!belongsToSameApplication(c, false)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (c->isDesktop()) {
|
|
|
|
breakShowingDesktop = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (breakShowingDesktop)
|
|
|
|
workspace()->setShowingDesktop(false);
|
2015-03-16 11:14:04 +03:00
|
|
|
}
|
|
|
|
|
2015-07-07 17:15:58 +03:00
|
|
|
void ShellClient::doSetActive()
|
|
|
|
{
|
2016-08-10 15:19:12 +03:00
|
|
|
if (!isActive()) {
|
|
|
|
return;
|
|
|
|
}
|
2015-07-07 17:15:58 +03:00
|
|
|
StackingUpdatesBlocker blocker(workspace());
|
|
|
|
workspace()->focusToNull();
|
|
|
|
}
|
|
|
|
|
2015-03-16 11:14:04 +03:00
|
|
|
void ShellClient::updateWindowRules(Rules::Types selection)
|
|
|
|
{
|
|
|
|
Q_UNUSED(selection)
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ShellClient::userCanSetFullScreen() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ShellClient::userCanSetNoBorder() const
|
|
|
|
{
|
2015-12-17 18:11:15 +03:00
|
|
|
if (m_serverDecoration && m_serverDecoration->mode() == ServerSideDecorationManagerInterface::Mode::Server) {
|
|
|
|
return !isFullScreen() && !isShade() && !tabGroup();
|
|
|
|
}
|
2016-05-09 15:48:10 +03:00
|
|
|
if (m_internal) {
|
|
|
|
return !m_internalWindowFlags.testFlag(Qt::FramelessWindowHint) || m_internalWindowFlags.testFlag(Qt::Popup);
|
|
|
|
}
|
2015-03-16 11:14:04 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ShellClient::wantsInput() const
|
2015-12-07 18:18:30 +03:00
|
|
|
{
|
|
|
|
return rules()->checkAcceptFocus(acceptsFocus());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ShellClient::acceptsFocus() const
|
2015-03-16 11:14:04 +03:00
|
|
|
{
|
2015-05-21 11:39:10 +03:00
|
|
|
if (isInternal()) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-04-18 14:33:23 +03:00
|
|
|
if (waylandServer()->inputMethodConnection() == surface()->client()) {
|
2015-06-13 05:06:12 +03:00
|
|
|
return false;
|
|
|
|
}
|
2016-06-17 09:32:15 +03:00
|
|
|
if (m_plasmaShellSurface) {
|
2016-06-17 10:46:16 +03:00
|
|
|
if (m_plasmaShellSurface->role() == PlasmaShellSurfaceInterface::Role::OnScreenDisplay ||
|
2016-06-28 14:25:15 +03:00
|
|
|
m_plasmaShellSurface->role() == PlasmaShellSurfaceInterface::Role::ToolTip ||
|
2016-06-17 10:46:16 +03:00
|
|
|
m_plasmaShellSurface->role() == PlasmaShellSurfaceInterface::Role::Notification) {
|
2016-06-17 09:32:15 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2016-09-12 11:05:49 +03:00
|
|
|
if (m_closing) {
|
|
|
|
// a closing window does not accept focus
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (m_unmapped) {
|
|
|
|
// an unmapped window does not accept focus
|
|
|
|
return false;
|
|
|
|
}
|
2016-04-18 14:33:23 +03:00
|
|
|
if (m_shellSurface) {
|
|
|
|
if (m_shellSurface->isPopup()) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-09-12 11:05:49 +03:00
|
|
|
return m_shellSurface->acceptsKeyboardFocus();
|
2015-09-11 14:33:57 +03:00
|
|
|
}
|
2016-04-22 15:13:37 +03:00
|
|
|
if (m_xdgShellSurface) {
|
|
|
|
// TODO: proper
|
|
|
|
return true;
|
|
|
|
}
|
2016-04-18 14:33:23 +03:00
|
|
|
return false;
|
2015-03-16 11:14:04 +03:00
|
|
|
}
|
|
|
|
|
2015-05-18 15:51:40 +03:00
|
|
|
void ShellClient::createWindowId()
|
|
|
|
{
|
|
|
|
if (m_internalWindow) {
|
|
|
|
m_windowId = m_internalWindow->winId();
|
2015-05-21 10:59:45 +03:00
|
|
|
} else {
|
2016-04-18 14:33:23 +03:00
|
|
|
m_windowId = waylandServer()->createWindowId(surface());
|
2015-05-18 15:51:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShellClient::findInternalWindow()
|
|
|
|
{
|
2016-04-18 14:33:23 +03:00
|
|
|
if (surface()->client() != waylandServer()->internalConnection()) {
|
2015-05-18 15:51:40 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const QWindowList windows = kwinApp()->topLevelWindows();
|
|
|
|
for (QWindow *w: windows) {
|
2015-09-15 13:18:36 +03:00
|
|
|
auto s = KWayland::Client::Surface::fromWindow(w);
|
2015-05-18 15:51:40 +03:00
|
|
|
if (!s) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (s->id() != surface()->id()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
m_internalWindow = w;
|
2016-05-09 15:48:10 +03:00
|
|
|
m_internalWindowFlags = m_internalWindow->flags();
|
2015-05-20 09:27:48 +03:00
|
|
|
connect(m_internalWindow, &QWindow::xChanged, this, &ShellClient::updateInternalWindowGeometry);
|
2015-05-20 09:57:51 +03:00
|
|
|
connect(m_internalWindow, &QWindow::yChanged, this, &ShellClient::updateInternalWindowGeometry);
|
2015-11-18 17:43:54 +03:00
|
|
|
connect(m_internalWindow, &QWindow::destroyed, this, [this] { m_internalWindow = nullptr; });
|
2017-01-03 09:28:29 +03:00
|
|
|
connect(m_internalWindow, &QWindow::opacityChanged, this, &ShellClient::setOpacity);
|
2015-06-08 22:27:55 +03:00
|
|
|
|
|
|
|
// Try reading the window type from the QWindow. PlasmaCore.Dialog provides a dynamic type property
|
|
|
|
// let's check whether it exists, if it does it's our window type
|
|
|
|
const QVariant windowType = m_internalWindow->property("type");
|
|
|
|
if (!windowType.isNull()) {
|
|
|
|
m_windowType = static_cast<NET::WindowType>(windowType.toInt());
|
|
|
|
}
|
2017-01-03 09:28:29 +03:00
|
|
|
setOpacity(m_internalWindow->opacity());
|
2017-01-11 22:00:40 +03:00
|
|
|
|
|
|
|
// skip close animation support
|
|
|
|
setSkipCloseAnimation(m_internalWindow->property(s_skipClosePropertyName).toBool());
|
|
|
|
m_internalWindow->installEventFilter(this);
|
2015-05-18 15:51:40 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-20 09:27:48 +03:00
|
|
|
void ShellClient::updateInternalWindowGeometry()
|
|
|
|
{
|
|
|
|
if (!m_internalWindow) {
|
|
|
|
return;
|
|
|
|
}
|
2016-05-09 15:48:10 +03:00
|
|
|
doSetGeometry(QRect(m_internalWindow->geometry().topLeft() - QPoint(borderLeft(), borderTop()),
|
|
|
|
m_internalWindow->geometry().size() + QSize(borderLeft() + borderRight(), borderTop() + borderBottom())));
|
2015-05-20 09:27:48 +03:00
|
|
|
}
|
|
|
|
|
2017-05-08 03:44:52 +03:00
|
|
|
pid_t ShellClient::pid() const
|
|
|
|
{
|
|
|
|
return surface()->client()->processId();
|
|
|
|
}
|
|
|
|
|
2015-05-21 11:31:19 +03:00
|
|
|
bool ShellClient::isInternal() const
|
|
|
|
{
|
2015-12-18 19:26:21 +03:00
|
|
|
return m_internal;
|
2015-05-21 11:31:19 +03:00
|
|
|
}
|
|
|
|
|
2015-11-06 17:08:13 +03:00
|
|
|
bool ShellClient::isLockScreen() const
|
|
|
|
{
|
2017-03-23 23:40:51 +03:00
|
|
|
if (m_internalWindow) {
|
|
|
|
return m_internalWindow->property("org_kde_ksld_emergency").toBool();
|
|
|
|
}
|
2016-04-18 14:33:23 +03:00
|
|
|
return surface()->client() == waylandServer()->screenLockerClientConnection();
|
2015-11-06 17:08:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ShellClient::isInputMethod() const
|
|
|
|
{
|
2016-04-29 16:05:03 +03:00
|
|
|
if (m_internal && m_internalWindow) {
|
|
|
|
return m_internalWindow->property("__kwin_input_method").toBool();
|
|
|
|
}
|
2016-04-18 14:33:23 +03:00
|
|
|
return surface()->client() == waylandServer()->inputMethodConnection();
|
2015-11-06 17:08:13 +03:00
|
|
|
}
|
|
|
|
|
2015-05-19 13:03:53 +03:00
|
|
|
void ShellClient::requestGeometry(const QRect &rect)
|
|
|
|
{
|
2016-06-09 17:54:06 +03:00
|
|
|
if (m_requestGeometryBlockCounter != 0) {
|
|
|
|
m_blockedRequestGeometry = rect;
|
|
|
|
return;
|
|
|
|
}
|
2015-05-19 13:03:53 +03:00
|
|
|
m_positionAfterResize.setPoint(rect.topLeft());
|
2016-04-22 15:13:37 +03:00
|
|
|
const QSize size = rect.size() - QSize(borderLeft() + borderRight(), borderTop() + borderBottom());
|
2016-04-18 14:33:23 +03:00
|
|
|
if (m_shellSurface) {
|
2016-04-22 15:13:37 +03:00
|
|
|
m_shellSurface->requestSize(size);
|
|
|
|
}
|
|
|
|
if (m_xdgShellSurface) {
|
|
|
|
m_xdgShellSurface->configure(xdgSurfaceStates(), size);
|
2016-04-18 14:33:23 +03:00
|
|
|
}
|
2016-06-09 17:54:06 +03:00
|
|
|
m_blockedRequestGeometry = QRect();
|
2016-05-09 15:48:10 +03:00
|
|
|
if (m_internal) {
|
|
|
|
m_internalWindow->setGeometry(QRect(rect.topLeft() + QPoint(borderLeft(), borderTop()), rect.size() - QSize(borderLeft() + borderRight(), borderTop() + borderBottom())));
|
|
|
|
}
|
2015-05-19 13:03:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShellClient::clientFullScreenChanged(bool fullScreen)
|
|
|
|
{
|
2016-09-12 15:41:03 +03:00
|
|
|
RequestGeometryBlocker requestBlocker(this);
|
2015-05-19 13:03:53 +03:00
|
|
|
StackingUpdatesBlocker blocker(workspace());
|
|
|
|
|
2016-04-22 15:13:37 +03:00
|
|
|
const bool emitSignal = m_fullScreen != fullScreen;
|
|
|
|
m_fullScreen = fullScreen;
|
2016-09-12 15:41:03 +03:00
|
|
|
updateDecoration(false, false);
|
2016-04-22 15:13:37 +03:00
|
|
|
|
2016-09-13 11:33:28 +03:00
|
|
|
workspace()->updateClientLayer(this); // active fullscreens get different layer
|
|
|
|
|
2015-10-01 17:03:02 +03:00
|
|
|
if (fullScreen) {
|
2015-05-19 13:03:53 +03:00
|
|
|
m_geomFsRestore = geometry();
|
|
|
|
requestGeometry(workspace()->clientArea(FullScreenArea, this));
|
|
|
|
workspace()->raiseClient(this);
|
|
|
|
} else {
|
|
|
|
if (m_geomFsRestore.isValid()) {
|
|
|
|
requestGeometry(m_geomFsRestore);
|
|
|
|
} else {
|
|
|
|
requestGeometry(workspace()->clientArea(MaximizeArea, this));
|
|
|
|
}
|
|
|
|
}
|
2016-04-22 15:13:37 +03:00
|
|
|
if (emitSignal) {
|
2015-10-08 11:05:40 +03:00
|
|
|
emit fullScreenChanged();
|
|
|
|
}
|
2015-05-19 13:03:53 +03:00
|
|
|
}
|
|
|
|
|
2015-05-27 12:48:33 +03:00
|
|
|
void ShellClient::resizeWithChecks(int w, int h, ForceGeometry_t force)
|
|
|
|
{
|
|
|
|
Q_UNUSED(force)
|
|
|
|
QRect area = workspace()->clientArea(WorkArea, this);
|
|
|
|
// don't allow growing larger than workarea
|
|
|
|
if (w > area.width()) {
|
|
|
|
w = area.width();
|
|
|
|
}
|
|
|
|
if (h > area.height()) {
|
|
|
|
h = area.height();
|
|
|
|
}
|
2016-04-18 14:33:23 +03:00
|
|
|
if (m_shellSurface) {
|
|
|
|
m_shellSurface->requestSize(QSize(w, h));
|
|
|
|
}
|
2016-04-22 15:13:37 +03:00
|
|
|
if (m_xdgShellSurface) {
|
|
|
|
m_xdgShellSurface->configure(xdgSurfaceStates(), QSize(w, h));
|
|
|
|
}
|
2016-05-09 15:48:10 +03:00
|
|
|
if (m_internal) {
|
|
|
|
m_internalWindow->setGeometry(QRect(pos() + QPoint(borderLeft(), borderTop()), QSize(w, h) - QSize(borderLeft() + borderRight(), borderTop() + borderBottom())));
|
|
|
|
}
|
2015-05-27 12:48:33 +03:00
|
|
|
}
|
|
|
|
|
2015-06-03 22:19:00 +03:00
|
|
|
void ShellClient::unmap()
|
|
|
|
{
|
|
|
|
m_unmapped = true;
|
2015-07-09 10:10:33 +03:00
|
|
|
destroyWindowManagementInterface();
|
2015-10-22 12:42:52 +03:00
|
|
|
if (Workspace::self()) {
|
|
|
|
addWorkspaceRepaint(visibleRect());
|
|
|
|
workspace()->clientHidden(this);
|
|
|
|
}
|
2015-06-10 18:45:59 +03:00
|
|
|
emit windowHidden(this);
|
2015-06-03 22:19:00 +03:00
|
|
|
}
|
|
|
|
|
2015-06-09 20:10:56 +03:00
|
|
|
void ShellClient::installPlasmaShellSurface(PlasmaShellSurfaceInterface *surface)
|
|
|
|
{
|
|
|
|
m_plasmaShellSurface = surface;
|
|
|
|
auto updatePosition = [this, surface] {
|
2015-12-17 17:47:36 +03:00
|
|
|
doSetGeometry(QRect(surface->position(), m_clientSize + QSize(borderLeft() + borderRight(), borderTop() + borderBottom())));
|
2015-06-09 20:10:56 +03:00
|
|
|
};
|
|
|
|
auto updateRole = [this, surface] {
|
|
|
|
NET::WindowType type = NET::Unknown;
|
|
|
|
switch (surface->role()) {
|
|
|
|
case PlasmaShellSurfaceInterface::Role::Desktop:
|
|
|
|
type = NET::Desktop;
|
|
|
|
break;
|
|
|
|
case PlasmaShellSurfaceInterface::Role::Panel:
|
|
|
|
type = NET::Dock;
|
|
|
|
break;
|
2015-09-03 19:19:38 +03:00
|
|
|
case PlasmaShellSurfaceInterface::Role::OnScreenDisplay:
|
|
|
|
type = NET::OnScreenDisplay;
|
|
|
|
break;
|
2016-06-17 10:46:16 +03:00
|
|
|
case PlasmaShellSurfaceInterface::Role::Notification:
|
|
|
|
type = NET::Notification;
|
|
|
|
break;
|
2016-06-28 14:25:15 +03:00
|
|
|
case PlasmaShellSurfaceInterface::Role::ToolTip:
|
|
|
|
type = NET::Tooltip;
|
|
|
|
break;
|
2015-06-09 20:10:56 +03:00
|
|
|
case PlasmaShellSurfaceInterface::Role::Normal:
|
|
|
|
default:
|
|
|
|
type = NET::Normal;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (type != m_windowType) {
|
|
|
|
m_windowType = type;
|
2016-06-28 14:25:15 +03:00
|
|
|
if (m_windowType == NET::Desktop || type == NET::Dock || type == NET::OnScreenDisplay || type == NET::Notification || type == NET::Tooltip) {
|
2016-06-02 18:53:44 +03:00
|
|
|
setOnAllDesktops(true);
|
|
|
|
}
|
2015-06-09 20:10:56 +03:00
|
|
|
workspace()->updateClientArea();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
connect(surface, &PlasmaShellSurfaceInterface::positionChanged, this, updatePosition);
|
|
|
|
connect(surface, &PlasmaShellSurfaceInterface::roleChanged, this, updateRole);
|
2015-06-25 10:04:51 +03:00
|
|
|
connect(surface, &PlasmaShellSurfaceInterface::panelBehaviorChanged, this,
|
2016-09-15 22:03:40 +03:00
|
|
|
[this] {
|
|
|
|
updateShowOnScreenEdge();
|
2015-06-25 10:04:51 +03:00
|
|
|
workspace()->updateClientArea();
|
|
|
|
}
|
|
|
|
);
|
2016-10-17 12:17:48 +03:00
|
|
|
connect(surface, &PlasmaShellSurfaceInterface::panelAutoHideHideRequested, this,
|
|
|
|
[this] {
|
|
|
|
hideClient(true);
|
|
|
|
m_plasmaShellSurface->hideAutoHidingPanel();
|
|
|
|
updateShowOnScreenEdge();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(surface, &PlasmaShellSurfaceInterface::panelAutoHideShowRequested, this,
|
|
|
|
[this] {
|
|
|
|
hideClient(false);
|
|
|
|
ScreenEdges::self()->reserve(this, ElectricNone);
|
|
|
|
m_plasmaShellSurface->showAutoHidingPanel();
|
|
|
|
}
|
|
|
|
);
|
2015-06-09 20:10:56 +03:00
|
|
|
updatePosition();
|
|
|
|
updateRole();
|
2016-09-15 22:03:40 +03:00
|
|
|
updateShowOnScreenEdge();
|
|
|
|
connect(this, &ShellClient::geometryChanged, this, &ShellClient::updateShowOnScreenEdge);
|
2015-09-29 21:25:04 +03:00
|
|
|
|
|
|
|
setSkipTaskbar(surface->skipTaskbar());
|
|
|
|
connect(surface, &PlasmaShellSurfaceInterface::skipTaskbarChanged, this, [this] {
|
|
|
|
setSkipTaskbar(m_plasmaShellSurface->skipTaskbar());
|
|
|
|
});
|
2015-06-09 20:10:56 +03:00
|
|
|
}
|
|
|
|
|
2016-09-15 22:03:40 +03:00
|
|
|
void ShellClient::updateShowOnScreenEdge()
|
|
|
|
{
|
|
|
|
if (!ScreenEdges::self()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (m_unmapped || !m_plasmaShellSurface || m_plasmaShellSurface->role() != PlasmaShellSurfaceInterface::Role::Panel) {
|
|
|
|
ScreenEdges::self()->reserve(this, ElectricNone);
|
|
|
|
return;
|
|
|
|
}
|
2016-10-17 12:17:48 +03:00
|
|
|
if ((m_plasmaShellSurface->panelBehavior() == PlasmaShellSurfaceInterface::PanelBehavior::AutoHide && m_hidden) ||
|
2016-09-15 22:03:40 +03:00
|
|
|
m_plasmaShellSurface->panelBehavior() == PlasmaShellSurfaceInterface::PanelBehavior::WindowsCanCover) {
|
|
|
|
// screen edge API requires an edge, thus we need to figure out which edge the window borders
|
|
|
|
Qt::Edges edges;
|
|
|
|
for (int i = 0; i < screens()->count(); i++) {
|
|
|
|
const auto &screenGeo = screens()->geometry(i);
|
|
|
|
if (screenGeo.x() == geom.x()) {
|
|
|
|
edges |= Qt::LeftEdge;
|
|
|
|
}
|
|
|
|
if (screenGeo.x() + screenGeo.width() == geom.x() + geom.width()) {
|
|
|
|
edges |= Qt::RightEdge;
|
|
|
|
}
|
|
|
|
if (screenGeo.y() == geom.y()) {
|
|
|
|
edges |= Qt::TopEdge;
|
|
|
|
}
|
|
|
|
if (screenGeo.y() + screenGeo.height() == geom.y() + geom.height()) {
|
|
|
|
edges |= Qt::BottomEdge;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// a panel might border multiple screen edges. E.g. a horizontal panel at the bottom will
|
|
|
|
// also border the left and right edge
|
|
|
|
// let's remove such cases
|
|
|
|
if (edges.testFlag(Qt::LeftEdge) && edges.testFlag(Qt::RightEdge)) {
|
|
|
|
edges = edges & (~(Qt::LeftEdge | Qt::RightEdge));
|
|
|
|
}
|
|
|
|
if (edges.testFlag(Qt::TopEdge) && edges.testFlag(Qt::BottomEdge)) {
|
|
|
|
edges = edges & (~(Qt::TopEdge | Qt::BottomEdge));
|
|
|
|
}
|
|
|
|
// it's still possible that a panel borders two edges, e.g. bottom and left
|
|
|
|
// in that case the one which is sharing more with the edge wins
|
|
|
|
auto check = [this](Qt::Edges edges, Qt::Edge horiz, Qt::Edge vert) {
|
|
|
|
if (edges.testFlag(horiz) && edges.testFlag(vert)) {
|
|
|
|
if (geom.width() >= geom.height()) {
|
|
|
|
return edges & ~horiz;
|
|
|
|
} else {
|
|
|
|
return edges & ~vert;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return edges;
|
|
|
|
};
|
|
|
|
edges = check(edges, Qt::LeftEdge, Qt::TopEdge);
|
|
|
|
edges = check(edges, Qt::LeftEdge, Qt::BottomEdge);
|
|
|
|
edges = check(edges, Qt::RightEdge, Qt::TopEdge);
|
|
|
|
edges = check(edges, Qt::RightEdge, Qt::BottomEdge);
|
|
|
|
|
|
|
|
ElectricBorder border = ElectricNone;
|
|
|
|
if (edges.testFlag(Qt::LeftEdge)) {
|
|
|
|
border = ElectricLeft;
|
|
|
|
}
|
|
|
|
if (edges.testFlag(Qt::RightEdge)) {
|
|
|
|
border = ElectricRight;
|
|
|
|
}
|
|
|
|
if (edges.testFlag(Qt::TopEdge)) {
|
|
|
|
border = ElectricTop;
|
|
|
|
}
|
|
|
|
if (edges.testFlag(Qt::BottomEdge)) {
|
|
|
|
border = ElectricBottom;
|
|
|
|
}
|
|
|
|
ScreenEdges::self()->reserve(this, border);
|
|
|
|
} else {
|
|
|
|
ScreenEdges::self()->reserve(this, ElectricNone);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-09 20:10:56 +03:00
|
|
|
bool ShellClient::isInitialPositionSet() const
|
|
|
|
{
|
|
|
|
if (m_plasmaShellSurface) {
|
|
|
|
return m_plasmaShellSurface->isPositionSet();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-06-10 01:59:53 +03:00
|
|
|
void ShellClient::installQtExtendedSurface(QtExtendedSurfaceInterface *surface)
|
|
|
|
{
|
|
|
|
m_qtExtendedSurface = surface;
|
2015-09-16 17:36:26 +03:00
|
|
|
|
2015-09-28 15:09:10 +03:00
|
|
|
connect(m_qtExtendedSurface.data(), &QtExtendedSurfaceInterface::raiseRequested, this, [this]() {
|
2015-09-16 17:36:26 +03:00
|
|
|
workspace()->raiseClientRequest(this);
|
|
|
|
});
|
2015-09-28 15:09:10 +03:00
|
|
|
connect(m_qtExtendedSurface.data(), &QtExtendedSurfaceInterface::lowerRequested, this, [this]() {
|
2015-09-16 17:36:26 +03:00
|
|
|
workspace()->lowerClientRequest(this);
|
|
|
|
});
|
2016-10-13 10:35:32 +03:00
|
|
|
m_qtExtendedSurface->installEventFilter(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ShellClient::eventFilter(QObject *watched, QEvent *event)
|
|
|
|
{
|
|
|
|
if (watched == m_qtExtendedSurface.data() && event->type() == QEvent::DynamicPropertyChange) {
|
|
|
|
QDynamicPropertyChangeEvent *pe = static_cast<QDynamicPropertyChangeEvent*>(event);
|
|
|
|
if (pe->propertyName() == s_schemePropertyName) {
|
|
|
|
updateColorScheme(rules()->checkDecoColor(m_qtExtendedSurface->property(pe->propertyName().constData()).toString()));
|
2017-01-11 12:21:03 +03:00
|
|
|
} else if (pe->propertyName() == s_appMenuServiceNamePropertyName) {
|
|
|
|
updateApplicationMenuServiceName(m_qtExtendedSurface->property(pe->propertyName().constData()).toString());
|
|
|
|
} else if (pe->propertyName() == s_appMenuObjectPathPropertyName) {
|
|
|
|
updateApplicationMenuObjectPath(m_qtExtendedSurface->property(pe->propertyName().constData()).toString());
|
2016-10-13 10:35:32 +03:00
|
|
|
}
|
|
|
|
}
|
2017-01-11 22:00:40 +03:00
|
|
|
if (watched == m_internalWindow && event->type() == QEvent::DynamicPropertyChange) {
|
|
|
|
QDynamicPropertyChangeEvent *pe = static_cast<QDynamicPropertyChangeEvent*>(event);
|
|
|
|
if (pe->propertyName() == s_skipClosePropertyName) {
|
|
|
|
setSkipCloseAnimation(m_internalWindow->property(s_skipClosePropertyName).toBool());
|
|
|
|
}
|
|
|
|
}
|
2016-10-13 10:35:32 +03:00
|
|
|
return false;
|
2015-06-10 01:59:53 +03:00
|
|
|
}
|
|
|
|
|
2015-06-20 01:14:49 +03:00
|
|
|
bool ShellClient::hasStrut() const
|
|
|
|
{
|
|
|
|
if (!isShown(true)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!m_plasmaShellSurface) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (m_plasmaShellSurface->role() != PlasmaShellSurfaceInterface::Role::Panel) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-09-15 15:17:48 +03:00
|
|
|
return m_plasmaShellSurface->panelBehavior() == PlasmaShellSurfaceInterface::PanelBehavior::AlwaysVisible;
|
2015-06-20 01:14:49 +03:00
|
|
|
}
|
|
|
|
|
2015-06-20 02:11:42 +03:00
|
|
|
void ShellClient::updateIcon()
|
|
|
|
{
|
2016-10-11 17:32:47 +03:00
|
|
|
const QString waylandIconName = QStringLiteral("wayland");
|
2016-10-27 16:59:08 +03:00
|
|
|
const QString dfIconName = iconFromDesktopFile();
|
|
|
|
const QString iconName = dfIconName.isEmpty() ? waylandIconName : dfIconName;
|
|
|
|
if (iconName == icon().name()) {
|
|
|
|
return;
|
2015-07-15 18:18:39 +03:00
|
|
|
}
|
2016-10-27 16:59:08 +03:00
|
|
|
setIcon(QIcon::fromTheme(iconName));
|
2015-06-20 02:11:42 +03:00
|
|
|
}
|
|
|
|
|
2015-09-11 13:11:01 +03:00
|
|
|
bool ShellClient::isTransient() const
|
|
|
|
{
|
2015-10-08 12:04:06 +03:00
|
|
|
return m_transient;
|
2015-09-11 13:11:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShellClient::setTransient()
|
|
|
|
{
|
2016-04-18 14:33:23 +03:00
|
|
|
SurfaceInterface *s = nullptr;
|
|
|
|
if (m_shellSurface) {
|
|
|
|
s = m_shellSurface->transientFor().data();
|
|
|
|
}
|
2016-04-22 15:13:37 +03:00
|
|
|
if (m_xdgShellSurface) {
|
|
|
|
if (auto transient = m_xdgShellSurface->transientFor().data()) {
|
|
|
|
s = transient->surface();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (m_xdgShellPopup) {
|
|
|
|
s = m_xdgShellPopup->transientFor().data();
|
|
|
|
}
|
2016-04-18 14:33:23 +03:00
|
|
|
auto t = waylandServer()->findClient(s);
|
2015-10-01 15:12:46 +03:00
|
|
|
if (t != transientFor()) {
|
|
|
|
// remove from main client
|
|
|
|
if (transientFor())
|
|
|
|
transientFor()->removeTransient(this);
|
|
|
|
setTransientFor(t);
|
|
|
|
if (t) {
|
|
|
|
t->addTransient(this);
|
|
|
|
}
|
|
|
|
}
|
2016-04-18 14:33:23 +03:00
|
|
|
m_transient = (s != nullptr);
|
2015-09-11 13:11:01 +03:00
|
|
|
}
|
|
|
|
|
2015-09-11 14:31:41 +03:00
|
|
|
bool ShellClient::hasTransientPlacementHint() const
|
|
|
|
{
|
|
|
|
return isTransient() && transientFor() != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
QPoint ShellClient::transientPlacementHint() const
|
|
|
|
{
|
2016-04-18 14:33:23 +03:00
|
|
|
if (m_shellSurface) {
|
|
|
|
return m_shellSurface->transientOffset();
|
|
|
|
}
|
2016-04-22 15:13:37 +03:00
|
|
|
if (m_xdgShellPopup) {
|
|
|
|
return m_xdgShellPopup->transientOffset();
|
|
|
|
}
|
2016-04-18 14:33:23 +03:00
|
|
|
return QPoint();
|
2015-09-11 14:31:41 +03:00
|
|
|
}
|
|
|
|
|
2015-10-28 13:16:48 +03:00
|
|
|
bool ShellClient::isWaitingForMoveResizeSync() const
|
|
|
|
{
|
|
|
|
return m_positionAfterResize.isValid();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShellClient::doResizeSync()
|
|
|
|
{
|
|
|
|
requestGeometry(moveResizeGeometry());
|
|
|
|
}
|
|
|
|
|
2015-12-07 16:27:06 +03:00
|
|
|
QMatrix4x4 ShellClient::inputTransformation() const
|
|
|
|
{
|
|
|
|
QMatrix4x4 m = Toplevel::inputTransformation();
|
|
|
|
m.translate(-borderLeft(), -borderTop());
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
2015-12-17 13:14:54 +03:00
|
|
|
void ShellClient::installServerSideDecoration(KWayland::Server::ServerSideDecorationInterface *deco)
|
|
|
|
{
|
|
|
|
if (m_serverDecoration == deco) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_serverDecoration = deco;
|
|
|
|
connect(m_serverDecoration, &ServerSideDecorationInterface::destroyed, this,
|
|
|
|
[this] {
|
|
|
|
m_serverDecoration = nullptr;
|
2016-05-19 17:37:59 +03:00
|
|
|
if (m_closing || !Workspace::self()) {
|
2016-02-12 16:15:51 +03:00
|
|
|
return;
|
|
|
|
}
|
2016-05-19 17:37:59 +03:00
|
|
|
if (!m_unmapped) {
|
|
|
|
// maybe delay to next event cycle in case the ShellClient is getting destroyed, too
|
|
|
|
updateDecoration(true);
|
|
|
|
}
|
2015-12-17 13:14:54 +03:00
|
|
|
}
|
|
|
|
);
|
2015-12-17 17:47:36 +03:00
|
|
|
if (!m_unmapped) {
|
|
|
|
updateDecoration(true);
|
|
|
|
}
|
2015-12-17 13:14:54 +03:00
|
|
|
connect(m_serverDecoration, &ServerSideDecorationInterface::modeRequested, this,
|
|
|
|
[this] (ServerSideDecorationManagerInterface::Mode mode) {
|
|
|
|
const bool changed = mode != m_serverDecoration->mode();
|
|
|
|
// always acknowledge the requested mode
|
|
|
|
m_serverDecoration->setMode(mode);
|
2015-12-17 17:47:36 +03:00
|
|
|
if (changed && !m_unmapped) {
|
|
|
|
updateDecoration(false);
|
2015-12-17 13:14:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-06-03 14:37:24 +03:00
|
|
|
bool ShellClient::shouldExposeToWindowManagement()
|
|
|
|
{
|
|
|
|
if (isInternal()) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-06-03 16:27:36 +03:00
|
|
|
if (isLockScreen()) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-06-03 14:37:24 +03:00
|
|
|
if (m_shellSurface) {
|
|
|
|
if (m_shellSurface->isTransient() && !m_shellSurface->acceptsKeyboardFocus()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-22 15:13:37 +03:00
|
|
|
KWayland::Server::XdgShellSurfaceInterface::States ShellClient::xdgSurfaceStates() const
|
|
|
|
{
|
|
|
|
XdgShellSurfaceInterface::States states;
|
|
|
|
if (isActive()) {
|
|
|
|
states |= XdgShellSurfaceInterface::State::Activated;
|
|
|
|
}
|
|
|
|
if (isFullScreen()) {
|
|
|
|
states |= XdgShellSurfaceInterface::State::Fullscreen;
|
|
|
|
}
|
|
|
|
if (maximizeMode() == MaximizeMode::MaximizeFull) {
|
|
|
|
states |= XdgShellSurfaceInterface::State::Maximized;
|
|
|
|
}
|
|
|
|
if (isResize()) {
|
|
|
|
states |= XdgShellSurfaceInterface::State::Resizing;
|
|
|
|
}
|
|
|
|
return states;
|
|
|
|
}
|
|
|
|
|
2016-08-11 18:32:39 +03:00
|
|
|
void ShellClient::doMinimize()
|
|
|
|
{
|
2016-08-18 11:30:27 +03:00
|
|
|
if (isMinimized()) {
|
|
|
|
workspace()->clientHidden(this);
|
|
|
|
} else {
|
|
|
|
emit windowShown(this);
|
|
|
|
}
|
2016-08-11 18:32:39 +03:00
|
|
|
}
|
|
|
|
|
2016-08-19 13:33:59 +03:00
|
|
|
bool ShellClient::setupCompositing()
|
|
|
|
{
|
|
|
|
if (m_compositingSetup) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
m_compositingSetup = Toplevel::setupCompositing();
|
|
|
|
return m_compositingSetup;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShellClient::finishCompositing(ReleaseReason releaseReason)
|
|
|
|
{
|
|
|
|
m_compositingSetup = false;
|
|
|
|
Toplevel::finishCompositing(releaseReason);
|
|
|
|
}
|
|
|
|
|
2016-08-30 14:16:52 +03:00
|
|
|
void ShellClient::placeIn(QRect &area)
|
|
|
|
{
|
|
|
|
Placement::self()->place(this, area);
|
|
|
|
setGeometryRestore(geometry());
|
|
|
|
}
|
|
|
|
|
2016-09-15 22:03:40 +03:00
|
|
|
void ShellClient::showOnScreenEdge()
|
|
|
|
{
|
|
|
|
if (!m_plasmaShellSurface || m_unmapped) {
|
|
|
|
return;
|
|
|
|
}
|
2016-10-17 12:17:48 +03:00
|
|
|
hideClient(false);
|
2016-09-15 22:03:40 +03:00
|
|
|
workspace()->raiseClient(this);
|
2016-10-17 12:17:48 +03:00
|
|
|
if (m_plasmaShellSurface->panelBehavior() == PlasmaShellSurfaceInterface::PanelBehavior::AutoHide) {
|
|
|
|
m_plasmaShellSurface->showAutoHidingPanel();
|
|
|
|
}
|
2016-09-15 22:03:40 +03:00
|
|
|
}
|
|
|
|
|
2016-10-12 16:09:52 +03:00
|
|
|
bool ShellClient::dockWantsInput() const
|
|
|
|
{
|
|
|
|
if (m_plasmaShellSurface) {
|
|
|
|
if (m_plasmaShellSurface->role() == PlasmaShellSurfaceInterface::Role::Panel) {
|
|
|
|
return m_plasmaShellSurface->panelTakesFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-15 18:48:20 +03:00
|
|
|
void ShellClient::killWindow()
|
|
|
|
{
|
|
|
|
if (isInternal()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!surface()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto c = surface()->client();
|
|
|
|
if (c->processId() == getpid()) {
|
|
|
|
c->destroy();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
::kill(c->processId(), SIGTERM);
|
|
|
|
// give it time to terminate and only if terminate fails, try destroy Wayland connection
|
|
|
|
QTimer::singleShot(5000, c, &ClientConnection::destroy);
|
|
|
|
}
|
|
|
|
|
2017-01-11 12:21:03 +03:00
|
|
|
void ShellClient::updateApplicationMenu()
|
|
|
|
{
|
|
|
|
if (m_qtExtendedSurface) {
|
|
|
|
updateApplicationMenuServiceName(m_qtExtendedSurface->property(s_appMenuObjectPathPropertyName).toString());
|
|
|
|
updateApplicationMenuObjectPath(m_qtExtendedSurface->property(s_appMenuServiceNamePropertyName).toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-25 20:41:28 +03:00
|
|
|
bool ShellClient::hasPopupGrab() const
|
|
|
|
{
|
|
|
|
if (m_shellSurface) {
|
|
|
|
// TODO: verify grab serial
|
|
|
|
return m_shellSurface->isPopup();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShellClient::popupDone()
|
|
|
|
{
|
|
|
|
if (m_shellSurface) {
|
|
|
|
m_shellSurface->popupDone();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-04 11:21:10 +03:00
|
|
|
}
|