File indexing completed on 2025-03-16 11:23:05
0001 /* 0002 * SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@blue-systems.com> 0003 * 0004 * SPDX-License-Identifier: LGPL-3.0-or-later 0005 */ 0006 0007 #include "window.h" 0008 #include <layershellqt_logging.h> 0009 0010 #include <QPointer> 0011 #include <optional> 0012 0013 using namespace LayerShellQt; 0014 0015 class LayerShellQt::WindowPrivate 0016 { 0017 public: 0018 WindowPrivate(QWindow *window) 0019 : parentWindow(window) 0020 { 0021 } 0022 0023 QWindow *parentWindow; 0024 QString scope = QStringLiteral("window"); 0025 Window::Anchors anchors = {Window::AnchorTop | Window::AnchorBottom | Window::AnchorLeft | Window::AnchorRight}; 0026 int32_t exclusionZone = 0; 0027 Window::KeyboardInteractivity keyboardInteractivity = Window::KeyboardInteractivityExclusive; 0028 Window::Layer layer = Window::LayerTop; 0029 QMargins margins; 0030 std::optional<QPointer<QScreen>> desiredOutput; 0031 }; 0032 0033 static QMap<QWindow *, Window *> s_map; 0034 0035 Window::~Window() 0036 { 0037 s_map.remove(d->parentWindow); 0038 } 0039 0040 void Window::setAnchors(Anchors anchors) 0041 { 0042 d->anchors = anchors; 0043 Q_EMIT anchorsChanged(); 0044 } 0045 0046 Window::Anchors Window::anchors() const 0047 { 0048 return d->anchors; 0049 } 0050 0051 void Window::setExclusiveZone(int32_t zone) 0052 { 0053 d->exclusionZone = zone; 0054 Q_EMIT exclusionZoneChanged(); 0055 } 0056 0057 int32_t Window::exclusionZone() const 0058 { 0059 return d->exclusionZone; 0060 } 0061 0062 void Window::setMargins(const QMargins &margins) 0063 { 0064 d->margins = margins; 0065 Q_EMIT marginsChanged(); 0066 } 0067 0068 QMargins Window::margins() const 0069 { 0070 return d->margins; 0071 } 0072 0073 void Window::setKeyboardInteractivity(KeyboardInteractivity interactivity) 0074 { 0075 d->keyboardInteractivity = interactivity; 0076 Q_EMIT keyboardInteractivityChanged(); 0077 } 0078 0079 Window::KeyboardInteractivity Window::keyboardInteractivity() const 0080 { 0081 return d->keyboardInteractivity; 0082 } 0083 0084 void Window::setLayer(Layer layer) 0085 { 0086 d->layer = layer; 0087 } 0088 0089 void Window::setScope(const QString &scope) 0090 { 0091 d->scope = scope; 0092 // this is static and must be set before the platform window is created 0093 } 0094 0095 QString Window::scope() const 0096 { 0097 return d->scope; 0098 } 0099 0100 Window::Layer Window::layer() const 0101 { 0102 return d->layer; 0103 } 0104 0105 QScreen *Window::desiredOutput() const 0106 { 0107 // Don't use .value_or here to avoid a temporary QPointer 0108 if (d->desiredOutput.has_value()) { 0109 return d->desiredOutput.value(); 0110 } 0111 0112 return d->parentWindow->screen(); 0113 } 0114 0115 void Window::setDesiredOutput(QScreen *output) 0116 { 0117 d->desiredOutput = output; 0118 } 0119 0120 Window::Window(QWindow *window) 0121 : QObject(window) 0122 , d(new WindowPrivate(window)) 0123 { 0124 s_map.insert(d->parentWindow, this); 0125 } 0126 0127 Window *Window::get(QWindow *window) 0128 { 0129 auto layerShellWindow = s_map.value(window); 0130 if (layerShellWindow) { 0131 return layerShellWindow; 0132 } 0133 return new Window(window); 0134 }