Skip to content

[rcore] ToggleBorderlessWindowed() can't enable window decoration on Linux Mint (X11) #4889

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
and3md opened this issue Apr 12, 2025 · 1 comment
Labels
platform: Linux Linux platform windowing Issues about the window system

Comments

@and3md
Copy link

and3md commented Apr 12, 2025

Hi, I tried to add full screen/window mode to my project by using ToggleBorderlessWindowed(). I found that switching to full screen window mode without decoration works great but unfortunately calling ToggleBorderlessWindowed() again does not return to window mode with decorations. I also tried raylib current master and it does not work.

Environment

I use Linux Mint 22.1 with Cinnamon on X11, using NVIDIA GeForce GTX 1060 6GB (driver 550.120), raylib master

Issue workaround

After a little investigation I came across the code in issue #4149 (comment) that works great. Maybe there should be ifdef for linux in code.

Implementation that work for me (based on #4149 (comment) code from master commented) :

// Toggle borderless windowed mode
void ToggleBorderlessWindowed(void)
{
    // Leave fullscreen before attempting to set borderless windowed mode
    bool wasOnFullscreen = false;
    if (CORE.Window.fullscreen)
    {
        // fullscreen already saves the previous position so it does not need to be set here again
        ToggleFullscreen();
        wasOnFullscreen = true;
    }

    const int monitor = GetCurrentMonitor();
    int monitorCount;
    GLFWmonitor **monitors = glfwGetMonitors(&monitorCount);

    if ((monitor >= 0) && (monitor < monitorCount))
    {
        const GLFWvidmode *mode = glfwGetVideoMode(monitors[monitor]);

        if (mode)
        {
            if (!IsWindowState(FLAG_BORDERLESS_WINDOWED_MODE))
            {
                // Store screen position and size
                // NOTE: If it was on fullscreen, screen position was already stored, so skip setting it here
                if (!wasOnFullscreen) CORE.Window.previousPosition = CORE.Window.position;
                CORE.Window.previousScreen = CORE.Window.screen;

                // Set undecorated flag
                //glfwSetWindowAttrib(platform.handle, GLFW_DECORATED, GLFW_FALSE);
                glfwSetWindowMonitor(platform.handle, monitors[monitor], 0, 0, mode->width, mode->height, mode->refreshRate);
                CORE.Window.flags |= FLAG_WINDOW_UNDECORATED;

                // Get monitor position and size
                int monitorPosX = 0;
                int monitorPosY = 0;
                glfwGetMonitorPos(monitors[monitor], &monitorPosX, &monitorPosY);
                const int monitorWidth = mode->width;
                const int monitorHeight = mode->height;

                // Set screen position and size
                glfwSetWindowPos(platform.handle, monitorPosX, monitorPosY);
                glfwSetWindowSize(platform.handle, monitorWidth, monitorHeight);

                // Refocus window
                glfwFocusWindow(platform.handle);

                CORE.Window.flags |= FLAG_BORDERLESS_WINDOWED_MODE;
            }
            else
            {
                // Remove undecorated flag
                //glfwSetWindowAttrib(platform.handle, GLFW_DECORATED, GLFW_TRUE);
                int prevPosX = CORE.Window.previousPosition.x ;
                int prevPosY = CORE.Window.previousPosition.y ;
                int prevWidth = CORE.Window.previousScreen.width ;
                int prevHeight = CORE.Window.previousScreen.height ;
                glfwSetWindowMonitor(platform.handle, NULL, prevPosX , prevPosY, prevWidth, prevHeight, GLFW_DONT_CARE);
                CORE.Window.flags &= ~FLAG_WINDOW_UNDECORATED;

                // Return previous screen size and position
                // NOTE: The order matters here, it must set size first, then set position, otherwise the screen will be positioned incorrectly
                glfwSetWindowSize(platform.handle,  CORE.Window.previousScreen.width, CORE.Window.previousScreen.height);
                glfwSetWindowPos(platform.handle, CORE.Window.previousPosition.x, CORE.Window.previousPosition.y);

                // Refocus window
                glfwFocusWindow(platform.handle);

                CORE.Window.flags &= ~FLAG_BORDERLESS_WINDOWED_MODE;

                CORE.Window.position.x = CORE.Window.previousPosition.x;
                CORE.Window.position.y = CORE.Window.previousPosition.y;
            }
        }
        else TRACELOG(LOG_WARNING, "GLFW: Failed to find video mode for selected monitor");
    }
    else TRACELOG(LOG_WARNING, "GLFW: Failed to find selected monitor");
}
@and3md
Copy link
Author

and3md commented Apr 12, 2025

I tested the behavior of ToggleBorderlessWindowed() function also on a computer with integrated Intel graphics (i7 1255U, Mesa 24.2.8-1ubuntu1~24.04.1, Linux Mint 22.1) and in this case also the ToggleBorderlessWindowed() function from master does not work. Everything works when I make the correction I mentioned in above issue details.

@raysan5 raysan5 added the platform: Linux Linux platform label Apr 15, 2025
@raysan5 raysan5 changed the title [rcore] ToggleBorderlessWindowed() can't enable window decoration on Linux Mint (X11) [rcore] ToggleBorderlessWindowed() can't enable window decoration on Linux Mint (X11) Apr 15, 2025
@raysan5 raysan5 added the windowing Issues about the window system label Apr 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: Linux Linux platform windowing Issues about the window system
Projects
None yet
Development

No branches or pull requests

3 participants
@raysan5 @and3md and others