Changeset View
Changeset View
Standalone View
Standalone View
plugins/platforms/x11/standalone/x11_decoration_renderer.cpp
- This file was copied from decorations/decorationrenderer.cpp.
Show All 11 Lines | |||||
12 | This program is distributed in the hope that it will be useful, | 12 | This program is distributed in the hope that it will be useful, | ||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | GNU General Public License for more details. | 15 | GNU General Public License for more details. | ||
16 | 16 | | |||
17 | You should have received a copy of the GNU General Public License | 17 | You should have received a copy of the GNU General Public License | ||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | *********************************************************************/ | 19 | *********************************************************************/ | ||
20 | #include "decorationrenderer.h" | 20 | #include "x11_decoration_renderer.h" | ||
21 | #include "decoratedclient.h" | 21 | #include "decorations/decoratedclient.h" | ||
22 | #include "client.h" | 22 | #include "client.h" | ||
23 | #include "deleted.h" | 23 | #include "deleted.h" | ||
24 | 24 | | |||
25 | #include <kwinglobals.h> | 25 | #include <kwinglobals.h> | ||
26 | 26 | | |||
27 | #include <KDecoration2/Decoration> | 27 | #include <KDecoration2/Decoration> | ||
28 | #include <KDecoration2/DecoratedClient> | 28 | #include <KDecoration2/DecoratedClient> | ||
29 | 29 | | |||
30 | #include <QDebug> | | |||
31 | #include <QPainter> | | |||
32 | #include <QTimer> | 30 | #include <QTimer> | ||
33 | 31 | | |||
34 | namespace KWin | 32 | namespace KWin | ||
35 | { | 33 | { | ||
36 | namespace Decoration | 34 | namespace Decoration | ||
37 | { | 35 | { | ||
38 | 36 | | |||
39 | Renderer::Renderer(DecoratedClientImpl *client) | | |||
40 | : QObject(client) | | |||
41 | , m_client(client) | | |||
42 | , m_imageSizesDirty(true) | | |||
43 | { | | |||
44 | auto markImageSizesDirty = [this]{ m_imageSizesDirty = true; }; | | |||
45 | connect(client->decoration(), &KDecoration2::Decoration::bordersChanged, this, markImageSizesDirty); | | |||
46 | connect(client->decoratedClient(), &KDecoration2::DecoratedClient::widthChanged, this, markImageSizesDirty); | | |||
47 | connect(client->decoratedClient(), &KDecoration2::DecoratedClient::heightChanged, this, markImageSizesDirty); | | |||
48 | } | | |||
49 | | ||||
50 | Renderer::~Renderer() = default; | | |||
51 | | ||||
52 | void Renderer::schedule(const QRect &rect) | | |||
53 | { | | |||
54 | m_scheduled = m_scheduled.united(rect); | | |||
55 | emit renderScheduled(rect); | | |||
56 | } | | |||
57 | | ||||
58 | QRegion Renderer::getScheduled() | | |||
59 | { | | |||
60 | QRegion region = m_scheduled; | | |||
61 | m_scheduled = QRegion(); | | |||
62 | return region; | | |||
63 | } | | |||
64 | | ||||
65 | QImage Renderer::renderToImage(const QRect &geo) | | |||
66 | { | | |||
67 | Q_ASSERT(m_client); | | |||
68 | QImage image(geo.width(), geo.height(), QImage::Format_ARGB32_Premultiplied); | | |||
69 | image.fill(Qt::transparent); | | |||
70 | QPainter p(&image); | | |||
71 | p.setRenderHint(QPainter::Antialiasing); | | |||
72 | p.setWindow(geo); | | |||
73 | p.setClipRect(geo); | | |||
74 | client()->decoration()->paint(&p, geo); | | |||
75 | return image; | | |||
76 | } | | |||
77 | | ||||
78 | void Renderer::reparent(Deleted *deleted) | | |||
79 | { | | |||
80 | setParent(deleted); | | |||
81 | m_client = nullptr; | | |||
82 | } | | |||
83 | | ||||
84 | X11Renderer::X11Renderer(DecoratedClientImpl *client) | 37 | X11Renderer::X11Renderer(DecoratedClientImpl *client) | ||
85 | : Renderer(client) | 38 | : Renderer(client) | ||
86 | , m_scheduleTimer(new QTimer(this)) | 39 | , m_scheduleTimer(new QTimer(this)) | ||
87 | , m_gc(XCB_NONE) | 40 | , m_gc(XCB_NONE) | ||
88 | { | 41 | { | ||
89 | // delay any rendering to end of event cycle to catch multiple updates per cycle | 42 | // delay any rendering to end of event cycle to catch multiple updates per cycle | ||
90 | m_scheduleTimer->setSingleShot(true); | 43 | m_scheduleTimer->setSingleShot(true); | ||
91 | m_scheduleTimer->setInterval(0); | 44 | m_scheduleTimer->setInterval(0); | ||
▲ Show 20 Lines • Show All 65 Lines • Show Last 20 Lines |