Move EffectWindowImpl ownership to WindowItem

EffectWindowImpl affects rather the WindowItem, so move its ownership to
it. This encapsulates compositing setup so it's effectively same as
creating a window item, except some annoyances on X11.
master
Vlad Zahorodnii 1 year ago
parent f7045cbf96
commit 6974f54149

@ -1739,9 +1739,9 @@ EffectScreen::Transform EffectScreenImpl::transform() const
// EffectWindowImpl
//****************************************
EffectWindowImpl::EffectWindowImpl(Window *window)
: m_window(window)
, m_windowItem(nullptr)
EffectWindowImpl::EffectWindowImpl(WindowItem *windowItem)
: m_window(windowItem->window())
, m_windowItem(windowItem)
{
// Deleted windows are not managed. So, when windowClosed signal is
// emitted, effects can't distinguish managed windows from unmanaged
@ -1750,74 +1750,74 @@ EffectWindowImpl::EffectWindowImpl(Window *window)
// parent can be Client, XdgShellClient, or Unmanaged. So, later on, when
// an instance of Deleted becomes parent of the EffectWindow, effects
// can still figure out whether it is/was a managed window.
managed = window->isClient();
managed = m_window->isClient();
m_waylandWindow = qobject_cast<KWin::WaylandWindow *>(window) != nullptr;
m_x11Window = qobject_cast<KWin::X11Window *>(window) != nullptr;
m_waylandWindow = qobject_cast<KWin::WaylandWindow *>(m_window) != nullptr;
m_x11Window = qobject_cast<KWin::X11Window *>(m_window) != nullptr;
connect(window, &Window::windowShown, this, [this]() {
connect(m_window, &Window::windowShown, this, [this]() {
Q_EMIT windowShown(this);
});
connect(window, &Window::windowHidden, this, [this]() {
connect(m_window, &Window::windowHidden, this, [this]() {
Q_EMIT windowHidden(this);
});
connect(window, &Window::maximizedChanged, this, [this, window]() {
const MaximizeMode mode = window->maximizeMode();
connect(m_window, &Window::maximizedChanged, this, [this]() {
const MaximizeMode mode = m_window->maximizeMode();
Q_EMIT windowMaximizedStateChanged(this, mode & MaximizeHorizontal, mode & MaximizeVertical);
});
connect(window, &Window::maximizedAboutToChange, this, [this](MaximizeMode m) {
connect(m_window, &Window::maximizedAboutToChange, this, [this](MaximizeMode m) {
Q_EMIT windowMaximizedStateAboutToChange(this, m & MaximizeHorizontal, m & MaximizeVertical);
});
connect(window, &Window::frameGeometryAboutToChange, this, [this]() {
connect(m_window, &Window::frameGeometryAboutToChange, this, [this]() {
Q_EMIT windowFrameGeometryAboutToChange(this);
});
connect(window, &Window::interactiveMoveResizeStarted, this, [this]() {
connect(m_window, &Window::interactiveMoveResizeStarted, this, [this]() {
Q_EMIT windowStartUserMovedResized(this);
});
connect(window, &Window::interactiveMoveResizeStepped, this, [this](const QRectF &geometry) {
connect(m_window, &Window::interactiveMoveResizeStepped, this, [this](const QRectF &geometry) {
Q_EMIT windowStepUserMovedResized(this, geometry);
});
connect(window, &Window::interactiveMoveResizeFinished, this, [this]() {
connect(m_window, &Window::interactiveMoveResizeFinished, this, [this]() {
Q_EMIT windowFinishUserMovedResized(this);
});
connect(window, &Window::opacityChanged, this, [this](Window *window, qreal oldOpacity) {
connect(m_window, &Window::opacityChanged, this, [this](Window *window, qreal oldOpacity) {
Q_EMIT windowOpacityChanged(this, oldOpacity, window->opacity());
});
connect(window, &Window::minimizedChanged, this, [this, window]() {
if (window->isMinimized()) {
connect(m_window, &Window::minimizedChanged, this, [this]() {
if (m_window->isMinimized()) {
Q_EMIT windowMinimized(this);
} else {
Q_EMIT windowUnminimized(this);
}
});
connect(window, &Window::modalChanged, this, [this]() {
connect(m_window, &Window::modalChanged, this, [this]() {
Q_EMIT windowModalityChanged(this);
});
connect(window, &Window::frameGeometryChanged, this, [this](const QRectF &oldGeometry) {
connect(m_window, &Window::frameGeometryChanged, this, [this](const QRectF &oldGeometry) {
Q_EMIT windowFrameGeometryChanged(this, oldGeometry);
});
connect(window, &Window::damaged, this, [this]() {
connect(m_window, &Window::damaged, this, [this]() {
Q_EMIT windowDamaged(this);
});
connect(window, &Window::unresponsiveChanged, this, [this](bool unresponsive) {
connect(m_window, &Window::unresponsiveChanged, this, [this](bool unresponsive) {
Q_EMIT windowUnresponsiveChanged(this, unresponsive);
});
connect(window, &Window::keepAboveChanged, this, [this]() {
connect(m_window, &Window::keepAboveChanged, this, [this]() {
Q_EMIT windowKeepAboveChanged(this);
});
connect(window, &Window::keepBelowChanged, this, [this]() {
connect(m_window, &Window::keepBelowChanged, this, [this]() {
Q_EMIT windowKeepBelowChanged(this);
});
connect(window, &Window::fullScreenChanged, this, [this]() {
connect(m_window, &Window::fullScreenChanged, this, [this]() {
Q_EMIT windowFullScreenChanged(this);
});
connect(window, &Window::visibleGeometryChanged, this, [this]() {
connect(m_window, &Window::visibleGeometryChanged, this, [this]() {
Q_EMIT windowExpandedGeometryChanged(this);
});
connect(window, &Window::decorationChanged, this, [this]() {
connect(m_window, &Window::decorationChanged, this, [this]() {
Q_EMIT windowDecorationChanged(this);
});
connect(window, &Window::desktopsChanged, this, [this]() {
connect(m_window, &Window::desktopsChanged, this, [this]() {
Q_EMIT windowDesktopsChanged(this);
});
}
@ -1989,11 +1989,6 @@ QSizeF EffectWindowImpl::basicUnit() const
return QSize(1, 1);
}
void EffectWindowImpl::setWindowItem(WindowItem *item)
{
m_windowItem = item;
}
QRectF EffectWindowImpl::decorationInnerRect() const
{
return m_window->rect() - m_window->frameMargins();

@ -352,7 +352,7 @@ class EffectWindowImpl : public EffectWindow
{
Q_OBJECT
public:
explicit EffectWindowImpl(Window *window);
explicit EffectWindowImpl(WindowItem *windowItem);
~EffectWindowImpl() override;
void addRepaint(const QRect &r) override;
@ -462,7 +462,6 @@ public:
const Window *window() const;
Window *window();
void setWindowItem(WindowItem *item); // internal
WindowItem *windowItem() const; // internal
void elevate(bool elevate);

@ -5,6 +5,7 @@
*/
#include "scene/windowitem.h"
#include "effects.h"
#include "internalwindow.h"
#include "scene/decorationitem.h"
#include "scene/shadowitem.h"
@ -53,6 +54,8 @@ WindowItem::WindowItem(Window *window, Scene *scene, Item *parent)
connect(window, &Window::stackingOrderChanged, this, &WindowItem::updateStackingOrder);
updateStackingOrder();
m_effectWindow = std::make_unique<EffectWindowImpl>(this);
}
WindowItem::~WindowItem()
@ -79,6 +82,11 @@ Window *WindowItem::window() const
return m_window;
}
EffectWindowImpl *WindowItem::effectWindow() const
{
return m_effectWindow.get();
}
void WindowItem::refVisible(int reason)
{
if (reason & PAINT_DISABLED_BY_HIDDEN) {

@ -17,6 +17,7 @@ namespace KWin
{
class Window;
class DecorationItem;
class EffectWindowImpl;
class InternalWindow;
class Shadow;
class ShadowItem;
@ -47,6 +48,7 @@ public:
DecorationItem *decorationItem() const;
ShadowItem *shadowItem() const;
Window *window() const;
EffectWindowImpl *effectWindow() const;
void refVisible(int reason);
void unrefVisible(int reason);
@ -77,6 +79,7 @@ private:
std::unique_ptr<SurfaceItem> m_surfaceItem;
std::unique_ptr<DecorationItem> m_decorationItem;
std::unique_ptr<ShadowItem> m_shadowItem;
std::unique_ptr<EffectWindowImpl> m_effectWindow;
std::optional<int> m_elevation;
int m_forceVisibleByHiddenCount = 0;
int m_forceVisibleByDesktopCount = 0;

@ -292,7 +292,7 @@ void WorkspaceScene::preparePaintGenericScreen()
data.mask = m_paintContext.mask;
data.paint = infiniteRegion(); // no clipping, so doesn't really matter
effects->prePaintWindow(windowItem->window()->effectWindow(), data, m_expectedPresentTimestamp);
effects->prePaintWindow(windowItem->effectWindow(), data, m_expectedPresentTimestamp);
m_paintContext.phase2Data.append(Phase2Data{
.item = windowItem,
.region = infiniteRegion(),
@ -325,7 +325,7 @@ void WorkspaceScene::preparePaintSimpleScreen()
}
}
effects->prePaintWindow(window->effectWindow(), data, m_expectedPresentTimestamp);
effects->prePaintWindow(windowItem->effectWindow(), data, m_expectedPresentTimestamp);
m_paintContext.phase2Data.append(Phase2Data{
.item = windowItem,
.region = data.paint,
@ -352,7 +352,7 @@ void WorkspaceScene::preparePaintSimpleScreen()
void WorkspaceScene::postPaint()
{
for (WindowItem *w : std::as_const(stacking_order)) {
effects->postPaintWindow(w->window()->effectWindow());
effects->postPaintWindow(w->effectWindow());
}
effects->postPaintScreen();
@ -459,7 +459,7 @@ void WorkspaceScene::paintWindow(const RenderTarget &renderTarget, const RenderV
}
WindowPaintData data(viewport.projectionMatrix());
effects->paintWindow(renderTarget, viewport, item->window()->effectWindow(), mask, region, data);
effects->paintWindow(renderTarget, viewport, item->effectWindow(), mask, region, data);
}
// the function that'll be eventually called by paintWindow() above

@ -18,12 +18,12 @@
#include "core/output.h"
#include "decorations/decoratedclient.h"
#include "decorations/decorationpalette.h"
#include "effects.h"
#include "focuschain.h"
#include "input.h"
#include "outline.h"
#include "placement.h"
#include "scene/windowitem.h"
#include "scene/workspacescene.h"
#include "screenedge.h"
#include "shadow.h"
#if KWIN_BUILD_TABBOX
@ -211,11 +211,8 @@ bool Window::setupCompositing()
return false;
}
m_effectWindow = std::make_unique<EffectWindowImpl>(this);
m_windowItem = createItem(scene);
m_windowItem->setParentItem(scene->containerItem());
m_effectWindow->setWindowItem(m_windowItem.get());
connect(windowItem(), &WindowItem::positionChanged, this, &Window::visibleGeometryChanged);
connect(windowItem(), &WindowItem::boundingRectChanged, this, &Window::visibleGeometryChanged);
@ -225,7 +222,6 @@ bool Window::setupCompositing()
void Window::finishCompositing()
{
m_effectWindow.reset();
m_windowItem.reset();
}
@ -280,6 +276,16 @@ void Window::updateShadow()
}
}
EffectWindowImpl *Window::effectWindow()
{
return m_windowItem ? m_windowItem->effectWindow() : nullptr;
}
const EffectWindowImpl *Window::effectWindow() const
{
return m_windowItem ? m_windowItem->effectWindow() : nullptr;
}
SurfaceItem *Window::surfaceItem() const
{
if (m_windowItem) {
@ -305,10 +311,13 @@ bool Window::isUnmanaged() const
void Window::elevate(bool elevate)
{
if (!effectWindow()) {
return;
if (m_windowItem) {
if (elevate) {
m_windowItem->elevate();
} else {
m_windowItem->deelevate();
}
}
effectWindow()->elevate(elevate);
}
pid_t Window::pid() const

@ -1727,7 +1727,6 @@ protected:
int m_refCount = 1;
QUuid m_internalId;
std::unique_ptr<EffectWindowImpl> m_effectWindow;
std::unique_ptr<WindowItem> m_windowItem;
std::unique_ptr<Shadow> m_shadow;
QString resource_name;
@ -2021,16 +2020,6 @@ inline bool Window::isInternal() const
return false;
}
inline EffectWindowImpl *Window::effectWindow()
{
return m_effectWindow.get();
}
inline const EffectWindowImpl *Window::effectWindow() const
{
return m_effectWindow.get();
}
inline WindowItem *Window::windowItem() const
{
return m_windowItem.get();

Loading…
Cancel
Save