Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwaylandxdgtopleveliconv1.cpp
Go to the documentation of this file.
1// Copyright (C) 2024 David Reondo <kde@david-redondo.de>
2// Copyright (C) 2024 David Edmundson <davidedmundson@kde.org>
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#include "client/qwaylandshmbackingstore_p.h"
7
8#include <QtWaylandClient/private/qwaylandshmbackingstore_p.h>
9
10#include <QIcon>
11#include <QDir>
12#include <QPainter>
13
15
16namespace QtWaylandClient {
17
19{
20public:
21 QWaylandXdgToplevelIconV1(::xdg_toplevel_icon_v1 *object, QWaylandDisplay *display)
22 : QtWayland::xdg_toplevel_icon_v1(object), mDisplay(display)
23 {
24 }
25
27 destroy();
28 }
29
30 void addPixmap(const QPixmap &pixmap)
31 {
32 const QSize squareSize = pixmap.size().expandedTo(pixmap.size().transposed());
33 auto buffer = std::make_unique<QWaylandShmBuffer>(mDisplay, squareSize, QImage::Format_ARGB32, pixmap.devicePixelRatio());
34 QRect targetRect = pixmap.rect();
35 targetRect.moveCenter(buffer->image()->rect().center());
36 QPainter painter(buffer->image());
37 painter.drawPixmap(targetRect, pixmap, pixmap.rect());
38 add_buffer(buffer->buffer(), buffer->scale());
39 mBuffers.push_back(std::move(buffer));
40 }
41
42private:
43 QWaylandDisplay *mDisplay;
45};
46
48 wl_registry *registry,
49 uint32_t id, int version)
51{
52}
53
58
60{
61 mPreferredSizes.push_back(size);
62}
63
65
66void QWaylandXdgToplevelIconManagerV1::setIcon(const QIcon &icon, xdg_toplevel *window)
67{
68 if (icon.isNull()) {
69 set_icon(window, nullptr);
70 return;
71 }
72
73 auto toplevelIcon = std::make_unique<QWaylandXdgToplevelIconV1>(create_icon(), mDisplay);
74
75 if (const QString name = icon.name(); !name.isEmpty() && !QDir::isAbsolutePath(name)) {
76 toplevelIcon->set_name(name);
77 }
78
79 QList<QSize> iconSizes = icon.availableSizes();
80 // if icon has no default size (an SVG)
81 if (iconSizes.isEmpty()) {
82 iconSizes.reserve(mPreferredSizes.size());
83 for (int size : std::as_const(mPreferredSizes)) {
84 iconSizes.append(QSize(size, size));
85 }
86 }
87 // if the compositor hasn't sent a preferred size
88 if (iconSizes.isEmpty()) {
89 iconSizes.append(QSize(64, 64));
90 }
91
92 for (const QSize &size : std::as_const(iconSizes)) {
93 const QPixmap pixmap = icon.pixmap(size, 1.0);
94 toplevelIcon->addPixmap(pixmap);
95 }
96
97 set_icon(window, toplevelIcon->object());
98}
99
100} // namespace QtWaylandClient
101
102QT_END_NAMESPACE
void setIcon(const QIcon &icon, ::xdg_toplevel *window)
QWaylandXdgToplevelIconManagerV1(QWaylandDisplay *display, wl_registry *registry, uint32_t id, int version)
QWaylandXdgToplevelIconV1(::xdg_toplevel_icon_v1 *object, QWaylandDisplay *display)
Combined button and popup list for selecting options.