Various improvements to macOS platform

This commit is contained in:
Wojtek Figat
2023-10-22 20:06:54 +02:00
parent ccf6c28b02
commit 6ff3e0f488
5 changed files with 42 additions and 33 deletions

View File

@@ -83,6 +83,7 @@ namespace FlaxEditor.GUI.Docking
// Enable hit window presentation // Enable hit window presentation
Proxy.Window.RenderingEnabled = true; Proxy.Window.RenderingEnabled = true;
Proxy.Window.Show(); Proxy.Window.Show();
Proxy.Window.Focus();
} }
/// <summary> /// <summary>
@@ -270,15 +271,16 @@ namespace FlaxEditor.GUI.Docking
// Cache dock rectangles // Cache dock rectangles
var size = _rectDock.Size; var size = _rectDock.Size;
var offset = _rectDock.Location; var offset = _rectDock.Location;
float BorderMargin = 4.0f; var borderMargin = 4.0f;
float ProxyHintWindowsSize2 = Proxy.HintWindowsSize * 0.5f; var hintWindowsSize = Proxy.HintWindowsSize * Platform.DpiScale;
float centerX = size.X * 0.5f; var hintWindowsSize2 = hintWindowsSize * 0.5f;
float centerY = size.Y * 0.5f; var centerX = size.X * 0.5f;
_rUpper = new Rectangle(centerX - ProxyHintWindowsSize2, BorderMargin, Proxy.HintWindowsSize, Proxy.HintWindowsSize) + offset; var centerY = size.Y * 0.5f;
_rBottom = new Rectangle(centerX - ProxyHintWindowsSize2, size.Y - Proxy.HintWindowsSize - BorderMargin, Proxy.HintWindowsSize, Proxy.HintWindowsSize) + offset; _rUpper = new Rectangle(centerX - hintWindowsSize2, borderMargin, hintWindowsSize, hintWindowsSize) + offset;
_rLeft = new Rectangle(BorderMargin, centerY - ProxyHintWindowsSize2, Proxy.HintWindowsSize, Proxy.HintWindowsSize) + offset; _rBottom = new Rectangle(centerX - hintWindowsSize2, size.Y - hintWindowsSize - borderMargin, hintWindowsSize, hintWindowsSize) + offset;
_rRight = new Rectangle(size.X - Proxy.HintWindowsSize - BorderMargin, centerY - ProxyHintWindowsSize2, Proxy.HintWindowsSize, Proxy.HintWindowsSize) + offset; _rLeft = new Rectangle(borderMargin, centerY - hintWindowsSize2, hintWindowsSize, hintWindowsSize) + offset;
_rCenter = new Rectangle(centerX - ProxyHintWindowsSize2, centerY - ProxyHintWindowsSize2, Proxy.HintWindowsSize, Proxy.HintWindowsSize) + offset; _rRight = new Rectangle(size.X - hintWindowsSize - borderMargin, centerY - hintWindowsSize2, hintWindowsSize, hintWindowsSize) + offset;
_rCenter = new Rectangle(centerX - hintWindowsSize2, centerY - hintWindowsSize2, hintWindowsSize, hintWindowsSize) + offset;
// Hit test // Hit test
DockState toSet = DockState.Float; DockState toSet = DockState.Float;
@@ -428,7 +430,6 @@ namespace FlaxEditor.GUI.Docking
{ {
if (Window == null) if (Window == null)
{ {
// Create proxy window
var settings = CreateWindowSettings.Default; var settings = CreateWindowSettings.Default;
settings.Title = "DockHint.Window"; settings.Title = "DockHint.Window";
settings.Size = initSize; settings.Size = initSize;
@@ -440,12 +441,10 @@ namespace FlaxEditor.GUI.Docking
settings.IsRegularWindow = false; settings.IsRegularWindow = false;
settings.SupportsTransparency = true; settings.SupportsTransparency = true;
settings.ShowInTaskbar = false; settings.ShowInTaskbar = false;
settings.ShowAfterFirstPaint = true; settings.ShowAfterFirstPaint = false;
settings.IsTopmost = true; settings.IsTopmost = true;
Window = Platform.CreateWindow(ref settings); Window = Platform.CreateWindow(ref settings);
// Set opacity and background color
Window.Opacity = 0.6f; Window.Opacity = 0.6f;
Window.GUI.BackgroundColor = Style.Current.DragWindow; Window.GUI.BackgroundColor = Style.Current.DragWindow;
} }
@@ -465,7 +464,7 @@ namespace FlaxEditor.GUI.Docking
var settings = CreateWindowSettings.Default; var settings = CreateWindowSettings.Default;
settings.Title = name; settings.Title = name;
settings.Size = new Float2(HintWindowsSize); settings.Size = new Float2(HintWindowsSize * Platform.DpiScale);
settings.AllowInput = false; settings.AllowInput = false;
settings.AllowMaximize = false; settings.AllowMaximize = false;
settings.AllowMinimize = false; settings.AllowMinimize = false;
@@ -479,7 +478,6 @@ namespace FlaxEditor.GUI.Docking
settings.ShowAfterFirstPaint = false; settings.ShowAfterFirstPaint = false;
win = Platform.CreateWindow(ref settings); win = Platform.CreateWindow(ref settings);
win.Opacity = 0.6f; win.Opacity = 0.6f;
win.GUI.BackgroundColor = Style.Current.DragWindow; win.GUI.BackgroundColor = Style.Current.DragWindow;
} }

