浏览代码

[macOS] Prevent popups from stealing focus (#17794)

Julien Lebosquain 11 月之前
父节点
当前提交
032cdcb4c7
共有 1 个文件被更改,包括 9 次插入0 次删除
  1. 9 0
      native/Avalonia.Native/src/OSX/PopupImpl.mm

+ 9 - 0
native/Avalonia.Native/src/OSX/PopupImpl.mm

@@ -42,6 +42,15 @@ public:
         
         return WindowBaseImpl::Show(activate, true);
     }
+    
+    virtual bool ShouldTakeFocusOnShow() override
+    {
+        // Don't steal the focus from another windows if our parent is inactive
+        if (Parent != nullptr && Parent->Window != nullptr && ![Parent->Window isKeyWindow])
+            return false;
+
+        return WindowBaseImpl::ShouldTakeFocusOnShow();
+    }
 };