|
11 | 11 | #include <QGuiApplication> |
12 | 12 | #include <QLoggingCategory> |
13 | 13 |
|
14 | | -#include <private/qhighdpiscaling_p.h> |
15 | | -#include <qpa/qplatformscreen.h> |
16 | | -#include <qpa/qplatformscreen_p.h> |
17 | 14 | #include <qpa/qplatformwindow.h> |
18 | 15 | #include <qpa/qplatformwindow_p.h> |
19 | 16 |
|
@@ -110,72 +107,42 @@ void LayerShellEmulation::onLayerChanged() |
110 | 107 |
|
111 | 108 | void LayerShellEmulation::onPositionChanged() |
112 | 109 | { |
113 | | - // Work around QPA abstraction so we can use physical pixels, not logical pixels after Qt DPI transformation |
114 | | - auto platformScreen = m_window->screen()->handle(); |
115 | | - qreal factor = QHighDpiScaling::factor(platformScreen); |
116 | | - |
117 | | - // These geometries are in physical pixels |
118 | | - auto windowGeometry = m_window->handle()->geometry(); |
119 | | - auto screenGeom = platformScreen->geometry(); |
120 | | - |
121 | 110 | auto anchors = m_dlayerShellWindow->anchors(); |
122 | | - auto x = screenGeom.left() + (screenGeom.width() - windowGeometry.width()) / 2; |
123 | | - auto y = screenGeom.top() + (screenGeom.height() - windowGeometry.height()) / 2; |
124 | | - |
125 | | - // Set |
| 111 | + auto screen = m_window->screen(); |
| 112 | + auto screenRect = screen->geometry(); |
| 113 | + auto x = screenRect.left() + (screenRect.width() - m_window->width()) / 2; |
| 114 | + auto y = screenRect.top() + (screenRect.height() - m_window->height()) / 2; |
126 | 115 | if (anchors & DLayerShellWindow::AnchorRight) { |
127 | 116 | // https://doc.qt.io/qt-6/qrect.html#right |
128 | | - x = (screenGeom.right() + 1 - windowGeometry.width() - qRound(m_dlayerShellWindow->rightMargin() * factor)); |
| 117 | + x = (screen->geometry().right() + 1 - m_window->width() - m_dlayerShellWindow->rightMargin()); |
129 | 118 | } |
130 | 119 |
|
131 | 120 | if (anchors & DLayerShellWindow::AnchorBottom) { |
132 | 121 | // https://doc.qt.io/qt-6/qrect.html#bottom |
133 | | - y = (screenGeom.bottom() + 1 - windowGeometry.height() - qRound(m_dlayerShellWindow->bottomMargin() * factor)); |
| 122 | + y = (screen->geometry().bottom() + 1 - m_window->height() - m_dlayerShellWindow->bottomMargin()); |
134 | 123 | } |
135 | 124 | if (anchors & DLayerShellWindow::AnchorLeft) { |
136 | | - x = (screenGeom.left() + qRound(m_dlayerShellWindow->leftMargin() * factor)); |
| 125 | + x = (screen->geometry().left() + m_dlayerShellWindow->leftMargin()); |
137 | 126 | } |
138 | 127 | if (anchors & DLayerShellWindow::AnchorTop) { |
139 | | - y = (screenGeom.top() + qRound(m_dlayerShellWindow->topMargin() * factor)); |
| 128 | + y = (screen->geometry().top() + m_dlayerShellWindow->topMargin()); |
140 | 129 | } |
141 | 130 |
|
142 | | - QRect rect(x, y, windowGeometry.width(), windowGeometry.height()); |
| 131 | + QRect rect(x, y, m_window->width(), m_window->height()); |
143 | 132 |
|
144 | 133 | const bool horizontallyConstrained = anchors.testFlags({DLayerShellWindow::AnchorLeft, DLayerShellWindow::AnchorRight}); |
145 | 134 | const bool verticallyConstrained = anchors.testFlags({DLayerShellWindow::AnchorTop, DLayerShellWindow::AnchorBottom}); |
146 | 135 |
|
147 | 136 | if (horizontallyConstrained) { |
148 | | - rect.setX(screenGeom.left() + qRound(m_dlayerShellWindow->leftMargin() * factor)); |
149 | | - rect.setWidth(screenGeom.width() - qRound((m_dlayerShellWindow->leftMargin() + m_dlayerShellWindow->rightMargin()) * factor)); |
| 137 | + rect.setX(screen->geometry().left() + m_dlayerShellWindow->leftMargin()); |
| 138 | + rect.setWidth(screen->geometry().width() - m_dlayerShellWindow->leftMargin() - m_dlayerShellWindow->rightMargin()); |
150 | 139 | } |
151 | 140 | if (verticallyConstrained) { |
152 | | - rect.setY(screenGeom.top() + qRound(m_dlayerShellWindow->topMargin() * factor)); |
153 | | - rect.setHeight(screenGeom.height() - qRound((m_dlayerShellWindow->topMargin() + m_dlayerShellWindow->bottomMargin()) * factor)); |
| 141 | + rect.setY(screen->geometry().top() + m_dlayerShellWindow->topMargin()); |
| 142 | + rect.setHeight(screen->geometry().height() - m_dlayerShellWindow->topMargin() - m_dlayerShellWindow->bottomMargin()); |
154 | 143 | } |
155 | 144 |
|
156 | | - // Configure window geometry via XCB interface |
157 | | - auto x11App = qGuiApp->nativeInterface<QNativeInterface::QX11Application>(); |
158 | | - auto xcbConnection = x11App->connection(); |
159 | | - auto xcbWindow = m_window->winId(); |
160 | | - uint16_t mask = 0; |
161 | | - struct { |
162 | | - int32_t x; |
163 | | - int32_t y; |
164 | | - uint32_t width; |
165 | | - uint32_t height; |
166 | | - } targetWindowRect; |
167 | | - |
168 | | - targetWindowRect.x = rect.x(); |
169 | | - targetWindowRect.y = rect.y(); |
170 | | - targetWindowRect.width = rect.width(); |
171 | | - targetWindowRect.height = rect.height(); |
172 | | - mask |= XCB_CONFIG_WINDOW_X; |
173 | | - mask |= XCB_CONFIG_WINDOW_Y; |
174 | | - mask |= XCB_CONFIG_WINDOW_WIDTH; |
175 | | - mask |= XCB_CONFIG_WINDOW_HEIGHT; |
176 | | - |
177 | | - xcb_configure_window(xcbConnection, xcbWindow, mask, &targetWindowRect); |
178 | | - xcb_flush(xcbConnection); |
| 145 | + m_window->setGeometry(rect); |
179 | 146 | } |
180 | 147 |
|
181 | 148 | /** |
|
0 commit comments