Skip to content

Commit

Permalink
Add wxFullScreenEvent for macOS
Browse files Browse the repository at this point in the history
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 #2284
  • Loading branch information
TcT2k authored and vadz committed Apr 6, 2021
1 parent a495b1f commit 0ff1bde
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 10 deletions.
26 changes: 26 additions & 0 deletions include/wx/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@ class WXDLLIMPEXP_FWD_CORE wxWindowDestroyEvent;
class WXDLLIMPEXP_FWD_CORE wxShowEvent;
class WXDLLIMPEXP_FWD_CORE wxIconizeEvent;
class WXDLLIMPEXP_FWD_CORE wxMaximizeEvent;
class WXDLLIMPEXP_FWD_CORE wxFullScreenEvent;
class WXDLLIMPEXP_FWD_CORE wxMouseCaptureChangedEvent;
class WXDLLIMPEXP_FWD_CORE wxMouseCaptureLostEvent;
class WXDLLIMPEXP_FWD_CORE wxPaintEvent;
Expand Down Expand Up @@ -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_ICONIZE, wxIconizeEvent);
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_LOST, wxMouseCaptureLostEvent);
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_PAINT, wxPaintEvent);
Expand Down Expand Up @@ -2725,6 +2727,30 @@ class WXDLLIMPEXP_CORE wxMaximizeEvent : public wxEvent
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
/*
wxEVT_JOY_BUTTON_DOWN,
Expand Down
2 changes: 2 additions & 0 deletions include/wx/osx/cocoa/private.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ public :
CGWindowLevel GetWindowLevel() const wxOVERRIDE { return m_macWindowLevel; }
void RestoreWindowLevel() wxOVERRIDE;

bool m_macIgnoreNextFullscreenChange = false;

static WX_NSResponder GetNextFirstResponder() ;
static WX_NSResponder GetFormerFirstResponder() ;
protected :
Expand Down
41 changes: 40 additions & 1 deletion interface/wx/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -2262,6 +2262,46 @@ class wxMaximizeEvent : public wxEvent
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().
*/
Expand Down Expand Up @@ -5151,4 +5191,3 @@ wxEventType wxEVT_WINDOW_MODAL_DIALOG_CLOSED;
#endif // wxUSE_GUI

//@}

18 changes: 9 additions & 9 deletions interface/wx/toplevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ enum
See wxMoveEvent.
@event{EVT_SHOW(func)}
Process a @c wxEVT_SHOW event. See wxShowEvent.
@event{EVT_FULLSCREEN(id, func)}
Process a @c wxEVT_FULLSCREEN event. See wxFullScreenEvent.
@endEventTable
@library{wxcore}
Expand Down Expand Up @@ -632,17 +634,16 @@ class wxTopLevelWindow : public wxNonOwnedWindow
virtual void ShowWithoutActivating();

/**
Enables the maximize button to toggle full screen mode. Prior to
macOS 10.10 a full screen button is added to the right upper corner
of a window's title bar.
Enables the zoom button to toggle full screen mode.
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
If @true (default) adds the full screen button in the title bar;
if @false the button is removed.
If @true (default) make the zoom button toggle full screen;
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.
@note Having the button is also required to let ShowFullScreen()
Expand All @@ -653,7 +654,7 @@ class wxTopLevelWindow : public wxNonOwnedWindow
@onlyfor{wxosx}
@see ShowFullScreen()
@see ShowFullScreen(), wxFullScreenEvent
@since 3.1.0
*/
Expand Down Expand Up @@ -718,4 +719,3 @@ class wxTopLevelWindow : public wxNonOwnedWindow
*/
void UseNativeDecorationsByDefault(bool native = true);
};

2 changes: 2 additions & 0 deletions src/common/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
wxIMPLEMENT_DYNAMIC_CLASS(wxShowEvent, wxEvent);
wxIMPLEMENT_DYNAMIC_CLASS(wxMaximizeEvent, wxEvent);
wxIMPLEMENT_DYNAMIC_CLASS(wxIconizeEvent, wxEvent);
wxIMPLEMENT_DYNAMIC_CLASS(wxFullScreenEvent, wxEvent);
wxIMPLEMENT_DYNAMIC_CLASS(wxMenuEvent, wxEvent);
wxIMPLEMENT_DYNAMIC_CLASS(wxJoystickEvent, wxEvent);
wxIMPLEMENT_DYNAMIC_CLASS(wxDropFilesEvent, wxEvent);
Expand Down Expand Up @@ -288,6 +289,7 @@ wxDEFINE_EVENT( wxEVT_DESTROY, wxWindowDestroyEvent );
wxDEFINE_EVENT( wxEVT_SHOW, wxShowEvent );
wxDEFINE_EVENT( wxEVT_ICONIZE, wxIconizeEvent );
wxDEFINE_EVENT( wxEVT_MAXIMIZE, wxMaximizeEvent );
wxDEFINE_EVENT( wxEVT_FULLSCREEN, wxFullScreenEvent );
wxDEFINE_EVENT( wxEVT_MOUSE_CAPTURE_CHANGED, wxMouseCaptureChangedEvent );
wxDEFINE_EVENT( wxEVT_MOUSE_CAPTURE_LOST, wxMouseCaptureLostEvent );
wxDEFINE_EVENT( wxEVT_PAINT, wxPaintEvent );
Expand Down
27 changes: 27 additions & 0 deletions src/osx/cocoa/nonownedwnd.mm
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,25 @@ - (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame
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
// (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
Expand All @@ -624,6 +643,13 @@ - (void)windowWillEnterFullScreen:(NSNotification *)notification
{
[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
Expand Down Expand Up @@ -1178,6 +1204,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
{
if ( show != IsFullScreen() )
{
m_macIgnoreNextFullscreenChange = true;
[m_macWindow toggleFullScreen: nil];
}

Expand Down

0 comments on commit 0ff1bde

Please sign in to comment.