Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial refactor for more sane pan events #11

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- template: .ci/esy-build-steps.yml

- job: MacOS14
displayName: "MacOS High Sierra"
displayName: "MacOS Mojave"
pool:
vmImage: 'macOS-10.14'
steps:
Expand Down
12 changes: 5 additions & 7 deletions include/SDL_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,12 @@ typedef struct SDL_PanEvent
Uint32 type; /**< ::SDL_PANEVENT */
Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
Uint32 windowID; /**< The window with mouse focus, if any */
Uint64 x; /**< Precise scrolling amount on x axis. */
Uint64 y; /**< Precise scrolling amount on y axis. */
Uint32 which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
Uint32 source_type; /**< One of SDL_MOUSEWHEEL_SOURCE_[...] */
Uint8 contains_x; /**< Indicates event contains a useful value in scalar_x and a pan should be calculated */
Uint8 contains_y; /**< Indicates event contains a useful value in scalar_y and a pan should be calculated */
Uint8 interrupt; /**< If some fling event was dispatched, this is intended to terminate it */
Uint8 fling; /**< Indicates the user has "flung" the wheel and kinetic scrolling (if enabled) should begin here */
SDL_PanAxis axis;
SDL_PanType pantype;
SDL_PanContents contents;
glennsl marked this conversation as resolved.
Show resolved Hide resolved

SDL_MouseWheelSource source;
} SDL_PanEvent;

/**
Expand Down
34 changes: 34 additions & 0 deletions include/SDL_mouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,40 @@ typedef enum
SDL_MOUSEWHEEL_SOURCE_OTHER_KINETIC,
} SDL_MouseWheelSource;

typedef enum
{
SDL_PAN_AXIS_VERTICAL,
SDL_PAN_AXIS_HORIZONTAL,
} SDL_PanAxis;

typedef enum
{
SDL_PANEVENTTYPE_PAN,
SDL_PANEVENTTYPE_FLING,
SDL_PANEVENTTYPE_INTERRUPT,
SDL_PANEVENTTYPE_SOURCE,
} SDL_PanType;

typedef struct SDL_PanType_Pan
{
double delta;
} SDL_PanType_Pan;

typedef struct SDL_PanType_Interrupt
{
} SDL_PanType_Interrupt;

typedef struct SDL_PanType_Fling
{
} SDL_PanType_Fling;

typedef union SDL_PanContents
{
SDL_PanType_Pan pan;
SDL_PanType_Interrupt interrupt;
SDL_PanType_Fling fling;
} SDL_PanContents;

/* Function prototypes */

/**
Expand Down
95 changes: 79 additions & 16 deletions src/events/SDL_mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,17 +661,47 @@ SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, float x, float y, S
return posted;
}

static SDL_MouseWheelSource latest_source = SDL_MOUSEWHEEL_SOURCE_LAST;

static void
SDL_SetPanSource(SDL_MouseWheelSource source) {
latest_source = source;
}

static SDL_MouseWheelSource
SDL_GetPanLastSource() {
return latest_source;
}

int
SDL_SendPanDelta(
SDL_Window * window,
SDL_MouseID mouseID,
double delta,
SDL_PanAxis axis
) {
SDL_Mouse *mouse = SDL_GetMouse();
Et7f3 marked this conversation as resolved.
Show resolved Hide resolved

if( SDL_GetEventState(SDL_PANEVENT) == SDL_ENABLE ) {
SDL_Event event;
event.type = SDL_PANEVENT;
Et7f3 marked this conversation as resolved.
Show resolved Hide resolved
event.pan.windowID = mouse->focus ? mouse->focus->id : 0;
event.pan.which = mouseID;
event.pan.pantype = SDL_PANEVENTTYPE_PAN;
event.pan.contents.pan.delta = delta;
event.pan.source = SDL_GetPanLastSource();
event.pan.axis = axis;
return SDL_PushEvent(&event);
} else {
return 0;
}
}

int
SDL_SendPanEvent(
SDL_SendPanFling(
SDL_Window * window,
SDL_MouseID mouseID,
Sint64 precise_x,
Sint64 precise_y,
Uint8 contains_x,
Uint8 contains_y,
Uint8 is_fling,
Uint8 is_interrupt,
SDL_MouseWheelSource source_type
SDL_PanAxis axis
) {
SDL_Mouse *mouse = SDL_GetMouse();

Expand All @@ -680,19 +710,52 @@ SDL_SendPanEvent(
event.type = SDL_PANEVENT;
event.pan.windowID = mouse->focus ? mouse->focus->id : 0;
event.pan.which = mouseID;
event.pan.contains_x = contains_x;
event.pan.contains_y = contains_y;
event.pan.x = precise_x;
event.pan.y = precise_y;
event.pan.fling = is_fling;
event.pan.interrupt = is_interrupt;
event.pan.source_type = source_type;
return SDL_PushEvent(&event) > 0;
event.pan.pantype = SDL_PANEVENTTYPE_FLING;
// no union contents written for this event type
event.pan.source = SDL_GetPanLastSource();
event.pan.axis = axis;
return SDL_PushEvent(&event);
} else {
return 0;
}
}

int
SDL_SendPanInterrupt(
SDL_Window * window,
SDL_MouseID mouseID,
SDL_PanAxis axis
) {
SDL_Mouse *mouse = SDL_GetMouse();
Et7f3 marked this conversation as resolved.
Show resolved Hide resolved

if( SDL_GetEventState(SDL_PANEVENT) == SDL_ENABLE ) {
SDL_Event event;
event.type = SDL_PANEVENT;
Et7f3 marked this conversation as resolved.
Show resolved Hide resolved
event.pan.windowID = mouse->focus ? mouse->focus->id : 0;
event.pan.which = mouseID;
event.pan.pantype = SDL_PANEVENTTYPE_INTERRUPT;
// no union contents written for this event type
event.pan.source = SDL_GetPanLastSource();
event.pan.axis = axis;
return SDL_PushEvent(&event);
} else {
return 0;
}
}

int
SDL_SendPanSource(
SDL_Window * window,
SDL_MouseID mouseID,
SDL_MouseWheelSource source
) {
// may become a full event at some point,
// implemented very basically here. Expect semantics
// to be the same as other event dispatch functions
SDL_SetPanSource(source);
return 1;
}

void
SDL_MouseQuit(void)
{
Expand Down
5 changes: 4 additions & 1 deletion src/events/SDL_mouse_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ extern int SDL_SendMouseButtonClicks(SDL_Window * window, SDL_MouseID mouseID, U
extern int SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, float x, float y, SDL_MouseWheelDirection direction);

/* Send a pan/scroll event */
extern int SDL_SendPanEvent( SDL_Window * window, SDL_MouseID mouseID, Sint64 precise_x, Sint64 precise_y, Uint8 contains_x, Uint8 contains_y, Uint8 is_fling, Uint8 is_interrupt, SDL_MouseWheelSource source_type);
extern int SDL_SendPanSource( SDL_Window * window, SDL_MouseID mouseID, SDL_MouseWheelSource source);
extern int SDL_SendPanDelta( SDL_Window * window, SDL_MouseID mouseID, double precise_delta, SDL_PanAxis axis);
extern int SDL_SendPanFling( SDL_Window * window, SDL_MouseID mouseID, SDL_PanAxis axis);
extern int SDL_SendPanInterrupt( SDL_Window * window, SDL_MouseID mouseID, SDL_PanAxis axis);

