Open
Description
Reproduction steps:
- Compile following example SDL2 application using SDL 2.0.22 or above
#include "SDL.h"
#include <stdio.h>
int main(int argc, char *argv[]) {
SDL_Window *window = NULL;
SDL_Renderer *renderer = NULL;
SDL_version compiled;
SDL_version linked;
// Get the version the program was compiled against
SDL_VERSION(&compiled);
// Get the version the program is linked against
SDL_GetVersion(&linked);
// Print versions
printf("We compiled against SDL version %d.%d.%d ...\n",
compiled.major, compiled.minor, compiled.patch);
printf("But we are linking against SDL version %d.%d.%d.\n",
linked.major, linked.minor, linked.patch);
// Initialize SDL
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
return 1;
}
SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1");
SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "0");
SDL_SetHint(SDL_HINT_MOUSE_TOUCH_EVENTS, "0");
// Create window
window = SDL_CreateWindow("SDL Example", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN);
if (window == NULL) {
fprintf(stderr, "Window could not be created! SDL_Error: %s\n", SDL_GetError());
SDL_Quit();
return 1;
}
// Create renderer for the window
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
if (renderer == NULL) {
SDL_DestroyWindow(window);
fprintf(stderr, "Renderer could not be created! SDL Error: %s\n", SDL_GetError());
SDL_Quit();
return 1;
}
SDL_bool quit = SDL_FALSE;
while (!quit) {
SDL_Event e;
while (SDL_PollEvent(&e) != 0) {
if (e.type == SDL_QUIT) {
quit = SDL_TRUE;
} else if (e.type == SDL_MOUSEBUTTONDOWN || e.type == SDL_MOUSEBUTTONUP) {
// Log mouse button events
const char *state = (e.type == SDL_MOUSEBUTTONDOWN) ? "down" : "up";
printf("Mouse button %d %s at (%d, %d)\n", e.button.button, state, e.button.x, e.button.y);
} else if (e.type == SDL_FINGERDOWN || e.type == SDL_FINGERUP) {
// Log touch events
const char *state = (e.type == SDL_FINGERDOWN) ? "down" : "up";
printf("Finger %lld %s at (%f, %f)\n", e.tfinger.fingerId, state, e.tfinger.x, e.tfinger.y);
}
}
// Clear screen
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
SDL_RenderClear(renderer);
// Render updated graphics
SDL_RenderPresent(renderer);
}
// Clean up
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
- Open the application using terminal (This way we can see the logs)
- Touch the SDL2 window using one finger and don't lift the finger (You'll see a log message for finger down event)
- While the finger is touching the SDL2 window press any key on the mouse (You'll see two log messages for mouse up and down events)
- Now release the finger that is touching the SDL2 window (No finger up event received)
Expected behavior: Finger up event received for the corresponding finger (SDL versions below 2.0.22)
Actual behavior: No Finger up event received for the corresponding finger
After bisecting between 2.0.20 and 2.0.22. Bisection was pointing the following commit which introduced SDL_HINT_MOUSE_AUTO_CAPTURE hint.
commit 5ff4243
Author: Sam Lantinga [email protected]
Date: Thu Mar 17 17:39:46 2022 -0700
Added a hint to capture the mouse when mouse buttons are pressed, defaulting on
Fixes https://github.com/libsdl-org/SDL/issues/5301
include/SDL_hints.h | 13 +++++++++++
src/events/SDL_mouse.c | 58 ++++++++++++++++++++++++++++++++++++------------
src/events/SDL_mouse_c.h | 1 +
3 files changed, 58 insertions(+), 14 deletions(-)
Thank you so much and have a wonderful day,
Kalana
Metadata
Metadata
Assignees
Labels
No labels