diff --git a/include/glfw/video-driver.hpp b/include/glfw/video-driver.hpp index b1780aafd..5d068a2b9 100644 --- a/include/glfw/video-driver.hpp +++ b/include/glfw/video-driver.hpp @@ -42,6 +42,7 @@ class GLFWVideoDriver : public OpenGlVideoDriver { virtual Size viewport_size() const { return _viewport_size; } virtual Size screen_size() const { return _screen_size; } + virtual void set_fullscreen(const bool on); virtual Point get_mouse(); virtual InputMode input_mode() const; diff --git a/include/mac/c/CocoaVideoDriver.h b/include/mac/c/CocoaVideoDriver.h index a5ec48a75..5bde0d35d 100644 --- a/include/mac/c/CocoaVideoDriver.h +++ b/include/mac/c/CocoaVideoDriver.h @@ -44,6 +44,7 @@ int32_t antares_window_screen_width(const AntaresWindow* window); int32_t antares_window_screen_height(const AntaresWindow* window); int32_t antares_window_viewport_width(const AntaresWindow* window); int32_t antares_window_viewport_height(const AntaresWindow* window); +void antares_window_toggle_fullscreen(AntaresWindow* window); void antares_get_mouse_location(AntaresWindow* window, int32_t* x, int32_t* y); diff --git a/include/mac/video-driver.hpp b/include/mac/video-driver.hpp index 6f3a53fc5..6d347236a 100644 --- a/include/mac/video-driver.hpp +++ b/include/mac/video-driver.hpp @@ -40,6 +40,7 @@ class CocoaVideoDriver : public OpenGlVideoDriver { virtual Size viewport_size() const; virtual Size screen_size() const; + virtual void set_fullscreen(const bool on); virtual Point get_mouse(); virtual InputMode input_mode() const; diff --git a/include/video/driver.hpp b/include/video/driver.hpp index f955b6c1d..6618f59b9 100644 --- a/include/video/driver.hpp +++ b/include/video/driver.hpp @@ -43,10 +43,11 @@ class VideoDriver { VideoDriver& operator=(const VideoDriver&) = delete; virtual ~VideoDriver(); - virtual Point get_mouse() = 0; - virtual InputMode input_mode() const = 0; - virtual int scale() const = 0; - virtual Size screen_size() const = 0; + virtual Point get_mouse() = 0; + virtual InputMode input_mode() const = 0; + virtual int scale() const = 0; + virtual Size screen_size() const = 0; + virtual void set_fullscreen(const bool on) = 0; virtual bool start_editing(TextReceiver* text) = 0; virtual void stop_editing(TextReceiver* text) = 0; diff --git a/include/video/offscreen-driver.hpp b/include/video/offscreen-driver.hpp index 26d600c0a..c0a92acac 100644 --- a/include/video/offscreen-driver.hpp +++ b/include/video/offscreen-driver.hpp @@ -43,6 +43,7 @@ class OffscreenVideoDriver : public OpenGlVideoDriver { return {_screen_size.width * _scale, _screen_size.height * _scale}; } virtual Size screen_size() const { return _screen_size; } + virtual void set_fullscreen(const bool on) {}; virtual Point get_mouse() { return _scheduler->get_mouse(); } virtual InputMode input_mode() const { return _scheduler->input_mode(); } diff --git a/include/video/text-driver.hpp b/include/video/text-driver.hpp index e06c7526f..c4c252194 100644 --- a/include/video/text-driver.hpp +++ b/include/video/text-driver.hpp @@ -36,6 +36,7 @@ class TextVideoDriver : public VideoDriver { virtual InputMode input_mode() const { return KEYBOARD_MOUSE; } virtual int scale() const; virtual Size screen_size() const { return _size; } + virtual void set_fullscreen(const bool on); virtual bool start_editing(TextReceiver* text); virtual void stop_editing(TextReceiver* text); diff --git a/src/glfw/video-driver.cpp b/src/glfw/video-driver.cpp index f13a03940..2f14900bd 100644 --- a/src/glfw/video-driver.cpp +++ b/src/glfw/video-driver.cpp @@ -182,6 +182,10 @@ GLFWVideoDriver::~GLFWVideoDriver() { glfwTerminate(); } pn::string_view GLFWVideoDriver::glsl_version() const { return _glsl_version; } +void GLFWVideoDriver::set_fullscreen(const bool on) { + window_maximize(on); +} + Point GLFWVideoDriver::get_mouse() { double x, y; glfwGetCursorPos(_window, &x, &y); diff --git a/src/mac/c/CocoaVideoDriver.m b/src/mac/c/CocoaVideoDriver.m index c36831efd..c4d562008 100644 --- a/src/mac/c/CocoaVideoDriver.m +++ b/src/mac/c/CocoaVideoDriver.m @@ -126,10 +126,9 @@ void antares_mouse_show() { [window.window setContentView:window.view]; [window.window makeKeyAndOrderFront:NSApp]; [window.window makeFirstResponder:window.view]; + [window.window center]; if (fullscreen) { [window.window toggleFullScreen:nil]; - } else { - [window.window center]; } window.window.delegate = window.view; return memdup(&window, sizeof(AntaresWindow)); @@ -170,6 +169,10 @@ static bool translate_coords(AntaresView* view, NSEvent* event, NSPoint* p) { return true; } +void antares_window_toggle_fullscreen(AntaresWindow* window) { + [window->window toggleFullScreen:nil]; +} + void antares_get_mouse_location(AntaresWindow* window, int32_t* x, int32_t* y) { NSPoint location = [NSEvent mouseLocation]; NSRect r = NSMakeRect(location.x, location.y, 1, 1); diff --git a/src/mac/video-driver.cpp b/src/mac/video-driver.cpp index de3d697dc..7ebedd22b 100644 --- a/src/mac/video-driver.cpp +++ b/src/mac/video-driver.cpp @@ -107,6 +107,13 @@ Size CocoaVideoDriver::screen_size() const { }; } +void CocoaVideoDriver::set_fullscreen(const bool on) { + if (sys.prefs->fullscreen() != on) { + antares_window_toggle_fullscreen(_window); + sys.prefs->set_fullscreen(on); + } +} + Point CocoaVideoDriver::get_mouse() { Point p; antares_get_mouse_location(_window, &p.h, &p.v); diff --git a/src/ui/screens/options.cpp b/src/ui/screens/options.cpp index c32aa9ebe..316ca0757 100644 --- a/src/ui/screens/options.cpp +++ b/src/ui/screens/options.cpp @@ -233,7 +233,7 @@ VideoControlScreen::VideoControlScreen(OptionsScreen::State* state) ->bind({ [] { return sys.prefs->fullscreen(); }, [](bool on) { - sys.prefs->set_fullscreen(on); + sys.video->set_fullscreen(on); }, }); diff --git a/src/video/text-driver.cpp b/src/video/text-driver.cpp index bcf55db57..9d57fbd1d 100644 --- a/src/video/text-driver.cpp +++ b/src/video/text-driver.cpp @@ -168,6 +168,10 @@ TextVideoDriver::TextVideoDriver(Size screen_size, const sfz::optional