/* Shutdown the mouse subsystem */
extern void SDL_MouseQuit(void);
Expand Down
26 changes: 17 additions & 9 deletions src/video/wayland/SDL_waylandevents.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,11 +389,11 @@ pointer_handle_axis(void *data, struct wl_pointer *pointer,

// dispatch new pan event
switch(axis) {
case 0: y = value; break;
case 1: x = value; break;
case 0: axis = SDL_PAN_AXIS_VERTICAL; break;
case 1: axis = SDL_PAN_AXIS_HORIZONTAL; break;
}

SDL_SendPanEvent(window->sdlwindow, 0, x, y, axis, !axis, 0, 0, SDL_MOUSEWHEEL_SOURCE_LAST);
SDL_SendPanDelta(window->sdlwindow, 0, wl_fixed_to_double(value), axis);
}

static void
Expand All @@ -409,7 +409,7 @@ pointer_handle_axis_source(void *data, struct wl_pointer *pointer,
struct SDL_WaylandInput *input = data;
SDL_WindowData *window = input->pointer_focus;

int source;
SDL_MouseWheelSource source;

switch(axis_source) {
case 0: source = SDL_MOUSEWHEEL_SOURCE_WHEEL; break;
Expand All @@ -419,7 +419,7 @@ pointer_handle_axis_source(void *data, struct wl_pointer *pointer,
default: source = SDL_MOUSEWHEEL_SOURCE_UNDEFINED; break;
}

SDL_SendPanEvent(window->sdlwindow, 0, 0, 0, 0, 0, 0, 0, source);
SDL_SendPanSource(window->sdlwindow, 0, source);
}

static void
Expand All @@ -429,7 +429,13 @@ pointer_handle_axis_stop(void *data, struct wl_pointer *pointer,
struct SDL_WaylandInput *input = data;
SDL_WindowData *window = input->pointer_focus;

SDL_SendPanEvent(window->sdlwindow, 0, 0, 0, 0, 0, 1, 0, SDL_MOUSEWHEEL_SOURCE_LAST);
uint32_t mapped_axis;
switch(axis) {
case 0: mapped_axis = SDL_PAN_AXIS_VERTICAL; break;
case 1: mapped_axis = SDL_PAN_AXIS_HORIZONTAL; break;
}

SDL_SendPanFling(window->sdlwindow, 0, mapped_axis);
}

static void
Expand All @@ -441,12 +447,14 @@ pointer_handle_axis_discrete(void *data, struct wl_pointer *pointer,
Uint64 x = 0;
Uint64 y = 0;

uint32_t mapped_axis;
switch(axis) {
case 0: y = discrete;
case 1: x = discrete;
case 0: mapped_axis = SDL_PAN_AXIS_VERTICAL; break;
case 1: mapped_axis = SDL_PAN_AXIS_HORIZONTAL; break;
}

SDL_SendPanEvent(window->sdlwindow, 0, x, y, axis, !axis, 0, 0, SDL_MOUSEWHEEL_SOURCE_WHEEL);
// Is this actually something that should be picked up for mousewheels or do they already go through
// the normal axis pan event? TODO: figure this out
}

static const struct wl_pointer_listener pointer_listener = {
Expand Down