23static const int s_lineWidth = 4;
24static const QColor s_lineColor = QColor(128, 128, 128, 128);
26static QRegion computeDirtyRegion(
const QRectF &windowRect)
28 const QMargins outlineMargins(
37 for (Output *screen : screens) {
40 QRectF screenWindowRect = windowRect;
41 screenWindowRect.moveCenter(screenRect.center());
43 QRectF verticalBarRect(0, 0, s_lineWidth, screenRect.height());
44 verticalBarRect.moveCenter(screenRect.center());
45 verticalBarRect.adjust(-1, -1, 1, 1);
46 dirtyRegion += verticalBarRect.toAlignedRect();
48 QRectF horizontalBarRect(0, 0, screenRect.width(), s_lineWidth);
49 horizontalBarRect.moveCenter(screenRect.center());
50 horizontalBarRect.adjust(-1, -1, 1, 1);
51 dirtyRegion += horizontalBarRect.toAlignedRect();
53 const QRectF outlineOuterRect = screenWindowRect
54 .marginsAdded(outlineMargins)
55 .adjusted(-1, -1, 1, 1);
56 const QRectF outlineInnerRect = screenWindowRect
57 .marginsRemoved(outlineMargins)
58 .adjusted(1, 1, -1, -1);
59 dirtyRegion += QRegion(outlineOuterRect.toRect()) - QRegion(outlineInnerRect.toRect());
74 slotWindowAdded(window);
85 std::chrono::milliseconds(
static_cast<int>(
animationTime(250))));
90 if (m_animation.active) {
91 m_animation.timeLine.
advance(presentTime);
101 const qreal opacityFactor = m_animation.active
102 ? m_animation.timeLine.
value()
106 const auto scale = viewport.
scale();
116 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
118 QColor color = s_lineColor;
119 color.setAlphaF(color.alphaF() * opacityFactor);
122 glLineWidth(s_lineWidth);
123 QList<QVector2D> verts;
124 verts.reserve(screens.count() * 24);
125 for (
Output *screen : screens) {
127 const int midX = rect.x() + rect.width() / 2;
128 const int midY = rect.y() + rect.height() / 2;
129 const int halfWidth = m_geometry.width() / 2;
130 const int halfHeight = m_geometry.height() / 2;
133 verts.push_back(QVector2D((rect.x() + rect.width() / 2) * scale, rect.y() * scale));
134 verts.push_back(QVector2D((rect.x() + rect.width() / 2) * scale, (rect.y() + rect.height()) * scale));
137 verts.push_back(QVector2D(rect.x() * scale, (rect.y() + rect.height() / 2) * scale));
138 verts.push_back(QVector2D((rect.x() + rect.width()) * scale, (rect.y() + rect.height() / 2) * scale));
141 verts.push_back(QVector2D((midX - halfWidth - s_lineWidth / 2) * scale, (midY - halfHeight) * scale));
142 verts.push_back(QVector2D((midX + halfWidth + s_lineWidth / 2) * scale, (midY - halfHeight) * scale));
145 verts.push_back(QVector2D((midX + halfWidth) * scale, (midY - halfHeight + s_lineWidth / 2) * scale));
146 verts.push_back(QVector2D((midX + halfWidth) * scale, (midY + halfHeight - s_lineWidth / 2) * scale));
149 verts.push_back(QVector2D((midX + halfWidth + s_lineWidth / 2) * scale, (midY + halfHeight) * scale));
150 verts.push_back(QVector2D((midX - halfWidth - s_lineWidth / 2) * scale, (midY + halfHeight) * scale));
153 verts.push_back(QVector2D((midX - halfWidth) * scale, (midY + halfHeight - s_lineWidth / 2) * scale));
154 verts.push_back(QVector2D((midX - halfWidth) * scale, (midY - halfHeight + s_lineWidth / 2) * scale));
164 QColor color = s_lineColor;
165 color.setAlphaF(color.alphaF() * opacityFactor);
167 pen.setWidth(s_lineWidth);
168 painter->setPen(pen);
169 painter->setBrush(Qt::NoBrush);
171 for (
Output *screen : screens) {
174 painter->drawLine(rect.center().x(), rect.y(), rect.center().x(), rect.y() + rect.height());
175 painter->drawLine(rect.x(), rect.center().y(), rect.x() + rect.width(), rect.center().y());
178 QRectF outlineRect(0, 0, m_geometry.width(), m_geometry.height());
179 outlineRect.moveCenter(rect.center());
180 painter->drawRect(outlineRect);
188 if (m_animation.active) {
192 if (m_animation.timeLine.
done()) {
193 m_animation.active =
false;
206void SnapHelperEffect::slotWindowClosed(EffectWindow *w)
214 m_animation.active =
true;
217 if (m_animation.timeLine.
done()) {
218 m_animation.timeLine.
reset();
224void SnapHelperEffect::slotWindowStartUserMovedResized(EffectWindow *w)
226 if (!w->isMovable()) {
231 m_geometry = w->frameGeometry();
233 m_animation.active =
true;
236 if (m_animation.timeLine.
done()) {
237 m_animation.timeLine.
reset();
243void SnapHelperEffect::slotWindowFinishUserMovedResized(EffectWindow *w)
250 m_geometry = w->frameGeometry();
252 m_animation.active =
true;
255 if (m_animation.timeLine.
done()) {
256 m_animation.timeLine.
reset();
262void SnapHelperEffect::slotWindowFrameGeometryChanged(EffectWindow *w,
const QRectF &old)
268 m_geometry = w->frameGeometry();
275 return m_window !=
nullptr || m_animation.active;
280#include "moc_snaphelper.cpp"
Representation of a window used by/for Effect classes.
void windowStartUserMovedResized(KWin::EffectWindow *w)
void windowFrameGeometryChanged(KWin::EffectWindow *window, const QRectF &oldGeometry)
void windowFinishUserMovedResized(KWin::EffectWindow *w)
void windowClosed(KWin::EffectWindow *w)
void paintScreen(const RenderTarget &renderTarget, const RenderViewport &viewport, int mask, const QRegion ®ion, Output *screen)
QList< EffectWindow * > stackingOrder
Q_SCRIPTABLE void addRepaint(const QRectF &r)
CompositingType compositingType
KWin::VirtualDesktop * currentDesktop
void prePaintScreen(ScreenPrePaintData &data, std::chrono::milliseconds presentTime)
QList< Output * > screens() const
bool isOpenGLCompositing() const
Whether the Compositor is OpenGL based (either GL 1 or 2).
QRectF clientArea(clientAreaOption, const Output *screen, const VirtualDesktop *desktop) const
void windowAdded(KWin::EffectWindow *w)
QPainter * scenePainter()
Provides access to the QPainter which is rendering to the back buffer.
bool setColorspaceUniformsFromSRGB(const ColorDescription &dst)
@ ModelViewProjectionMatrix
bool setUniform(const char *name, float value)
static GLVertexBuffer * streamingBuffer()
void render(GLenum primitiveMode)
void setVertices(const T &range)
const ColorDescription & colorDescription() const
QMatrix4x4 projectionMatrix() const
void prePaintScreen(ScreenPrePaintData &data, std::chrono::milliseconds presentTime) override
void reconfigure(ReconfigureFlags flags) override
bool isActive() const override
void postPaintScreen() override
~SnapHelperEffect() override
void paintScreen(const RenderTarget &renderTarget, const RenderViewport &viewport, int mask, const QRegion ®ion, Output *screen) override
void advance(std::chrono::milliseconds timestamp)
void setDuration(std::chrono::milliseconds duration)
void setDirection(Direction direction)
static double animationTime(const KConfigGroup &cfg, const QString &key, int defaultTime)