libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
10.2k stars 1.86k forks source link

SDL2: SDL_ShowCursor(SDL_DISABLE) doesn't disable mouse under WSL #9972

Open ShlomiRex opened 5 months ago

ShlomiRex commented 5 months ago

I want to disable the mouse cursor, but i'm using WSL to develop my program.

Here is an example, we can see the cursor even though I disabled the cursor: 93bf9e9a-bc4c-4f48-b57b-727ed761ca1c

When I compile under Windows (VC++), the mouse is indeed hidden: 62cc28c9-cb24-4da2-8ef4-8d3abf49705e

Example source code to replicate this issue:

#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <iostream>

int main(int argc, char* argv[]) {
    SDL_Window* window = nullptr;
    SDL_Renderer* renderer = nullptr;

    // Initialize SDL
    if (SDL_Init(SDL_INIT_VIDEO) != 0) {
        std::cerr << "SDL_Init Error: " << SDL_GetError() << std::endl;
        return 1;
    }

    // Create window
    window = SDL_CreateWindow("Test Program", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, 0);

    // Create renderer
    renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);

    // Disable cursor
    SDL_ShowCursor(SDL_DISABLE);

    bool running = true;
    while (running) {
        SDL_Event event;
        while (SDL_PollEvent(&event)) {
            if (event.type == SDL_QUIT) {
                running = false;
            }
        }
        SDL_RenderClear(renderer);

        // do nothing

        SDL_RenderPresent(renderer);
    }

    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);
    SDL_Quit();

    return 0;
}

Compile it under unix: g++ main.cpp -lSDL2main -lSDL2 Run: ./a.out

Why I want to disable the cursor? because I want to render different cursor (some games use different cursors).

Here we can see VSCode using WSL as remote: image

SDL2 Version on WSL: 2.0.20

SDL2 Version on Windows (VC++): 2.30.3

slouken commented 5 months ago

Can you try version 2.30.3 on WSL?

korrectional commented 4 months ago

@ShlomiRex Did it work out? I'm having the same issue. @slouken I'm using the most recent version and the problem continues. Possibly its happening because Windows doesn't want to allow a WSL program to control its mouse.