SDL2: SDL_ShowCursor(SDL_DISABLE) doesn't disable mouse under WSL
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:
When I compile under Windows (VC++), the mouse is indeed hidden:
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:
SDL2 Version on WSL: 2.0.20
SDL2 Version on Windows (VC++): 2.30.3
Can you try version 2.30.3 on WSL?
@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.
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.