From e5b46f3ea75ea5f0980695b0655a8347f6f1965e Mon Sep 17 00:00:00 2001 From: Ws ShawnWoo Date: Tue, 7 Nov 2023 14:16:32 +0800 Subject: [PATCH] macOS: Implement NSTextInputClient.windowLevel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Without this optional NSTextInputClient method the input methods will assume it's safe to place the input panel somewhere above NSFloatingWindowLevel. But our NSWindow level can potentially be higher than that, if set via QWindow::setFlags(), or directly on the NSWindow. In practice this can be observed by setting a level higher than kCGDockWindowLevel on the NSWindow. Account for this by returning the true window level. Pick-to: 6.5 6.2 Change-Id: I77d9ac3c59e2f6de9b768c7519b2bc0f1e5fda1d Reviewed-by: Tor Arne Vestbø (cherry picked from commit 709d2848e1d33be70c2b9a9ff0219a3bba1a5114) Reviewed-by: Qt Cherry-pick Bot --- .../platforms/cocoa/qnsview_complextext.mm | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/plugins/platforms/cocoa/qnsview_complextext.mm b/src/plugins/platforms/cocoa/qnsview_complextext.mm index 3ccaf8269ee..2372ff403c7 100644 --- a/src/plugins/platforms/cocoa/qnsview_complextext.mm +++ b/src/plugins/platforms/cocoa/qnsview_complextext.mm @@ -505,6 +505,23 @@ return NSNotFound; } +/* + Returns the window level of the text input. + + This allows the input method to place its input panel + above the text input. +*/ +- (NSInteger)windowLevel +{ + // The default level assumed by input methods is NSFloatingWindowLevel, + // but our NSWindow level could be higher than that for many reasons, + // including being set via QWindow::setFlags() or directly on the + // NSWindow, or because we're embedded into a native view hierarchy. + // Return the actual window level to account for this. + return m_platformWindow ? m_platformWindow->nativeWindow().level + : NSNormalWindowLevel; +} + // ------------- Helper functions ------------- /*