View File

@@ -2622,9 +2622,7 @@ bool LinuxPlatform::GetHasFocus()
if (window->IsFocused()) if (window->IsFocused())
return true; return true;
} }
return false;
// Default to true if has no windows open
return WindowsManager::Windows.IsEmpty();
} }
bool LinuxPlatform::CanOpenUrl(const StringView& url) bool LinuxPlatform::CanOpenUrl(const StringView& url)

View File

@@ -710,6 +710,8 @@ MacWindow::MacWindow(const CreateWindowSettings& settings)
{ {
styleMask |= NSWindowStyleMaskBorderless; styleMask |= NSWindowStyleMaskBorderless;
} }
if (settings.Fullscreen)
styleMask |= NSWindowStyleMaskFullScreen;
if (settings.HasBorder) if (settings.HasBorder)
{ {
styleMask |= NSWindowStyleMaskTitled; styleMask |= NSWindowStyleMaskTitled;
@@ -736,6 +738,7 @@ MacWindow::MacWindow(const CreateWindowSettings& settings)
[window setMaxSize:NSMakeSize(settings.MaximumSize.X, settings.MaximumSize.Y)]; [window setMaxSize:NSMakeSize(settings.MaximumSize.X, settings.MaximumSize.Y)];
[window setOpaque:!settings.SupportsTransparency]; [window setOpaque:!settings.SupportsTransparency];
[window setContentView:view]; [window setContentView:view];
if (settings.AllowInput)
[window setAcceptsMouseMovedEvents:YES]; [window setAcceptsMouseMovedEvents:YES];
[window setDelegate:window]; [window setDelegate:window];
_window = window; _window = window;
@@ -751,8 +754,6 @@ MacWindow::MacWindow(const CreateWindowSettings& settings)
layer.contentsScale = screenScale; layer.contentsScale = screenScale;
// TODO: impl Parent for MacWindow // TODO: impl Parent for MacWindow
// TODO: impl StartPosition for MacWindow
// TODO: impl Fullscreen for MacWindow
// TODO: impl ShowInTaskbar for MacWindow // TODO: impl ShowInTaskbar for MacWindow
// TODO: impl IsTopmost for MacWindow // TODO: impl IsTopmost for MacWindow
} }
@@ -816,7 +817,10 @@ void MacWindow::Show()
// Show // Show
NSWindow* window = (NSWindow*)_window; NSWindow* window = (NSWindow*)_window;
if (_settings.AllowInput)
[window makeKeyAndOrderFront:window]; [window makeKeyAndOrderFront:window];
else
[window orderFront:window];
if (_settings.ActivateWhenFirstShown) if (_settings.ActivateWhenFirstShown)
[NSApp activateIgnoringOtherApps:YES]; [NSApp activateIgnoringOtherApps:YES];
_focused = true; _focused = true;
@@ -870,14 +874,9 @@ void MacWindow::Restore()
[window zoom:nil]; [window zoom:nil];
} }
bool MacWindow::IsClosed() const
{
return _window != nullptr;
}
bool MacWindow::IsForegroundWindow() const bool MacWindow::IsForegroundWindow() const
{ {
return Platform::GetHasFocus() && IsFocused(); return IsFocused() && Platform::GetHasFocus();
} }
void MacWindow::BringToFront(bool force) void MacWindow::BringToFront(bool force)
@@ -1039,6 +1038,22 @@ DragDropEffect MacWindow::DoDragDrop(const StringView& data)
return result; return result;
} }
void MacWindow::StartTrackingMouse(bool useMouseScreenOffset)
{
if (_isTrackingMouse || !_window)
return;
_isTrackingMouse = true;
_trackingMouseOffset = Float2::Zero;
_isUsingMouseOffset = useMouseScreenOffset;
}
void MacWindow::EndTrackingMouse()
{
if (!_isTrackingMouse || !_window)
return;
_isTrackingMouse = false;
}
void MacWindow::SetCursor(CursorType type) void MacWindow::SetCursor(CursorType type)
{ {
CursorType prev = _cursor; CursorType prev = _cursor;

View File

@@ -13,14 +13,12 @@
class FLAXENGINE_API MacWindow : public WindowBase class FLAXENGINE_API MacWindow : public WindowBase
{ {
private: private:
void* _window = nullptr; void* _window = nullptr;
void* _view = nullptr; void* _view = nullptr;
bool _isMouseOver = false; bool _isMouseOver = false;
String _dragText; String _dragText;
public: public:
MacWindow(const CreateWindowSettings& settings); MacWindow(const CreateWindowSettings& settings);
~MacWindow(); ~MacWindow();
@@ -32,7 +30,6 @@ public:
} }
public: public:
// [WindowBase] // [WindowBase]
void* GetNativePtr() const override; void* GetNativePtr() const override;
void Show() override; void Show() override;
@@ -40,7 +37,6 @@ public:
void Minimize() override; void Minimize() override;
void Maximize() override; void Maximize() override;
void Restore() override; void Restore() override;
bool IsClosed() const override;
bool IsForegroundWindow() const override; bool IsForegroundWindow() const override;
void BringToFront(bool force = false) override; void BringToFront(bool force = false) override;
void SetClientBounds(const Rectangle& clientArea) override; void SetClientBounds(const Rectangle& clientArea) override;
@@ -56,6 +52,8 @@ public:
void Focus() override; void Focus() override;
void SetTitle(const StringView& title) override; void SetTitle(const StringView& title) override;
DragDropEffect DoDragDrop(const StringView& data) override; DragDropEffect DoDragDrop(const StringView& data) override;
void StartTrackingMouse(bool useMouseScreenOffset) override;
void EndTrackingMouse() override;
void SetCursor(CursorType type) override; void SetCursor(CursorType type) override;
}; };

View File

@@ -410,7 +410,7 @@ bool iOSWindow::IsClosed() const
bool iOSWindow::IsForegroundWindow() const bool iOSWindow::IsForegroundWindow() const
{ {
return Platform::GetHasFocus() && IsFocused(); return IsFocused() && Platform::GetHasFocus();
} }
void iOSWindow::BringToFront(bool force) void iOSWindow::BringToFront(bool force)