Skip to content

Commit 1008c2f

Browse files
committed
fix fullscreen on linux
1 parent 9be4c71 commit 1008c2f

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

sources/libengine/window/window.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -495,26 +495,36 @@ namespace cage
495495

496496
namespace
497497
{
498-
void normalizeWindow(WindowImpl *impl, WindowFlags flags)
498+
void normalizeWindow(WindowImpl *impl, WindowFlags flags, bool fullscreen = false)
499499
{
500500
if (impl->isFullscreen())
501501
glfwSetWindowMonitor(impl->window, nullptr, 100, 100, 800, 600, 0);
502502
if (impl->isHidden())
503503
glfwShowWindow(impl->window);
504504
if (impl->isMinimized() || impl->isMaximized())
505505
glfwRestoreWindow(impl->window);
506-
glfwSetWindowAttrib(impl->window, GLFW_DECORATED, any(flags & WindowFlags::Border));
507-
glfwSetWindowAttrib(impl->window, GLFW_RESIZABLE, any(flags & WindowFlags::Resizeable));
506+
507+
// linux: the window minimizes immediately after fullscreen if these attributes are changed
508+
#ifdef CAGE_SYSTEM_WINDOWS
509+
fullscreen = false;
510+
#endif
511+
if (!fullscreen)
512+
{
513+
glfwSetWindowAttrib(impl->window, GLFW_DECORATED, any(flags & WindowFlags::Border));
514+
glfwSetWindowAttrib(impl->window, GLFW_RESIZABLE, any(flags & WindowFlags::Resizeable));
515+
}
508516
}
509517
}
510518

511519
void Window::setFullscreen(Vec2i resolution, uint32 frequency, const String &deviceId)
512520
{
513521
WindowImpl *impl = (WindowImpl *)this;
514-
normalizeWindow(impl, WindowFlags::None);
522+
normalizeWindow(impl, WindowFlags::None, true);
515523
GLFWmonitor *m = getMonitorById(deviceId);
524+
CAGE_ASSERT(m);
516525
const GLFWvidmode *v = glfwGetVideoMode(m);
517-
glfwSetWindowMonitor(impl->window, m, 0, 0, resolution[0] == 0 ? v->width : resolution[0], resolution[1] == 0 ? v->height : resolution[1], frequency == 0 ? glfwGetVideoMode(m)->refreshRate : frequency);
526+
CAGE_ASSERT(v);
527+
glfwSetWindowMonitor(impl->window, m, 0, 0, resolution[0] > 0 ? resolution[0] : v->width, resolution[1] > 0 ? resolution[1] : v->height, frequency > 0 ? frequency : v->refreshRate);
518528
}
519529

520530
void Window::setMaximized()

0 commit comments

Comments
 (0)