glfw window with no title bar

Viewed 544

I am trying to make a way to toggle my window between windowed mode and fullscreen mode. I had done it successfully except for one problem. The title bar is not working! You can’t move the window either. Without this piece of code everything works just fine.

setFullscreen method:

void Window::setFullscreen(bool fullscreen)
{
    GLFWmonitor* monitor = glfwGetPrimaryMonitor();
    const GLFWvidmode* mode = glfwGetVideoMode(monitor);

    if (fullscreen) {
        glfwSetWindowMonitor(m_window, monitor, 0, 0, mode->width, mode->height, mode->refreshRate);
        glViewport(0, 0, mode->width, mode->height);
    }

    if (!fullscreen) {
        glfwSetWindowMonitor(m_window, nullptr, 0, 0, m_width, m_height, GLFW_DONT_CARE);
        glViewport(0, 0, m_width, m_height);
    }
}

The result of the code:

The Result of the code

2 Answers

@tomasantunes help me figure this out.

in setFullscreen I am setting the window to be at 0, 0 or the top left of the screen. The title bar didn't actually disappear is was just off screen. so if I set the window to be at 100, 100 instead I get the title bar back. This was pretty dumb of me to make a stupid mistake like this.

if (!fullscreen) {
    glfwSetWindowMonitor(m_window, nullptr, 0, 0, m_width, m_height, GLFW_DONT_CARE); // I set the position to 0,0 in the 3rd and 4th parameter
    glViewport(0, 0, m_width, m_height);
}

Fixed code:

if (!fullscreen) {
    glfwSetWindowMonitor(m_window, nullptr, 100, 100, m_width, m_height, GLFW_DONT_CARE); // I set the position to 100, 100 
    glViewport(0, 0, m_width, m_height);
}

New result:

The result of the fix

Not sure if you are still looking for an answer, however, the code I have here fixes that same problem you were initially having.

Before changing to full-screen mode, save the window position and size.

    int xPos, yPos, width, height; //have somewhere stored out of function scope.
    glfwGetWindowPos(windowPtr, &xPos, &yPos);
    glfwGetWindowSize(windowPtr, &width, &height);

and then when changing from full-screen back to windowed mode, apply the saved positions and size properties.

    glfwSetWindowMonitor(windowPtr, nullptr, xPos, yPos, width, height, 0); //Refresh rate is ignored without an active monitor.
Related