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
qwaylandadwaitadecoration_p.h
Go to the documentation of this file.
1// Copyright (C) 2023 Jan Grulich <jgrulich@redhat.com>
2// Copyright (C) 2023 The Qt Company Ltd.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4// Qt-Security score:significant reason:default
5
6#ifndef QWAYLANDADWAITADECORATION_P_H
7#define QWAYLANDADWAITADECORATION_P_H
8
9#include <QtWaylandClient/private/qwaylandabstractdecoration_p.h>
10
11#include <QtGui/qcolor.h>
12#include <QtGui/qfont.h>
13#include <QtGui/qstatictext.h>
14
15#include <QtCore/QDateTime>
16#include <QtCore/qflags.h>
17#include <QtCore/qmap.h>
18#include <QtCore/qpoint.h>
19#include <QtCore/qstring.h>
20
21#include <memory>
22
23QT_BEGIN_NAMESPACE
24
25class QDBusVariant;
26class QPainter;
27
28namespace QtWaylandClient {
29
30//
31// INFO
32// -------------
33//
34// This is a Qt decoration plugin implementing Adwaita-like (GNOME) client-side
35// window decorations. It uses xdg-desktop-portal to get the user configuration.
36// This plugin was originally part of QGnomePlatform and later made a separate
37// project named QAdwaitaDecorations.
38//
39// INFO: How SVG icons are used here?
40// We try to find an SVG icon for a particular button from the current icon theme.
41// This icon is then opened as a file, it's content saved and later loaded to be
42// painted with QSvgRenderer, but before it's painted, we try to find following
43// patterns:
44// 1) fill=[\"']#[0-9A-F]{6}[\"']
45// 2) fill:#[0-9A-F]{6}
46// 3) fill=[\"']currentColor[\"']
47// The color in this case doesn't match the theme and is replaced by Foreground color.
48//
49// FIXME/TODO:
50// This plugin currently have all the colors for the decorations hardcoded.
51// There might be a way to get these from GTK/libadwaita (not sure), but problem is
52// we want Gtk4 version and using Gtk4 together with QGtk3Theme from QtBase that links
53// to Gtk3 will not work out. Possibly in future we can make a QGtk4Theme providing us
54// what we need to paint the decorations without having to deal with the colors ourself.
55//
56// TODO: Implement shadows
57
58
60{
62public:
76
77 enum Placement {
78 Left = 0,
80 };
81
82 enum Button {
83 None = 0x0,
84 Close = 0x1,
85 Minimize = 0x02,
86 Maximize = 0x04
87 };
89
96
98 virtual ~QWaylandAdwaitaDecoration() = default;
99
100protected:
101 QMargins margins(MarginsType marginsType = Full) const override;
102 void paintTop(QPainter *painter) override;
103 void paintLeft(QPainter *painter) override;
104 void paintRight(QPainter *painter) override;
105 void paintBottom(QPainter *painter) override;
106 bool handleMouse(QWaylandInputDevice *inputDevice, const QPointF &local, const QPointF &global,
107 Qt::MouseButtons b, Qt::KeyboardModifiers mods) override;
108 bool handleTouch(QWaylandInputDevice *inputDevice, const QPointF &local, const QPointF &global,
109 QEventPoint::State state, Qt::KeyboardModifiers mods) override;
110
111private Q_SLOTS:
112 void settingChanged(const QString &group, const QString &key, const QDBusVariant &value);
113
114private:
115 // Makes a call to xdg-desktop-portal (Settings) to load initial configuration
116 void loadConfiguration();
117 // Updates color scheme from light to dark and vice-versa
118 void updateColors(bool isDark);
119 // Updates titlebar layout with position and button order
120 void updateTitlebarLayout(const QString &layout);
121
122 // Returns the rect of the full decorated surface, including shadows
123 QRect surfaceRect() const;
124 // Draws the window border and background, clipped to the given rect
125 void paintFrame(QPainter *painter, const QRect &clip);
126
127 // Returns a bounding rect for a given button type
128 QRectF buttonRect(Button button) const;
129 // Draw given button type using SVG icon (when found) or fallback to QPixmap icon
130 void drawButton(Button button, QPainter *painter);
131
132 // Returns color for given type and button
133 QColor color(ColorType type, Button button = None);
134
135 // Returns whether the left button was clicked i.e. pressed and released
136 bool clickButton(Qt::MouseButtons b, Button btn);
137 // Returns whether the left button was double-clicked
138 bool doubleClickButton(Qt::MouseButtons b, const QPointF &local, const QDateTime &currentTime);
139 // Updates button hover state
140 void updateButtonHoverState(Button hoveredButton);
141
142 void processMouseTop(QWaylandInputDevice *inputDevice, const QPointF &local, Qt::MouseButtons b,
143 Qt::KeyboardModifiers mods);
144 void processMouseBottom(QWaylandInputDevice *inputDevice, const QPointF &local,
145 Qt::MouseButtons b, Qt::KeyboardModifiers mods);
146 void processMouseLeft(QWaylandInputDevice *inputDevice, const QPointF &local,
147 Qt::MouseButtons b, Qt::KeyboardModifiers mods);
148 void processMouseRight(QWaylandInputDevice *inputDevice, const QPointF &local,
149 Qt::MouseButtons b, Qt::KeyboardModifiers mods);
150 // Request to repaint the decorations. This will be invoked when button hover changes or
151 // when there is a setting change (e.g. layout change).
152 void requestRepaint() const;
153
154 // Button states
155 Button m_clicking = None;
156 Buttons m_hoveredButtons = None;
157 QDateTime m_lastButtonClick;
158 QPointF m_lastButtonClickPosition;
159
160 // Configuration
161 QMap<Button, uint> m_buttons;
162 QMap<ColorType, QColor> m_colors;
163 QMap<ButtonIcon, QString> m_icons;
164 std::unique_ptr<QFont> m_font;
165 Placement m_placement = Right;
166
167 QStaticText m_windowTitle;
168};
169Q_DECLARE_OPERATORS_FOR_FLAGS(QWaylandAdwaitaDecoration::Buttons)
170
171} // namespace QtWaylandClient
172
173QT_END_NAMESPACE
174
175#endif // QWAYLANDADWAITADECORATION_P_H
friend class QPainter
bool handleMouse(QWaylandInputDevice *inputDevice, const QPointF &local, const QPointF &global, Qt::MouseButtons b, Qt::KeyboardModifiers mods) override
bool handleTouch(QWaylandInputDevice *inputDevice, const QPointF &local, const QPointF &global, QEventPoint::State state, Qt::KeyboardModifiers mods) override
QMargins margins(MarginsType marginsType=Full) const override
Combined button and popup list for selecting options.