Add wxFullScreenEvent for macOS
Send a wxFullScreenEvent when the user enters or exits full screen on macOS. EnableFullScreenView() has to be used to enable the native full screen API. Closes https://github.com/wxWidgets/wxWidgets/pull/2284
This commit is contained in:
		
				
					committed by
					
						
						Vadim Zeitlin
					
				
			
			
				
	
			
			
			
						parent
						
							a495b1fd23
						
					
				
				
					commit
					0ff1bdec09
				
			@@ -681,6 +681,7 @@ class WXDLLIMPEXP_FWD_CORE wxWindowDestroyEvent;
 | 
				
			|||||||
class WXDLLIMPEXP_FWD_CORE wxShowEvent;
 | 
					class WXDLLIMPEXP_FWD_CORE wxShowEvent;
 | 
				
			||||||
class WXDLLIMPEXP_FWD_CORE wxIconizeEvent;
 | 
					class WXDLLIMPEXP_FWD_CORE wxIconizeEvent;
 | 
				
			||||||
class WXDLLIMPEXP_FWD_CORE wxMaximizeEvent;
 | 
					class WXDLLIMPEXP_FWD_CORE wxMaximizeEvent;
 | 
				
			||||||
 | 
					class WXDLLIMPEXP_FWD_CORE wxFullScreenEvent;
 | 
				
			||||||
class WXDLLIMPEXP_FWD_CORE wxMouseCaptureChangedEvent;
 | 
					class WXDLLIMPEXP_FWD_CORE wxMouseCaptureChangedEvent;
 | 
				
			||||||
class WXDLLIMPEXP_FWD_CORE wxMouseCaptureLostEvent;
 | 
					class WXDLLIMPEXP_FWD_CORE wxMouseCaptureLostEvent;
 | 
				
			||||||
class WXDLLIMPEXP_FWD_CORE wxPaintEvent;
 | 
					class WXDLLIMPEXP_FWD_CORE wxPaintEvent;
 | 
				
			||||||
@@ -832,6 +833,7 @@ wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_DESTROY, wxWindowDestroyEvent);
 | 
				
			|||||||
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SHOW, wxShowEvent);
 | 
					wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SHOW, wxShowEvent);
 | 
				
			||||||
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_ICONIZE, wxIconizeEvent);
 | 
					wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_ICONIZE, wxIconizeEvent);
 | 
				
			||||||
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MAXIMIZE, wxMaximizeEvent);
 | 
					wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MAXIMIZE, wxMaximizeEvent);
 | 
				
			||||||
 | 
					wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_FULLSCREEN, wxFullScreenEvent);
 | 
				
			||||||
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MOUSE_CAPTURE_CHANGED, wxMouseCaptureChangedEvent);
 | 
					wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MOUSE_CAPTURE_CHANGED, wxMouseCaptureChangedEvent);
 | 
				
			||||||
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MOUSE_CAPTURE_LOST, wxMouseCaptureLostEvent);
 | 
					wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MOUSE_CAPTURE_LOST, wxMouseCaptureLostEvent);
 | 
				
			||||||
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_PAINT, wxPaintEvent);
 | 
					wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_PAINT, wxPaintEvent);
 | 
				
			||||||
