|
7 | 7 | #include <private/qwaylandscreen_p.h> |
8 | 8 | #include <private/qwaylandwindow_p.h> |
9 | 9 | #include <qcontainerfwd.h> |
| 10 | +#include <qguiapplication.h> |
10 | 11 | #include <qlogging.h> |
11 | 12 | #include <qloggingcategory.h> |
12 | 13 | #include <qobject.h> |
@@ -181,22 +182,58 @@ void ToplevelHandle::zwlr_foreign_toplevel_handle_v1_state(wl_array* stateArray) |
181 | 182 |
|
182 | 183 | void ToplevelHandle::zwlr_foreign_toplevel_handle_v1_output_enter(wl_output* output) { |
183 | 184 | auto* display = QtWaylandClient::QWaylandIntegration::instance()->display(); |
184 | | - auto* screen = display->screenForOutput(output)->screen(); |
| 185 | + |
| 186 | + auto* platformScreen = display->screenForOutput(output); |
| 187 | + if (!platformScreen) { |
| 188 | + qCDebug(logToplevelManagement) << this << "got pending output enter" << output; |
| 189 | + |
| 190 | + if (this->mPendingVisibleScreens.isEmpty()) { |
| 191 | + QObject::connect( |
| 192 | + static_cast<QGuiApplication*>(QGuiApplication::instance()), // NOLINT |
| 193 | + &QGuiApplication::screenAdded, |
| 194 | + this, |
| 195 | + &ToplevelHandle::onScreenAdded |
| 196 | + ); |
| 197 | + } |
| 198 | + |
| 199 | + this->mPendingVisibleScreens.append(output); |
| 200 | + return; |
| 201 | + } |
| 202 | + |
| 203 | + auto* screen = platformScreen->screen(); |
185 | 204 |
|
186 | 205 | qCDebug(logToplevelManagement) << this << "got output enter" << screen; |
187 | 206 |
|
188 | | - this->mVisibleScreens.push_back(screen); |
| 207 | + this->mVisibleScreens.append(screen); |
189 | 208 | emit this->visibleScreenAdded(screen); |
190 | 209 | } |
191 | 210 |
|
192 | 211 | void ToplevelHandle::zwlr_foreign_toplevel_handle_v1_output_leave(wl_output* output) { |
193 | 212 | auto* display = QtWaylandClient::QWaylandIntegration::instance()->display(); |
194 | | - auto* screen = display->screenForOutput(output)->screen(); |
| 213 | + auto* platformScreen = display->screenForOutput(output); |
| 214 | + |
| 215 | + if (!this->mPendingVisibleScreens.isEmpty()) { |
| 216 | + this->mPendingVisibleScreens.removeOne(output); |
| 217 | + |
| 218 | + if (this->mPendingVisibleScreens.isEmpty()) { |
| 219 | + qCDebug(logToplevelManagement) << this << "got pending output leave" << output; |
| 220 | + |
| 221 | + QObject::disconnect( |
| 222 | + static_cast<QGuiApplication*>(QGuiApplication::instance()), // NOLINT |
| 223 | + nullptr, |
| 224 | + this, |
| 225 | + nullptr |
| 226 | + ); |
| 227 | + } |
| 228 | + } |
| 229 | + |
| 230 | + if (!platformScreen) return; |
| 231 | + auto* screen = platformScreen->screen(); |
195 | 232 |
|
196 | 233 | qCDebug(logToplevelManagement) << this << "got output leave" << screen; |
197 | 234 |
|
198 | | - emit this->visibleScreenRemoved(screen); |
199 | 235 | this->mVisibleScreens.removeOne(screen); |
| 236 | + emit this->visibleScreenRemoved(screen); |
200 | 237 | } |
201 | 238 |
|
202 | 239 | void ToplevelHandle::zwlr_foreign_toplevel_handle_v1_parent( |
@@ -225,4 +262,26 @@ void ToplevelHandle::onParentClosed() { |
225 | 262 | emit this->parentChanged(); |
226 | 263 | } |
227 | 264 |
|
| 265 | +void ToplevelHandle::onScreenAdded(QScreen* screen) { |
| 266 | + auto* waylandScreen = dynamic_cast<QtWaylandClient::QWaylandScreen*>(screen->handle()); |
| 267 | + if (!waylandScreen) return; |
| 268 | + |
| 269 | + auto* output = waylandScreen->output(); |
| 270 | + |
| 271 | + if (this->mPendingVisibleScreens.removeOne(output)) { |
| 272 | + qCDebug(logToplevelManagement) << this << "got pending entered output init" << screen; |
| 273 | + this->mVisibleScreens.append(screen); |
| 274 | + emit this->visibleScreenAdded(screen); |
| 275 | + } |
| 276 | + |
| 277 | + if (this->mPendingVisibleScreens.isEmpty()) { |
| 278 | + QObject::disconnect( |
| 279 | + static_cast<QGuiApplication*>(QGuiApplication::instance()), // NOLINT |
| 280 | + nullptr, |
| 281 | + this, |
| 282 | + nullptr |
| 283 | + ); |
| 284 | + } |
| 285 | +} |
| 286 | + |
228 | 287 | } // namespace qs::wayland::toplevel_management::impl |
0 commit comments