From 28ee76fd0b9ce59291341c8a9937a6c98fcb926d Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 21 Dec 2015 15:06:40 +0100 Subject: QtPlatformHeaders/Windows: Add function to set window activation behavior. The Windows OS by default does not activate windows when the calling process is not active; only the taskbar entry is flashed as not to distract the user. Nevertheless, for some use cases, it is desirable to activate the window also in the inactive state. Introduce an enumeration specifying the behavior to QtPlatformHeaders and employ a workaround using the Win32 API AttachThreadInput() to attach to other processes while setting the foreground window to achieve the AlwaysActivateWindow behavior. Task-number: QTBUG-14062 Task-number: QTBUG-37435 Change-Id: I79cb6cd3fab29d55b5d3db7f9af01bbaa5096a37 Reviewed-by: Joerg Bornemann --- src/platformheaders/doc/qtplatformheaders.qdocconf | 1 + .../windowsfunctions/qwindowswindowfunctions.h | 15 +++++++ .../windowsfunctions/qwindowswindowfunctions.qdoc | 49 ++++++++++++++++++++++ 3 files changed, 65 insertions(+) (limited to 'src/platformheaders') diff --git a/src/platformheaders/doc/qtplatformheaders.qdocconf b/src/platformheaders/doc/qtplatformheaders.qdocconf index fc8a9d8731..989df524e6 100644 --- a/src/platformheaders/doc/qtplatformheaders.qdocconf +++ b/src/platformheaders/doc/qtplatformheaders.qdocconf @@ -27,6 +27,7 @@ qhp.QtPlatformHeaders.subprojects.classes.sortPages = true depends += \ qtcore \ qtgui \ + qtwidgets \ qtdoc headerdirs += .. diff --git a/src/platformheaders/windowsfunctions/qwindowswindowfunctions.h b/src/platformheaders/windowsfunctions/qwindowswindowfunctions.h index 2b1efcdd6d..d0826bdb50 100644 --- a/src/platformheaders/windowsfunctions/qwindowswindowfunctions.h +++ b/src/platformheaders/windowsfunctions/qwindowswindowfunctions.h @@ -57,6 +57,11 @@ public: Q_DECLARE_FLAGS(TouchWindowTouchTypes, TouchWindowTouchType) + enum WindowActivationBehavior { + DefaultActivateWindow, + AlwaysActivateWindow + }; + typedef void (*SetTouchWindowTouchType)(QWindow *window, QWindowsWindowFunctions::TouchWindowTouchTypes touchType); static const QByteArray setTouchWindowTouchTypeIdentifier() { return QByteArrayLiteral("WindowsSetTouchWindowTouchType"); } @@ -75,6 +80,16 @@ public: if (func) func(window, border); } + + typedef void (*SetWindowActivationBehaviorType)(WindowActivationBehavior); + static const QByteArray setWindowActivationBehaviorIdentifier() { return QByteArrayLiteral("WindowsSetWindowActivationBehavior"); } + + static void setWindowActivationBehavior(WindowActivationBehavior behavior) + { + SetWindowActivationBehaviorType func = reinterpret_cast(QGuiApplication::platformFunction(setWindowActivationBehaviorIdentifier())); + if (func) + func(behavior); + } }; Q_DECLARE_OPERATORS_FOR_FLAGS(QWindowsWindowFunctions::TouchWindowTouchTypes) diff --git a/src/platformheaders/windowsfunctions/qwindowswindowfunctions.qdoc b/src/platformheaders/windowsfunctions/qwindowswindowfunctions.qdoc index d6b8764e7b..196f9f22ce 100644 --- a/src/platformheaders/windowsfunctions/qwindowswindowfunctions.qdoc +++ b/src/platformheaders/windowsfunctions/qwindowswindowfunctions.qdoc @@ -95,3 +95,52 @@ See also \l [QtDoc] {Fullscreen OpenGL Based Windows} */ + +/*! + \enum QWindowsWindowFunctions::WindowActivationBehavior + + This enum specifies the behavior of QWidget::activateWindow() and + QWindow::requestActivate(). + + \value DefaultActivateWindow The window is activated according to the default + behavior of the Windows operating system. This means the window will not + be activated in some circumstances (most notably when the calling process + is not the active process); only the taskbar entry will be flashed. + \value AlwaysActivateWindow The window is always activated, even when the + calling process is not the active process. + + \sa QWidget::activateWindow(), QWindow::requestActivate() + \since 5.7 +*/ + +/*! + \typedef QWindowsWindowFunctions::SetWindowActivationBehaviorType + + This is the typedef for the function returned by QGuiApplication::platformFunction() + when passed setWindowActivationBehaviorIdentifier(). + + \sa QWidget::activateWindow(), QWindow::requestActivate() + \since 5.7 +*/ + +/*! + \fn QByteArray setWindowActivationBehaviorIdentifier() + + This function returns a bytearray that can be used to query + QGuiApplication::platformFunction() to retrieve the SetWindowActivationBehaviorType + function. + + \sa QWidget::activateWindow(), QWindow::requestActivate() + \since 5.7 +*/ + +/*! + \fn void QWindowsWindowFunctions::setWindowActivationBehavior(WindowActivationBehavior behavior) + + This is a convenience function that can be used directly instead of resolving + the function pointer. \a behavior will be relayed to the function retrieved + by QGuiApplication. + + \sa QWidget::activateWindow(), QWindow::requestActivate() + \since 5.7 +*/ -- cgit v1.2.3