From 8deb1007cdf4437b63b896615a71422c208327fd Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 9 Jan 2024 22:13:34 +0100 Subject: [PATCH] Backends: OSX: Fixed IME position in multi-monitor/multi-viewports setups. (#7028) --- backends/imgui_impl_osx.mm | 24 ++++++++++++++++++++---- docs/CHANGELOG.txt | 1 + 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/backends/imgui_impl_osx.mm b/backends/imgui_impl_osx.mm index 134141371..f5f554b27 100644 --- a/backends/imgui_impl_osx.mm +++ b/backends/imgui_impl_osx.mm @@ -141,12 +141,28 @@ static bool ImGui_ImplOSX_HandleEvent(NSEvent* event, NSView* view); - (void)updateImePosWithView:(NSView *)view { - NSWindow *window = view.window; + NSWindow* window = view.window; if (!window) return; - NSRect contentRect = [window contentRectForFrameRect:window.frame]; - NSRect rect = NSMakeRect(_posX, contentRect.size.height - _posY, 0, 0); - _imeRect = [window convertRectToScreen:rect]; + + ImGuiIO& io = ImGui::GetIO(); + if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) + { + NSRect frame = window.frame; + NSRect contentRect = window.contentLayoutRect; + if (window.styleMask & NSWindowStyleMaskFullSizeContentView) // No title bar windows should be considered. + contentRect = frame; + + NSRect firstScreenFrame = NSScreen.screens[0].frame; + _imeRect = NSMakeRect(_posX, _posY, 0, 0); + _imeRect.origin.y = firstScreenFrame.size.height - _imeRect.size.height - _imeRect.origin.y; // Opposite of ConvertNSRect() + } + else + { + NSRect contentRect = [window contentRectForFrameRect:window.frame]; + NSRect rect = NSMakeRect(_posX, contentRect.size.height - _posY, 0, 0); + _imeRect = [window convertRectToScreen:rect]; + } } - (void)viewDidMoveToWindow diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 4d5d26d5e..9f109eb8f 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -115,6 +115,7 @@ Docking+Viewports Branch: queued frames aren't synchronized with platform window resizes. (#7152, #7153) [@SuperWangKai] - Backends: OSX: Fixed monitor and window position by correctly transforming Y origin on multi-viewports multi-monitor setups. (#7028, #7101, #6009, #6432) [@dmirty-kuzmenko, @734vin] +- Backends: OSX: Fixed IME position in multi-monitor multi-viewports setups. (#7028) [@734vin] -----------------------------------------------------------------------