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
qwaylandcutouts.cpp
Go to the documentation of this file.
1// Copyright (C) 2026 Volker Krause <vkrause@kde.org>
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
6
7#include <QtCore/qdebug.h>
8
10
11namespace QtWaylandClient {
12
13Cutouts::Cutouts(::xx_cutouts_v1 *object, QWaylandWindow *window)
15 , m_window(window)
16{
17}
18
20{
21 destroy();
22}
23
24void Cutouts::xx_cutouts_v1_cutout_box(int32_t x, int32_t y, int32_t width, int32_t height, [[maybe_unused]] uint32_t type, [[maybe_unused]] uint32_t id)
25{
26 // compute the minimum screen area we would lose on each side, and pick the minimum one
27 // this produces optimal/expected results also for less-obvious cases like square cutouts towards
28 // a screen corner, but you can find a set of multiple cutouts where it wont, as it doesn't do
29 // a global optimization. That's not a practically relevant scenario so far though.
30 std::array<int32_t, 4> areas; // top, left, bottom, right
31 areas[0] = (y + height) * m_window->window()->width();
32 areas[1] = (x + width) * m_window->window()->height();
33 areas[2] = (m_window->window()->height() - y) * m_window->window()->width();
34 areas[3] = (m_window->window()->width() - x) * m_window->window()->height();
35 const auto minSide = std::distance(areas.begin(), std::min_element(areas.begin(), areas.end()));
36
37 switch (minSide) {
38 case 0:
39 m_margins.setTop(std::max(m_margins.top(), y + height));
40 break;
41 case 1:
42 m_margins.setLeft(std::max(m_margins.left(), x + width));
43 break;
44 case 2:
45 m_margins.setBottom(std::max(m_margins.bottom(), y));
46 break;
47 case 3:
48 m_margins.setRight(std::max(m_margins.right(), x));
49 break;
50 }
51}
52
53void Cutouts::xx_cutouts_v1_cutout_corner([[maybe_unused]] uint32_t position, [[maybe_unused]] uint32_t radius, uint32_t id)
54{
55 // corners are currently not considered as the impact on screen area
56 // loss is disproportianl to the risk of covering relevant application details.
57 // This matches behavior observed on Android.
58 // If we want to change this we should also do global optimziation over all cutouts,
59 // as a notch on one side can effectively cover corners already as well, reducing
60 // the amount of margin needed on their respective other sides.
61
62 m_unhandled.push_back(id);
63}
64
66{
67 m_window->setSafeAreaMargins(m_margins);
68 m_margins = {};
69
70 if (!m_unhandled.empty()) {
71 const auto data = QByteArray::fromRawData(reinterpret_cast<const char*>(m_unhandled.data()), sizeof(uint32_t) * m_unhandled.size());
72 set_unhandled(data);
73 m_unhandled.clear();
74 }
75}
76
77} // namespace QtWaylandClient
78
79QT_END_NAMESPACE
void xx_cutouts_v1_configure() override
void xx_cutouts_v1_cutout_corner(uint32_t position, uint32_t radius, uint32_t id) override
Cutouts(::xx_cutouts_v1 *object, QWaylandWindow *window)
void xx_cutouts_v1_cutout_box(int32_t x, int32_t y, int32_t width, int32_t height, uint32_t type, uint32_t id) override
Combined button and popup list for selecting options.