Skip to content

glfwSetInputMode to GLFW_CURSOR_DISABLED after setting a cursor using glfwSetCursor does not hide the cursor #2893

Description

@KleberPF

Reproducible example:

#include <GLFW/glfw3.h>

void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
    if (action == GLFW_PRESS) return;

    if (key == GLFW_KEY_F1) {
        glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
        GLFWcursor* cursor = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
        glfwSetCursor(window, cursor);
    } else if (key == GLFW_KEY_F2) {
        glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
    }
}

int main(void)
{
    GLFWwindow* window;

    if (!glfwInit()) {
        return -1;
    }

    window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
    if (!window) {
        glfwTerminate();
        return -1;
    }

    glfwMakeContextCurrent(window);
    glfwSetKeyCallback(window, key_callback);

    while (!glfwWindowShouldClose(window)) {
        glClear(GL_COLOR_BUFFER_BIT);
        glfwSwapBuffers(window);
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;
}

Sorry if this has been brought up already (or is user error on my part). I'm using Sway 1.12 (Wayland) and when running this example, if I press F2 it works as expected (cursor is grabbed and hidden), but if I press F1 to set the input mode back to GLFW_CURSOR_NORMAL and the cursor to GLFW_ARROW_CURSOR (which I believe should be a no-op here as that's already the default) and then press F2 again the cursor is grabbed (hard to see in this demo but I tested it) but not hidden. It just stays stuck wherever it was when I pressed F2, not moving around. I'm using glfw-1:3.5.1-1 (AUR) but I also tried using the current master. I cannot reproduce the behavior using i3 and X11.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions