summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorteza Jamshidi <[email protected]>2025-01-30 16:41:35 +0100
committerMorteza Jamshidi <[email protected]>2025-05-30 18:16:41 +0200
commitc2bdf7636eb46e56760f3e2f6d457c8f14627576 (patch)
tree8522701120f01241c3c8793ea3611ecd3e22279d
parente115c60b6da0db7013229e678720f36632c2e614 (diff)
Use WS_EX_NOACTIVATE to prevent window from getting focused
On top of handling ActivateWindowEvent,MouseActivateWindowEvent and PointerActivateWindowEvent events and returning MA_NOACTIVATE we can also set the window extended style to prevent windows from stealing focus in special cases. Also on top all those mentioned events, when the window is requested to get keyboard focus, it should check if the window accepts focus or not. If it does not, then it should inform the underlying system that the window does not accept the focusIn event. [ChangeLog][Windows] Windows with flag Qt::WindowDoesNotAcceptFocus no longer have a taskbar entry. Pick-to: 6.9 Fixes: QTBUG-131714 Change-Id: I79f767b1622449ba05b41f8b80bf390d8cecfff8 Reviewed-by: Oliver Wolff <[email protected]> Reviewed-by: Zhao Yuhang <[email protected]>
-rw-r--r--src/corelib/global/qnamespace.qdoc2
-rw-r--r--src/plugins/platforms/windows/qwindowscontext.cpp2
-rw-r--r--src/plugins/platforms/windows/qwindowswindow.cpp3
3 files changed, 7 insertions, 0 deletions
diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc
index 1d6a25f3075..cfc47324734 100644
--- a/src/corelib/global/qnamespace.qdoc
+++ b/src/corelib/global/qnamespace.qdoc
@@ -2346,6 +2346,8 @@
\value WindowDoesNotAcceptFocus Informs the window system that this window should
not receive the input focus.
+ \note On Windows, this prevents the window from appearing in the taskbar.
+
\value MaximizeUsingFullscreenGeometryHint Deprecated alias for Qt::ExpandedClientAreaHint
\value [since 6.9] ExpandedClientAreaHint Requests that the window's client area is
diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp
index dd9265d8b50..c484d97479a 100644
--- a/src/plugins/platforms/windows/qwindowscontext.cpp
+++ b/src/plugins/platforms/windows/qwindowscontext.cpp
@@ -1214,6 +1214,8 @@ bool QWindowsContext::windowsProc(HWND hwnd, UINT message,
case QtWindows::PointerEvent:
return sessionManagerInteractionBlocked() || d->m_pointerHandler.translatePointerEvent(platformWindow->window(), hwnd, et, msg, result);
case QtWindows::FocusInEvent: // see QWindowsWindow::requestActivateWindow().
+ if (platformWindow->window()->flags() & Qt::WindowDoesNotAcceptFocus)
+ return false;
case QtWindows::FocusOutEvent:
handleFocusEvent(et, platformWindow);
return true;
diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp
index a7284cc30aa..c1530789f4c 100644
--- a/src/plugins/platforms/windows/qwindowswindow.cpp
+++ b/src/plugins/platforms/windows/qwindowswindow.cpp
@@ -835,6 +835,9 @@ void WindowCreationData::fromWindow(const QWindow *w, const Qt::WindowFlags flag
style |= WS_CLIPSIBLINGS | WS_CLIPCHILDREN ;
+ if (flags & Qt::WindowDoesNotAcceptFocus)
+ exStyle |= WS_EX_NOACTIVATE;
+
if (topLevel) {
if ((type == Qt::Window || dialog || tool)) {
if (!(flags & Qt::FramelessWindowHint)) {