MauiKit Controls

linux/blurhelper/windowblur.cpp
1/*
2 * Copyright (C) 2021 CutefishOS Team.
3 *
4 * Author: cutefish <cutefishos@foxmail.com>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "windowblur.h"
21
22#include <QApplication>
23#include <QPainterPath>
24#include <QScreen>
25
26#include <xcb/xcb.h>
27#include <xcb/shape.h>
28#include <xcb/xcb_icccm.h>
29#include <KWindowSystem>
30#include <KWindowEffects>
31#include "style.h"
32
33WindowBlur::WindowBlur(QObject *parent) noexcept
34: QObject(parent)
35, m_view(nullptr)
36, m_enabled(false)
37, m_windowRadius(0.0)
38{
39}
40
41WindowBlur::~WindowBlur()
42{
43}
44
45void WindowBlur::classBegin()
46{
47}
48
49void WindowBlur::componentComplete()
50{
51 Style::instance()->setTranslucencyAvailable(m_enabled);
52 updateBlur();
53}
54
55void WindowBlur::setView(QWindow *view)
56{
57 if (view != m_view) {
58 m_view = view;
59 updateBlur();
60 Q_EMIT viewChanged();
61
62 connect(m_view, &QWindow::visibleChanged, this, &WindowBlur::onViewVisibleChanged);
63 }
64}
65
66QWindow* WindowBlur::view() const
67{
68 return m_view;
69}
70
71void WindowBlur::setGeometry(const QRect &rect)
72{
73 if (rect != m_rect) {
74 m_rect = rect;
75
76
77 updateBlur();
78
79 Q_EMIT geometryChanged();
80 }
81}
82
83QRect WindowBlur::geometry() const
84{
85 return m_rect;
86}
87
88void WindowBlur::setEnabled(bool enabled)
89{
90 if (enabled != m_enabled) {
91 m_enabled = enabled;
92 updateBlur();
93 Q_EMIT enabledChanged();
94 }
95}
96
97bool WindowBlur::enabled() const
98{
99 return m_enabled;
100}
101
102void WindowBlur::setWindowRadius(qreal radius)
103{
104 if (radius != m_windowRadius) {
105 m_windowRadius = radius;
106
107 updateBlur();
108
109 Q_EMIT windowRadiusChanged();
110 }
111}
112
113qreal WindowBlur::windowRadius() const
114{
115 return m_windowRadius;
116}
117
118void WindowBlur::onViewVisibleChanged(bool visible)
119{
120 if (visible)
121 updateBlur();
122}
123
124void WindowBlur::updateBlur()
125{
126 if (!m_view)
127 return;
128
130 {
131 qDebug() << "SETTING BLURRED WINDOW BG WAYLAND KDE;" << m_enabled << m_view;
132 KWindowEffects::enableBlurBehind(m_view, m_enabled, m_rect);
134 }
135}
static bool isPlatformWayland()
void enableBlurBehind(QWindow *window, bool enable=true, const QRegion &region=QRegion())
void enableBackgroundContrast(QWindow *window, bool enable=true, qreal contrast=1, qreal intensity=1, qreal saturation=1, const QRegion &region=QRegion())
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void visibleChanged(bool arg)
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri May 2 2025 11:57:11 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.