@@ -2725,6 +2727,30 @@ private:
 | 
				
			|||||||
    wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxMaximizeEvent);
 | 
					    wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxMaximizeEvent);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 wxEVT_FULLSCREEN
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					class WXDLLIMPEXP_CORE wxFullScreenEvent : public wxEvent
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					public:
 | 
				
			||||||
 | 
					    wxFullScreenEvent(int winid = 0, bool fullscreen = true)
 | 
				
			||||||
 | 
					        : wxEvent(winid, wxEVT_FULLSCREEN)
 | 
				
			||||||
 | 
					        { m_fullscreen = fullscreen; }
 | 
				
			||||||
 | 
					    wxFullScreenEvent(const wxFullScreenEvent& event)
 | 
				
			||||||
 | 
					        : wxEvent(event)
 | 
				
			||||||
 | 
					        { m_fullscreen = event.m_fullscreen; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    bool IsFullScreen() const { return m_fullscreen; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    virtual wxEvent *Clone() const wxOVERRIDE { return new wxFullScreenEvent(*this); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					protected:
 | 
				
			||||||
 | 
					    bool m_fullscreen;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					private:
 | 
				
			||||||
 | 
					    wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxFullScreenEvent);
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Joystick event class
 | 
					// Joystick event class
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 wxEVT_JOY_BUTTON_DOWN,
 | 
					 wxEVT_JOY_BUTTON_DOWN,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -341,6 +341,8 @@ public :
 | 
				
			|||||||
    CGWindowLevel   GetWindowLevel() const wxOVERRIDE { return m_macWindowLevel; }
 | 
					    CGWindowLevel   GetWindowLevel() const wxOVERRIDE { return m_macWindowLevel; }
 | 
				
			||||||
    void            RestoreWindowLevel() wxOVERRIDE;
 | 
					    void            RestoreWindowLevel() wxOVERRIDE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    bool m_macIgnoreNextFullscreenChange = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    static WX_NSResponder GetNextFirstResponder() ;
 | 
					    static WX_NSResponder GetNextFirstResponder() ;
 | 
				
			||||||
    static WX_NSResponder GetFormerFirstResponder() ;
 | 
					    static WX_NSResponder GetFormerFirstResponder() ;
 | 
				
			||||||
protected :
 | 
					protected :
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2262,6 +2262,46 @@ public:
 | 
				
			|||||||
    wxMaximizeEvent(int id = 0);
 | 
					    wxMaximizeEvent(int id = 0);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					    @class wxFullScreenEvent
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    An event being sent when the user enters or exits full screen mode.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Currently this event is only generated in the wxOSX/Cocoa port when
 | 
				
			||||||
 | 
					    wxTopLevelWindow::EnableFullScreenView() is enabled and the user
 | 
				
			||||||
 | 
					    the user enters or exits full screen. Note that this event is @e not
 | 
				
			||||||
 | 
					    generated when wxTopLevelWindow::ShowFullScreen().
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @beginEventTable{wxFullScreenEvent}
 | 
				
			||||||
 | 
					    @event{EVT_FULLSCREEN(func)}
 | 
				
			||||||
 | 
					        Process a @c wxEVT_FULLSCREEN event.
 | 
				
			||||||
 | 
					    @endEventTable
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @library{wxcore}
 | 
				
			||||||
 | 
					    @category{events}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @since 3.1.5
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @see @ref overview_events, wxTopLevelWindow::EnableFullScreenView,
 | 
				
			||||||
 | 
					         wxTopLevelWindow::IsFullScreen
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					class wxFullScreenEvent : public wxEvent
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					public:
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					        Constructor.
 | 
				
			||||||
 | 
					    */
 | 
				
			||||||
 | 
					    wxFullScreenEvent(int id = 0, bool fullscreen = true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					        Returns @true if the frame entered full screen, @false if exited
 | 
				
			||||||
 | 
					        full screen.
 | 
				
			||||||
 | 
					    */
 | 
				
			||||||
 | 
					    bool IsFullScreen() const;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
    The possibles modes to pass to wxUpdateUIEvent::SetMode().
 | 
					    The possibles modes to pass to wxUpdateUIEvent::SetMode().
 | 
				
			||||||
*/
 | 
					*/
 | 
				
			||||||
@@ -5151,4 +5191,3 @@ wxEventType wxEVT_WINDOW_MODAL_DIALOG_CLOSED;
 | 
				
			|||||||
#endif // wxUSE_GUI
 | 
					#endif // wxUSE_GUI
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//@}
 | 
					//@}
 | 
				
			||||||
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -68,6 +68,8 @@ enum
 | 
				
			|||||||
        See wxMoveEvent.
 | 
					        See wxMoveEvent.
 | 
				
			||||||
    @event{EVT_SHOW(func)}
 | 
					    @event{EVT_SHOW(func)}
 | 
				
			||||||
        Process a @c wxEVT_SHOW event. See wxShowEvent.
 | 
					        Process a @c wxEVT_SHOW event. See wxShowEvent.
 | 
				
			||||||
 | 
					    @event{EVT_FULLSCREEN(id, func)}
 | 
				
			||||||
 | 
					        Process a @c wxEVT_FULLSCREEN event. See wxFullScreenEvent.
 | 
				
			||||||
    @endEventTable
 | 
					    @endEventTable
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @library{wxcore}
 | 
					    @library{wxcore}
 | 
				
			||||||
@@ -632,17 +634,16 @@ public:
 | 
				
			|||||||
    virtual void ShowWithoutActivating();
 | 
					    virtual void ShowWithoutActivating();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
        Enables the maximize button to toggle full screen mode. Prior to
 | 
					        Enables the zoom button to toggle full screen mode.
 | 
				
			||||||
        macOS 10.10 a full screen button is added to the right upper corner
 | 
					 | 
				
			||||||
        of a window's title bar.
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Currently only available for wxOSX/Cocoa.
 | 
					        A wxFullScreenEvent is generated when the users enters or exits
 | 
				
			||||||
 | 
					        full screen via the enter/exit full screen button.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        @param enable
 | 
					        @param enable
 | 
				
			||||||
            If @true (default) adds the full screen button in the title bar;
 | 
					            If @true (default) make the zoom button toggle full screen;
 | 
				
			||||||
            if @false the button is removed.
 | 
					            if @false the button does only toggle zoom.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        @return @true if the button was added or removed, @false if running
 | 
					        @return @true if the button behaviour has been changed, @false if running
 | 
				
			||||||
        under another OS.
 | 
					        under another OS.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        @note Having the button is also required to let ShowFullScreen()
 | 
					        @note Having the button is also required to let ShowFullScreen()
 | 
				
			||||||
@@ -653,7 +654,7 @@ public:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        @onlyfor{wxosx}
 | 
					        @onlyfor{wxosx}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        @see ShowFullScreen()
 | 
					        @see ShowFullScreen(), wxFullScreenEvent
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        @since 3.1.0
 | 
					        @since 3.1.0
 | 
				
			||||||
    */
 | 
					    */
 | 
				
			||||||
@@ -718,4 +719,3 @@ public:
 | 
				
			|||||||
    */
 | 
					    */
 | 
				
			||||||
    void UseNativeDecorationsByDefault(bool native = true);
 | 
					    void UseNativeDecorationsByDefault(bool native = true);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -80,6 +80,7 @@
 | 
				
			|||||||
    wxIMPLEMENT_DYNAMIC_CLASS(wxShowEvent, wxEvent);
 | 
					    wxIMPLEMENT_DYNAMIC_CLASS(wxShowEvent, wxEvent);
 | 
				
			||||||
    wxIMPLEMENT_DYNAMIC_CLASS(wxMaximizeEvent, wxEvent);
 | 
					    wxIMPLEMENT_DYNAMIC_CLASS(wxMaximizeEvent, wxEvent);
 | 
				
			||||||
    wxIMPLEMENT_DYNAMIC_CLASS(wxIconizeEvent, wxEvent);
 | 
					    wxIMPLEMENT_DYNAMIC_CLASS(wxIconizeEvent, wxEvent);
 | 
				
			||||||
 | 
					    wxIMPLEMENT_DYNAMIC_CLASS(wxFullScreenEvent, wxEvent);
 | 
				
			||||||
    wxIMPLEMENT_DYNAMIC_CLASS(wxMenuEvent, wxEvent);
 | 
					    wxIMPLEMENT_DYNAMIC_CLASS(wxMenuEvent, wxEvent);
 | 
				
			||||||
    wxIMPLEMENT_DYNAMIC_CLASS(wxJoystickEvent, wxEvent);
 | 
					    wxIMPLEMENT_DYNAMIC_CLASS(wxJoystickEvent, wxEvent);
 | 
				
			||||||
    wxIMPLEMENT_DYNAMIC_CLASS(wxDropFilesEvent, wxEvent);
 | 
					    wxIMPLEMENT_DYNAMIC_CLASS(wxDropFilesEvent, wxEvent);
 | 
				
			||||||
@@ -288,6 +289,7 @@ wxDEFINE_EVENT( wxEVT_DESTROY, wxWindowDestroyEvent );
 | 
				
			|||||||
wxDEFINE_EVENT( wxEVT_SHOW, wxShowEvent );
 | 
					wxDEFINE_EVENT( wxEVT_SHOW, wxShowEvent );
 | 
				
			||||||
wxDEFINE_EVENT( wxEVT_ICONIZE, wxIconizeEvent );
 | 
					wxDEFINE_EVENT( wxEVT_ICONIZE, wxIconizeEvent );
 | 
				
			||||||
wxDEFINE_EVENT( wxEVT_MAXIMIZE, wxMaximizeEvent );
 | 
					wxDEFINE_EVENT( wxEVT_MAXIMIZE, wxMaximizeEvent );
 | 
				
			||||||
 | 
					wxDEFINE_EVENT( wxEVT_FULLSCREEN, wxFullScreenEvent );
 | 
				
			||||||
wxDEFINE_EVENT( wxEVT_MOUSE_CAPTURE_CHANGED, wxMouseCaptureChangedEvent );
 | 
					wxDEFINE_EVENT( wxEVT_MOUSE_CAPTURE_CHANGED, wxMouseCaptureChangedEvent );
 | 
				
			||||||
wxDEFINE_EVENT( wxEVT_MOUSE_CAPTURE_LOST, wxMouseCaptureLostEvent );
 | 
					wxDEFINE_EVENT( wxEVT_MOUSE_CAPTURE_LOST, wxMouseCaptureLostEvent );
 | 
				
			||||||
wxDEFINE_EVENT( wxEVT_PAINT, wxPaintEvent );
 | 
					wxDEFINE_EVENT( wxEVT_PAINT, wxPaintEvent );
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -606,6 +606,25 @@ extern int wxOSXGetIdFromSelector(SEL action );
 | 
				
			|||||||
    return true;
 | 
					    return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void SendFullScreenWindowEvent(NSNotification* notification, bool fullscreen)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    NSWindow* window = (NSWindow*) [notification object];
 | 
				
			||||||
 | 
					    wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
 | 
				
			||||||
 | 
					    if ( windowimpl )
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        if (windowimpl->m_macIgnoreNextFullscreenChange)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            windowimpl->m_macIgnoreNextFullscreenChange = false;
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
 | 
				
			||||||
 | 
					        wxFullScreenEvent event(wxpeer->GetId(), fullscreen);
 | 
				
			||||||
 | 
					        event.SetEventObject(wxpeer);
 | 
				
			||||||
 | 
					        wxpeer->HandleWindowEvent(event);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// work around OS X bug, on a secondary monitor an already fully sized window
 | 
					// work around OS X bug, on a secondary monitor an already fully sized window
 | 
				
			||||||
// (eg maximized) will not be correctly put to full screen size and keeps a 22px
 | 
					// (eg maximized) will not be correctly put to full screen size and keeps a 22px
 | 
				
			||||||
// title band at the top free, therefore we force the correct content size
 | 
					// title band at the top free, therefore we force the correct content size
 | 
				
			||||||
@@ -624,6 +643,13 @@ extern int wxOSXGetIdFromSelector(SEL action );
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        [view setFrameSize: expectedframerect.size];
 | 
					        [view setFrameSize: expectedframerect.size];
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    SendFullScreenWindowEvent(notification, true);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- (void)windowWillExitFullScreen:(NSNotification *)notification
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    SendFullScreenWindowEvent(notification, false);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// from https://developer.apple.com/library/archive/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/CapturingScreenContents/CapturingScreenContents.html
 | 
					// from https://developer.apple.com/library/archive/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/CapturingScreenContents/CapturingScreenContents.html
 | 
				
			||||||
@@ -1178,6 +1204,7 @@ bool wxNonOwnedWindowCocoaImpl::ShowFullScreen(bool show, long WXUNUSED(style))
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        if ( show != IsFullScreen() )
 | 
					        if ( show != IsFullScreen() )
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
					            m_macIgnoreNextFullscreenChange = true;
 | 
				
			||||||
            [m_macWindow toggleFullScreen: nil];
 | 
					            [m_macWindow toggleFullScreen: nil];
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user