SDL icon indicating copy to clipboard operation
SDL copied to clipboard

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

Open ShlomiRex opened this issue 1 year ago • 2 comments

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

ShlomiRex avatar Jun 04 '24 21:06 ShlomiRex

Can you try version 2.30.3 on WSL?

slouken avatar Jun 04 '24 22:06 slouken

@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.

korrectional avatar Aug 01 '24 21:08 korrectional

This issue occurs because since WSL isn't the actual operating system but it's being ran in a confined box, when WSL tries to hide the cursor it fails to do so because it can't change things inside windows.

korrectional avatar Feb 02 '25 01:02 korrectional