Skip to content

Commit 6f24391

Browse files
author
Brian Doyle
committed
fix full screen display on main monitor (hide menus until mouseover)
1 parent 8fa8e4e commit 6f24391

3 files changed

Lines changed: 75 additions & 5 deletions

File tree

src/slic3r/GUI/CameraFullscreenMac.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22

33
#ifdef __APPLE__
44

5+
class wxWindow;
6+
57
namespace Slic3r { namespace GUI {
68

79
using CameraFullscreenEscapeCallback = void (*)(void *);
810

911
void *install_camera_fullscreen_escape_monitor(CameraFullscreenEscapeCallback callback, void *context);
1012
void uninstall_camera_fullscreen_escape_monitor(void *monitor);
13+
void *enter_camera_fullscreen_presentation(wxWindow *window);
14+
void apply_camera_fullscreen_frame(wxWindow *window);
15+
void restore_camera_fullscreen_presentation(void *presentation);
1116

1217
}} // namespace Slic3r::GUI
1318

src/slic3r/GUI/CameraFullscreenMac.mm

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#import <Cocoa/Cocoa.h>
66

7+
#include <wx/window.h>
8+
79
namespace Slic3r { namespace GUI {
810

911
namespace {
@@ -17,6 +19,20 @@
1719
void *context{ nullptr };
1820
};
1921

22+
struct CameraFullscreenPresentationState
23+
{
24+
NSApplicationPresentationOptions presentation_options{ NSApplicationPresentationDefault };
25+
};
26+
27+
NSWindow *camera_fullscreen_window(wxWindow *window)
28+
{
29+
if (!window || !window->GetHandle())
30+
return nil;
31+
32+
NSView *view = (NSView *) window->GetHandle();
33+
return [view window];
34+
}
35+
2036
} // namespace
2137

2238
void *install_camera_fullscreen_escape_monitor(CameraFullscreenEscapeCallback callback, void *context)
@@ -45,6 +61,43 @@ void uninstall_camera_fullscreen_escape_monitor(void *monitor)
4561
delete state;
4662
}
4763

64+
void *enter_camera_fullscreen_presentation(wxWindow *window)
65+
{
66+
auto *state = new CameraFullscreenPresentationState;
67+
state->presentation_options = [NSApp presentationOptions];
68+
69+
NSApplicationPresentationOptions fullscreen_options = state->presentation_options;
70+
fullscreen_options &= ~(NSApplicationPresentationHideDock | NSApplicationPresentationHideMenuBar);
71+
fullscreen_options |= NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar;
72+
[NSApp setPresentationOptions:fullscreen_options];
73+
74+
apply_camera_fullscreen_frame(window);
75+
return state;
76+
}
77+
78+
void apply_camera_fullscreen_frame(wxWindow *window)
79+
{
80+
NSWindow *ns_window = camera_fullscreen_window(window);
81+
if (!ns_window)
82+
return;
83+
84+
NSScreen *screen = [ns_window screen] ?: [NSScreen mainScreen];
85+
if (!screen)
86+
return;
87+
88+
[ns_window setFrame:[screen frame] display:YES animate:NO];
89+
}
90+
91+
void restore_camera_fullscreen_presentation(void *presentation)
92+
{
93+
auto *state = static_cast<CameraFullscreenPresentationState *>(presentation);
94+
if (!state)
95+
return;
96+
97+
[NSApp setPresentationOptions:state->presentation_options];
98+
delete state;
99+
}
100+
48101
}} // namespace Slic3r::GUI
49102

50103
#endif

src/slic3r/GUI/StatusPanel.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ class CameraFullscreenFrame : public wxFrame
222222
~CameraFullscreenFrame() override
223223
{
224224
#ifdef __APPLE__
225+
restore_camera_fullscreen_presentation(m_presentation_state);
225226
uninstall_camera_fullscreen_escape_monitor(m_escape_monitor);
226227
#endif
227228
}
@@ -230,18 +231,24 @@ class CameraFullscreenFrame : public wxFrame
230231

231232
void show_camera_view(bool active_monitor_only)
232233
{
233-
#ifdef __APPLE__
234-
m_native_fullscreen = !active_monitor_only;
235-
#else
236234
m_native_fullscreen = false;
237-
#endif
238235
if (active_monitor_only) {
236+
#ifdef __APPLE__
237+
m_presentation_state = enter_camera_fullscreen_presentation(this);
238+
#endif
239239
SetSize(display_geometry_for(m_owner ? static_cast<wxWindow *>(m_owner) : this));
240240
Show();
241+
#ifdef __APPLE__
242+
apply_camera_fullscreen_frame(this);
243+
#else
244+
ShowFullScreen(true, wxFULLSCREEN_ALL);
245+
m_native_fullscreen = true;
246+
#endif
241247
} else {
242248
#ifdef __APPLE__
243249
Show();
244250
ShowFullScreen(true, wxFULLSCREEN_ALL);
251+
m_native_fullscreen = true;
245252
#else
246253
SetSize(all_display_geometry());
247254
Show();
@@ -255,6 +262,10 @@ class CameraFullscreenFrame : public wxFrame
255262
void exit_camera_view()
256263
{
257264
if (m_native_fullscreen) ShowFullScreen(false);
265+
#ifdef __APPLE__
266+
restore_camera_fullscreen_presentation(m_presentation_state);
267+
m_presentation_state = nullptr;
268+
#endif
258269
}
259270

260271
void attach_media(wxMediaCtrl3 *media_ctrl)
@@ -431,7 +442,8 @@ class CameraFullscreenFrame : public wxFrame
431442
wxTimer m_hide_timer;
432443
wxTimer m_fade_timer;
433444
#ifdef __APPLE__
434-
void *m_escape_monitor{ nullptr };
445+
void *m_escape_monitor{nullptr};
446+
void *m_presentation_state{nullptr};
435447
#endif
436448
wxWindowID m_escape_accel_id{ wxID_ANY };
437449
int m_close_alpha{ 0 };

0 commit comments

Comments
 (0)