2015-08-14 14:52:40 +00: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 "window.h"
|
2019-06-29 00:01:07 +00:00
|
|
|
#include "integration.h"
|
2019-01-11 22:48:04 +00:00
|
|
|
#include "screens.h"
|
2015-08-14 14:52:40 +00:00
|
|
|
#include "../../shell_client.h"
|
|
|
|
#include "../../wayland_server.h"
|
2016-07-18 14:34:03 +00:00
|
|
|
#include <logging.h>
|
2015-08-14 14:52:40 +00:00
|
|
|
|
|
|
|
#include <QOpenGLFramebufferObject>
|
2016-05-09 12:48:10 +00:00
|
|
|
#include <qpa/qwindowsysteminterface.h>
|
2015-08-14 14:52:40 +00:00
|
|
|
|
|
|
|
#include <KWayland/Client/buffer.h>
|
|
|
|
#include <KWayland/Client/connection_thread.h>
|
|
|
|
#include <KWayland/Client/shell.h>
|
|
|
|
#include <KWayland/Client/surface.h>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
namespace QPA
|
|
|
|
{
|
|
|
|
static quint32 s_windowId = 0;
|
|
|
|
|
|
|
|
Window::Window(QWindow *window, KWayland::Client::Surface *surface, KWayland::Client::ShellSurface *shellSurface, const Integration *integration)
|
|
|
|
: QPlatformWindow(window)
|
|
|
|
, m_surface(surface)
|
|
|
|
, m_shellSurface(shellSurface)
|
|
|
|
, m_windowId(++s_windowId)
|
|
|
|
, m_integration(integration)
|
2019-01-11 22:48:04 +00:00
|
|
|
, m_scale(screens()->maxScale())
|
2015-08-14 14:52:40 +00:00
|
|
|
{
|
2019-01-11 22:48:04 +00:00
|
|
|
m_surface->setScale(m_scale);
|
|
|
|
|
2015-11-10 10:35:00 +00:00
|
|
|
QObject::connect(m_surface, &QObject::destroyed, window, [this] { m_surface = nullptr;});
|
|
|
|
QObject::connect(m_shellSurface, &QObject::destroyed, window, [this] { m_shellSurface = nullptr;});
|
2015-08-14 14:52:40 +00:00
|
|
|
waylandServer()->internalClientConection()->flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
Window::~Window()
|
|
|
|
{
|
|
|
|
unmap();
|
|
|
|
delete m_shellSurface;
|
|
|
|
delete m_surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
WId Window::winId() const
|
|
|
|
{
|
|
|
|
return m_windowId;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::setVisible(bool visible)
|
|
|
|
{
|
|
|
|
if (!visible) {
|
|
|
|
unmap();
|
|
|
|
}
|
|
|
|
QPlatformWindow::setVisible(visible);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::setGeometry(const QRect &rect)
|
|
|
|
{
|
|
|
|
const QRect &oldRect = geometry();
|
|
|
|
QPlatformWindow::setGeometry(rect);
|
|
|
|
if (rect.x() != oldRect.x()) {
|
|
|
|
emit window()->xChanged(rect.x());
|
|
|
|
}
|
|
|
|
if (rect.y() != oldRect.y()) {
|
|
|
|
emit window()->yChanged(rect.y());
|
|
|
|
}
|
|
|
|
if (rect.width() != oldRect.width()) {
|
|
|
|
emit window()->widthChanged(rect.width());
|
|
|
|
}
|
|
|
|
if (rect.height() != oldRect.height()) {
|
|
|
|
emit window()->heightChanged(rect.height());
|
|
|
|
}
|
2019-01-11 22:48:04 +00:00
|
|
|
|
|
|
|
const QSize nativeSize = rect.size() * m_scale;
|
|
|
|
|
2015-08-14 14:52:40 +00:00
|
|
|
if (m_contentFBO) {
|
2019-01-11 22:48:04 +00:00
|
|
|
if (m_contentFBO->size() != nativeSize) {
|
2015-08-14 14:52:40 +00:00
|
|
|
m_resized = true;
|
|
|
|
}
|
|
|
|
}
|
2016-05-09 12:48:10 +00:00
|
|
|
QWindowSystemInterface::handleGeometryChange(window(), geometry());
|
2015-08-14 14:52:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Window::unmap()
|
|
|
|
{
|
|
|
|
if (m_shellClient) {
|
|
|
|
m_shellClient->setInternalFramebufferObject(QSharedPointer<QOpenGLFramebufferObject>());
|
|
|
|
}
|
2015-11-10 10:35:00 +00:00
|
|
|
if (m_surface) {
|
|
|
|
m_surface->attachBuffer(KWayland::Client::Buffer::Ptr());
|
|
|
|
m_surface->commit(KWayland::Client::Surface::CommitFlag::None);
|
|
|
|
}
|
2015-11-10 07:52:40 +00:00
|
|
|
if (waylandServer()->internalClientConection()) {
|
|
|
|
waylandServer()->internalClientConection()->flush();
|
|
|
|
}
|
2015-08-14 14:52:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Window::bindContentFBO()
|
|
|
|
{
|
|
|
|
if (m_resized || !m_contentFBO) {
|
|
|
|
createFBO();
|
|
|
|
}
|
|
|
|
m_contentFBO->bind();
|
|
|
|
}
|
|
|
|
|
|
|
|
QSharedPointer<QOpenGLFramebufferObject> Window::swapFBO()
|
|
|
|
{
|
|
|
|
auto fbo = m_contentFBO;
|
|
|
|
m_contentFBO.clear();
|
2019-01-08 15:51:47 +00:00
|
|
|
m_surface->commit(KWayland::Client::Surface::CommitFlag::None);
|
2015-08-14 14:52:40 +00:00
|
|
|
return fbo;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::createFBO()
|
|
|
|
{
|
|
|
|
const QRect &r = geometry();
|
2017-04-13 19:23:40 +00:00
|
|
|
if (m_contentFBO && r.size().isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
2019-01-11 22:48:04 +00:00
|
|
|
const QSize nativeSize = r.size() * m_scale;
|
|
|
|
m_contentFBO.reset(new QOpenGLFramebufferObject(nativeSize.width(), nativeSize.height(), QOpenGLFramebufferObject::CombinedDepthStencil));
|
2016-07-18 14:34:03 +00:00
|
|
|
if (!m_contentFBO->isValid()) {
|
|
|
|
qCWarning(KWIN_QPA) << "Content FBO is not valid";
|
|
|
|
}
|
2015-08-14 14:52:40 +00:00
|
|
|
m_resized = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ShellClient *Window::shellClient()
|
|
|
|
{
|
|
|
|
if (!m_shellClient) {
|
2015-08-20 12:05:55 +00:00
|
|
|
waylandServer()->dispatch();
|
2015-08-14 14:52:40 +00:00
|
|
|
m_shellClient = waylandServer()->findClient(window());
|
|
|
|
}
|
|
|
|
return m_shellClient;
|
|
|
|
}
|
|
|
|
|
2019-01-11 22:48:04 +00:00
|
|
|
int Window::scale() const
|
|
|
|
{
|
|
|
|
return m_scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal Window::devicePixelRatio() const
|
|
|
|
{
|
|
|
|
return m_scale;
|
|
|
|
}
|
|
|
|
|
2015-08-14 14:52:40 +00:00
|
|
|
}
|
|
|
|
}
|