Fixed fullscreen main window for OSX

This commit is contained in:
brunoherbelin
2020-11-01 13:18:49 +01:00
parent 41f87aa927
commit 46b9a8f663
3 changed files with 27 additions and 17 deletions

View File

@@ -84,7 +84,7 @@ static void WindowMoveCallback( GLFWwindow *w, int x, int y)
} }
} }
static void WindowEscapeFullscreen( GLFWwindow *w, int key, int scancode, int action, int) static void WindowEscapeFullscreen( GLFWwindow *w, int key, int, int action, int)
{ {
if (action == GLFW_PRESS && key == GLFW_KEY_ESCAPE) if (action == GLFW_PRESS && key == GLFW_KEY_ESCAPE)
{ {
@@ -223,7 +223,6 @@ void Rendering::pushBackDrawCallback(RenderingCallback function)
void Rendering::draw() void Rendering::draw()
{ {
// operate on main window context // operate on main window context
main_.makeCurrent(); main_.makeCurrent();
@@ -254,6 +253,7 @@ void Rendering::draw()
glfwSwapBuffers(main_.window()); glfwSwapBuffers(main_.window());
glfwSwapBuffers(output_.window()); glfwSwapBuffers(output_.window());
// Poll and handle events (inputs, window resize, etc.) // Poll and handle events (inputs, window resize, etc.)
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application.
@@ -261,8 +261,13 @@ void Rendering::draw()
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
glfwPollEvents(); glfwPollEvents();
// change windows
main_.toggleFullscreen_();
output_.toggleFullscreen_();
// no g_main_loop_run(loop) : update global GMainContext // no g_main_loop_run(loop) : update global GMainContext
g_main_context_iteration(NULL, FALSE); g_main_context_iteration(NULL, FALSE);
} }
@@ -398,7 +403,7 @@ WindowSurface::WindowSurface(Shader *s) : Primitive(s)
RenderingWindow::RenderingWindow() : window_(nullptr), master_(nullptr), RenderingWindow::RenderingWindow() : window_(nullptr), master_(nullptr),
index_(-1), dpi_scale_(1.f), textureid_(0), fbo_(0), surface_(nullptr) index_(-1), dpi_scale_(1.f), textureid_(0), fbo_(0), surface_(nullptr), request_toggle_fullscreen_(false)
{ {
} }
@@ -433,8 +438,8 @@ void RenderingWindow::setIcon(const std::string &resource)
bool RenderingWindow::isFullscreen () bool RenderingWindow::isFullscreen ()
{ {
return (glfwGetWindowMonitor(window_) != nullptr); // return (glfwGetWindowMonitor(window_) != nullptr);
// return Settings::application.windows[index_].fullscreen; return Settings::application.windows[index_].fullscreen;
} }
GLFWmonitor *RenderingWindow::monitorAt(int x, int y) GLFWmonitor *RenderingWindow::monitorAt(int x, int y)
@@ -507,25 +512,31 @@ GLFWmonitor *RenderingWindow::monitor()
void RenderingWindow::setFullscreen_(GLFWmonitor *mo) void RenderingWindow::setFullscreen_(GLFWmonitor *mo)
{ {
// done request
request_toggle_fullscreen_ = false;
// if in fullscreen mode // if in fullscreen mode
if (mo == nullptr) { if (mo == nullptr) {
// store fullscreen mode
Settings::application.windows[index_].fullscreen = false;
// set to window mode // set to window mode
glfwSetInputMode( window_, GLFW_CURSOR, GLFW_CURSOR_NORMAL); glfwSetInputMode( window_, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
glfwSetWindowMonitor( window_, nullptr, Settings::application.windows[index_].x, glfwSetWindowMonitor( window_, nullptr, Settings::application.windows[index_].x,
Settings::application.windows[index_].y, Settings::application.windows[index_].y,
Settings::application.windows[index_].w, Settings::application.windows[index_].w,
Settings::application.windows[index_].h, 0 ); Settings::application.windows[index_].h, 0 );
Settings::application.windows[index_].fullscreen = false;
} }
// not in fullscreen mode // not in fullscreen mode
else { else {
// set to fullscreen mode // store fullscreen mode
Settings::application.windows[index_].fullscreen = true; Settings::application.windows[index_].fullscreen = true;
Settings::application.windows[index_].monitor = glfwGetMonitorName(mo); Settings::application.windows[index_].monitor = glfwGetMonitorName(mo);
// set to fullscreen mode
const GLFWvidmode * mode = glfwGetVideoMode(mo); const GLFWvidmode * mode = glfwGetVideoMode(mo);
glfwSetWindowMonitor( window_, mo, 0, 0, mode->width, mode->height, mode->refreshRate);
glfwSetInputMode( window_, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); glfwSetInputMode( window_, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
glfwSetWindowMonitor( window_, mo, 0, 0, mode->width, mode->height, mode->refreshRate);
} }
} }
@@ -545,8 +556,9 @@ void RenderingWindow::toggleFullscreen()
void RenderingWindow::toggleFullscreen_() void RenderingWindow::toggleFullscreen_()
{ {
if (request_toggle_fullscreen_) { if (request_toggle_fullscreen_) {
// if in fullscreen mode // if in fullscreen mode
if (isFullscreen()) { if (glfwGetWindowMonitor(window_) != nullptr) {
// exit fullscreen // exit fullscreen
setFullscreen_(nullptr); setFullscreen_(nullptr);
} }
@@ -556,7 +568,6 @@ void RenderingWindow::toggleFullscreen_()
setFullscreen_(monitor()); setFullscreen_(monitor());
} }
} }
request_toggle_fullscreen_ = false;
} }
int RenderingWindow::width() int RenderingWindow::width()
@@ -689,8 +700,6 @@ void RenderingWindow::show()
void RenderingWindow::makeCurrent() void RenderingWindow::makeCurrent()
{ {
toggleFullscreen_();
// handle window resize // handle window resize
glfwGetFramebufferSize(window_, &(window_attributes_.viewport.x), &(window_attributes_.viewport.y)); glfwGetFramebufferSize(window_, &(window_attributes_.viewport.x), &(window_attributes_.viewport.y));
@@ -711,8 +720,6 @@ void RenderingWindow::draw(FrameBuffer *fb)
if (!window_ || !fb) if (!window_ || !fb)
return; return;
toggleFullscreen_();
// only draw if window is not iconified // only draw if window is not iconified
if( !glfwGetWindowAttrib(window_, GLFW_ICONIFIED ) ) { if( !glfwGetWindowAttrib(window_, GLFW_ICONIFIED ) ) {

View File

@@ -24,6 +24,8 @@ struct RenderingAttrib
class RenderingWindow class RenderingWindow
{ {
friend class Rendering;
GLFWwindow *window_, *master_; GLFWwindow *window_, *master_;
RenderingAttrib window_attributes_; RenderingAttrib window_attributes_;
int index_; int index_;

View File

@@ -337,6 +337,9 @@ void UserInterface::handleKeyboard()
if (clipboard != nullptr && strlen(clipboard) > 0) if (clipboard != nullptr && strlen(clipboard) > 0)
Mixer::manager().paste(clipboard); Mixer::manager().paste(clipboard);
} }
else if (ImGui::IsKeyPressed( GLFW_KEY_F ) && shift_modifier_active) {
Rendering::manager().mainWindow().toggleFullscreen();
}
} }
// No CTRL modifier // No CTRL modifier
else { else {
@@ -349,8 +352,6 @@ void UserInterface::handleKeyboard()
Mixer::manager().setView(View::GEOMETRY); Mixer::manager().setView(View::GEOMETRY);
else if (ImGui::IsKeyPressed( GLFW_KEY_F3 )) else if (ImGui::IsKeyPressed( GLFW_KEY_F3 ))
Mixer::manager().setView(View::LAYER); Mixer::manager().setView(View::LAYER);
else if (ImGui::IsKeyPressed( GLFW_KEY_F11 ))
Rendering::manager().mainWindow().toggleFullscreen();
else if (ImGui::IsKeyPressed( GLFW_KEY_F12 )) else if (ImGui::IsKeyPressed( GLFW_KEY_F12 ))
StartScreenshot(); StartScreenshot();
// normal keys // make sure no entry / window box is active // normal keys // make sure no entry / window box is active
@@ -2364,7 +2365,7 @@ void Navigator::RenderMainPannel()
// Icon to switch fullscreen // Icon to switch fullscreen
ImGui::SetCursorPos(ImVec2(pannel_width_ - 35.f, 15.f)); ImGui::SetCursorPos(ImVec2(pannel_width_ - 35.f, 15.f));
const char *tooltip[2] = {"Enter Fullscreen", "Exit Fullscreen"}; const char *tooltip[2] = {"Enter Fullscreen (" CTRL_MOD "Shift+F)", "Exit Fullscreen (" CTRL_MOD "Shift+F)"};
bool fs = Rendering::manager().mainWindow().isFullscreen(); bool fs = Rendering::manager().mainWindow().isFullscreen();
if ( ImGuiToolkit::IconToggle(3,15,2,15, &fs, tooltip ) ) { if ( ImGuiToolkit::IconToggle(3,15,2,15, &fs, tooltip ) ) {
Rendering::manager().mainWindow().toggleFullscreen(); Rendering::manager().mainWindow().toggleFullscreen();