/src/qtbase/src/gui/kernel/qwindow.cpp
Line | Count | Source |
1 | | // Copyright (C) 2016 The Qt Company Ltd. |
2 | | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | | // Qt-Security score:significant reason:default |
4 | | |
5 | | #include "qwindow.h" |
6 | | |
7 | | #include <qpa/qplatformwindow.h> |
8 | | #include <qpa/qplatformintegration.h> |
9 | | #ifndef QT_NO_CONTEXTMENU |
10 | | #include <qpa/qplatformtheme.h> |
11 | | #endif |
12 | | #include "qsurfaceformat.h" |
13 | | #ifndef QT_NO_OPENGL |
14 | | #include <qpa/qplatformopenglcontext.h> |
15 | | #include "qopenglcontext.h" |
16 | | #include "qopenglcontext_p.h" |
17 | | #endif |
18 | | #include "qscreen.h" |
19 | | |
20 | | #include "qwindow_p.h" |
21 | | #include "qguiapplication_p.h" |
22 | | #if QT_CONFIG(accessibility) |
23 | | # include "qaccessible.h" |
24 | | # include <private/qaccessiblecache_p.h> |
25 | | #endif |
26 | | #include "qhighdpiscaling_p.h" |
27 | | #if QT_CONFIG(draganddrop) |
28 | | #include "qshapedpixmapdndwindow_p.h" |
29 | | #endif // QT_CONFIG(draganddrop) |
30 | | |
31 | | #include <private/qevent_p.h> |
32 | | #include <private/qeventpoint_p.h> |
33 | | #include <private/qguiapplication_p.h> |
34 | | |
35 | | #include <QtCore/QTimer> |
36 | | #include <QtCore/QDebug> |
37 | | |
38 | | #include <QStyleHints> |
39 | | #include <qpa/qplatformcursor.h> |
40 | | #include <qpa/qplatformwindow_p.h> |
41 | | |
42 | | QT_BEGIN_NAMESPACE |
43 | | |
44 | | /*! |
45 | | \class QWindow |
46 | | \inmodule QtGui |
47 | | \since 5.0 |
48 | | \brief The QWindow class represents a window in the underlying windowing system. |
49 | | |
50 | | A window that is supplied a parent becomes a native child window of |
51 | | their parent window. |
52 | | |
53 | | An application will typically use QWidget or QQuickView for its UI, and not |
54 | | QWindow directly. Still, it is possible to render directly to a QWindow |
55 | | with QBackingStore or QOpenGLContext, when wanting to keep dependencies to |
56 | | a minimum or when wanting to use OpenGL directly. The |
57 | | \l{Raster Window Example} and \l{OpenGL Window Example} |
58 | | are useful reference examples for how to render to a QWindow using |
59 | | either approach. |
60 | | |
61 | | \section1 Resource Management |
62 | | |
63 | | Windows can potentially use a lot of memory. A usual measurement is |
64 | | width times height times color depth. A window might also include multiple |
65 | | buffers to support double and triple buffering, as well as depth and stencil |
66 | | buffers. To release a window's memory resources, call the destroy() function. |
67 | | |
68 | | \section1 Content Orientation |
69 | | |
70 | | QWindow has reportContentOrientationChange() that can be used to specify |
71 | | the layout of the window contents in relation to the screen. The content |
72 | | orientation is simply a hint to the windowing system about which |
73 | | orientation the window contents are in. It's useful when you wish to keep |
74 | | the same window size, but rotate the contents instead, especially when |
75 | | doing rotation animations between different orientations. The windowing |
76 | | system might use this value to determine the layout of system popups or |
77 | | dialogs. |
78 | | |
79 | | \section1 Visibility and Windowing System Exposure |
80 | | |
81 | | By default, the window is not visible, and you must call setVisible(true), |
82 | | or show() or similar to make it visible. To make a window hidden again, |
83 | | call setVisible(false) or hide(). The visible property describes the state |
84 | | the application wants the window to be in. Depending on the underlying |
85 | | system, a visible window might still not be shown on the screen. It could, |
86 | | for instance, be covered by other opaque windows or moved outside the |
87 | | physical area of the screen. On windowing systems that have exposure |
88 | | notifications, the isExposed() accessor describes whether the window should |
89 | | be treated as directly visible on screen. The exposeEvent() function is |
90 | | called whenever an area of the window is invalidated, for example due to the |
91 | | exposure in the windowing system changing. On windowing systems that do not |
92 | | make this information visible to the application, isExposed() will simply |
93 | | return the same value as isVisible(). |
94 | | |
95 | | QWindow::Visibility queried through visibility() is a convenience API |
96 | | combining the functions of visible() and windowStates(). |
97 | | |
98 | | \section1 Rendering |
99 | | |
100 | | There are two Qt APIs that can be used to render content into a window, |
101 | | QBackingStore for rendering with a QPainter and flushing the contents |
102 | | to a window with type QSurface::RasterSurface, and QOpenGLContext for |
103 | | rendering with OpenGL to a window with type QSurface::OpenGLSurface. |
104 | | |
105 | | The application can start rendering as soon as isExposed() returns \c true, |
106 | | and can keep rendering until it isExposed() returns \c false. To find out when |
107 | | isExposed() changes, reimplement exposeEvent(). The window will always get |
108 | | a resize event before the first expose event. |
109 | | |
110 | | \section1 Initial Geometry |
111 | | |
112 | | If the window's width and height are left uninitialized, the window will |
113 | | get a reasonable default geometry from the platform window. If the position |
114 | | is left uninitialized, then the platform window will allow the windowing |
115 | | system to position the window. For example on X11, the window manager |
116 | | usually does some kind of smart positioning to try to avoid having new |
117 | | windows completely obscure existing windows. However setGeometry() |
118 | | initializes both the position and the size, so if you want a fixed size but |
119 | | an automatic position, you should call resize() or setWidth() and |
120 | | setHeight() instead. |
121 | | */ |
122 | | |
123 | | /*! |
124 | | Creates a window as a top level on the \a targetScreen. |
125 | | |
126 | | The window is not shown until setVisible(true), show(), or similar is called. |
127 | | |
128 | | \sa setScreen() |
129 | | */ |
130 | | QWindow::QWindow(QScreen *targetScreen) |
131 | 0 | : QObject(*new QWindowPrivate(), nullptr) |
132 | 0 | , QSurface(QSurface::Window) |
133 | 0 | { |
134 | 0 | Q_D(QWindow); |
135 | 0 | d->init(nullptr, targetScreen); |
136 | 0 | } |
137 | | |
138 | | /*! |
139 | | Creates a window as a child of the given \a parent window. |
140 | | |
141 | | The window will be embedded inside the parent window, its coordinates |
142 | | relative to the parent. |
143 | | |
144 | | The screen is inherited from the parent. |
145 | | |
146 | | \sa setParent() |
147 | | */ |
148 | | QWindow::QWindow(QWindow *parent) |
149 | 0 | : QWindow(*new QWindowPrivate(), parent) |
150 | 0 | { |
151 | 0 | } |
152 | | |
153 | | /*! |
154 | | Creates a window as a child of the given \a parent window with the \a dd |
155 | | private implementation. |
156 | | |
157 | | The window will be embedded inside the parent window, its coordinates |
158 | | relative to the parent. |
159 | | |
160 | | The screen is inherited from the parent. |
161 | | |
162 | | \internal |
163 | | \sa setParent() |
164 | | */ |
165 | | QWindow::QWindow(QWindowPrivate &dd, QWindow *parent) |
166 | 0 | : QObject(dd, nullptr) |
167 | 0 | , QSurface(QSurface::Window) |
168 | 0 | { |
169 | 0 | Q_D(QWindow); |
170 | 0 | d->init(parent); |
171 | 0 | } |
172 | | |
173 | | /*! |
174 | | Destroys the window. |
175 | | */ |
176 | | QWindow::~QWindow() |
177 | 0 | { |
178 | 0 | Q_D(QWindow); |
179 | |
|
180 | 0 | #if QT_CONFIG(accessibility) |
181 | 0 | if (QGuiApplicationPrivate::is_app_running && !QGuiApplicationPrivate::is_app_closing && QAccessible::isActive()) |
182 | 0 | QAccessibleCache::instance()->sendObjectDestroyedEvent(this); |
183 | 0 | #endif |
184 | | |
185 | | // Delete child windows up front, instead of waiting for ~QObject, |
186 | | // in case the destruction of the child references its parent as |
187 | | // a (no longer valid) QWindow. |
188 | 0 | qDeleteAll(findChildren<QWindow *>(Qt::FindDirectChildrenOnly)); |
189 | |
|
190 | 0 | d->destroy(); |
191 | | // Decouple from parent before window goes under |
192 | 0 | setParent(nullptr); |
193 | 0 | QGuiApplicationPrivate::window_list.removeAll(this); |
194 | 0 | QGuiApplicationPrivate::popup_list.removeAll(this); |
195 | 0 | if (!QGuiApplicationPrivate::is_app_closing) |
196 | 0 | QGuiApplicationPrivate::instance()->modalWindowList.removeOne(this); |
197 | | |
198 | | // thse are normally cleared in destroy(), but the window may in |
199 | | // some cases end up becoming the focus window again, or receive an enter |
200 | | // event. Clear it again here as a workaround. See QTBUG-75326. |
201 | 0 | if (QGuiApplicationPrivate::focus_window == this) |
202 | 0 | QGuiApplicationPrivate::focus_window = nullptr; |
203 | 0 | if (QGuiApplicationPrivate::currentMouseWindow == this) |
204 | 0 | QGuiApplicationPrivate::currentMouseWindow = nullptr; |
205 | 0 | if (QGuiApplicationPrivate::currentMousePressWindow == this) |
206 | 0 | QGuiApplicationPrivate::currentMousePressWindow = nullptr; |
207 | |
|
208 | 0 | d->isWindow = false; |
209 | 0 | } |
210 | | |
211 | | QWindowPrivate::QWindowPrivate(decltype(QObjectPrivateVersion) version) |
212 | 0 | : QObjectPrivate(version) |
213 | 0 | {} |
214 | | |
215 | 0 | QWindowPrivate::~QWindowPrivate() |
216 | | = default; |
217 | | |
218 | | void QWindowPrivate::init(QWindow *parent, QScreen *targetScreen) |
219 | 0 | { |
220 | 0 | Q_Q(QWindow); |
221 | |
|
222 | 0 | q->QObject::setParent(parent); |
223 | |
|
224 | 0 | isWindow = true; |
225 | 0 | parentWindow = static_cast<QWindow *>(q->QObject::parent()); |
226 | |
|
227 | 0 | QScreen *connectScreen = targetScreen ? targetScreen : QGuiApplication::primaryScreen(); |
228 | |
|
229 | 0 | if (!parentWindow) |
230 | 0 | connectToScreen(connectScreen); |
231 | | |
232 | | // If your application aborts here, you are probably creating a QWindow |
233 | | // before the screen list is populated. |
234 | 0 | if (Q_UNLIKELY(!parentWindow && !topLevelScreen)) { |
235 | 0 | qFatal("Cannot create window: no screens available"); |
236 | 0 | } |
237 | 0 | QGuiApplicationPrivate::window_list.prepend(q); |
238 | |
|
239 | 0 | requestedFormat = QSurfaceFormat::defaultFormat(); |
240 | 0 | devicePixelRatio = connectScreen->devicePixelRatio(); |
241 | |
|
242 | 0 | QObject::connect(q, &QWindow::screenChanged, q, [q, this](QScreen *){ |
243 | | // We may have changed scaling; trigger resize event if needed, |
244 | | // except on Windows, where we send resize events during WM_DPICHANGED |
245 | | // event handling. FIXME: unify DPI change handling across all platforms. |
246 | 0 | #ifndef Q_OS_WIN |
247 | 0 | if (const auto *handle = q->handle()) { |
248 | 0 | QWindowSystemInterfacePrivate::GeometryChangeEvent gce(q, |
249 | 0 | QHighDpi::fromNativeWindowGeometry(handle->QPlatformWindow::geometry(), q), |
250 | 0 | QHighDpi::fromNativePixels(handle->geometry(), q)); |
251 | 0 | QGuiApplicationPrivate::processGeometryChangeEvent(&gce); |
252 | 0 | } |
253 | | #else |
254 | | Q_UNUSED(q); |
255 | | #endif |
256 | 0 | updateDevicePixelRatio(); |
257 | 0 | }); |
258 | |
|
259 | 0 | if (parentWindow) { |
260 | 0 | QChildWindowEvent childAddedEvent(QEvent::ChildWindowAdded, q); |
261 | 0 | QCoreApplication::sendEvent(parentWindow, &childAddedEvent); |
262 | 0 | } |
263 | 0 | } |
264 | | |
265 | | /*! |
266 | | \enum QWindow::Visibility |
267 | | \since 5.1 |
268 | | |
269 | | This enum describes what part of the screen the window occupies or should |
270 | | occupy. |
271 | | |
272 | | \value Windowed The window occupies part of the screen, but not necessarily |
273 | | the entire screen. This state will occur only on windowing systems which |
274 | | support showing multiple windows simultaneously. In this state it is |
275 | | possible for the user to move and resize the window manually, if |
276 | | WindowFlags permit it and if it is supported by the windowing system. |
277 | | |
278 | | \value Minimized The window is reduced to an entry or icon on the task bar, |
279 | | dock, task list or desktop, depending on how the windowing system handles |
280 | | minimized windows. |
281 | | |
282 | | \value Maximized The window occupies one entire screen, and the titlebar is |
283 | | still visible. On most windowing systems this is the state achieved by |
284 | | clicking the maximize button on the toolbar. |
285 | | |
286 | | \value FullScreen The window occupies one entire screen, is not resizable, |
287 | | and there is no titlebar. On some platforms which do not support showing |
288 | | multiple simultaneous windows, this can be the usual visibility when the |
289 | | window is not hidden. |
290 | | |
291 | | \value AutomaticVisibility This means to give the window a default visible |
292 | | state, which might be fullscreen or windowed depending on the platform. |
293 | | It can be given as a parameter to setVisibility but will never be |
294 | | read back from the visibility accessor. |
295 | | |
296 | | \value Hidden The window is not visible in any way, however it may remember |
297 | | a latent visibility which can be restored by setting AutomaticVisibility. |
298 | | */ |
299 | | |
300 | | /*! |
301 | | \property QWindow::visibility |
302 | | \brief the screen-occupation state of the window |
303 | | \since 5.1 |
304 | | |
305 | | Visibility is whether the window should appear in the windowing system as |
306 | | normal, minimized, maximized, fullscreen or hidden. |
307 | | |
308 | | To set the visibility to AutomaticVisibility means to give the window |
309 | | a default visible state, which might be fullscreen or windowed depending on |
310 | | the platform. |
311 | | When reading the visibility property you will always get the actual state, |
312 | | never AutomaticVisibility. |
313 | | |
314 | | The default value is Hidden. |
315 | | */ |
316 | | QWindow::Visibility QWindow::visibility() const |
317 | 0 | { |
318 | 0 | Q_D(const QWindow); |
319 | 0 | return d->visibility; |
320 | 0 | } |
321 | | |
322 | | void QWindow::setVisibility(Visibility v) |
323 | 0 | { |
324 | 0 | switch (v) { |
325 | 0 | case Hidden: |
326 | 0 | hide(); |
327 | 0 | break; |
328 | 0 | case AutomaticVisibility: |
329 | 0 | show(); |
330 | 0 | break; |
331 | 0 | case Windowed: |
332 | 0 | showNormal(); |
333 | 0 | break; |
334 | 0 | case Minimized: |
335 | 0 | showMinimized(); |
336 | 0 | break; |
337 | 0 | case Maximized: |
338 | 0 | showMaximized(); |
339 | 0 | break; |
340 | 0 | case FullScreen: |
341 | 0 | showFullScreen(); |
342 | 0 | break; |
343 | 0 | default: |
344 | 0 | Q_ASSERT(false); |
345 | 0 | } |
346 | 0 | } |
347 | | |
348 | | /* |
349 | | Subclasses may override this function to run custom setVisible |
350 | | logic. Subclasses that do so must call the base class implementation |
351 | | at some point to make the native window visible, and must not |
352 | | call QWindow::setVisble() since that will recurse back here. |
353 | | */ |
354 | | void QWindowPrivate::setVisible(bool visible) |
355 | 0 | { |
356 | 0 | Q_Q(QWindow); |
357 | |
|
358 | 0 | if (this->visible != visible) { |
359 | 0 | this->visible = visible; |
360 | 0 | emit q->visibleChanged(visible); |
361 | 0 | updateVisibility(); |
362 | 0 | } else if (platformWindow) { |
363 | | // Visibility hasn't changed, and the platform window is in sync |
364 | 0 | return; |
365 | 0 | } |
366 | | |
367 | 0 | if (!platformWindow) { |
368 | | // If we have a parent window, but the parent hasn't been created yet, we |
369 | | // can defer creation until the parent is created or we're re-parented. |
370 | 0 | if (parentWindow && !parentWindow->handle()) |
371 | 0 | return; |
372 | | |
373 | | // We only need to create the window if it's being shown |
374 | 0 | if (visible) { |
375 | | // FIXME: At this point we've already updated the visible state of |
376 | | // the QWindow, so if the platform layer reads the window state during |
377 | | // creation, and reflects that in the native window, it will end up |
378 | | // with a visible window. This may in turn result in resize or expose |
379 | | // events from the platform before we have sent the show event below. |
380 | 0 | q->create(); |
381 | 0 | } |
382 | 0 | } |
383 | | |
384 | 0 | if (visible) { |
385 | | // remove posted quit events when showing a new window |
386 | 0 | QCoreApplication::removePostedEvents(qApp, QEvent::Quit); |
387 | |
|
388 | 0 | if (q->type() == Qt::Window) { |
389 | 0 | QGuiApplicationPrivate *app_priv = QGuiApplicationPrivate::instance(); |
390 | 0 | QString &firstWindowTitle = app_priv->firstWindowTitle; |
391 | 0 | if (!firstWindowTitle.isEmpty()) { |
392 | 0 | q->setTitle(firstWindowTitle); |
393 | 0 | firstWindowTitle = QString(); |
394 | 0 | } |
395 | 0 | if (!app_priv->forcedWindowIcon.isNull()) |
396 | 0 | q->setIcon(app_priv->forcedWindowIcon); |
397 | | |
398 | | // Handling of the -qwindowgeometry, -geometry command line arguments |
399 | 0 | static bool geometryApplied = false; |
400 | 0 | if (!geometryApplied) { |
401 | 0 | geometryApplied = true; |
402 | 0 | QGuiApplicationPrivate::applyWindowGeometrySpecificationTo(q); |
403 | 0 | } |
404 | 0 | } |
405 | |
|
406 | 0 | QShowEvent showEvent; |
407 | 0 | QGuiApplication::sendEvent(q, &showEvent); |
408 | 0 | } |
409 | |
|
410 | 0 | if (q->isModal()) { |
411 | 0 | if (visible) |
412 | 0 | QGuiApplicationPrivate::showModalWindow(q); |
413 | 0 | else |
414 | 0 | QGuiApplicationPrivate::hideModalWindow(q); |
415 | | // QShapedPixmapWindow is used on some platforms for showing a drag pixmap, so don't block |
416 | | // input to this window as it is performing a drag - QTBUG-63846 |
417 | 0 | } else if (visible && QGuiApplication::modalWindow() |
418 | 0 | #if QT_CONFIG(draganddrop) |
419 | 0 | && !qobject_cast<QShapedPixmapWindow *>(q) |
420 | 0 | #endif // QT_CONFIG(draganddrop) |
421 | 0 | ) { |
422 | 0 | QGuiApplicationPrivate::updateBlockedStatus(q); |
423 | 0 | } |
424 | |
|
425 | 0 | if (q->type() == Qt::Popup) { |
426 | 0 | if (visible) |
427 | 0 | QGuiApplicationPrivate::activatePopup(q); |
428 | 0 | else |
429 | 0 | QGuiApplicationPrivate::closePopup(q); |
430 | 0 | } |
431 | |
|
432 | 0 | #ifndef QT_NO_CURSOR |
433 | 0 | if (visible && (hasCursor || QGuiApplication::overrideCursor())) |
434 | 0 | applyCursor(); |
435 | 0 | #endif |
436 | |
|
437 | 0 | if (platformWindow) |
438 | 0 | platformWindow->setVisible(visible); |
439 | |
|
440 | 0 | if (!visible) { |
441 | 0 | QHideEvent hideEvent; |
442 | 0 | QGuiApplication::sendEvent(q, &hideEvent); |
443 | 0 | } |
444 | 0 | } |
445 | | |
446 | | void QWindowPrivate::updateVisibility() |
447 | 0 | { |
448 | 0 | Q_Q(QWindow); |
449 | |
|
450 | 0 | QWindow::Visibility old = visibility; |
451 | |
|
452 | 0 | if (!visible) |
453 | 0 | visibility = QWindow::Hidden; |
454 | 0 | else if (windowState & Qt::WindowMinimized) |
455 | 0 | visibility = QWindow::Minimized; |
456 | 0 | else if (windowState & Qt::WindowFullScreen) |
457 | 0 | visibility = QWindow::FullScreen; |
458 | 0 | else if (windowState & Qt::WindowMaximized) |
459 | 0 | visibility = QWindow::Maximized; |
460 | 0 | else |
461 | 0 | visibility = QWindow::Windowed; |
462 | |
|
463 | 0 | if (visibility != old) |
464 | 0 | emit q->visibilityChanged(visibility); |
465 | 0 | } |
466 | | |
467 | | void QWindowPrivate::updateSiblingPosition(SiblingPosition position) |
468 | 0 | { |
469 | 0 | Q_Q(QWindow); |
470 | |
|
471 | 0 | if (!q->parent()) |
472 | 0 | return; |
473 | | |
474 | 0 | QObjectList &siblings = q->parent()->d_ptr->children; |
475 | |
|
476 | 0 | const qsizetype siblingCount = siblings.size() - 1; |
477 | 0 | if (siblingCount == 0) |
478 | 0 | return; |
479 | | |
480 | 0 | const qsizetype currentPosition = siblings.indexOf(q); |
481 | 0 | Q_ASSERT(currentPosition >= 0); |
482 | |
|
483 | 0 | const qsizetype targetPosition = position == PositionTop ? siblingCount : 0; |
484 | |
|
485 | 0 | if (currentPosition == targetPosition) |
486 | 0 | return; |
487 | | |
488 | 0 | siblings.move(currentPosition, targetPosition); |
489 | 0 | } |
490 | | |
491 | | bool QWindowPrivate::windowRecreationRequired(QScreen *newScreen) const |
492 | 0 | { |
493 | 0 | Q_Q(const QWindow); |
494 | 0 | const QScreen *oldScreen = q->screen(); |
495 | 0 | return oldScreen != newScreen && (platformWindow || !oldScreen) |
496 | 0 | && !(oldScreen && oldScreen->virtualSiblings().contains(newScreen)); |
497 | 0 | } |
498 | | |
499 | | void QWindowPrivate::disconnectFromScreen() |
500 | 0 | { |
501 | 0 | if (topLevelScreen) |
502 | 0 | topLevelScreen = nullptr; |
503 | 0 | } |
504 | | |
505 | | void QWindowPrivate::connectToScreen(QScreen *screen) |
506 | 0 | { |
507 | 0 | disconnectFromScreen(); |
508 | 0 | topLevelScreen = screen; |
509 | 0 | } |
510 | | |
511 | | void QWindowPrivate::emitScreenChangedRecursion(QScreen *newScreen) |
512 | 0 | { |
513 | 0 | Q_Q(QWindow); |
514 | 0 | emit q->screenChanged(newScreen); |
515 | 0 | for (QObject *child : q->children()) { |
516 | 0 | if (child->isWindowType()) |
517 | 0 | static_cast<QWindow *>(child)->d_func()->emitScreenChangedRecursion(newScreen); |
518 | 0 | } |
519 | 0 | } |
520 | | |
521 | | void QWindowPrivate::setTopLevelScreen(QScreen *newScreen, bool recreate) |
522 | 0 | { |
523 | 0 | Q_Q(QWindow); |
524 | |
|
525 | 0 | if (parentWindow) { |
526 | 0 | qWarning() << q << '(' << newScreen << "): Attempt to set a screen on a child window."; |
527 | 0 | return; |
528 | 0 | } |
529 | 0 | if (newScreen != topLevelScreen) { |
530 | 0 | const bool shouldRecreate = recreate && windowRecreationRequired(newScreen); |
531 | 0 | const bool shouldShow = visibilityOnDestroy && !topLevelScreen; |
532 | 0 | if (shouldRecreate && platformWindow) |
533 | 0 | q->destroy(); |
534 | 0 | connectToScreen(newScreen); |
535 | 0 | if (shouldShow) |
536 | 0 | q->setVisible(true); |
537 | 0 | else if (newScreen && shouldRecreate) |
538 | 0 | create(true); |
539 | 0 | emitScreenChangedRecursion(newScreen); |
540 | 0 | } |
541 | 0 | } |
542 | | |
543 | | static constexpr auto kForeignWindowId = "_q_foreignWinId"; |
544 | | |
545 | | void QWindowPrivate::create(bool recursive) |
546 | 0 | { |
547 | 0 | Q_Q(QWindow); |
548 | 0 | if (platformWindow) |
549 | 0 | return; |
550 | | |
551 | | // avoid losing update requests when re-creating |
552 | 0 | const bool needsUpdate = updateRequestPending; |
553 | | // the platformWindow, if there was one, is now gone, so make this flag reflect reality now |
554 | 0 | updateRequestPending = false; |
555 | |
|
556 | 0 | if (q->parent()) |
557 | 0 | q->parent()->create(); |
558 | |
|
559 | 0 | if (platformWindow) { |
560 | | // Creating the parent window will end up creating any child window |
561 | | // that was already visible, via setVisible. If this applies to us, |
562 | | // we will already have a platform window at this point. |
563 | 0 | return; |
564 | 0 | } |
565 | | |
566 | | // QPlatformWindow will poll geometry() during construction below. Set the |
567 | | // screen here so that high-dpi scaling will use the correct scale factor. |
568 | 0 | if (q->isTopLevel()) { |
569 | 0 | if (QScreen *screen = screenForGeometry(geometry)) |
570 | 0 | setTopLevelScreen(screen, false); |
571 | 0 | } |
572 | |
|
573 | 0 | const WId nativeHandle = q->property(kForeignWindowId).value<WId>(); |
574 | |
|
575 | 0 | QPlatformIntegration *platformIntegration = QGuiApplicationPrivate::platformIntegration(); |
576 | 0 | platformWindow = nativeHandle ? platformIntegration->createForeignWindow(q, nativeHandle) |
577 | 0 | : platformIntegration->createPlatformWindow(q); |
578 | 0 | Q_ASSERT(platformWindow); |
579 | |
|
580 | 0 | if (!platformWindow) { |
581 | 0 | qWarning() << "Failed to create platform window for" << q << "with flags" << q->flags(); |
582 | 0 | return; |
583 | 0 | } |
584 | | |
585 | 0 | platformWindow->initialize(); |
586 | |
|
587 | 0 | QObjectList childObjects = q->children(); |
588 | 0 | for (int i = 0; i < childObjects.size(); i ++) { |
589 | 0 | QObject *object = childObjects.at(i); |
590 | 0 | if (!object->isWindowType()) |
591 | 0 | continue; |
592 | | |
593 | 0 | QWindow *childWindow = static_cast<QWindow *>(object); |
594 | 0 | if (recursive) |
595 | 0 | childWindow->d_func()->create(recursive); |
596 | | |
597 | | // The child may have had deferred creation due to this window not being created |
598 | | // at the time setVisible was called, so we re-apply the visible state, which |
599 | | // may result in creating the child, and emitting the appropriate signals. |
600 | 0 | if (childWindow->isVisible()) |
601 | 0 | childWindow->setVisible(true); |
602 | |
|
603 | 0 | if (QPlatformWindow *childPlatformWindow = childWindow->d_func()->platformWindow) |
604 | 0 | childPlatformWindow->setParent(this->platformWindow); |
605 | 0 | } |
606 | |
|
607 | 0 | QPlatformSurfaceEvent e(QPlatformSurfaceEvent::SurfaceCreated); |
608 | 0 | QGuiApplication::sendEvent(q, &e); |
609 | |
|
610 | 0 | updateDevicePixelRatio(); |
611 | |
|
612 | 0 | if (needsUpdate) |
613 | 0 | q->requestUpdate(); |
614 | 0 | } |
615 | | |
616 | | void QWindowPrivate::clearFocusObject() |
617 | 0 | { |
618 | 0 | } |
619 | | |
620 | | // Allows for manipulating the suggested geometry before a resize/move |
621 | | // event in derived classes for platforms that support it, for example to |
622 | | // implement heightForWidth(). |
623 | | QRectF QWindowPrivate::closestAcceptableGeometry(const QRectF &rect) const |
624 | 0 | { |
625 | 0 | Q_UNUSED(rect); |
626 | 0 | return QRectF(); |
627 | 0 | } |
628 | | |
629 | | void QWindowPrivate::setMinOrMaxSize(QSize *oldSizeMember, const QSize &size, |
630 | | qxp::function_ref<void()> funcWidthChanged, |
631 | | qxp::function_ref<void()> funcHeightChanged) |
632 | 0 | { |
633 | 0 | Q_Q(QWindow); |
634 | 0 | Q_ASSERT(oldSizeMember); |
635 | 0 | const QSize adjustedSize = |
636 | 0 | size.expandedTo(QSize(0, 0)).boundedTo(QSize(QWINDOWSIZE_MAX, QWINDOWSIZE_MAX)); |
637 | 0 | if (*oldSizeMember == adjustedSize) |
638 | 0 | return; |
639 | 0 | const bool widthChanged = adjustedSize.width() != oldSizeMember->width(); |
640 | 0 | const bool heightChanged = adjustedSize.height() != oldSizeMember->height(); |
641 | 0 | *oldSizeMember = adjustedSize; |
642 | |
|
643 | 0 | if (platformWindow && q->isTopLevel()) |
644 | 0 | platformWindow->propagateSizeHints(); |
645 | |
|
646 | 0 | if (widthChanged) |
647 | 0 | funcWidthChanged(); |
648 | 0 | if (heightChanged) |
649 | 0 | funcHeightChanged(); |
650 | | |
651 | | // resize window if current size is outside of min and max limits |
652 | 0 | if (minimumSize.width() <= maximumSize.width() |
653 | 0 | || minimumSize.height() <= maximumSize.height()) { |
654 | 0 | const QSize currentSize = q->size(); |
655 | 0 | const QSize boundedSize = currentSize.expandedTo(minimumSize).boundedTo(maximumSize); |
656 | 0 | q->resize(boundedSize); |
657 | 0 | } |
658 | 0 | } |
659 | | |
660 | | /*! |
661 | | Sets the \a surfaceType of the window. |
662 | | |
663 | | Specifies whether the window is meant for raster rendering with |
664 | | QBackingStore, or OpenGL rendering with QOpenGLContext. |
665 | | |
666 | | The surfaceType will be used when the native surface is created |
667 | | in the create() function. Calling this function after the native |
668 | | surface has been created requires calling destroy() and create() |
669 | | to release the old native surface and create a new one. |
670 | | |
671 | | \sa QBackingStore, QOpenGLContext, create(), destroy() |
672 | | */ |
673 | | void QWindow::setSurfaceType(SurfaceType surfaceType) |
674 | 0 | { |
675 | 0 | Q_D(QWindow); |
676 | 0 | d->surfaceType = surfaceType; |
677 | 0 | } |
678 | | |
679 | | /*! |
680 | | Returns the surface type of the window. |
681 | | |
682 | | \sa setSurfaceType() |
683 | | */ |
684 | | QWindow::SurfaceType QWindow::surfaceType() const |
685 | 0 | { |
686 | 0 | Q_D(const QWindow); |
687 | 0 | return d->surfaceType; |
688 | 0 | } |
689 | | |
690 | | /*! |
691 | | \property QWindow::visible |
692 | | \brief whether the window is visible or not |
693 | | |
694 | | This property controls the visibility of the window in the windowing system. |
695 | | |
696 | | By default, the window is not visible, you must call setVisible(true), or |
697 | | show() or similar to make it visible. |
698 | | |
699 | | \note Hiding a window does not remove the window from the windowing system, |
700 | | it only hides it. On windowing systems that give full screen applications a |
701 | | dedicated desktop (such as macOS), hiding a full screen window will not remove |
702 | | that desktop, but leave it blank. Another window from the same application |
703 | | might be shown full screen, and will fill that desktop. Use QWindow::close to |
704 | | completely remove a window from the windowing system. |
705 | | |
706 | | \sa show() |
707 | | */ |
708 | | void QWindow::setVisible(bool visible) |
709 | 0 | { |
710 | 0 | Q_D(QWindow); |
711 | |
|
712 | 0 | d->setVisible(visible); |
713 | 0 | } |
714 | | |
715 | | bool QWindow::isVisible() const |
716 | 0 | { |
717 | 0 | Q_D(const QWindow); |
718 | |
|
719 | 0 | return d->visible; |
720 | 0 | } |
721 | | |
722 | | /*! |
723 | | Allocates the platform resources associated with the window. |
724 | | |
725 | | It is at this point that the surface format set using setFormat() gets resolved |
726 | | into an actual native surface. However, the window remains hidden until setVisible() is called. |
727 | | |
728 | | Note that it is not usually necessary to call this function directly, as it will be implicitly |
729 | | called by show(), setVisible(), winId(), and other functions that require access to the platform |
730 | | resources. |
731 | | |
732 | | Call destroy() to free the platform resources if necessary. |
733 | | |
734 | | \sa destroy() |
735 | | */ |
736 | | void QWindow::create() |
737 | 0 | { |
738 | 0 | Q_D(QWindow); |
739 | 0 | d->create(false); |
740 | 0 | } |
741 | | |
742 | | /*! |
743 | | Returns the window's platform id. |
744 | | |
745 | | \note This function will cause the platform window to be created if it is not already. |
746 | | Returns 0, if the platform window creation failed. |
747 | | |
748 | | For platforms where this id might be useful, the value returned |
749 | | will uniquely represent the window inside the corresponding screen. |
750 | | |
751 | | \sa screen() |
752 | | */ |
753 | | WId QWindow::winId() const |
754 | 0 | { |
755 | 0 | Q_D(const QWindow); |
756 | |
|
757 | 0 | if (!d->platformWindow) |
758 | 0 | const_cast<QWindow *>(this)->create(); |
759 | |
|
760 | 0 | if (!d->platformWindow) |
761 | 0 | return 0; |
762 | | |
763 | 0 | return d->platformWindow->winId(); |
764 | 0 | } |
765 | | |
766 | | /*! |
767 | | Returns the parent window, if any. |
768 | | |
769 | | If \a mode is IncludeTransients, then the transient parent is returned |
770 | | if there is no parent. |
771 | | |
772 | | A window without a parent is known as a top level window. |
773 | | |
774 | | \since 5.9 |
775 | | */ |
776 | | QWindow *QWindow::parent(AncestorMode mode) const |
777 | 0 | { |
778 | 0 | Q_D(const QWindow); |
779 | 0 | return d->parentWindow ? d->parentWindow : (mode == IncludeTransients ? transientParent() : nullptr); |
780 | 0 | } |
781 | | |
782 | | /*! |
783 | | Sets the \a parent Window. This will lead to the windowing system managing |
784 | | the clip of the window, so it will be clipped to the \a parent window. |
785 | | |
786 | | Setting \a parent to be \nullptr will make the window become a top level |
787 | | window. |
788 | | |
789 | | If \a parent is a window created by fromWinId(), then the current window |
790 | | will be embedded inside \a parent, if the platform supports it. |
791 | | */ |
792 | | void QWindow::setParent(QWindow *parent) |
793 | 0 | { |
794 | 0 | Q_D(QWindow); |
795 | 0 | if (d->parentWindow == parent |
796 | | // Allow explicit reparenting to top level for embedded windows |
797 | 0 | && !(d->platformWindow && d->platformWindow->isEmbedded())) { |
798 | 0 | return; |
799 | 0 | } |
800 | | |
801 | 0 | QScreen *oldScreen = screen(); |
802 | 0 | QScreen *newScreen = parent ? parent->screen() : oldScreen; |
803 | 0 | if (d->windowRecreationRequired(newScreen)) { |
804 | 0 | qWarning() << this << '(' << parent << "): Cannot change screens (" << oldScreen << newScreen << ')'; |
805 | 0 | return; |
806 | 0 | } |
807 | | |
808 | 0 | QEvent parentAboutToChangeEvent(QEvent::ParentWindowAboutToChange); |
809 | 0 | QCoreApplication::sendEvent(this, &parentAboutToChangeEvent); |
810 | |
|
811 | 0 | const auto previousParent = d->parentWindow; |
812 | 0 | QObject::setParent(parent); |
813 | 0 | d->parentWindow = parent; |
814 | |
|
815 | 0 | if (parent) |
816 | 0 | d->disconnectFromScreen(); |
817 | 0 | else |
818 | 0 | d->connectToScreen(newScreen); |
819 | | |
820 | | // If we were set visible, but not created because we were a child, and we're now |
821 | | // re-parented into a created parent, or to being a top level, we need re-apply the |
822 | | // visibility state, which will also create. |
823 | 0 | if (isVisible() && (!parent || parent->handle())) |
824 | 0 | setVisible(true); |
825 | |
|
826 | 0 | if (d->platformWindow) { |
827 | 0 | if (parent) |
828 | 0 | parent->create(); |
829 | |
|
830 | 0 | d->platformWindow->setParent(parent ? parent->d_func()->platformWindow : nullptr); |
831 | 0 | } |
832 | |
|
833 | 0 | QGuiApplicationPrivate::updateBlockedStatus(this); |
834 | |
|
835 | 0 | if (previousParent) { |
836 | 0 | QChildWindowEvent childRemovedEvent(QEvent::ChildWindowRemoved, this); |
837 | 0 | QCoreApplication::sendEvent(previousParent, &childRemovedEvent); |
838 | 0 | } |
839 | |
|
840 | 0 | if (parent) { |
841 | 0 | QChildWindowEvent childAddedEvent(QEvent::ChildWindowAdded, this); |
842 | 0 | QCoreApplication::sendEvent(parent, &childAddedEvent); |
843 | 0 | } |
844 | |
|
845 | 0 | QEvent parentChangedEvent(QEvent::ParentWindowChange); |
846 | 0 | QCoreApplication::sendEvent(this, &parentChangedEvent); |
847 | |
|
848 | 0 | #if QT_CONFIG(accessibility) |
849 | 0 | if (!d->accessibleParent |
850 | 0 | && QGuiApplicationPrivate::is_app_running && !QGuiApplicationPrivate::is_app_closing) { |
851 | 0 | QAccessibleEvent qaEvent(this, QAccessible::ParentChanged); |
852 | 0 | QAccessible::updateAccessibility(&qaEvent); |
853 | 0 | } |
854 | 0 | #endif |
855 | | |
856 | | // The QPA layer should detect screen changes for child windows, and emit |
857 | | // QWSI::handleWindowScreenChanged, but due to the ordering above where the |
858 | | // parentWindow member is updated before calling setParent on the platform |
859 | | // window we'll end up treating those callbacks from the QPA layer as noops |
860 | | // in processWindowScreenChangedEvent since the screen is already up to date. |
861 | | // To work around this we emit an explicit update here. |
862 | 0 | if (parent && screen() != oldScreen) |
863 | 0 | d->emitScreenChangedRecursion(screen()); |
864 | 0 | } |
865 | | |
866 | | /*! |
867 | | Returns whether the window is top level, i.e. has no parent window. |
868 | | */ |
869 | | bool QWindow::isTopLevel() const |
870 | 0 | { |
871 | 0 | Q_D(const QWindow); |
872 | 0 | return d->parentWindow == nullptr; |
873 | 0 | } |
874 | | |
875 | | /*! |
876 | | Returns whether the window is modal. |
877 | | |
878 | | A modal window prevents other windows from getting any input. |
879 | | |
880 | | \sa QWindow::modality |
881 | | */ |
882 | | bool QWindow::isModal() const |
883 | 0 | { |
884 | 0 | Q_D(const QWindow); |
885 | 0 | return d->modality != Qt::NonModal; |
886 | 0 | } |
887 | | |
888 | | /*! \property QWindow::modality |
889 | | \brief the modality of the window |
890 | | |
891 | | A modal window prevents other windows from receiving input events. Qt |
892 | | supports two types of modality: Qt::WindowModal and Qt::ApplicationModal. |
893 | | |
894 | | By default, this property is Qt::NonModal |
895 | | |
896 | | \sa Qt::WindowModality |
897 | | */ |
898 | | |
899 | | Qt::WindowModality QWindow::modality() const |
900 | 0 | { |
901 | 0 | Q_D(const QWindow); |
902 | 0 | return d->modality; |
903 | 0 | } |
904 | | |
905 | | void QWindow::setModality(Qt::WindowModality modality) |
906 | 0 | { |
907 | 0 | Q_D(QWindow); |
908 | 0 | if (d->modality == modality) |
909 | 0 | return; |
910 | 0 | d->modality = modality; |
911 | 0 | emit modalityChanged(modality); |
912 | 0 | } |
913 | | |
914 | | /*! \fn void QWindow::modalityChanged(Qt::WindowModality modality) |
915 | | |
916 | | This signal is emitted when the Qwindow::modality property changes to \a modality. |
917 | | */ |
918 | | |
919 | | /*! |
920 | | Sets the window's surface \a format. |
921 | | |
922 | | The format determines properties such as color depth, alpha, depth and |
923 | | stencil buffer size, etc. For example, to give a window a transparent |
924 | | background (provided that the window system supports compositing, and |
925 | | provided that other content in the window does not make it opaque again): |
926 | | |
927 | | \code |
928 | | QSurfaceFormat format; |
929 | | format.setAlphaBufferSize(8); |
930 | | window.setFormat(format); |
931 | | \endcode |
932 | | |
933 | | The surface format will be resolved in the create() function. Calling |
934 | | this function after create() has been called will not re-resolve the |
935 | | surface format of the native surface. |
936 | | |
937 | | When the format is not explicitly set via this function, the format returned |
938 | | by QSurfaceFormat::defaultFormat() will be used. This means that when having |
939 | | multiple windows, individual calls to this function can be replaced by one |
940 | | single call to QSurfaceFormat::setDefaultFormat() before creating the first |
941 | | window. |
942 | | |
943 | | \sa create(), destroy(), QSurfaceFormat::setDefaultFormat() |
944 | | */ |
945 | | void QWindow::setFormat(const QSurfaceFormat &format) |
946 | 0 | { |
947 | 0 | Q_D(QWindow); |
948 | 0 | d->requestedFormat = format; |
949 | 0 | } |
950 | | |
951 | | /*! |
952 | | Returns the requested surface format of this window. |
953 | | |
954 | | If the requested format was not supported by the platform implementation, |
955 | | the requestedFormat will differ from the actual window format. |
956 | | |
957 | | This is the value set with setFormat(). |
958 | | |
959 | | \sa setFormat(), format() |
960 | | */ |
961 | | QSurfaceFormat QWindow::requestedFormat() const |
962 | 0 | { |
963 | 0 | Q_D(const QWindow); |
964 | 0 | return d->requestedFormat; |
965 | 0 | } |
966 | | |
967 | | /*! |
968 | | Returns the actual format of this window. |
969 | | |
970 | | After the window has been created, this function will return the actual surface format |
971 | | of the window. It might differ from the requested format if the requested format could |
972 | | not be fulfilled by the platform. It might also be a superset, for example certain |
973 | | buffer sizes may be larger than requested. |
974 | | |
975 | | \note Depending on the platform, certain values in this surface format may still |
976 | | contain the requested values, that is, the values that have been passed to |
977 | | setFormat(). Typical examples are the OpenGL version, profile and options. These may |
978 | | not get updated during create() since these are context specific and a single window |
979 | | may be used together with multiple contexts over its lifetime. Use the |
980 | | QOpenGLContext's format() instead to query such values. |
981 | | |
982 | | \sa create(), requestedFormat(), QOpenGLContext::format() |
983 | | */ |
984 | | QSurfaceFormat QWindow::format() const |
985 | 0 | { |
986 | 0 | Q_D(const QWindow); |
987 | 0 | if (d->platformWindow) |
988 | 0 | return d->platformWindow->format(); |
989 | 0 | return d->requestedFormat; |
990 | 0 | } |
991 | | |
992 | | /*! |
993 | | \property QWindow::flags |
994 | | \brief the window flags of the window |
995 | | |
996 | | The window flags control the window's appearance in the windowing system, |
997 | | whether it's a dialog, popup, or a regular window, and whether it should |
998 | | have a title bar, etc. |
999 | | |
1000 | | The actual window flags might differ from the flags set with setFlags() |
1001 | | if the requested flags could not be fulfilled. |
1002 | | |
1003 | | \sa setFlag() |
1004 | | */ |
1005 | | void QWindow::setFlags(Qt::WindowFlags flags) |
1006 | 0 | { |
1007 | 0 | Q_D(QWindow); |
1008 | 0 | if (d->windowFlags == flags) |
1009 | 0 | return; |
1010 | | |
1011 | 0 | if (d->platformWindow) |
1012 | 0 | d->platformWindow->setWindowFlags(flags); |
1013 | |
|
1014 | 0 | d->windowFlags = flags; |
1015 | |
|
1016 | 0 | emit flagsChanged(this->flags()); |
1017 | 0 | } |
1018 | | |
1019 | | Qt::WindowFlags QWindow::flags() const |
1020 | 0 | { |
1021 | 0 | Q_D(const QWindow); |
1022 | 0 | Qt::WindowFlags flags = d->windowFlags; |
1023 | |
|
1024 | 0 | if (d->platformWindow && d->platformWindow->isForeignWindow()) |
1025 | 0 | flags |= Qt::ForeignWindow; |
1026 | |
|
1027 | 0 | return flags; |
1028 | 0 | } |
1029 | | |
1030 | | /*! |
1031 | | \since 5.9 |
1032 | | |
1033 | | Sets the window flag \a flag on this window if \a on is true; |
1034 | | otherwise clears the flag. |
1035 | | |
1036 | | \sa setFlags(), flags(), type() |
1037 | | */ |
1038 | | void QWindow::setFlag(Qt::WindowType flag, bool on) |
1039 | 0 | { |
1040 | 0 | Q_D(QWindow); |
1041 | 0 | if (on) |
1042 | 0 | setFlags(d->windowFlags | flag); |
1043 | 0 | else |
1044 | 0 | setFlags(d->windowFlags & ~flag); |
1045 | 0 | } |
1046 | | |
1047 | | /*! |
1048 | | Returns the type of the window. |
1049 | | |
1050 | | This returns the part of the window flags that represents |
1051 | | whether the window is a dialog, tooltip, popup, regular window, etc. |
1052 | | |
1053 | | \sa flags(), setFlags() |
1054 | | */ |
1055 | | Qt::WindowType QWindow::type() const |
1056 | 0 | { |
1057 | 0 | return static_cast<Qt::WindowType>(int(flags() & Qt::WindowType_Mask)); |
1058 | 0 | } |
1059 | | |
1060 | | /*! |
1061 | | \property QWindow::title |
1062 | | \brief the window's title in the windowing system |
1063 | | |
1064 | | The window title might appear in the title area of the window decorations, |
1065 | | depending on the windowing system and the window flags. It might also |
1066 | | be used by the windowing system to identify the window in other contexts, |
1067 | | such as in the task switcher. |
1068 | | |
1069 | | \sa flags() |
1070 | | */ |
1071 | | void QWindow::setTitle(const QString &title) |
1072 | 0 | { |
1073 | 0 | Q_D(QWindow); |
1074 | 0 | bool changed = false; |
1075 | 0 | if (d->windowTitle != title) { |
1076 | 0 | d->windowTitle = title; |
1077 | 0 | changed = true; |
1078 | 0 | } |
1079 | 0 | if (d->platformWindow) |
1080 | 0 | d->platformWindow->setWindowTitle(title); |
1081 | 0 | if (changed) |
1082 | 0 | emit windowTitleChanged(title); |
1083 | 0 | } |
1084 | | |
1085 | | QString QWindow::title() const |
1086 | 0 | { |
1087 | 0 | Q_D(const QWindow); |
1088 | 0 | return d->windowTitle; |
1089 | 0 | } |
1090 | | |
1091 | | /*! |
1092 | | \brief set the file name this window is representing. |
1093 | | |
1094 | | The windowing system might use \a filePath to display the |
1095 | | path of the document this window is representing in the tile bar. |
1096 | | |
1097 | | */ |
1098 | | void QWindow::setFilePath(const QString &filePath) |
1099 | 0 | { |
1100 | 0 | Q_D(QWindow); |
1101 | 0 | d->windowFilePath = filePath; |
1102 | 0 | if (d->platformWindow) |
1103 | 0 | d->platformWindow->setWindowFilePath(filePath); |
1104 | 0 | } |
1105 | | |
1106 | | /*! |
1107 | | \brief the file name this window is representing. |
1108 | | |
1109 | | \sa setFilePath() |
1110 | | */ |
1111 | | QString QWindow::filePath() const |
1112 | 0 | { |
1113 | 0 | Q_D(const QWindow); |
1114 | 0 | return d->windowFilePath; |
1115 | 0 | } |
1116 | | |
1117 | | /*! |
1118 | | \brief Sets the window's \a icon in the windowing system |
1119 | | |
1120 | | The window icon might be used by the windowing system for example to |
1121 | | decorate the window, and/or in the task switcher. |
1122 | | |
1123 | | \note On \macos, the window title bar icon is meant for windows representing |
1124 | | documents, and will only show up if a file path is also set. |
1125 | | |
1126 | | \sa setFilePath() |
1127 | | */ |
1128 | | void QWindow::setIcon(const QIcon &icon) |
1129 | 0 | { |
1130 | 0 | Q_D(QWindow); |
1131 | 0 | d->windowIcon = icon; |
1132 | 0 | if (d->platformWindow) |
1133 | 0 | d->platformWindow->setWindowIcon(icon); |
1134 | 0 | QEvent e(QEvent::WindowIconChange); |
1135 | 0 | QCoreApplication::sendEvent(this, &e); |
1136 | 0 | } |
1137 | | |
1138 | | /*! |
1139 | | \brief Returns the window's icon in the windowing system |
1140 | | |
1141 | | \sa setIcon() |
1142 | | */ |
1143 | | QIcon QWindow::icon() const |
1144 | 0 | { |
1145 | 0 | Q_D(const QWindow); |
1146 | 0 | if (d->windowIcon.isNull()) |
1147 | 0 | return QGuiApplication::windowIcon(); |
1148 | 0 | return d->windowIcon; |
1149 | 0 | } |
1150 | | |
1151 | | /*! |
1152 | | Raise the window in the windowing system. |
1153 | | |
1154 | | Requests that the window be raised to appear above other windows. |
1155 | | */ |
1156 | | void QWindow::raise() |
1157 | 0 | { |
1158 | 0 | Q_D(QWindow); |
1159 | |
|
1160 | 0 | d->updateSiblingPosition(QWindowPrivate::PositionTop); |
1161 | |
|
1162 | 0 | if (d->platformWindow) |
1163 | 0 | d->platformWindow->raise(); |
1164 | 0 | } |
1165 | | |
1166 | | /*! |
1167 | | Lower the window in the windowing system. |
1168 | | |
1169 | | Requests that the window be lowered to appear below other windows. |
1170 | | */ |
1171 | | void QWindow::lower() |
1172 | 0 | { |
1173 | 0 | Q_D(QWindow); |
1174 | |
|
1175 | 0 | d->updateSiblingPosition(QWindowPrivate::PositionBottom); |
1176 | |
|
1177 | 0 | if (d->platformWindow) |
1178 | 0 | d->platformWindow->lower(); |
1179 | 0 | } |
1180 | | |
1181 | | /*! |
1182 | | \brief Start a system-specific resize operation |
1183 | | \since 5.15 |
1184 | | |
1185 | | Calling this will start an interactive resize operation on the window by platforms |
1186 | | that support it. The actual behavior may vary depending on the platform. Usually, |
1187 | | it will make the window resize so that its edge follows the mouse cursor. |
1188 | | |
1189 | | On platforms that support it, this method of resizing windows is preferred over |
1190 | | \c setGeometry, because it allows a more native look and feel of resizing windows, e.g. |
1191 | | letting the window manager snap this window against other windows, or special resizing |
1192 | | behavior with animations when dragged to the edge of the screen. |
1193 | | |
1194 | | \a edges should either be a single edge, or two adjacent edges (a corner). Other values |
1195 | | are not allowed. |
1196 | | |
1197 | | Returns true if the operation was supported by the system. |
1198 | | */ |
1199 | | bool QWindow::startSystemResize(Qt::Edges edges) |
1200 | 0 | { |
1201 | 0 | Q_D(QWindow); |
1202 | 0 | if (Q_UNLIKELY(!isVisible() || !d->platformWindow || d->maximumSize == d->minimumSize)) |
1203 | 0 | return false; |
1204 | | |
1205 | 0 | const bool isSingleEdge = edges == Qt::TopEdge || edges == Qt::RightEdge || edges == Qt::BottomEdge || edges == Qt::LeftEdge; |
1206 | 0 | const bool isCorner = |
1207 | 0 | edges == (Qt::TopEdge | Qt::LeftEdge) || |
1208 | 0 | edges == (Qt::TopEdge | Qt::RightEdge) || |
1209 | 0 | edges == (Qt::BottomEdge | Qt::RightEdge) || |
1210 | 0 | edges == (Qt::BottomEdge | Qt::LeftEdge); |
1211 | |
|
1212 | 0 | if (Q_UNLIKELY(!isSingleEdge && !isCorner)) { |
1213 | 0 | qWarning() << "Invalid edges" << edges << "passed to QWindow::startSystemResize, ignoring."; |
1214 | 0 | return false; |
1215 | 0 | } |
1216 | | |
1217 | 0 | return d->platformWindow->startSystemResize(edges); |
1218 | 0 | } |
1219 | | |
1220 | | /*! |
1221 | | \brief Start a system-specific move operation |
1222 | | \since 5.15 |
1223 | | |
1224 | | Calling this will start an interactive move operation on the window by platforms |
1225 | | that support it. The actual behavior may vary depending on the platform. Usually, |
1226 | | it will make the window follow the mouse cursor until a mouse button is released. |
1227 | | |
1228 | | On platforms that support it, this method of moving windows is preferred over |
1229 | | \c setPosition, because it allows a more native look-and-feel of moving windows, e.g. |
1230 | | letting the window manager snap this window against other windows, or special tiling |
1231 | | or resizing behavior with animations when dragged to the edge of the screen. |
1232 | | Furthermore, on some platforms such as Wayland, \c setPosition is not supported, so |
1233 | | this is the only way the application can influence its position. |
1234 | | |
1235 | | Returns true if the operation was supported by the system. |
1236 | | */ |
1237 | | bool QWindow::startSystemMove() |
1238 | 0 | { |
1239 | 0 | Q_D(QWindow); |
1240 | 0 | if (Q_UNLIKELY(!isVisible() || !d->platformWindow)) |
1241 | 0 | return false; |
1242 | | |
1243 | 0 | return d->platformWindow->startSystemMove(); |
1244 | 0 | } |
1245 | | |
1246 | | /*! |
1247 | | \property QWindow::opacity |
1248 | | \brief The opacity of the window in the windowing system. |
1249 | | \since 5.1 |
1250 | | |
1251 | | If the windowing system supports window opacity, this can be used to fade the |
1252 | | window in and out, or to make it semitransparent. |
1253 | | |
1254 | | A value of 1.0 or above is treated as fully opaque, whereas a value of 0.0 or below |
1255 | | is treated as fully transparent. Values inbetween represent varying levels of |
1256 | | translucency between the two extremes. |
1257 | | |
1258 | | The default value is 1.0. |
1259 | | */ |
1260 | | void QWindow::setOpacity(qreal level) |
1261 | 0 | { |
1262 | 0 | Q_D(QWindow); |
1263 | 0 | if (level == d->opacity) |
1264 | 0 | return; |
1265 | 0 | d->opacity = level; |
1266 | 0 | if (d->platformWindow) { |
1267 | 0 | d->platformWindow->setOpacity(level); |
1268 | 0 | emit opacityChanged(level); |
1269 | 0 | } |
1270 | 0 | } |
1271 | | |
1272 | | qreal QWindow::opacity() const |
1273 | 0 | { |
1274 | 0 | Q_D(const QWindow); |
1275 | 0 | return d->opacity; |
1276 | 0 | } |
1277 | | |
1278 | | /*! |
1279 | | Sets the mask of the window. |
1280 | | |
1281 | | The mask is a hint to the windowing system that the application does not |
1282 | | want to receive mouse or touch input outside the given \a region. |
1283 | | |
1284 | | The window manager may or may not choose to display any areas of the window |
1285 | | not included in the mask, thus it is the application's responsibility to |
1286 | | clear to transparent the areas that are not part of the mask. |
1287 | | */ |
1288 | | void QWindow::setMask(const QRegion ®ion) |
1289 | 0 | { |
1290 | 0 | Q_D(QWindow); |
1291 | 0 | if (d->platformWindow) |
1292 | 0 | d->platformWindow->setMask(QHighDpi::toNativeLocalRegion(region, this)); |
1293 | 0 | d->mask = region; |
1294 | 0 | } |
1295 | | |
1296 | | /*! |
1297 | | Returns the mask set on the window. |
1298 | | |
1299 | | The mask is a hint to the windowing system that the application does not |
1300 | | want to receive mouse or touch input outside the given region. |
1301 | | */ |
1302 | | QRegion QWindow::mask() const |
1303 | 0 | { |
1304 | 0 | Q_D(const QWindow); |
1305 | 0 | return d->mask; |
1306 | 0 | } |
1307 | | |
1308 | | /*! |
1309 | | Requests the window to be activated, i.e. receive keyboard focus. |
1310 | | |
1311 | | \sa isActive(), QGuiApplication::focusWindow() |
1312 | | */ |
1313 | | void QWindow::requestActivate() |
1314 | 0 | { |
1315 | 0 | Q_D(QWindow); |
1316 | 0 | if (flags() & Qt::WindowDoesNotAcceptFocus) { |
1317 | 0 | qWarning() << "requestActivate() called for " << this << " which has Qt::WindowDoesNotAcceptFocus set."; |
1318 | 0 | return; |
1319 | 0 | } |
1320 | 0 | if (d->platformWindow) |
1321 | 0 | d->platformWindow->requestActivateWindow(); |
1322 | 0 | } |
1323 | | |
1324 | | /*! |
1325 | | Returns if this window is exposed in the windowing system. |
1326 | | |
1327 | | When the window is not exposed, it is shown by the application |
1328 | | but it is still not showing in the windowing system, so the application |
1329 | | should minimize animations and other graphical activities. |
1330 | | |
1331 | | An exposeEvent() is sent every time this value changes. |
1332 | | |
1333 | | \sa exposeEvent() |
1334 | | */ |
1335 | | bool QWindow::isExposed() const |
1336 | 0 | { |
1337 | 0 | Q_D(const QWindow); |
1338 | 0 | return d->exposed; |
1339 | 0 | } |
1340 | | |
1341 | | /*! |
1342 | | \property QWindow::active |
1343 | | \brief the active status of the window |
1344 | | \since 5.1 |
1345 | | |
1346 | | \sa requestActivate() |
1347 | | */ |
1348 | | |
1349 | | /*! |
1350 | | Returns \c true if the window is active. |
1351 | | |
1352 | | This is the case for the window that has input focus as well as windows |
1353 | | that are in the same parent / transient parent chain as the focus window. |
1354 | | |
1355 | | Typically active windows should appear active from a style perspective. |
1356 | | |
1357 | | To get the window that currently has focus, use QGuiApplication::focusWindow(). |
1358 | | |
1359 | | \sa requestActivate() |
1360 | | */ |
1361 | | bool QWindow::isActive() const |
1362 | 0 | { |
1363 | 0 | Q_D(const QWindow); |
1364 | 0 | if (!d->platformWindow) |
1365 | 0 | return false; |
1366 | | |
1367 | 0 | QWindow *focus = QGuiApplication::focusWindow(); |
1368 | | |
1369 | | // Means the whole application lost the focus |
1370 | 0 | if (!focus) |
1371 | 0 | return false; |
1372 | | |
1373 | 0 | if (focus == this) |
1374 | 0 | return true; |
1375 | | |
1376 | 0 | if (QWindow *p = parent(IncludeTransients)) |
1377 | 0 | return p->isActive(); |
1378 | 0 | else |
1379 | 0 | return isAncestorOf(focus); |
1380 | 0 | } |
1381 | | |
1382 | | /*! |
1383 | | \property QWindow::contentOrientation |
1384 | | \brief the orientation of the window's contents |
1385 | | |
1386 | | This is a hint to the window manager in case it needs to display |
1387 | | additional content like popups, dialogs, status bars, or similar |
1388 | | in relation to the window. |
1389 | | |
1390 | | The recommended orientation is QScreen::orientation() but |
1391 | | an application doesn't have to support all possible orientations, |
1392 | | and thus can opt to ignore the current screen orientation. |
1393 | | |
1394 | | The difference between the window and the content orientation |
1395 | | determines how much to rotate the content by. QScreen::angleBetween(), |
1396 | | QScreen::transformBetween(), and QScreen::mapBetween() can be used |
1397 | | to compute the necessary transform. |
1398 | | |
1399 | | The default value is Qt::PrimaryOrientation |
1400 | | */ |
1401 | | void QWindow::reportContentOrientationChange(Qt::ScreenOrientation orientation) |
1402 | 0 | { |
1403 | 0 | Q_D(QWindow); |
1404 | 0 | if (d->contentOrientation == orientation) |
1405 | 0 | return; |
1406 | 0 | if (d->platformWindow) |
1407 | 0 | d->platformWindow->handleContentOrientationChange(orientation); |
1408 | 0 | d->contentOrientation = orientation; |
1409 | 0 | emit contentOrientationChanged(orientation); |
1410 | 0 | } |
1411 | | |
1412 | | Qt::ScreenOrientation QWindow::contentOrientation() const |
1413 | 0 | { |
1414 | 0 | Q_D(const QWindow); |
1415 | 0 | return d->contentOrientation; |
1416 | 0 | } |
1417 | | |
1418 | | /*! |
1419 | | Returns the ratio between physical pixels and device-independent pixels |
1420 | | for the window. This value is dependent on the screen the window is on, |
1421 | | and may change when the window is moved. |
1422 | | |
1423 | | The QWindow instance receives an event of type |
1424 | | QEvent::DevicePixelRatioChange when the device pixel ratio changes. |
1425 | | |
1426 | | Common values are 1.0 on normal displays and 2.0 on Apple "retina" displays. |
1427 | | |
1428 | | \note For windows not backed by a platform window, meaning that create() was not |
1429 | | called, the function will fall back to the associated QScreen's device pixel ratio. |
1430 | | |
1431 | | \sa QScreen::devicePixelRatio(), QEvent::DevicePixelRatioChange |
1432 | | */ |
1433 | | qreal QWindow::devicePixelRatio() const |
1434 | 0 | { |
1435 | 0 | Q_D(const QWindow); |
1436 | 0 | return d->devicePixelRatio; |
1437 | 0 | } |
1438 | | |
1439 | | /* |
1440 | | Updates the cached devicePixelRatio value by polling for a new value. |
1441 | | Sends QEvent::DevicePixelRatioChange to the window if the DPR has changed. |
1442 | | Returns true if the DPR was changed. |
1443 | | */ |
1444 | | bool QWindowPrivate::updateDevicePixelRatio() |
1445 | 0 | { |
1446 | 0 | Q_Q(QWindow); |
1447 | |
|
1448 | 0 | const qreal newDevicePixelRatio = [this, q]{ |
1449 | 0 | if (platformWindow) |
1450 | 0 | return platformWindow->devicePixelRatio() * QHighDpiScaling::factor(q); |
1451 | | |
1452 | | // If there is no platform window use the associated screen's devicePixelRatio, |
1453 | | // which typically is the primary screen and will be correct for single-display |
1454 | | // systems (a very common case). |
1455 | 0 | if (auto *screen = q->screen()) |
1456 | 0 | return screen->devicePixelRatio(); |
1457 | | |
1458 | | // In some cases we are running without any QScreens, so fall back to QGuiApp |
1459 | 0 | return qGuiApp->devicePixelRatio(); |
1460 | 0 | }(); |
1461 | |
|
1462 | 0 | if (newDevicePixelRatio == devicePixelRatio) |
1463 | 0 | return false; |
1464 | | |
1465 | 0 | devicePixelRatio = newDevicePixelRatio; |
1466 | 0 | QEvent dprChangeEvent(QEvent::DevicePixelRatioChange); |
1467 | 0 | QGuiApplication::sendEvent(q, &dprChangeEvent); |
1468 | 0 | return true; |
1469 | 0 | } |
1470 | | |
1471 | | Qt::WindowState QWindowPrivate::effectiveState(Qt::WindowStates state) |
1472 | 0 | { |
1473 | 0 | if (state & Qt::WindowMinimized) |
1474 | 0 | return Qt::WindowMinimized; |
1475 | 0 | else if (state & Qt::WindowFullScreen) |
1476 | 0 | return Qt::WindowFullScreen; |
1477 | 0 | else if (state & Qt::WindowMaximized) |
1478 | 0 | return Qt::WindowMaximized; |
1479 | 0 | return Qt::WindowNoState; |
1480 | 0 | } |
1481 | | |
1482 | | /*! |
1483 | | \brief set the screen-occupation state of the window |
1484 | | |
1485 | | The window \a state represents whether the window appears in the |
1486 | | windowing system as maximized, minimized, fullscreen, or normal. |
1487 | | |
1488 | | The enum value Qt::WindowActive is not an accepted parameter. |
1489 | | |
1490 | | \sa showNormal(), showFullScreen(), showMinimized(), showMaximized(), setWindowStates() |
1491 | | */ |
1492 | | void QWindow::setWindowState(Qt::WindowState state) |
1493 | 0 | { |
1494 | 0 | setWindowStates(state); |
1495 | 0 | } |
1496 | | |
1497 | | /*! |
1498 | | \brief set the screen-occupation state of the window |
1499 | | \since 5.10 |
1500 | | |
1501 | | The window \a state represents whether the window appears in the |
1502 | | windowing system as maximized, minimized and/or fullscreen. |
1503 | | |
1504 | | The window can be in a combination of several states. For example, if |
1505 | | the window is both minimized and maximized, the window will appear |
1506 | | minimized, but clicking on the task bar entry will restore it to the |
1507 | | maximized state. |
1508 | | |
1509 | | The enum value Qt::WindowActive should not be set. |
1510 | | |
1511 | | \sa showNormal(), showFullScreen(), showMinimized(), showMaximized() |
1512 | | */ |
1513 | | void QWindow::setWindowStates(Qt::WindowStates state) |
1514 | 0 | { |
1515 | 0 | Q_D(QWindow); |
1516 | 0 | if (state & Qt::WindowActive) { |
1517 | 0 | qWarning("QWindow::setWindowStates does not accept Qt::WindowActive"); |
1518 | 0 | state &= ~Qt::WindowActive; |
1519 | 0 | } |
1520 | |
|
1521 | 0 | if (d->platformWindow) |
1522 | 0 | d->platformWindow->setWindowState(state); |
1523 | |
|
1524 | 0 | auto originalEffectiveState = QWindowPrivate::effectiveState(d->windowState); |
1525 | 0 | d->windowState = state; |
1526 | 0 | auto newEffectiveState = QWindowPrivate::effectiveState(d->windowState); |
1527 | 0 | if (newEffectiveState != originalEffectiveState) |
1528 | 0 | emit windowStateChanged(newEffectiveState); |
1529 | |
|
1530 | 0 | d->updateVisibility(); |
1531 | 0 | } |
1532 | | |
1533 | | /*! |
1534 | | \brief the screen-occupation state of the window |
1535 | | |
1536 | | \sa setWindowState(), windowStates() |
1537 | | */ |
1538 | | Qt::WindowState QWindow::windowState() const |
1539 | 0 | { |
1540 | 0 | Q_D(const QWindow); |
1541 | 0 | return QWindowPrivate::effectiveState(d->windowState); |
1542 | 0 | } |
1543 | | |
1544 | | /*! |
1545 | | \brief the screen-occupation state of the window |
1546 | | \since 5.10 |
1547 | | |
1548 | | The window can be in a combination of several states. For example, if |
1549 | | the window is both minimized and maximized, the window will appear |
1550 | | minimized, but clicking on the task bar entry will restore it to |
1551 | | the maximized state. |
1552 | | |
1553 | | \sa setWindowStates() |
1554 | | */ |
1555 | | Qt::WindowStates QWindow::windowStates() const |
1556 | 0 | { |
1557 | 0 | Q_D(const QWindow); |
1558 | 0 | return d->windowState; |
1559 | 0 | } |
1560 | | |
1561 | | /*! |
1562 | | \fn QWindow::windowStateChanged(Qt::WindowState windowState) |
1563 | | |
1564 | | This signal is emitted when the \a windowState changes, either |
1565 | | by being set explicitly with setWindowStates(), or automatically when |
1566 | | the user clicks one of the titlebar buttons or by other means. |
1567 | | */ |
1568 | | |
1569 | | /*! |
1570 | | \property QWindow::transientParent |
1571 | | \brief the window for which this window is a transient pop-up |
1572 | | \since 5.13 |
1573 | | |
1574 | | This is a hint to the window manager that this window is a dialog or pop-up |
1575 | | on behalf of the transient parent. |
1576 | | |
1577 | | In order to cause the window to be centered above its transient \a parent by |
1578 | | default, depending on the window manager, it may also be necessary to call |
1579 | | setFlags() with a suitable \l Qt::WindowType (such as \c Qt::Dialog). |
1580 | | |
1581 | | \sa parent() |
1582 | | */ |
1583 | | void QWindow::setTransientParent(QWindow *parent) |
1584 | 0 | { |
1585 | 0 | Q_D(QWindow); |
1586 | 0 | if (parent && !parent->isTopLevel()) { |
1587 | 0 | qWarning() << parent << "must be a top level window."; |
1588 | 0 | return; |
1589 | 0 | } |
1590 | 0 | if (parent == this) { |
1591 | 0 | qWarning() << "transient parent" << parent << "cannot be same as window"; |
1592 | 0 | return; |
1593 | 0 | } |
1594 | | |
1595 | 0 | d->transientParent = parent; |
1596 | |
|
1597 | 0 | QGuiApplicationPrivate::updateBlockedStatus(this); |
1598 | 0 | emit transientParentChanged(parent); |
1599 | 0 | } |
1600 | | |
1601 | | QWindow *QWindow::transientParent() const |
1602 | 0 | { |
1603 | 0 | Q_D(const QWindow); |
1604 | 0 | return d->transientParent.data(); |
1605 | 0 | } |
1606 | | |
1607 | | /* |
1608 | | The setter for the QWindow::transientParent property. |
1609 | | The only reason this exists is to set the transientParentPropertySet flag |
1610 | | so that Qt Quick knows whether it was set programmatically (because of |
1611 | | Window declaration context) or because the user set the property. |
1612 | | */ |
1613 | | void QWindowPrivate::setTransientParent(QWindow *parent) |
1614 | 0 | { |
1615 | 0 | Q_Q(QWindow); |
1616 | 0 | q->setTransientParent(parent); |
1617 | 0 | transientParentPropertySet = true; |
1618 | 0 | } |
1619 | | |
1620 | | /*! |
1621 | | \enum QWindow::AncestorMode |
1622 | | |
1623 | | This enum is used to control whether or not transient parents |
1624 | | should be considered ancestors. |
1625 | | |
1626 | | \value ExcludeTransients Transient parents are not considered ancestors. |
1627 | | \value IncludeTransients Transient parents are considered ancestors. |
1628 | | */ |
1629 | | |
1630 | | /*! |
1631 | | Returns \c true if the window is an ancestor of the given \a child. If \a mode |
1632 | | is IncludeTransients, then transient parents are also considered ancestors. |
1633 | | */ |
1634 | | bool QWindow::isAncestorOf(const QWindow *child, AncestorMode mode) const |
1635 | 0 | { |
1636 | 0 | if (child->parent() == this || (mode == IncludeTransients && child->transientParent() == this)) |
1637 | 0 | return true; |
1638 | | |
1639 | 0 | if (QWindow *parent = child->parent(mode)) { |
1640 | 0 | if (isAncestorOf(parent, mode)) |
1641 | 0 | return true; |
1642 | 0 | } else if (handle() && child->handle()) { |
1643 | 0 | if (handle()->isAncestorOf(child->handle())) |
1644 | 0 | return true; |
1645 | 0 | } |
1646 | | |
1647 | 0 | return false; |
1648 | 0 | } |
1649 | | |
1650 | | /*! |
1651 | | Returns the minimum size of the window. |
1652 | | |
1653 | | \sa setMinimumSize() |
1654 | | */ |
1655 | | QSize QWindow::minimumSize() const |
1656 | 0 | { |
1657 | 0 | Q_D(const QWindow); |
1658 | 0 | return d->minimumSize; |
1659 | 0 | } |
1660 | | |
1661 | | /*! |
1662 | | Returns the maximum size of the window. |
1663 | | |
1664 | | \sa setMaximumSize() |
1665 | | */ |
1666 | | QSize QWindow::maximumSize() const |
1667 | 0 | { |
1668 | 0 | Q_D(const QWindow); |
1669 | 0 | return d->maximumSize; |
1670 | 0 | } |
1671 | | |
1672 | | /*! |
1673 | | Returns the base size of the window. |
1674 | | |
1675 | | \sa setBaseSize() |
1676 | | */ |
1677 | | QSize QWindow::baseSize() const |
1678 | 0 | { |
1679 | 0 | Q_D(const QWindow); |
1680 | 0 | return d->baseSize; |
1681 | 0 | } |
1682 | | |
1683 | | /*! |
1684 | | Returns the size increment of the window. |
1685 | | |
1686 | | \sa setSizeIncrement() |
1687 | | */ |
1688 | | QSize QWindow::sizeIncrement() const |
1689 | 0 | { |
1690 | 0 | Q_D(const QWindow); |
1691 | 0 | return d->sizeIncrement; |
1692 | 0 | } |
1693 | | |
1694 | | /*! |
1695 | | Sets the minimum size of the window. |
1696 | | |
1697 | | This is a hint to the window manager to prevent resizing below the specified \a size. |
1698 | | |
1699 | | \sa setMaximumSize(), minimumSize() |
1700 | | */ |
1701 | | void QWindow::setMinimumSize(const QSize &size) |
1702 | 0 | { |
1703 | 0 | Q_D(QWindow); |
1704 | 0 | d->setMinOrMaxSize( |
1705 | 0 | &d->minimumSize, size, [this, d]() { emit minimumWidthChanged(d->minimumSize.width()); }, |
1706 | 0 | [this, d]() { emit minimumHeightChanged(d->minimumSize.height()); }); |
1707 | 0 | } |
1708 | | |
1709 | | /*! |
1710 | | \property QWindow::x |
1711 | | \brief the x position of the window's geometry |
1712 | | */ |
1713 | | void QWindow::setX(int arg) |
1714 | 0 | { |
1715 | 0 | Q_D(QWindow); |
1716 | 0 | if (x() != arg) |
1717 | 0 | setGeometry(QRect(arg, y(), width(), height())); |
1718 | 0 | else |
1719 | 0 | d->positionAutomatic = false; |
1720 | 0 | } |
1721 | | |
1722 | | /*! |
1723 | | \property QWindow::y |
1724 | | \brief the y position of the window's geometry |
1725 | | */ |
1726 | | void QWindow::setY(int arg) |
1727 | 0 | { |
1728 | 0 | Q_D(QWindow); |
1729 | 0 | if (y() != arg) |
1730 | 0 | setGeometry(QRect(x(), arg, width(), height())); |
1731 | 0 | else |
1732 | 0 | d->positionAutomatic = false; |
1733 | 0 | } |
1734 | | |
1735 | | /*! |
1736 | | \property QWindow::width |
1737 | | \brief the width of the window's geometry |
1738 | | */ |
1739 | | void QWindow::setWidth(int w) |
1740 | 0 | { |
1741 | 0 | resize(w, height()); |
1742 | 0 | } |
1743 | | |
1744 | | /*! |
1745 | | \property QWindow::height |
1746 | | \brief the height of the window's geometry |
1747 | | */ |
1748 | | void QWindow::setHeight(int h) |
1749 | 0 | { |
1750 | 0 | resize(width(), h); |
1751 | 0 | } |
1752 | | |
1753 | | /*! |
1754 | | \property QWindow::minimumWidth |
1755 | | \brief the minimum width of the window's geometry |
1756 | | */ |
1757 | | void QWindow::setMinimumWidth(int w) |
1758 | 0 | { |
1759 | 0 | setMinimumSize(QSize(w, minimumHeight())); |
1760 | 0 | } |
1761 | | |
1762 | | /*! |
1763 | | \property QWindow::minimumHeight |
1764 | | \brief the minimum height of the window's geometry |
1765 | | */ |
1766 | | void QWindow::setMinimumHeight(int h) |
1767 | 0 | { |
1768 | 0 | setMinimumSize(QSize(minimumWidth(), h)); |
1769 | 0 | } |
1770 | | |
1771 | | /*! |
1772 | | Sets the maximum size of the window. |
1773 | | |
1774 | | This is a hint to the window manager to prevent resizing above the specified \a size. |
1775 | | |
1776 | | \sa setMinimumSize(), maximumSize() |
1777 | | */ |
1778 | | void QWindow::setMaximumSize(const QSize &size) |
1779 | 0 | { |
1780 | 0 | Q_D(QWindow); |
1781 | 0 | d->setMinOrMaxSize( |
1782 | 0 | &d->maximumSize, size, [this, d]() { emit maximumWidthChanged(d->maximumSize.width()); }, |
1783 | 0 | [this, d]() { emit maximumHeightChanged(d->maximumSize.height()); }); |
1784 | 0 | } |
1785 | | |
1786 | | /*! |
1787 | | \property QWindow::maximumWidth |
1788 | | \brief the maximum width of the window's geometry |
1789 | | */ |
1790 | | void QWindow::setMaximumWidth(int w) |
1791 | 0 | { |
1792 | 0 | setMaximumSize(QSize(w, maximumHeight())); |
1793 | 0 | } |
1794 | | |
1795 | | /*! |
1796 | | \property QWindow::maximumHeight |
1797 | | \brief the maximum height of the window's geometry |
1798 | | */ |
1799 | | void QWindow::setMaximumHeight(int h) |
1800 | 0 | { |
1801 | 0 | setMaximumSize(QSize(maximumWidth(), h)); |
1802 | 0 | } |
1803 | | |
1804 | | /*! |
1805 | | Sets the base \a size of the window. |
1806 | | |
1807 | | The base size is used to calculate a proper window size if the |
1808 | | window defines sizeIncrement(). |
1809 | | |
1810 | | \sa setMinimumSize(), setMaximumSize(), setSizeIncrement(), baseSize() |
1811 | | */ |
1812 | | void QWindow::setBaseSize(const QSize &size) |
1813 | 0 | { |
1814 | 0 | Q_D(QWindow); |
1815 | 0 | if (d->baseSize == size) |
1816 | 0 | return; |
1817 | 0 | d->baseSize = size; |
1818 | 0 | if (d->platformWindow && isTopLevel()) |
1819 | 0 | d->platformWindow->propagateSizeHints(); |
1820 | 0 | } |
1821 | | |
1822 | | /*! |
1823 | | Sets the size increment (\a size) of the window. |
1824 | | |
1825 | | When the user resizes the window, the size will move in steps of |
1826 | | sizeIncrement().width() pixels horizontally and |
1827 | | sizeIncrement().height() pixels vertically, with baseSize() as the |
1828 | | basis. |
1829 | | |
1830 | | By default, this property contains a size with zero width and height. |
1831 | | |
1832 | | The windowing system might not support size increments. |
1833 | | |
1834 | | \sa setBaseSize(), setMinimumSize(), setMaximumSize() |
1835 | | */ |
1836 | | void QWindow::setSizeIncrement(const QSize &size) |
1837 | 0 | { |
1838 | 0 | Q_D(QWindow); |
1839 | 0 | if (d->sizeIncrement == size) |
1840 | 0 | return; |
1841 | 0 | d->sizeIncrement = size; |
1842 | 0 | if (d->platformWindow && isTopLevel()) |
1843 | 0 | d->platformWindow->propagateSizeHints(); |
1844 | 0 | } |
1845 | | |
1846 | | /*! |
1847 | | Sets the geometry of the window, excluding its window frame, to a |
1848 | | rectangle constructed from \a posx, \a posy, \a w and \a h. |
1849 | | |
1850 | | The geometry is in relation to the virtualGeometry() of its screen. |
1851 | | |
1852 | | \sa geometry() |
1853 | | */ |
1854 | | void QWindow::setGeometry(int posx, int posy, int w, int h) |
1855 | 0 | { |
1856 | 0 | setGeometry(QRect(posx, posy, w, h)); |
1857 | 0 | } |
1858 | | |
1859 | | /*! |
1860 | | \brief Sets the geometry of the window, excluding its window frame, to \a rect. |
1861 | | |
1862 | | The geometry is in relation to the virtualGeometry() of its screen. |
1863 | | |
1864 | | \sa geometry() |
1865 | | */ |
1866 | | void QWindow::setGeometry(const QRect &rect) |
1867 | 0 | { |
1868 | 0 | Q_D(QWindow); |
1869 | 0 | d->positionAutomatic = false; |
1870 | 0 | const QRect oldRect = geometry(); |
1871 | 0 | if (rect == oldRect) |
1872 | 0 | return; |
1873 | | |
1874 | 0 | d->positionPolicy = QWindowPrivate::WindowFrameExclusive; |
1875 | 0 | if (d->platformWindow) { |
1876 | 0 | if (isTopLevel()) { |
1877 | 0 | QScreen *newScreen = d->screenForGeometry(rect); |
1878 | 0 | d->platformWindow->setGeometry(QHighDpi::toNativeGlobalPosition(rect, newScreen)); |
1879 | 0 | } else { |
1880 | 0 | d->platformWindow->setGeometry(QHighDpi::toNativeWindowGeometry(rect, this)); |
1881 | 0 | } |
1882 | 0 | } else { |
1883 | 0 | d->geometry = rect; |
1884 | |
|
1885 | 0 | if (rect.x() != oldRect.x()) |
1886 | 0 | emit xChanged(rect.x()); |
1887 | 0 | if (rect.y() != oldRect.y()) |
1888 | 0 | emit yChanged(rect.y()); |
1889 | 0 | if (rect.width() != oldRect.width()) |
1890 | 0 | emit widthChanged(rect.width()); |
1891 | 0 | if (rect.height() != oldRect.height()) |
1892 | 0 | emit heightChanged(rect.height()); |
1893 | 0 | } |
1894 | 0 | } |
1895 | | |
1896 | | /* |
1897 | | This is equivalent to QPlatformWindow::screenForGeometry, but in platform |
1898 | | independent coordinates. The duplication is unfortunate, but there is a |
1899 | | chicken and egg problem here: we cannot convert to native coordinates |
1900 | | before we know which screen we are on. |
1901 | | */ |
1902 | | QScreen *QWindowPrivate::screenForGeometry(const QRect &newGeometry) const |
1903 | 0 | { |
1904 | 0 | Q_Q(const QWindow); |
1905 | 0 | QScreen *currentScreen = q->screen(); |
1906 | 0 | QScreen *fallback = currentScreen; |
1907 | 0 | QPoint center = newGeometry.center(); |
1908 | 0 | if (!q->parent() && currentScreen && !currentScreen->geometry().contains(center)) { |
1909 | 0 | const auto screens = currentScreen->virtualSiblings(); |
1910 | 0 | for (QScreen* screen : screens) { |
1911 | 0 | if (screen->geometry().contains(center)) |
1912 | 0 | return screen; |
1913 | 0 | if (screen->geometry().intersects(newGeometry)) |
1914 | 0 | fallback = screen; |
1915 | 0 | } |
1916 | 0 | } |
1917 | 0 | return fallback; |
1918 | 0 | } |
1919 | | |
1920 | | |
1921 | | /*! |
1922 | | Returns the geometry of the window, excluding its window frame. |
1923 | | |
1924 | | The geometry is in relation to the virtualGeometry() of its screen. |
1925 | | |
1926 | | \sa frameMargins(), frameGeometry() |
1927 | | */ |
1928 | | QRect QWindow::geometry() const |
1929 | 0 | { |
1930 | 0 | Q_D(const QWindow); |
1931 | 0 | if (d->platformWindow) { |
1932 | 0 | const auto nativeGeometry = d->platformWindow->geometry(); |
1933 | 0 | return QHighDpi::fromNativeWindowGeometry(nativeGeometry, this); |
1934 | 0 | } |
1935 | 0 | return d->geometry; |
1936 | 0 | } |
1937 | | |
1938 | | /*! |
1939 | | Returns the window frame margins surrounding the window. |
1940 | | |
1941 | | \sa geometry(), frameGeometry() |
1942 | | */ |
1943 | | QMargins QWindow::frameMargins() const |
1944 | 0 | { |
1945 | 0 | Q_D(const QWindow); |
1946 | 0 | if (d->platformWindow) |
1947 | 0 | return QHighDpi::fromNativePixels(d->platformWindow->frameMargins(), this); |
1948 | 0 | return QMargins(); |
1949 | 0 | } |
1950 | | |
1951 | | /*! |
1952 | | Returns the geometry of the window, including its window frame. |
1953 | | |
1954 | | The geometry is in relation to the virtualGeometry() of its screen. |
1955 | | |
1956 | | \sa geometry(), frameMargins() |
1957 | | */ |
1958 | | QRect QWindow::frameGeometry() const |
1959 | 0 | { |
1960 | 0 | Q_D(const QWindow); |
1961 | 0 | if (d->platformWindow) { |
1962 | 0 | QMargins m = frameMargins(); |
1963 | 0 | return QHighDpi::fromNativeWindowGeometry(d->platformWindow->geometry(), this).adjusted(-m.left(), -m.top(), m.right(), m.bottom()); |
1964 | 0 | } |
1965 | 0 | return d->geometry; |
1966 | 0 | } |
1967 | | |
1968 | | /*! |
1969 | | Returns the top left position of the window, including its window frame. |
1970 | | |
1971 | | This returns the same value as frameGeometry().topLeft(). |
1972 | | |
1973 | | \sa geometry(), frameGeometry() |
1974 | | */ |
1975 | | QPoint QWindow::framePosition() const |
1976 | 0 | { |
1977 | 0 | Q_D(const QWindow); |
1978 | 0 | if (d->platformWindow) { |
1979 | 0 | QMargins margins = frameMargins(); |
1980 | 0 | return QHighDpi::fromNativeWindowGeometry(d->platformWindow->geometry().topLeft(), this) - QPoint(margins.left(), margins.top()); |
1981 | 0 | } |
1982 | 0 | return d->geometry.topLeft(); |
1983 | 0 | } |
1984 | | |
1985 | | /*! |
1986 | | Sets the upper left position of the window (\a point) including its window frame. |
1987 | | |
1988 | | The position is in relation to the virtualGeometry() of its screen. |
1989 | | |
1990 | | \sa setGeometry(), frameGeometry() |
1991 | | */ |
1992 | | void QWindow::setFramePosition(const QPoint &point) |
1993 | 0 | { |
1994 | 0 | Q_D(QWindow); |
1995 | 0 | d->positionPolicy = QWindowPrivate::WindowFrameInclusive; |
1996 | 0 | d->positionAutomatic = false; |
1997 | 0 | if (d->platformWindow) { |
1998 | 0 | d->platformWindow->setGeometry(QHighDpi::toNativeWindowGeometry(QRect(point, size()), this)); |
1999 | 0 | } else { |
2000 | 0 | d->geometry.moveTopLeft(point); |
2001 | 0 | } |
2002 | 0 | } |
2003 | | |
2004 | | /*! |
2005 | | \fn void QWindow::setFramePosition(int x, int y) |
2006 | | \brief Sets the upper left position of the window, including its window frame, to \a x, \a y |
2007 | | |
2008 | | The position is in relation to the virtualGeometry() of its screen. |
2009 | | |
2010 | | \since 6.12 |
2011 | | \sa setGeometry(), frameGeometry() |
2012 | | */ |
2013 | | |
2014 | | /*! |
2015 | | Returns the safe area margins of the window. |
2016 | | |
2017 | | The safe area represents the part of the window where content |
2018 | | can be safely placed without risk of being obscured by, or |
2019 | | conflicting with, other UI elements, such as system UIs. |
2020 | | |
2021 | | The margins are relative to the internal geometry of the |
2022 | | window, i.e QRect(0, 0, width(), height()). |
2023 | | |
2024 | | \code |
2025 | | void PaintDeviceWindow::paintEvent(QPaintEvent *) |
2026 | | { |
2027 | | QPainter painter(this); |
2028 | | QRect rect(0, 0, width(), height()); |
2029 | | painter.fillRect(rect, QGradient::SunnyMorning); |
2030 | | painter.fillRect(rect - safeAreaMargins(), QGradient::DustyGrass); |
2031 | | } |
2032 | | \endcode |
2033 | | |
2034 | | \since 6.9 |
2035 | | \sa geometry(), safeAreaMarginsChanged() |
2036 | | */ |
2037 | | QMargins QWindow::safeAreaMargins() const |
2038 | 0 | { |
2039 | 0 | Q_D(const QWindow); |
2040 | 0 | if (d->platformWindow) |
2041 | 0 | return QHighDpi::fromNativePixels(d->platformWindow->safeAreaMargins(), this); |
2042 | 0 | return {}; |
2043 | 0 | } |
2044 | | |
2045 | | /*! |
2046 | | \fn void QWindow::safeAreaMarginsChanged(QMargins margins) |
2047 | | \since 6.9 |
2048 | | |
2049 | | This signal is emitted when the safe area margins changed to \a margins. |
2050 | | |
2051 | | \sa safeAreaMargins() |
2052 | | */ |
2053 | | |
2054 | | /*! |
2055 | | \brief set the position of the window on the desktop to \a pt |
2056 | | |
2057 | | The position is in relation to the virtualGeometry() of its screen. |
2058 | | |
2059 | | For interactively moving windows, see startSystemMove(). For interactively |
2060 | | resizing windows, see startSystemResize(). |
2061 | | |
2062 | | \note Not all windowing systems support setting or querying top level window positions. |
2063 | | On such a system, programmatically moving windows may not have any effect, and artificial |
2064 | | values may be returned for the current positions, such as \c QPoint(0, 0). |
2065 | | |
2066 | | \sa position(), startSystemMove() |
2067 | | */ |
2068 | | void QWindow::setPosition(const QPoint &pt) |
2069 | 0 | { |
2070 | 0 | setGeometry(QRect(pt, size())); |
2071 | 0 | } |
2072 | | |
2073 | | /*! |
2074 | | \brief set the position of the window on the desktop to \a posx, \a posy |
2075 | | |
2076 | | The position is in relation to the virtualGeometry() of its screen. |
2077 | | |
2078 | | \sa position() |
2079 | | */ |
2080 | | void QWindow::setPosition(int posx, int posy) |
2081 | 0 | { |
2082 | 0 | setPosition(QPoint(posx, posy)); |
2083 | 0 | } |
2084 | | |
2085 | | /*! |
2086 | | \fn QPoint QWindow::position() const |
2087 | | \brief Returns the position of the window on the desktop excluding any window frame |
2088 | | |
2089 | | \note Not all windowing systems support setting or querying top level window positions. |
2090 | | On such a system, programmatically moving windows may not have any effect, and artificial |
2091 | | values may be returned for the current positions, such as \c QPoint(0, 0). |
2092 | | |
2093 | | \sa setPosition() |
2094 | | */ |
2095 | | |
2096 | | /*! |
2097 | | \fn QSize QWindow::size() const |
2098 | | \brief Returns the size of the window excluding any window frame |
2099 | | |
2100 | | \sa resize() |
2101 | | */ |
2102 | | |
2103 | | /*! |
2104 | | set the size of the window, excluding any window frame, to a QSize |
2105 | | constructed from width \a w and height \a h |
2106 | | |
2107 | | For interactively resizing windows, see startSystemResize(). |
2108 | | |
2109 | | \sa size(), geometry() |
2110 | | */ |
2111 | | void QWindow::resize(int w, int h) |
2112 | 0 | { |
2113 | 0 | resize(QSize(w, h)); |
2114 | 0 | } |
2115 | | |
2116 | | /*! |
2117 | | \brief set the size of the window, excluding any window frame, to \a newSize |
2118 | | |
2119 | | \sa size(), geometry() |
2120 | | */ |
2121 | | void QWindow::resize(const QSize &newSize) |
2122 | 0 | { |
2123 | 0 | Q_D(QWindow); |
2124 | |
|
2125 | 0 | const QSize oldSize = size(); |
2126 | 0 | if (newSize == oldSize) |
2127 | 0 | return; |
2128 | | |
2129 | 0 | d->positionPolicy = QWindowPrivate::WindowFrameExclusive; |
2130 | 0 | if (d->platformWindow) { |
2131 | 0 | d->platformWindow->setGeometry( |
2132 | 0 | QHighDpi::toNativeWindowGeometry(QRect(position(), newSize), this)); |
2133 | 0 | } else { |
2134 | 0 | d->geometry.setSize(newSize); |
2135 | 0 | if (newSize.width() != oldSize.width()) |
2136 | 0 | emit widthChanged(newSize.width()); |
2137 | 0 | if (newSize.height() != oldSize.height()) |
2138 | 0 | emit heightChanged(newSize.height()); |
2139 | 0 | } |
2140 | 0 | } |
2141 | | |
2142 | | /*! |
2143 | | Releases the native platform resources associated with this window. |
2144 | | |
2145 | | \sa create() |
2146 | | */ |
2147 | | void QWindow::destroy() |
2148 | 0 | { |
2149 | 0 | Q_D(QWindow); |
2150 | 0 | if (!d->platformWindow) |
2151 | 0 | return; |
2152 | | |
2153 | 0 | if (d->platformWindow->isForeignWindow()) |
2154 | 0 | return; |
2155 | | |
2156 | 0 | d->destroy(); |
2157 | 0 | } |
2158 | | |
2159 | | void QWindowPrivate::destroy() |
2160 | 0 | { |
2161 | 0 | if (!platformWindow) |
2162 | 0 | return; |
2163 | | |
2164 | 0 | Q_Q(QWindow); |
2165 | 0 | QObjectList childrenWindows = q->children(); |
2166 | 0 | for (int i = 0; i < childrenWindows.size(); i++) { |
2167 | 0 | QObject *object = childrenWindows.at(i); |
2168 | 0 | if (object->isWindowType()) { |
2169 | 0 | QWindow *w = static_cast<QWindow*>(object); |
2170 | 0 | qt_window_private(w)->destroy(); |
2171 | 0 | } |
2172 | 0 | } |
2173 | |
|
2174 | 0 | bool wasVisible = q->isVisible(); |
2175 | 0 | visibilityOnDestroy = wasVisible && platformWindow; |
2176 | |
|
2177 | 0 | q->setVisible(false); |
2178 | | |
2179 | | // Let subclasses act, typically by doing graphics resource cleaup, when |
2180 | | // the window, to which graphics resource may be tied, is going away. |
2181 | | // |
2182 | | // NB! This is dysfunctional when destroy() is invoked from the dtor since |
2183 | | // a reimplemented event() will not get called in the subclasses at that |
2184 | | // stage. However, the typical QWindow cleanup involves either close() or |
2185 | | // going through QWindowContainer, both of which will do an explicit, early |
2186 | | // destroy(), which is good here. |
2187 | |
|
2188 | 0 | QPlatformSurfaceEvent e(QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed); |
2189 | 0 | QGuiApplication::sendEvent(q, &e); |
2190 | | |
2191 | | // Unset platformWindow before deleting, so that the destructor of the |
2192 | | // platform window does not recurse back into the platform window via |
2193 | | // this window during destruction (e.g. as a result of platform events). |
2194 | 0 | delete std::exchange(platformWindow, nullptr); |
2195 | |
|
2196 | 0 | if (QGuiApplicationPrivate::focus_window == q) |
2197 | 0 | QGuiApplicationPrivate::focus_window = q->parent(); |
2198 | 0 | if (QGuiApplicationPrivate::currentMouseWindow == q) |
2199 | 0 | QGuiApplicationPrivate::currentMouseWindow = q->parent(); |
2200 | 0 | if (QGuiApplicationPrivate::currentMousePressWindow == q) |
2201 | 0 | QGuiApplicationPrivate::currentMousePressWindow = q->parent(); |
2202 | |
|
2203 | 0 | for (int i = 0; i < QGuiApplicationPrivate::tabletDevicePoints.size(); ++i) |
2204 | 0 | if (QGuiApplicationPrivate::tabletDevicePoints.at(i).target == q) |
2205 | 0 | QGuiApplicationPrivate::tabletDevicePoints[i].target = q->parent(); |
2206 | |
|
2207 | 0 | resizeEventPending = true; |
2208 | 0 | receivedExpose = false; |
2209 | 0 | exposed = false; |
2210 | | |
2211 | | // Position set via setFramePosition will have propagated back to |
2212 | | // our geometry member as client geometry, so when creating the |
2213 | | // window again we need to ensure the policy matches that. |
2214 | 0 | positionPolicy = QWindowPrivate::WindowFrameExclusive; |
2215 | 0 | } |
2216 | | |
2217 | | /*! |
2218 | | Returns the platform window corresponding to the window. |
2219 | | |
2220 | | \internal |
2221 | | */ |
2222 | | QPlatformWindow *QWindow::handle() const |
2223 | 0 | { |
2224 | 0 | Q_D(const QWindow); |
2225 | 0 | return d->platformWindow; |
2226 | 0 | } |
2227 | | |
2228 | | /*! |
2229 | | Returns the platform surface corresponding to the window. |
2230 | | |
2231 | | \internal |
2232 | | */ |
2233 | | QPlatformSurface *QWindow::surfaceHandle() const |
2234 | 0 | { |
2235 | 0 | Q_D(const QWindow); |
2236 | 0 | return d->platformWindow; |
2237 | 0 | } |
2238 | | |
2239 | | /*! |
2240 | | Sets whether keyboard grab should be enabled or not (\a grab). |
2241 | | |
2242 | | If the return value is true, the window receives all key events until |
2243 | | setKeyboardGrabEnabled(false) is called; other windows get no key events at |
2244 | | all. Mouse events are not affected. Use setMouseGrabEnabled() if you want |
2245 | | to grab that. |
2246 | | |
2247 | | \sa setMouseGrabEnabled() |
2248 | | */ |
2249 | | bool QWindow::setKeyboardGrabEnabled(bool grab) |
2250 | 0 | { |
2251 | 0 | Q_D(QWindow); |
2252 | 0 | if (d->platformWindow) |
2253 | 0 | return d->platformWindow->setKeyboardGrabEnabled(grab); |
2254 | 0 | return false; |
2255 | 0 | } |
2256 | | |
2257 | | /*! |
2258 | | Sets whether mouse grab should be enabled or not (\a grab). |
2259 | | |
2260 | | If the return value is true, the window receives all mouse events until setMouseGrabEnabled(false) is |
2261 | | called; other windows get no mouse events at all. Keyboard events are not affected. |
2262 | | Use setKeyboardGrabEnabled() if you want to grab that. |
2263 | | |
2264 | | \sa setKeyboardGrabEnabled() |
2265 | | */ |
2266 | | bool QWindow::setMouseGrabEnabled(bool grab) |
2267 | 0 | { |
2268 | 0 | Q_D(QWindow); |
2269 | 0 | if (d->platformWindow) |
2270 | 0 | return d->platformWindow->setMouseGrabEnabled(grab); |
2271 | 0 | return false; |
2272 | 0 | } |
2273 | | |
2274 | | /*! |
2275 | | Returns the screen on which the window is shown, or null if there is none. |
2276 | | |
2277 | | For child windows, this returns the screen of the corresponding top level window. |
2278 | | |
2279 | | \sa setScreen(), QScreen::virtualSiblings() |
2280 | | */ |
2281 | | QScreen *QWindow::screen() const |
2282 | 0 | { |
2283 | 0 | Q_D(const QWindow); |
2284 | 0 | return d->parentWindow ? d->parentWindow->screen() : d->topLevelScreen.data(); |
2285 | 0 | } |
2286 | | |
2287 | | /*! |
2288 | | Sets the screen on which the window should be shown. |
2289 | | |
2290 | | If the window has been created, it will be recreated on the \a newScreen. |
2291 | | |
2292 | | \note If the screen is part of a virtual desktop of multiple screens, |
2293 | | the window will not move automatically to \a newScreen. To place the |
2294 | | window relative to the screen, use the screen's topLeft() position. |
2295 | | |
2296 | | This function only works for top level windows. |
2297 | | |
2298 | | \sa screen(), QScreen::virtualSiblings() |
2299 | | */ |
2300 | | void QWindow::setScreen(QScreen *newScreen) |
2301 | 0 | { |
2302 | 0 | Q_D(QWindow); |
2303 | 0 | if (!newScreen) |
2304 | 0 | newScreen = QGuiApplication::primaryScreen(); |
2305 | 0 | d->setTopLevelScreen(newScreen, newScreen != nullptr); |
2306 | 0 | } |
2307 | | |
2308 | | /*! |
2309 | | \fn QWindow::screenChanged(QScreen *screen) |
2310 | | |
2311 | | This signal is emitted when a window's \a screen changes, either |
2312 | | by being set explicitly with setScreen(), or automatically when |
2313 | | the window's screen is removed. |
2314 | | */ |
2315 | | |
2316 | | /*! |
2317 | | Returns the accessibility interface for the object that the window represents |
2318 | | \internal |
2319 | | \sa QAccessible |
2320 | | */ |
2321 | | QAccessibleInterface *QWindow::accessibleRoot() const |
2322 | 0 | { |
2323 | 0 | return nullptr; |
2324 | 0 | } |
2325 | | |
2326 | | #if QT_CONFIG(accessibility) |
2327 | | /*! |
2328 | | \internal |
2329 | | |
2330 | | Sets the accessible parent of the window to \a parent. |
2331 | | |
2332 | | A window container represents the window it hosts as a child in its |
2333 | | accessibility interface, so the window has to point back to the container |
2334 | | as well. |
2335 | | */ |
2336 | | void QWindowPrivate::setAccessibleParent(QObject *parent) |
2337 | 0 | { |
2338 | 0 | Q_Q(QWindow); |
2339 | |
|
2340 | 0 | if (accessibleParent == parent) |
2341 | 0 | return; |
2342 | | |
2343 | 0 | accessibleParent = parent; |
2344 | |
|
2345 | 0 | if (QGuiApplicationPrivate::is_app_running && !QGuiApplicationPrivate::is_app_closing) { |
2346 | 0 | QAccessibleEvent event(q, QAccessible::ParentChanged); |
2347 | 0 | QAccessible::updateAccessibility(&event); |
2348 | 0 | } |
2349 | 0 | } |
2350 | | #endif |
2351 | | |
2352 | | /*! |
2353 | | \fn QWindow::focusObjectChanged(QObject *object) |
2354 | | |
2355 | | This signal is emitted when the final receiver of events tied to focus |
2356 | | is changed to \a object. |
2357 | | |
2358 | | \sa focusObject() |
2359 | | */ |
2360 | | |
2361 | | /*! |
2362 | | Returns the QObject that will be the final receiver of events tied focus, such |
2363 | | as key events. |
2364 | | */ |
2365 | | QObject *QWindow::focusObject() const |
2366 | 0 | { |
2367 | 0 | return const_cast<QWindow *>(this); |
2368 | 0 | } |
2369 | | |
2370 | | /*! |
2371 | | Shows the window. |
2372 | | |
2373 | | For child windows, this is equivalent to calling showNormal(). |
2374 | | Otherwise, it is equivalent to calling showFullScreen(), showMaximized(), or showNormal(), |
2375 | | depending on the platform's default behavior for the window type and flags. |
2376 | | |
2377 | | \sa showFullScreen(), showMaximized(), showNormal(), hide(), QStyleHints::showIsFullScreen(), flags() |
2378 | | */ |
2379 | | void QWindow::show() |
2380 | 0 | { |
2381 | 0 | if (parent()) { |
2382 | 0 | showNormal(); |
2383 | 0 | } else { |
2384 | 0 | const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration(); |
2385 | 0 | Qt::WindowState defaultState = platformIntegration->defaultWindowState(d_func()->windowFlags); |
2386 | 0 | if (defaultState == Qt::WindowFullScreen) |
2387 | 0 | showFullScreen(); |
2388 | 0 | else if (defaultState == Qt::WindowMaximized) |
2389 | 0 | showMaximized(); |
2390 | 0 | else |
2391 | 0 | showNormal(); |
2392 | 0 | } |
2393 | 0 | } |
2394 | | |
2395 | | /*! |
2396 | | Hides the window. |
2397 | | |
2398 | | Equivalent to calling setVisible(false). |
2399 | | |
2400 | | \sa show(), setVisible() |
2401 | | */ |
2402 | | void QWindow::hide() |
2403 | 0 | { |
2404 | 0 | setVisible(false); |
2405 | 0 | } |
2406 | | |
2407 | | /*! |
2408 | | Shows the window as minimized. |
2409 | | |
2410 | | Equivalent to calling setWindowStates(Qt::WindowMinimized) and then |
2411 | | setVisible(true). |
2412 | | |
2413 | | \sa setWindowStates(), setVisible() |
2414 | | */ |
2415 | | void QWindow::showMinimized() |
2416 | 0 | { |
2417 | 0 | setWindowStates(Qt::WindowMinimized); |
2418 | 0 | setVisible(true); |
2419 | 0 | } |
2420 | | |
2421 | | /*! |
2422 | | Shows the window as maximized. |
2423 | | |
2424 | | Equivalent to calling setWindowStates(Qt::WindowMaximized) and then |
2425 | | setVisible(true). |
2426 | | |
2427 | | \sa setWindowStates(), setVisible() |
2428 | | */ |
2429 | | void QWindow::showMaximized() |
2430 | 0 | { |
2431 | 0 | setWindowStates(Qt::WindowMaximized); |
2432 | 0 | setVisible(true); |
2433 | 0 | } |
2434 | | |
2435 | | /*! |
2436 | | Shows the window as fullscreen. |
2437 | | |
2438 | | Equivalent to calling setWindowStates(Qt::WindowFullScreen) and then |
2439 | | setVisible(true). |
2440 | | |
2441 | | See the \l{QWidget::showFullScreen()} documentation for platform-specific |
2442 | | considerations and limitations. |
2443 | | |
2444 | | \sa setWindowStates(), setVisible() |
2445 | | */ |
2446 | | void QWindow::showFullScreen() |
2447 | 0 | { |
2448 | 0 | setWindowStates(Qt::WindowFullScreen); |
2449 | 0 | setVisible(true); |
2450 | 0 | #if !defined Q_OS_QNX // On QNX this window will be activated anyway from libscreen |
2451 | | // activating it here before libscreen activates it causes problems |
2452 | 0 | requestActivate(); |
2453 | 0 | #endif |
2454 | 0 | } |
2455 | | |
2456 | | /*! |
2457 | | Shows the window as normal, i.e. neither maximized, minimized, nor fullscreen. |
2458 | | |
2459 | | Equivalent to calling setWindowStates(Qt::WindowNoState) and then |
2460 | | setVisible(true). |
2461 | | |
2462 | | \sa setWindowStates(), setVisible() |
2463 | | */ |
2464 | | void QWindow::showNormal() |
2465 | 0 | { |
2466 | 0 | setWindowStates(Qt::WindowNoState); |
2467 | 0 | setVisible(true); |
2468 | 0 | } |
2469 | | |
2470 | | /*! |
2471 | | Close the window. |
2472 | | |
2473 | | This closes the window, effectively calling destroy(), and potentially |
2474 | | quitting the application. Returns \c true on success, false if it has a parent |
2475 | | window (in which case the top level window should be closed instead). |
2476 | | |
2477 | | \sa destroy(), QGuiApplication::quitOnLastWindowClosed(), closeEvent() |
2478 | | */ |
2479 | | bool QWindow::close() |
2480 | 0 | { |
2481 | 0 | Q_D(QWindow); |
2482 | 0 | if (d->inClose) |
2483 | 0 | return true; |
2484 | | |
2485 | | // Do not close non top level windows |
2486 | 0 | if (!isTopLevel()) |
2487 | 0 | return false; |
2488 | | |
2489 | 0 | if (!d->platformWindow) { |
2490 | | // dock widgets can transition back and forth to being popups; |
2491 | | // avoid getting stuck |
2492 | 0 | if (QGuiApplicationPrivate::activePopupWindow() == this) |
2493 | 0 | QGuiApplicationPrivate::closePopup(this); |
2494 | 0 | return true; |
2495 | 0 | } |
2496 | | |
2497 | | // The window might be deleted during close, |
2498 | | // as a result of delivering the close event. |
2499 | 0 | QPointer guard(this); |
2500 | 0 | d->inClose = true; |
2501 | 0 | bool success = d->platformWindow->close(); |
2502 | 0 | if (guard) |
2503 | 0 | d->inClose = false; |
2504 | |
|
2505 | 0 | return success; |
2506 | 0 | } |
2507 | | |
2508 | | bool QWindowPrivate::participatesInLastWindowClosed() const |
2509 | 0 | { |
2510 | 0 | Q_Q(const QWindow); |
2511 | |
|
2512 | 0 | if (!q->isTopLevel()) |
2513 | 0 | return false; |
2514 | | |
2515 | | // Tool-tip widgets do not normally have Qt::WA_QuitOnClose, |
2516 | | // but since we do not have a similar flag for non-widget |
2517 | | // windows we need an explicit exclusion here as well. |
2518 | 0 | if (q->type() == Qt::ToolTip) |
2519 | 0 | return false; |
2520 | | |
2521 | | // A window with a transient parent is not a primary window, |
2522 | | // it's a secondary window. |
2523 | 0 | if (q->transientParent()) |
2524 | 0 | return false; |
2525 | | |
2526 | 0 | return true; |
2527 | 0 | } |
2528 | | |
2529 | | bool QWindowPrivate::treatAsVisible() const |
2530 | 0 | { |
2531 | 0 | Q_Q(const QWindow); |
2532 | 0 | return q->isVisible(); |
2533 | 0 | } |
2534 | | |
2535 | | /*! \internal |
2536 | | Returns the popup window that has consumed \a event, if any. |
2537 | | \a activePopupOnPress is the window that we have observed previously handling the press. |
2538 | | */ |
2539 | | const QWindow *QWindowPrivate::forwardToPopup(QEvent *event, const QWindow */*activePopupOnPress*/) |
2540 | 0 | { |
2541 | 0 | Q_Q(const QWindow); |
2542 | 0 | qCDebug(lcPopup) << "checking for popup alternative to" << q << "for" << event |
2543 | 0 | << "active popup?" << QGuiApplicationPrivate::activePopupWindow(); |
2544 | 0 | QWindow *ret = nullptr; |
2545 | 0 | if (QWindow *popupWindow = QGuiApplicationPrivate::activePopupWindow()) { |
2546 | 0 | if (q == popupWindow) |
2547 | 0 | return nullptr; // avoid infinite recursion: we're already handling it |
2548 | 0 | if (event->isPointerEvent()) { |
2549 | | // detach eventPoints before modifying them |
2550 | 0 | QScopedPointer<QPointerEvent> pointerEvent(static_cast<QPointerEvent *>(event)->clone()); |
2551 | 0 | for (int i = 0; i < pointerEvent->pointCount(); ++i) { |
2552 | 0 | QEventPoint &eventPoint = pointerEvent->point(i); |
2553 | 0 | const QPoint globalPos = eventPoint.globalPosition().toPoint(); |
2554 | 0 | const QPointF mapped = popupWindow->mapFromGlobal(globalPos); |
2555 | 0 | QMutableEventPoint::setPosition(eventPoint, mapped); |
2556 | 0 | QMutableEventPoint::setScenePosition(eventPoint, mapped); |
2557 | 0 | } |
2558 | | |
2559 | | /* Popups are expected to be able to directly handle the |
2560 | | drag-release sequence after pressing to open, as well as |
2561 | | any other mouse events that occur within the popup's bounds. */ |
2562 | 0 | if (QCoreApplication::sendSpontaneousEvent(popupWindow, pointerEvent.get())) { |
2563 | 0 | event->setAccepted(pointerEvent->isAccepted()); |
2564 | 0 | if (pointerEvent->isAccepted()) |
2565 | 0 | ret = popupWindow; |
2566 | 0 | } |
2567 | 0 | qCDebug(lcPopup) << q << "forwarded" << event->type() << "to popup" << popupWindow |
2568 | 0 | << "handled?" << (ret != nullptr) |
2569 | 0 | << "accepted?" << event->isAccepted(); |
2570 | 0 | return ret; |
2571 | 0 | } else if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) { |
2572 | 0 | if (QCoreApplication::sendSpontaneousEvent(popupWindow, event)) |
2573 | 0 | ret = popupWindow; |
2574 | 0 | qCDebug(lcPopup) << q << "forwarded" << event->type() << "to popup" << popupWindow |
2575 | 0 | << "handled?" << (ret != nullptr) |
2576 | 0 | << "accepted?" << event->isAccepted(); |
2577 | 0 | return ret; |
2578 | 0 | } |
2579 | 0 | } |
2580 | 0 | return ret; |
2581 | 0 | } |
2582 | | |
2583 | | /*! |
2584 | | The expose event (\a ev) is sent by the window system when a window moves |
2585 | | between the un-exposed and exposed states. |
2586 | | |
2587 | | An exposed window is potentially visible to the user. If the window is moved |
2588 | | off screen, is made totally obscured by another window, is minimized, or |
2589 | | similar, this function might be called and the value of isExposed() might |
2590 | | change to false. You may use this event to limit expensive operations such |
2591 | | as animations to only run when the window is exposed. |
2592 | | |
2593 | | This event should not be used to paint. To handle painting implement |
2594 | | paintEvent() instead. |
2595 | | |
2596 | | A resize event will always be sent before the expose event the first time |
2597 | | a window is shown. |
2598 | | |
2599 | | \sa paintEvent(), isExposed() |
2600 | | */ |
2601 | | void QWindow::exposeEvent(QExposeEvent *ev) |
2602 | 0 | { |
2603 | 0 | ev->ignore(); |
2604 | 0 | } |
2605 | | |
2606 | | /*! |
2607 | | The paint event (\a ev) is sent by the window system whenever an area of |
2608 | | the window needs a repaint, for example when initially showing the window, |
2609 | | or due to parts of the window being uncovered by moving another window. |
2610 | | |
2611 | | The application is expected to render into the window in response to the |
2612 | | paint event, regardless of the exposed state of the window. For example, |
2613 | | a paint event may be sent before the window is exposed, to prepare it for |
2614 | | showing to the user. |
2615 | | |
2616 | | \since 6.0 |
2617 | | |
2618 | | \sa exposeEvent() |
2619 | | */ |
2620 | | void QWindow::paintEvent(QPaintEvent *ev) |
2621 | 0 | { |
2622 | 0 | ev->ignore(); |
2623 | 0 | } |
2624 | | |
2625 | | /*! |
2626 | | Override this to handle window move events (\a ev). |
2627 | | */ |
2628 | | void QWindow::moveEvent(QMoveEvent *ev) |
2629 | 0 | { |
2630 | 0 | ev->ignore(); |
2631 | 0 | } |
2632 | | |
2633 | | /*! |
2634 | | Override this to handle resize events (\a ev). |
2635 | | |
2636 | | The resize event is called whenever the window is resized in the windowing system, |
2637 | | either directly through the windowing system acknowledging a setGeometry() or resize() request, |
2638 | | or indirectly through the user resizing the window manually. |
2639 | | */ |
2640 | | void QWindow::resizeEvent(QResizeEvent *ev) |
2641 | 0 | { |
2642 | 0 | ev->ignore(); |
2643 | 0 | } |
2644 | | |
2645 | | /*! |
2646 | | Override this to handle show events (\a ev). |
2647 | | |
2648 | | The function is called when the window has requested becoming visible. |
2649 | | |
2650 | | If the window is successfully shown by the windowing system, this will |
2651 | | be followed by a resize and an expose event. |
2652 | | */ |
2653 | | void QWindow::showEvent(QShowEvent *ev) |
2654 | 0 | { |
2655 | 0 | ev->ignore(); |
2656 | 0 | } |
2657 | | |
2658 | | /*! |
2659 | | Override this to handle hide events (\a ev). |
2660 | | |
2661 | | The function is called when the window has requested being hidden in the |
2662 | | windowing system. |
2663 | | */ |
2664 | | void QWindow::hideEvent(QHideEvent *ev) |
2665 | 0 | { |
2666 | 0 | ev->ignore(); |
2667 | 0 | } |
2668 | | |
2669 | | /*! |
2670 | | Override this to handle close events (\a ev). |
2671 | | |
2672 | | The function is called when the window is requested to close. Call \l{QEvent::ignore()} |
2673 | | on the event if you want to prevent the window from being closed. |
2674 | | |
2675 | | \sa close() |
2676 | | */ |
2677 | | void QWindow::closeEvent(QCloseEvent *ev) |
2678 | 0 | { |
2679 | 0 | Q_UNUSED(ev); |
2680 | 0 | } |
2681 | | |
2682 | | /*! |
2683 | | Override this to handle any event (\a ev) sent to the window. |
2684 | | Return \c true if the event was recognized and processed. |
2685 | | |
2686 | | Remember to call the base class version if you wish for mouse events, |
2687 | | key events, resize events, etc to be dispatched as usual. |
2688 | | */ |
2689 | | bool QWindow::event(QEvent *ev) |
2690 | 0 | { |
2691 | 0 | Q_D(QWindow); |
2692 | 0 | switch (ev->type()) { |
2693 | 0 | case QEvent::MouseMove: |
2694 | 0 | mouseMoveEvent(static_cast<QMouseEvent*>(ev)); |
2695 | 0 | break; |
2696 | | |
2697 | 0 | case QEvent::MouseButtonPress: { |
2698 | 0 | auto *me = static_cast<QMouseEvent*>(ev); |
2699 | 0 | mousePressEvent(me); |
2700 | 0 | if (!ev->isAccepted()) |
2701 | 0 | d->maybeSynthesizeContextMenuEvent(me); |
2702 | 0 | break; |
2703 | 0 | } |
2704 | | |
2705 | 0 | case QEvent::MouseButtonRelease: { |
2706 | 0 | auto *me = static_cast<QMouseEvent*>(ev); |
2707 | 0 | mouseReleaseEvent(me); |
2708 | 0 | if (!ev->isAccepted()) |
2709 | 0 | d->maybeSynthesizeContextMenuEvent(me); |
2710 | 0 | break; |
2711 | 0 | } |
2712 | | |
2713 | 0 | case QEvent::MouseButtonDblClick: |
2714 | 0 | mouseDoubleClickEvent(static_cast<QMouseEvent*>(ev)); |
2715 | 0 | break; |
2716 | | |
2717 | 0 | case QEvent::TouchBegin: |
2718 | 0 | case QEvent::TouchUpdate: |
2719 | 0 | case QEvent::TouchEnd: |
2720 | 0 | case QEvent::TouchCancel: |
2721 | 0 | touchEvent(static_cast<QTouchEvent *>(ev)); |
2722 | 0 | break; |
2723 | | |
2724 | 0 | case QEvent::Move: |
2725 | 0 | moveEvent(static_cast<QMoveEvent*>(ev)); |
2726 | 0 | break; |
2727 | | |
2728 | 0 | case QEvent::Resize: |
2729 | 0 | resizeEvent(static_cast<QResizeEvent*>(ev)); |
2730 | 0 | break; |
2731 | | |
2732 | 0 | case QEvent::KeyPress: |
2733 | 0 | keyPressEvent(static_cast<QKeyEvent *>(ev)); |
2734 | 0 | break; |
2735 | | |
2736 | 0 | case QEvent::KeyRelease: |
2737 | 0 | keyReleaseEvent(static_cast<QKeyEvent *>(ev)); |
2738 | 0 | break; |
2739 | | |
2740 | 0 | case QEvent::FocusIn: { |
2741 | 0 | focusInEvent(static_cast<QFocusEvent *>(ev)); |
2742 | 0 | #if QT_CONFIG(accessibility) |
2743 | 0 | QAccessible::State state; |
2744 | 0 | state.active = true; |
2745 | 0 | QAccessibleStateChangeEvent event(this, state); |
2746 | 0 | QAccessible::updateAccessibility(&event); |
2747 | 0 | #endif |
2748 | 0 | break; } |
2749 | | |
2750 | 0 | case QEvent::FocusOut: { |
2751 | 0 | focusOutEvent(static_cast<QFocusEvent *>(ev)); |
2752 | 0 | #if QT_CONFIG(accessibility) |
2753 | 0 | QAccessible::State state; |
2754 | 0 | state.active = true; |
2755 | 0 | QAccessibleStateChangeEvent event(this, state); |
2756 | 0 | QAccessible::updateAccessibility(&event); |
2757 | 0 | #endif |
2758 | 0 | break; } |
2759 | | |
2760 | 0 | #if QT_CONFIG(wheelevent) |
2761 | 0 | case QEvent::Wheel: |
2762 | 0 | wheelEvent(static_cast<QWheelEvent*>(ev)); |
2763 | 0 | break; |
2764 | 0 | #endif |
2765 | | |
2766 | 0 | case QEvent::Close: { |
2767 | |
|
2768 | 0 | const bool wasVisible = d->treatAsVisible(); |
2769 | 0 | const bool participatesInLastWindowClosed = d->participatesInLastWindowClosed(); |
2770 | | |
2771 | | // The window might be deleted in the close event handler |
2772 | 0 | QPointer<QWindow> deletionGuard(this); |
2773 | 0 | closeEvent(static_cast<QCloseEvent*>(ev)); |
2774 | |
|
2775 | 0 | if (ev->isAccepted()) { |
2776 | 0 | if (deletionGuard) |
2777 | 0 | destroy(); |
2778 | 0 | if (wasVisible && participatesInLastWindowClosed) |
2779 | 0 | QGuiApplicationPrivate::instance()->maybeLastWindowClosed(); |
2780 | 0 | } |
2781 | |
|
2782 | 0 | break; |
2783 | 0 | } |
2784 | | |
2785 | 0 | case QEvent::Expose: |
2786 | 0 | exposeEvent(static_cast<QExposeEvent *>(ev)); |
2787 | 0 | break; |
2788 | | |
2789 | 0 | case QEvent::Paint: |
2790 | 0 | paintEvent(static_cast<QPaintEvent *>(ev)); |
2791 | 0 | break; |
2792 | | |
2793 | 0 | case QEvent::Show: |
2794 | 0 | showEvent(static_cast<QShowEvent *>(ev)); |
2795 | 0 | break; |
2796 | | |
2797 | 0 | case QEvent::Hide: |
2798 | 0 | hideEvent(static_cast<QHideEvent *>(ev)); |
2799 | 0 | break; |
2800 | | |
2801 | 0 | case QEvent::ApplicationWindowIconChange: |
2802 | 0 | setIcon(icon()); |
2803 | 0 | break; |
2804 | | |
2805 | 0 | #if QT_CONFIG(tabletevent) |
2806 | 0 | case QEvent::TabletPress: |
2807 | 0 | case QEvent::TabletMove: |
2808 | 0 | case QEvent::TabletRelease: |
2809 | 0 | tabletEvent(static_cast<QTabletEvent *>(ev)); |
2810 | 0 | break; |
2811 | 0 | #endif |
2812 | | |
2813 | 0 | case QEvent::PlatformSurface: { |
2814 | 0 | if ((static_cast<QPlatformSurfaceEvent *>(ev))->surfaceEventType() == QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed) { |
2815 | | #ifndef QT_NO_OPENGL |
2816 | | QOpenGLContext *context = QOpenGLContext::currentContext(); |
2817 | | if (context && context->surface() == static_cast<QSurface *>(this)) |
2818 | | context->doneCurrent(); |
2819 | | #endif |
2820 | 0 | } |
2821 | 0 | break; |
2822 | 0 | } |
2823 | | |
2824 | 0 | default: |
2825 | 0 | return QObject::event(ev); |
2826 | 0 | } |
2827 | | |
2828 | 0 | return true; |
2829 | 0 | } |
2830 | | |
2831 | | /*! \internal |
2832 | | Synthesize and send a QContextMenuEvent if the given \a event is a suitable |
2833 | | mouse event (a right-button press or release, depending on |
2834 | | QStyleHints::contextMenuTrigger()). On most platforms, it's done on mouse |
2835 | | press; on Windows, it's done on release, because of the potential to |
2836 | | support right-button clicks and drags to select or lasso items, and then |
2837 | | still getting a context menu at the end of that gesture. (That is in |
2838 | | conflict with supporting the press-drag-release gesture to select menu |
2839 | | items on the context menus themselves. Context menus can be implemented |
2840 | | that way by handling the separate press, move and release events.) |
2841 | | |
2842 | | Any time the \a event was already handled in some way, it *should* be |
2843 | | accepted, but mere acceptance of the mouse event cannot be taken to |
2844 | | indicate that it's not necessary to synthesize a QContextMenuEvent here, |
2845 | | because the Windows use case requires doing one thing (selecting items) |
2846 | | with the mouse events, and then doing something completely different with |
2847 | | the QContextMenuEvent. In other words, QContextMenuEvent is very different |
2848 | | from other kinds of optional followup events synthesized from unhandled |
2849 | | events (like the way we synthesize a QMouseEvent only if a QTabletEvent was |
2850 | | not handled). Furthermore, there's enough legacy widget code that doesn't |
2851 | | call ignore() on unhandled mouse events. So it's uncertain whether this can |
2852 | | change in Qt 7. |
2853 | | |
2854 | | The QContextMenuEvent occurs at the scenePosition(). The position() |
2855 | | was likely already "localized" during the previous delivery. |
2856 | | |
2857 | | The synthesis from a mouse button event could be done in the platform |
2858 | | plugin, but so far on Windows it's not done: WM_CONTEXTMENU is not |
2859 | | generated by the OS, because we never call the default window procedure |
2860 | | that would do that in response to unhandled WM_RBUTTONUP. If we |
2861 | | eventually want to do that, we would have to avoid doing it here, |
2862 | | on platforms where the platform plugin is responsible for it. |
2863 | | |
2864 | | QGuiApplicationPrivate::processContextMenuEvent also allows |
2865 | | keyboard-triggered context menu events that the QPA plugin might generate. |
2866 | | On Windows, the keyboard may have a menu key. On macOS, control-return |
2867 | | is the usual shortcut; on Gnome, it's shift-F10; and so on. |
2868 | | */ |
2869 | | void QWindowPrivate::maybeSynthesizeContextMenuEvent(QMouseEvent *event) |
2870 | 0 | { |
2871 | 0 | #ifndef QT_NO_CONTEXTMENU |
2872 | 0 | if (event->button() == Qt::RightButton |
2873 | 0 | && event->type() == QGuiApplicationPrivate::contextMenuEventType()) { |
2874 | 0 | QContextMenuEvent e(QContextMenuEvent::Mouse, event->scenePosition().toPoint(), |
2875 | 0 | event->globalPosition().toPoint(), event->modifiers()); |
2876 | 0 | qCDebug(lcPopup) << "synthesized after" |
2877 | 0 | << (event->isAccepted() ? "ACCEPTED (legacy behavior)" : "ignored") |
2878 | 0 | << event->type() << ":" << &e; |
2879 | 0 | QCoreApplication::forwardEvent(q_func(), &e, event); |
2880 | 0 | if (e.isAccepted()) |
2881 | 0 | event->accept(); |
2882 | 0 | } |
2883 | 0 | #endif |
2884 | 0 | } |
2885 | | |
2886 | | /*! |
2887 | | Schedules a QEvent::UpdateRequest event to be delivered to this window. |
2888 | | |
2889 | | The event is delivered in sync with the display vsync on platforms where |
2890 | | this is possible. Otherwise, the event is delivered after a delay of at |
2891 | | most 5 ms. If the window's associated screen reports a |
2892 | | \l{QScreen::refreshRate()}{refresh rate} higher than 60 Hz, the interval is |
2893 | | scaled down to a value smaller than 5. The additional time is there to give |
2894 | | the event loop a bit of idle time to gather system events, and can be |
2895 | | overridden using the QT_QPA_UPDATE_IDLE_TIME environment variable. |
2896 | | |
2897 | | When driving animations, this function should be called once after drawing |
2898 | | has completed. Calling this function multiple times will result in a single |
2899 | | event being delivered to the window. |
2900 | | |
2901 | | Subclasses of QWindow should reimplement event(), intercept the event and |
2902 | | call the application's rendering code, then call the base class |
2903 | | implementation. |
2904 | | |
2905 | | \note The subclass' reimplementation of event() must invoke the base class |
2906 | | implementation, unless it is absolutely sure that the event does not need to |
2907 | | be handled by the base class. For example, the default implementation of |
2908 | | this function relies on QEvent::Timer events. Filtering them away would |
2909 | | therefore break the delivery of the update events. |
2910 | | |
2911 | | \since 5.5 |
2912 | | */ |
2913 | | void QWindow::requestUpdate() |
2914 | 0 | { |
2915 | 0 | Q_ASSERT_X(QThread::isMainThread(), |
2916 | 0 | "QWindow", "Updates can only be scheduled from the GUI (main) thread"); |
2917 | |
|
2918 | 0 | Q_D(QWindow); |
2919 | 0 | if (d->updateRequestPending || !d->platformWindow) |
2920 | 0 | return; |
2921 | 0 | d->updateRequestPending = true; |
2922 | 0 | d->platformWindow->requestUpdate(); |
2923 | 0 | } |
2924 | | |
2925 | | /*! |
2926 | | Override this to handle key press events (\a ev). |
2927 | | |
2928 | | \sa keyReleaseEvent() |
2929 | | */ |
2930 | | void QWindow::keyPressEvent(QKeyEvent *ev) |
2931 | 0 | { |
2932 | 0 | ev->ignore(); |
2933 | 0 | } |
2934 | | |
2935 | | /*! |
2936 | | Override this to handle key release events (\a ev). |
2937 | | |
2938 | | \sa keyPressEvent() |
2939 | | */ |
2940 | | void QWindow::keyReleaseEvent(QKeyEvent *ev) |
2941 | 0 | { |
2942 | 0 | ev->ignore(); |
2943 | 0 | } |
2944 | | |
2945 | | /*! |
2946 | | Override this to handle focus in events (\a ev). |
2947 | | |
2948 | | Focus in events are sent when the window receives keyboard focus. |
2949 | | |
2950 | | \sa focusOutEvent() |
2951 | | */ |
2952 | | void QWindow::focusInEvent(QFocusEvent *ev) |
2953 | 0 | { |
2954 | 0 | ev->ignore(); |
2955 | 0 | } |
2956 | | |
2957 | | /*! |
2958 | | Override this to handle focus out events (\a ev). |
2959 | | |
2960 | | Focus out events are sent when the window loses keyboard focus. |
2961 | | |
2962 | | \sa focusInEvent() |
2963 | | */ |
2964 | | void QWindow::focusOutEvent(QFocusEvent *ev) |
2965 | 0 | { |
2966 | 0 | ev->ignore(); |
2967 | 0 | } |
2968 | | |
2969 | | /*! |
2970 | | Override this to handle mouse press events (\a ev). |
2971 | | |
2972 | | \sa mouseReleaseEvent() |
2973 | | */ |
2974 | | void QWindow::mousePressEvent(QMouseEvent *ev) |
2975 | 0 | { |
2976 | 0 | ev->ignore(); |
2977 | 0 | } |
2978 | | |
2979 | | /*! |
2980 | | Override this to handle mouse release events (\a ev). |
2981 | | |
2982 | | \sa mousePressEvent() |
2983 | | */ |
2984 | | void QWindow::mouseReleaseEvent(QMouseEvent *ev) |
2985 | 0 | { |
2986 | 0 | ev->ignore(); |
2987 | 0 | } |
2988 | | |
2989 | | /*! |
2990 | | Override this to handle mouse double click events (\a ev). |
2991 | | |
2992 | | \sa mousePressEvent(), QStyleHints::mouseDoubleClickInterval() |
2993 | | */ |
2994 | | void QWindow::mouseDoubleClickEvent(QMouseEvent *ev) |
2995 | 0 | { |
2996 | 0 | ev->ignore(); |
2997 | 0 | } |
2998 | | |
2999 | | /*! |
3000 | | Override this to handle mouse move events (\a ev). |
3001 | | */ |
3002 | | void QWindow::mouseMoveEvent(QMouseEvent *ev) |
3003 | 0 | { |
3004 | 0 | ev->ignore(); |
3005 | 0 | } |
3006 | | |
3007 | | #if QT_CONFIG(wheelevent) |
3008 | | /*! |
3009 | | Override this to handle mouse wheel or other wheel events (\a ev). |
3010 | | */ |
3011 | | void QWindow::wheelEvent(QWheelEvent *ev) |
3012 | 0 | { |
3013 | 0 | ev->ignore(); |
3014 | 0 | } |
3015 | | #endif // QT_CONFIG(wheelevent) |
3016 | | |
3017 | | /*! |
3018 | | Override this to handle touch events (\a ev). |
3019 | | */ |
3020 | | void QWindow::touchEvent(QTouchEvent *ev) |
3021 | 0 | { |
3022 | 0 | ev->ignore(); |
3023 | 0 | } |
3024 | | |
3025 | | #if QT_CONFIG(tabletevent) |
3026 | | /*! |
3027 | | Override this to handle tablet press, move, and release events (\a ev). |
3028 | | |
3029 | | Proximity enter and leave events are not sent to windows, they are |
3030 | | delivered to the application instance. |
3031 | | */ |
3032 | | void QWindow::tabletEvent(QTabletEvent *ev) |
3033 | 0 | { |
3034 | 0 | ev->ignore(); |
3035 | 0 | } |
3036 | | #endif |
3037 | | |
3038 | | /*! |
3039 | | Override this to handle platform dependent events. |
3040 | | Will be given \a eventType, \a message and \a result. |
3041 | | |
3042 | | This might make your application non-portable. |
3043 | | |
3044 | | Should return true only if the event was handled. |
3045 | | */ |
3046 | | |
3047 | | bool QWindow::nativeEvent(const QByteArray &eventType, void *message, qintptr *result) |
3048 | 0 | { |
3049 | 0 | Q_UNUSED(eventType); |
3050 | 0 | Q_UNUSED(message); |
3051 | 0 | Q_UNUSED(result); |
3052 | 0 | return false; |
3053 | 0 | } |
3054 | | |
3055 | | /*! |
3056 | | \fn QPointF QWindow::mapToGlobal(const QPointF &pos) const |
3057 | | |
3058 | | Translates the window coordinate \a pos to global screen |
3059 | | coordinates. For example, \c{mapToGlobal(QPointF(0,0))} would give |
3060 | | the global coordinates of the top-left pixel of the window. |
3061 | | |
3062 | | \sa mapFromGlobal() |
3063 | | \since 6.0 |
3064 | | */ |
3065 | | QPointF QWindow::mapToGlobal(const QPointF &pos) const |
3066 | 0 | { |
3067 | 0 | Q_D(const QWindow); |
3068 | | // QTBUG-43252, prefer platform implementation for foreign windows. |
3069 | 0 | if (d->platformWindow |
3070 | 0 | && (d->platformWindow->isForeignWindow() || d->platformWindow->isEmbedded())) { |
3071 | 0 | return QHighDpi::fromNativeGlobalPosition(d->platformWindow->mapToGlobalF(QHighDpi::toNativeLocalPosition(pos, this)), this); |
3072 | 0 | } |
3073 | | |
3074 | 0 | if (!QHighDpiScaling::isActive()) |
3075 | 0 | return pos + d->globalPosition(); |
3076 | | |
3077 | | // The normal pos + windowGlobalPos calculation may give a point which is outside |
3078 | | // screen geometry for windows which span multiple screens, due to the way QHighDpiScaling |
3079 | | // creates gaps between screens in the the device indendent cooordinate system. |
3080 | | // |
3081 | | // Map the position (and the window's global position) to native coordinates, perform |
3082 | | // the addition, and then map back to device independent coordinates. |
3083 | 0 | QPointF nativeLocalPos = QHighDpi::toNativeLocalPosition(pos, this); |
3084 | | // Get the native window position directly from the platform window |
3085 | | // if available (it can be null if the window hasn't been shown yet), |
3086 | | // or fall back to scaling the QWindow position. |
3087 | 0 | QPointF nativeWindowGlobalPos = d->platformWindow |
3088 | 0 | ? d->platformWindow->mapToGlobal(QPoint(0,0)).toPointF() |
3089 | 0 | : QHighDpi::toNativeGlobalPosition(QPointF(d->globalPosition()), this); |
3090 | 0 | QPointF nativeGlobalPos = nativeLocalPos + nativeWindowGlobalPos; |
3091 | 0 | QPointF deviceIndependentGlobalPos = QHighDpi::fromNativeGlobalPosition(nativeGlobalPos, this); |
3092 | 0 | return deviceIndependentGlobalPos; |
3093 | 0 | } |
3094 | | |
3095 | | /*! |
3096 | | \overload |
3097 | | */ |
3098 | | QPoint QWindow::mapToGlobal(const QPoint &pos) const |
3099 | 0 | { |
3100 | 0 | return mapToGlobal(QPointF(pos)).toPoint(); |
3101 | 0 | } |
3102 | | |
3103 | | /*! |
3104 | | \fn QPointF QWindow::mapFromGlobal(const QPointF &pos) const |
3105 | | |
3106 | | Translates the global screen coordinate \a pos to window |
3107 | | coordinates. |
3108 | | |
3109 | | \sa mapToGlobal() |
3110 | | \since 6.0 |
3111 | | */ |
3112 | | QPointF QWindow::mapFromGlobal(const QPointF &pos) const |
3113 | 0 | { |
3114 | 0 | Q_D(const QWindow); |
3115 | | // QTBUG-43252, prefer platform implementation for foreign windows. |
3116 | 0 | if (d->platformWindow |
3117 | 0 | && (d->platformWindow->isForeignWindow() || d->platformWindow->isEmbedded())) { |
3118 | 0 | return QHighDpi::fromNativeLocalPosition(d->platformWindow->mapFromGlobalF(QHighDpi::toNativeGlobalPosition(pos, this)), this); |
3119 | 0 | } |
3120 | | |
3121 | 0 | if (!QHighDpiScaling::isActive()) |
3122 | 0 | return pos - d->globalPosition(); |
3123 | | |
3124 | | // Calculate local position in the native coordinate system. (See comment for the |
3125 | | // corresponding mapToGlobal() code above). |
3126 | 0 | QPointF nativeGlobalPos = QHighDpi::toNativeGlobalPosition(pos, this); |
3127 | | // Get the native window position directly from the platform window |
3128 | | // if available (it can be null if the window hasn't been shown yet), |
3129 | | // or fall back to scaling the QWindow position. |
3130 | 0 | QPointF nativeWindowGlobalPos = d->platformWindow |
3131 | 0 | ? d->platformWindow->mapToGlobal(QPoint(0,0)).toPointF() |
3132 | 0 | : QHighDpi::toNativeGlobalPosition(QPointF(d->globalPosition()), this); |
3133 | 0 | QPointF nativeLocalPos = nativeGlobalPos - nativeWindowGlobalPos; |
3134 | 0 | QPointF deviceIndependentLocalPos = QHighDpi::fromNativeLocalPosition(nativeLocalPos, this); |
3135 | 0 | return deviceIndependentLocalPos; |
3136 | 0 | } |
3137 | | |
3138 | | /*! |
3139 | | \overload |
3140 | | */ |
3141 | | QPoint QWindow::mapFromGlobal(const QPoint &pos) const |
3142 | 0 | { |
3143 | 0 | return QWindow::mapFromGlobal(QPointF(pos)).toPoint(); |
3144 | 0 | } |
3145 | | |
3146 | | QPoint QWindowPrivate::globalPosition() const |
3147 | 0 | { |
3148 | 0 | Q_Q(const QWindow); |
3149 | 0 | QPoint offset = q->position(); |
3150 | 0 | for (const QWindow *p = q->parent(); p; p = p->parent()) { |
3151 | 0 | QPlatformWindow *pw = p->handle(); |
3152 | 0 | if (pw && (pw->isForeignWindow() || pw->isEmbedded())) { |
3153 | | // Use mapToGlobal() for foreign windows |
3154 | 0 | offset += p->mapToGlobal(QPoint(0, 0)); |
3155 | 0 | break; |
3156 | 0 | } else { |
3157 | 0 | offset += p->position(); |
3158 | 0 | } |
3159 | 0 | } |
3160 | 0 | return offset; |
3161 | 0 | } |
3162 | | |
3163 | | Q_GUI_EXPORT QWindowPrivate *qt_window_private(QWindow *window) |
3164 | 0 | { |
3165 | 0 | return window->d_func(); |
3166 | 0 | } |
3167 | | |
3168 | | QWindow *QWindowPrivate::topLevelWindow(QWindow::AncestorMode mode) const |
3169 | 0 | { |
3170 | 0 | Q_Q(const QWindow); |
3171 | |
|
3172 | 0 | QWindow *window = const_cast<QWindow *>(q); |
3173 | |
|
3174 | 0 | while (window) { |
3175 | 0 | QWindow *parent = window->parent(mode); |
3176 | 0 | if (!parent) |
3177 | 0 | break; |
3178 | | |
3179 | 0 | window = parent; |
3180 | 0 | } |
3181 | |
|
3182 | 0 | return window; |
3183 | 0 | } |
3184 | | |
3185 | | /* |
3186 | | \internal |
3187 | | \class QForeignWindow |
3188 | | |
3189 | | QForeignWindow represents a native window handle created by another |
3190 | | UI toolkit, wrapped via QWindow::fromWinId(). |
3191 | | */ |
3192 | | class QForeignWindow : public QWindow |
3193 | | { |
3194 | 0 | Q_OBJECT |
3195 | 0 | public: |
3196 | 0 | #if QT_CONFIG(accessibility) |
3197 | 0 | /* |
3198 | 0 | Represent the foreign window as itself in the accessibility tree, so |
3199 | 0 | that the accessibility bridges can substitute it for the underlying |
3200 | 0 | native handle if needed, or otherwise represent it as an opaque node |
3201 | 0 | with possible child windows. |
3202 | 0 | */ |
3203 | 0 | QAccessibleInterface *accessibleRoot() const override |
3204 | 0 | { |
3205 | 0 | return QAccessible::queryAccessibleInterface(const_cast<QForeignWindow *>(this)); |
3206 | 0 | } |
3207 | | #endif |
3208 | | }; |
3209 | | |
3210 | | /*! |
3211 | | Creates a local representation of a window created by another process or by |
3212 | | using native libraries below Qt. |
3213 | | |
3214 | | Given the handle \a id to a native window, this method creates a QWindow |
3215 | | object which can be used to represent the window when invoking methods like |
3216 | | setParent() and setTransientParent(). |
3217 | | |
3218 | | This can be used, on platforms which support it, to embed a QWindow inside a |
3219 | | native window, or to embed a native window inside a QWindow. |
3220 | | |
3221 | | If foreign windows are not supported or embedding the native window |
3222 | | failed in the platform plugin, this function returns \nullptr. |
3223 | | |
3224 | | \note The resulting QWindow should not be used to manipulate the underlying |
3225 | | native window (besides re-parenting), or to observe state changes of the |
3226 | | native window. Any support for these kind of operations is incidental, highly |
3227 | | platform dependent and untested. |
3228 | | |
3229 | | \sa setParent() |
3230 | | */ |
3231 | | QWindow *QWindow::fromWinId(WId id) |
3232 | 0 | { |
3233 | 0 | if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ForeignWindows)) { |
3234 | 0 | qWarning("QWindow::fromWinId(): platform plugin does not support foreign windows."); |
3235 | 0 | return nullptr; |
3236 | 0 | } |
3237 | | |
3238 | 0 | QWindow *window = new QForeignWindow; |
3239 | | |
3240 | | // Persist the winId in a private property so that we |
3241 | | // can recreate the window after being destroyed. |
3242 | 0 | window->setProperty(kForeignWindowId, id); |
3243 | 0 | window->create(); |
3244 | |
|
3245 | 0 | if (!window->handle()) { |
3246 | 0 | delete window; |
3247 | 0 | return nullptr; |
3248 | 0 | } |
3249 | | |
3250 | 0 | return window; |
3251 | 0 | } |
3252 | | |
3253 | | /*! |
3254 | | Causes an alert to be shown for \a msec milliseconds. If \a msec is \c 0 (the |
3255 | | default), then the alert is shown indefinitely until the window becomes |
3256 | | active again. This function has no effect on an active window. |
3257 | | |
3258 | | In alert state, the window indicates that it demands attention, for example by |
3259 | | flashing or bouncing the taskbar entry. |
3260 | | |
3261 | | \since 5.1 |
3262 | | */ |
3263 | | |
3264 | | void QWindow::alert(int msec) |
3265 | 0 | { |
3266 | 0 | Q_D(QWindow); |
3267 | 0 | if (!d->platformWindow || d->platformWindow->isAlertState() || isActive()) |
3268 | 0 | return; |
3269 | 0 | d->platformWindow->setAlertState(true); |
3270 | 0 | if (d->platformWindow->isAlertState() && msec) |
3271 | 0 | QTimer::singleShot(msec, this, SLOT(_q_clearAlert())); |
3272 | 0 | } |
3273 | | |
3274 | | void QWindowPrivate::_q_clearAlert() |
3275 | 0 | { |
3276 | 0 | if (platformWindow && platformWindow->isAlertState()) |
3277 | 0 | platformWindow->setAlertState(false); |
3278 | 0 | } |
3279 | | |
3280 | | #ifndef QT_NO_CURSOR |
3281 | | /*! |
3282 | | \brief set the cursor shape for this window |
3283 | | |
3284 | | The mouse \a cursor will assume this shape when it is over this |
3285 | | window, unless an override cursor is set. |
3286 | | See the \l{Qt::CursorShape}{list of predefined cursor objects} for a |
3287 | | range of useful shapes. |
3288 | | |
3289 | | If no cursor has been set, or after a call to unsetCursor(), the |
3290 | | parent window's cursor is used. |
3291 | | |
3292 | | By default, the cursor has the Qt::ArrowCursor shape. |
3293 | | |
3294 | | Some underlying window implementations will reset the cursor if it |
3295 | | leaves a window even if the mouse is grabbed. If you want to have |
3296 | | a cursor set for all windows, even when outside the window, consider |
3297 | | QGuiApplication::setOverrideCursor(). |
3298 | | |
3299 | | \sa QGuiApplication::setOverrideCursor() |
3300 | | */ |
3301 | | void QWindow::setCursor(const QCursor &cursor) |
3302 | 0 | { |
3303 | 0 | Q_D(QWindow); |
3304 | 0 | d->setCursor(&cursor); |
3305 | 0 | } |
3306 | | |
3307 | | /*! |
3308 | | \brief Restores the default arrow cursor for this window. |
3309 | | */ |
3310 | | void QWindow::unsetCursor() |
3311 | 0 | { |
3312 | 0 | Q_D(QWindow); |
3313 | 0 | d->setCursor(nullptr); |
3314 | 0 | } |
3315 | | |
3316 | | /*! |
3317 | | \brief the cursor shape for this window |
3318 | | |
3319 | | \sa setCursor(), unsetCursor() |
3320 | | */ |
3321 | | QCursor QWindow::cursor() const |
3322 | 0 | { |
3323 | 0 | Q_D(const QWindow); |
3324 | 0 | return d->cursor; |
3325 | 0 | } |
3326 | | |
3327 | | void QWindowPrivate::setCursor(const QCursor *newCursor) |
3328 | 0 | { |
3329 | |
|
3330 | 0 | Q_Q(QWindow); |
3331 | 0 | if (newCursor) { |
3332 | 0 | const Qt::CursorShape newShape = newCursor->shape(); |
3333 | 0 | if (newShape <= Qt::LastCursor && hasCursor && newShape == cursor.shape()) |
3334 | 0 | return; // Unchanged and no bitmap/custom cursor. |
3335 | 0 | cursor = *newCursor; |
3336 | 0 | hasCursor = true; |
3337 | 0 | } else { |
3338 | 0 | if (!hasCursor) |
3339 | 0 | return; |
3340 | 0 | cursor = QCursor(Qt::ArrowCursor); |
3341 | 0 | hasCursor = false; |
3342 | 0 | } |
3343 | | // Only attempt to emit signal if there is an actual platform cursor |
3344 | 0 | if (applyCursor()) { |
3345 | 0 | QEvent event(QEvent::CursorChange); |
3346 | 0 | QGuiApplication::sendEvent(q, &event); |
3347 | 0 | } |
3348 | 0 | } |
3349 | | |
3350 | | // Apply the cursor and returns true iff the platform cursor exists |
3351 | | bool QWindowPrivate::applyCursor() |
3352 | 0 | { |
3353 | 0 | Q_Q(QWindow); |
3354 | 0 | if (QScreen *screen = q->screen()) { |
3355 | 0 | if (QPlatformCursor *platformCursor = screen->handle()->cursor()) { |
3356 | 0 | if (!platformWindow) |
3357 | 0 | return true; |
3358 | 0 | QCursor *c = QGuiApplication::overrideCursor(); |
3359 | 0 | if (c != nullptr && platformCursor->capabilities().testFlag(QPlatformCursor::OverrideCursor)) |
3360 | 0 | return true; |
3361 | 0 | if (!c && hasCursor) |
3362 | 0 | c = &cursor; |
3363 | 0 | platformCursor->changeCursor(c, q); |
3364 | 0 | return true; |
3365 | 0 | } |
3366 | 0 | } |
3367 | 0 | return false; |
3368 | 0 | } |
3369 | | #endif // QT_NO_CURSOR |
3370 | | |
3371 | | void *QWindow::resolveInterface(const char *name, int revision) const |
3372 | 0 | { |
3373 | 0 | using namespace QNativeInterface::Private; |
3374 | |
|
3375 | 0 | auto *platformWindow = handle(); |
3376 | 0 | Q_UNUSED(platformWindow); |
3377 | 0 | Q_UNUSED(name); |
3378 | 0 | Q_UNUSED(revision); |
3379 | |
|
3380 | | #if defined(Q_OS_WIN) |
3381 | | QT_NATIVE_INTERFACE_RETURN_IF(QWindowsWindow, platformWindow); |
3382 | | #endif |
3383 | |
|
3384 | | #if QT_CONFIG(xcb) |
3385 | | QT_NATIVE_INTERFACE_RETURN_IF(QXcbWindow, platformWindow); |
3386 | | #endif |
3387 | |
|
3388 | | #if defined(Q_OS_MACOS) |
3389 | | QT_NATIVE_INTERFACE_RETURN_IF(QCocoaWindow, platformWindow); |
3390 | | #endif |
3391 | |
|
3392 | | #if QT_CONFIG(wayland) |
3393 | | QT_NATIVE_INTERFACE_RETURN_IF(QWaylandWindow, platformWindow); |
3394 | | #endif |
3395 | |
|
3396 | | #if defined(Q_OS_WASM) |
3397 | | QT_NATIVE_INTERFACE_RETURN_IF(QWasmWindow, platformWindow); |
3398 | | #endif |
3399 | |
|
3400 | 0 | return nullptr; |
3401 | 0 | } |
3402 | | |
3403 | | #ifndef QT_NO_DEBUG_STREAM |
3404 | | QDebug operator<<(QDebug debug, const QWindow *window) |
3405 | 0 | { |
3406 | 0 | QDebugStateSaver saver(debug); |
3407 | 0 | debug.nospace(); |
3408 | 0 | if (window) { |
3409 | 0 | debug << window->metaObject()->className() << '(' << (const void *)window; |
3410 | 0 | if (!window->objectName().isEmpty()) |
3411 | 0 | debug << ", name=" << window->objectName(); |
3412 | 0 | if (debug.verbosity() > 2) { |
3413 | 0 | const QRect geometry = window->geometry(); |
3414 | 0 | if (window->isVisible()) |
3415 | 0 | debug << ", visible"; |
3416 | 0 | if (window->isExposed()) |
3417 | 0 | debug << ", exposed"; |
3418 | 0 | debug << ", state=" << window->windowState() |
3419 | 0 | << ", type=" << window->type() << ", flags=" << window->flags() |
3420 | 0 | << ", surface type=" << window->surfaceType(); |
3421 | 0 | if (window->isTopLevel()) |
3422 | 0 | debug << ", toplevel"; |
3423 | 0 | debug << ", " << geometry.width() << 'x' << geometry.height() |
3424 | 0 | << Qt::forcesign << geometry.x() << geometry.y() << Qt::noforcesign; |
3425 | 0 | const QMargins margins = window->frameMargins(); |
3426 | 0 | if (!margins.isNull()) |
3427 | 0 | debug << ", margins=" << margins; |
3428 | 0 | const QMargins safeAreaMargins = window->safeAreaMargins(); |
3429 | 0 | if (!safeAreaMargins.isNull()) |
3430 | 0 | debug << ", safeAreaMargins=" << safeAreaMargins; |
3431 | 0 | debug << ", devicePixelRatio=" << window->devicePixelRatio(); |
3432 | 0 | if (const QPlatformWindow *platformWindow = window->handle()) |
3433 | 0 | debug << ", winId=0x" << Qt::hex << platformWindow->winId() << Qt::dec; |
3434 | 0 | if (const QScreen *screen = window->screen()) |
3435 | 0 | debug << ", on " << screen->name(); |
3436 | 0 | } |
3437 | 0 | debug << ')'; |
3438 | 0 | } else { |
3439 | 0 | debug << "QWindow(0x0)"; |
3440 | 0 | } |
3441 | 0 | return debug; |
3442 | 0 | } |
3443 | | #endif // !QT_NO_DEBUG_STREAM |
3444 | | |
3445 | | #if QT_CONFIG(vulkan) || defined(Q_QDOC) |
3446 | | |
3447 | | /*! |
3448 | | Associates this window with the specified Vulkan \a instance. |
3449 | | |
3450 | | \a instance must stay valid as long as this QWindow instance exists. |
3451 | | */ |
3452 | | void QWindow::setVulkanInstance(QVulkanInstance *instance) |
3453 | | { |
3454 | | Q_D(QWindow); |
3455 | | d->vulkanInstance = instance; |
3456 | | } |
3457 | | |
3458 | | /*! |
3459 | | \return the associated Vulkan instance if any was set, otherwise \nullptr. |
3460 | | */ |
3461 | | QVulkanInstance *QWindow::vulkanInstance() const |
3462 | | { |
3463 | | Q_D(const QWindow); |
3464 | | return d->vulkanInstance; |
3465 | | } |
3466 | | |
3467 | | #endif // QT_CONFIG(vulkan) |
3468 | | |
3469 | | QT_END_NAMESPACE |
3470 | | |
3471 | | #include "moc_qwindow.cpp" |
3472 | | #include "qwindow.moc" |