dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.99k stars 1.72k forks source link

[Mac] Can I open mac window with fullScreen #7778

Closed ChisterWu closed 1 year ago

ChisterWu commented 2 years ago

Description

I would want to open my mac app with full screen, but I haven't found any effective way. I seen a solution in other posts. The method is: ("NsApplication.SharedApplication.delegate.hostWindowForUIWindow(UIWindow.Self)") 1)using ObjCRuntime 2) get NsApplication (use Runtime.GetNSObject(Class.GetHandle("NSApplication")) ) 3)get NsApplication.SharedApplication(use NsApplication.PerformSelector(new Selector("sharedApplication")) ) 4)get delegate from NsApplication.SharedApplication (this is a property for NsApplication, you can use dllimport [objc_msgSend] from "/usr/lib/libobjc.dylib" and execute it to achieve)(IntPtr_objc_msgSend(vSharedApplication.Handle, delegeteSelector.Handle)) 5)call the "hostWindowForUIWindow:" method with delegate(this is a hide method I can't find in the develop document )(delegateObject.PerformSelector(hostWindowForUIWindowSelector, _MainWindow.Self);) 6)affter completing the above steps, I get a empty object, which make me unable to perform the next step(toggleFullScreen with the NsWindow)

Public API Changes



    bool ToggleFullScreen(bool bFullScreen)
    {
        if (_MainWindow is null)
            return false;

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

        var sharedApplication= nsApplication.PerformSelector(new Selector("sharedApplication"));
        if (sharedApplicationis null)
            return false;

        var delegeteSelector = new Selector("delegate");
        if (!sharedApplication.RespondsToSelector(delegeteSelector))
            return false;

        var delegeteIntptr = RuntimeInterop.IntPtr_objc_msgSend(sharedApplication.Handle, delegeteSelector.Handle);
        var delegateObject = Runtime.GetNSObject(delegeteIntptr);

        if (delegateObject is null)
            return false;

        var hostWindowForUIWindowSelector = new Selector("_hostWindowForUIWindow:");
        if (!delegateObject.RespondsToSelector(hostWindowForUIWindowSelector))
            return false;

        var mainWindow = delegateObject.PerformSelector(hostWindowForUIWindowSelector, _MainWindow.Self);
        if (mainWindow is null)
            return false;

        var toggleFullScreenSelector = new Selector("toggleFullScreen:");
        if (!mainWindow.RespondsToSelector(toggleFullScreenSelector))
            return false;

        RuntimeInterop.void_objc_msgSend_IntPtr(mainWindow.Handle, toggleFullScreenSelector.Handle, IntPtr.Zero);

        return true;
    }

``

### Intended Use-Case

In my app, I want to use buton to enter fullScreen or exit fullscreen.
xiaohongSunLN commented 2 years ago

hi, sir. Thanks for your share. In my Mac Project with maui, I want to define the background color of the NSTitleBar, and merge the titlebar and toolbar. I don't know how to get the object of the NSWindow, the top code is very helpful for me, but I don't know the define of the "_MainWindow", can you give me the detail description for _MainWindow. Thanks a lot.

samhouts commented 1 year ago

Duplicate of #5478

ghost commented 1 year ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.