Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
5#ifndef QWAYLANDADWAITADECORATION_P_H
6#define QWAYLANDADWAITADECORATION_P_H
7
8#include <QtWaylandClient/private/qwaylandabstractdecoration_p.h>
9
10#include <QtCore/QDateTime>
11
13
14class QDBusVariant;
15class QPainter;
16
17namespace QtWaylandClient {
18
19//
20// INFO
21// -------------
22//
23// This is a Qt decoration plugin implementing Adwaita-like (GNOME) client-side
24// window decorations. It uses xdg-desktop-portal to get the user configuration.
25// This plugin was originally part of QGnomePlatform and later made a separate
26// project named QAdwaitaDecorations.
27//
28// INFO: How SVG icons are used here?
29// We try to find an SVG icon for a particular button from the current icon theme.
30// This icon is then opened as a file, it's content saved and later loaded to be
31// painted with QSvgRenderer, but before it's painted, we try to find following
32// patterns:
33// 1) fill=[\"']#[0-9A-F]{6}[\"']
34// 2) fill:#[0-9A-F]{6}
35// 3) fill=[\"']currentColor[\"']
36// The color in this case doesn't match the theme and is replaced by Foreground color.
37//
38// FIXME/TODO:
39// This plugin currently have all the colors for the decorations hardcoded.
40// There might be a way to get these from GTK/libadwaita (not sure), but problem is
41// we want Gtk4 version and using Gtk4 together with QGtk3Theme from QtBase that links
42// to Gtk3 will not work out. Possibly in future we can make a QGtk4Theme providing us
43// what we need to paint the decorations without having to deal with the colors ourself.
44//
45// TODO: Implement shadows
46
47
49{
51public:
64
65 enum Placement {
66 Left = 0,
67 Right = 1
68 };
69
70 enum Button {
71 None = 0x0,
72 Close = 0x1,
73 Minimize = 0x02,
74 Maximize = 0x04
75 };
77
84
86 virtual ~QWaylandAdwaitaDecoration() = default;
87
88protected:
89 QMargins margins(MarginsType marginsType = Full) const override;
90 void paint(QPaintDevice *device) override;
91 bool handleMouse(QWaylandInputDevice *inputDevice, const QPointF &local, const QPointF &global,
92 Qt::MouseButtons b, Qt::KeyboardModifiers mods) override;
93 bool handleTouch(QWaylandInputDevice *inputDevice, const QPointF &local, const QPointF &global,
94 QEventPoint::State state, Qt::KeyboardModifiers mods) override;
95
96private Q_SLOTS:
97 void settingChanged(const QString &group, const QString &key, const QDBusVariant &value);
98
99private:
100 // Makes a call to xdg-desktop-portal (Settings) to load initial configuration
101 void loadConfiguration();
102 // Updates color scheme from light to dark and vice-versa
103 void updateColors(bool isDark);
104 // Updates titlebar layout with position and button order
105 void updateTitlebarLayout(const QString &layout);
106
107 // Returns a bounding rect for a given button type
108 QRectF buttonRect(Button button) const;
109 // Draw given button type using SVG icon (when found) or fallback to QPixmap icon
110 void drawButton(Button button, QPainter *painter);
111
112 // Returns color for given type and button
114
115 // Returns whether the left button was clicked i.e. pressed and released
116 bool clickButton(Qt::MouseButtons b, Button btn);
117 // Returns whether the left button was double-clicked
118 bool doubleClickButton(Qt::MouseButtons b, const QPointF &local, const QDateTime &currentTime);
119 // Updates button hover state
120 void updateButtonHoverState(Button hoveredButton);
121
122 void processMouseTop(QWaylandInputDevice *inputDevice, const QPointF &local, Qt::MouseButtons b,
123 Qt::KeyboardModifiers mods);
124 void processMouseBottom(QWaylandInputDevice *inputDevice, const QPointF &local,
125 Qt::MouseButtons b, Qt::KeyboardModifiers mods);
126 void processMouseLeft(QWaylandInputDevice *inputDevice, const QPointF &local,
127 Qt::MouseButtons b, Qt::KeyboardModifiers mods);
128 void processMouseRight(QWaylandInputDevice *inputDevice, const QPointF &local,
129 Qt::MouseButtons b, Qt::KeyboardModifiers mods);
130 // Request to repaint the decorations. This will be invoked when button hover changes or
131 // when there is a setting change (e.g. layout change).
132 void requestRepaint() const;
133
134 // Button states
135 Button m_clicking = None;
136 Buttons m_hoveredButtons = None;
137 QDateTime m_lastButtonClick;
138 QPointF m_lastButtonClickPosition;
139
140 // Configuration
141 QMap<Button, uint> m_buttons;
142 QMap<ColorType, QColor> m_colors;
143 QMap<ButtonIcon, QString> m_icons;
144 std::unique_ptr<QFont> m_font;
145 Placement m_placement = Right;
146
147 QStaticText m_windowTitle;
148};
149Q_DECLARE_OPERATORS_FOR_FLAGS(QWaylandAdwaitaDecoration::Buttons)
150
151} // namespace QtWaylandClient
152
154
155#endif // QWAYLANDADWAITADECORATION_P_H
IOBluetoothDevice * device
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
\inmodule QtDBus
\inmodule QtCore\reentrant
Definition qdatetime.h:283
State
Specifies the state of this event point.
Definition qeventpoint.h:48
\inmodule QtCore
Definition qmargins.h:24
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
\inmodule QtCore\reentrant
Definition qpoint.h:217
\inmodule QtCore\reentrant
Definition qrect.h:484
The QStaticText class enables optimized drawing of text when the text and its layout is updated rarel...
Definition qstatictext.h:21
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
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
QPainter paint
QPushButton * button
[2]
else opt state
[0]
const QStyleOptionButton * btn
[3]
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
Definition qflags.h:194
GLboolean GLboolean GLboolean b
GLuint64 key
GLuint color
[2]
GLenum type
GLboolean GLuint group
#define Q_OBJECT
#define Q_SLOTS
static double currentTime()
QVBoxLayout * layout
QPainter painter(this)
[7]
QJSValue global