Skip to content

Commit

Permalink
pen: Send virtual mouse motion without a button press when a pen is h…
Browse files Browse the repository at this point in the history
…overing.

Fixes libsdl-org#11470.
  • Loading branch information
icculus committed Jan 19, 2025
1 parent 5da9d4e commit 32965b4
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/events/SDL_pen.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,17 +488,22 @@ void SDL_SendPenMotion(Uint64 timestamp, SDL_PenID instance_id, SDL_Window *wind
event.pmotion.y = y;
SDL_PushEvent(&event);

if (window && (pen_touching == instance_id)) {
if (window) {
SDL_Mouse *mouse = SDL_GetMouse();
if (mouse) {
if (mouse->pen_mouse_events) {
SDL_SendMouseMotion(timestamp, window, SDL_PEN_MOUSEID, false, x, y);
}
if (pen_touching == instance_id) {
if (mouse->pen_mouse_events) {
SDL_SendMouseMotion(timestamp, window, SDL_PEN_MOUSEID, false, x, y);
}

if (mouse->pen_touch_events) {
const float normalized_x = x / (float)window->w;
const float normalized_y = y / (float)window->h;
SDL_SendTouchMotion(timestamp, SDL_PEN_TOUCHID, SDL_BUTTON_LEFT, window, normalized_x, normalized_y, pen->axes[SDL_PEN_AXIS_PRESSURE]);
if (mouse->pen_touch_events) {
const float normalized_x = x / (float)window->w;
const float normalized_y = y / (float)window->h;
SDL_SendTouchMotion(timestamp, SDL_PEN_TOUCHID, SDL_BUTTON_LEFT, window, normalized_x, normalized_y, pen->axes[SDL_PEN_AXIS_PRESSURE]);
}
} else if (pen_touching == 0) { // send mouse motion (without a pressed button) for pens that aren't touching.
// this might cause a little chaos if you have multiple pens hovering at the same time, but this seems unlikely in the real world, and also something you did to yourself. :)
SDL_SendMouseMotion(timestamp, window, SDL_PEN_MOUSEID, false, x, y);
}
}
}
Expand Down

0 comments on commit 32965b4

Please sign in to comment.