Skip to content
This repository has been archived by the owner on Dec 19, 2022. It is now read-only.

Commit

Permalink
Add full screen for Mac
Browse files Browse the repository at this point in the history
  • Loading branch information
drasticactions committed Dec 31, 2021
1 parent fb82062 commit 2cc3a06
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions DrasticMaui/DrasticMauiWindow.MacCatalyst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Foundation;
using ObjCRuntime;
using UIKit;

namespace DrasticMaui
Expand All @@ -29,6 +32,48 @@ public void ToggleFullScreen(bool fullScreen)
}

// TODO: Get NSWindow.

var nsApplication = Runtime.GetNSObject(Class.GetHandle("NSApplication"));
if (nsApplication is null)
{
return;
}

var sharedApplication = nsApplication.PerformSelector(new Selector("sharedApplication"));
if (sharedApplication is null)
{
return;
}

var applicationDelegate = sharedApplication.PerformSelector(new Selector("delegate"));
if (applicationDelegate is null)
{
return;
}

var nsWindowHandle = IntPtr_objc_msgSend_IntPtr(applicationDelegate.Handle, Selector.GetHandle("hostWindowForUIWindow:"), window.Handle);
var nsWindow = Runtime.GetNSObject(nsWindowHandle);
if (nsWindow is null)
{
return;
}

void_objc_msgSend_bool(nsWindowHandle, Selector.GetHandle("toggleFullScreen:"), fullScreen);
}

[DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend")]
private static extern IntPtr IntPtr_objc_msgSend_nfloat(IntPtr receiver, IntPtr selector, nfloat arg1);

[DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend")]
private static extern IntPtr IntPtr_objc_msgSend_IntPtr(IntPtr receiver, IntPtr selector, IntPtr arg1);

[DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend")]
private static extern IntPtr IntPtr_objc_msgSend(IntPtr receiver, IntPtr selector);

[DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend")]
private static extern void void_objc_msgSend_IntPtr(IntPtr receiver, IntPtr selector, IntPtr arg1);

[DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend")]
private static extern void void_objc_msgSend_bool(IntPtr receiver, IntPtr selector, bool arg1);
}
}

0 comments on commit 2cc3a06

Please sign in to comment.