diff --git a/build-scripts/SDL_migration.cocci b/build-scripts/SDL_migration.cocci index ca2acfdf5..74da95390 100644 --- a/build-scripts/SDL_migration.cocci +++ b/build-scripts/SDL_migration.cocci @@ -3710,3 +3710,7 @@ identifier func =~ "^(SDL_AddEventWatch|SDL_AddHintCallback|SDL_AddSurfaceAltern - SDL_SetThreadPriority + SDL_SetCurrentThreadPriority (...) +@@ +@@ +- SDL_BUTTON ++ SDL_BUTTON_MASK diff --git a/docs/README-migration.md b/docs/README-migration.md index 08c0f2ab0..887b1bb59 100644 --- a/docs/README-migration.md +++ b/docs/README-migration.md @@ -1174,6 +1174,7 @@ The following functions have been removed: * SDL_GetRelativeMouseMode() - replaced with SDL_GetWindowRelativeMouseMode() The following symbols have been renamed: +* SDL_BUTTON => SDL_BUTTON_MASK * SDL_NUM_SYSTEM_CURSORS => SDL_SYSTEM_CURSOR_COUNT * SDL_SYSTEM_CURSOR_ARROW => SDL_SYSTEM_CURSOR_DEFAULT * SDL_SYSTEM_CURSOR_HAND => SDL_SYSTEM_CURSOR_POINTER diff --git a/include/SDL3/SDL_mouse.h b/include/SDL3/SDL_mouse.h index 0da68b3cf..ab3947bbf 100644 --- a/include/SDL3/SDL_mouse.h +++ b/include/SDL3/SDL_mouse.h @@ -124,12 +124,12 @@ typedef Uint32 SDL_MouseButtonFlags; #define SDL_BUTTON_X1 4 #define SDL_BUTTON_X2 5 -#define SDL_BUTTON(X) (1u << ((X)-1)) -#define SDL_BUTTON_LMASK SDL_BUTTON(SDL_BUTTON_LEFT) -#define SDL_BUTTON_MMASK SDL_BUTTON(SDL_BUTTON_MIDDLE) -#define SDL_BUTTON_RMASK SDL_BUTTON(SDL_BUTTON_RIGHT) -#define SDL_BUTTON_X1MASK SDL_BUTTON(SDL_BUTTON_X1) -#define SDL_BUTTON_X2MASK SDL_BUTTON(SDL_BUTTON_X2) +#define SDL_BUTTON_MASK(X) (1u << ((X)-1)) +#define SDL_BUTTON_LMASK SDL_BUTTON_MASK(SDL_BUTTON_LEFT) +#define SDL_BUTTON_MMASK SDL_BUTTON_MASK(SDL_BUTTON_MIDDLE) +#define SDL_BUTTON_RMASK SDL_BUTTON_MASK(SDL_BUTTON_RIGHT) +#define SDL_BUTTON_X1MASK SDL_BUTTON_MASK(SDL_BUTTON_X1) +#define SDL_BUTTON_X2MASK SDL_BUTTON_MASK(SDL_BUTTON_X2) /* Function prototypes */ @@ -194,7 +194,7 @@ extern SDL_DECLSPEC SDL_Window * SDLCALL SDL_GetMouseFocus(void); * Retrieve the current state of the mouse. * * The current button state is returned as a button bitmask, which can be - * tested using the SDL_BUTTON(X) macro (where `X` is generally 1 for the + * tested using the SDL_BUTTON_MASK(X) macro (where `X` is generally 1 for the * left, 2 for middle, 3 for the right button), and `x` and `y` are set to the * mouse cursor position relative to the focus window. You can pass NULL for * either `x` or `y`. @@ -233,7 +233,7 @@ extern SDL_DECLSPEC SDL_MouseButtonFlags SDLCALL SDL_GetMouseState(float *x, flo * \param y filled in with the current Y coord relative to the desktop; can be * NULL. * \returns the current button state as a bitmask which can be tested using - * the SDL_BUTTON(X) macros. + * the SDL_BUTTON_MASK(X) macros. * * \since This function is available since SDL 3.0.0. * @@ -246,7 +246,7 @@ extern SDL_DECLSPEC SDL_MouseButtonFlags SDLCALL SDL_GetGlobalMouseState(float * * Retrieve the relative state of the mouse. * * The current button state is returned as a button bitmask, which can be - * tested using the `SDL_BUTTON(X)` macros (where `X` is generally 1 for the + * tested using the `SDL_BUTTON_MASK(X)` macros (where `X` is generally 1 for the * left, 2 for middle, 3 for the right button), and `x` and `y` are set to the * mouse deltas since the last call to SDL_GetRelativeMouseState() or since * event initialization. You can pass NULL for either `x` or `y`. diff --git a/include/SDL3/SDL_oldnames.h b/include/SDL3/SDL_oldnames.h index 79fb1184f..bd79d594f 100644 --- a/include/SDL3/SDL_oldnames.h +++ b/include/SDL3/SDL_oldnames.h @@ -429,6 +429,7 @@ #define SDL_MESSAGEBOX_COLOR_MAX SDL_MESSAGEBOX_COLOR_COUNT /* ##SDL_mouse.h */ +#define SDL_BUTTON SDL_BUTTON_MASK #define SDL_FreeCursor SDL_DestroyCursor #define SDL_NUM_SYSTEM_CURSORS SDL_SYSTEM_CURSOR_COUNT #define SDL_SYSTEM_CURSOR_ARROW SDL_SYSTEM_CURSOR_DEFAULT @@ -1067,6 +1068,7 @@ #define SDL_MESSAGEBOX_COLOR_MAX SDL_MESSAGEBOX_COLOR_MAX_renamed_SDL_MESSAGEBOX_COLOR_COUNT /* ##SDL_mouse.h */ +#define SDL_BUTTON SDL_BUTTON_renamed_SDL_BUTTON_MASK #define SDL_FreeCursor SDL_FreeCursor_renamed_SDL_DestroyCursor #define SDL_NUM_SYSTEM_CURSORS SDL_NUM_SYSTEM_CURSORS_renamed_SDL_SYSTEM_CURSOR_COUNT #define SDL_SYSTEM_CURSOR_ARROW SDL_SYSTEM_CURSOR_ARROW_renamed_SDL_SYSTEM_CURSOR_DEFAULT diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c index 80a3c6329..6e30e9d75 100644 --- a/src/events/SDL_mouse.c +++ b/src/events/SDL_mouse.c @@ -485,7 +485,7 @@ void SDL_ResetMouse(void) int i; for (i = 1; i <= sizeof(buttonState)*8; ++i) { - if (buttonState & SDL_BUTTON(i)) { + if (buttonState & SDL_BUTTON_MASK(i)) { SDL_SendMouseButton(0, mouse->focus, mouse->mouseID, i, false); } } @@ -876,13 +876,13 @@ static SDL_MouseInputSource *GetMouseInputSource(SDL_Mouse *mouse, SDL_MouseID m } } - if (!down && (!match || !(match->buttonstate & SDL_BUTTON(button)))) { + if (!down && (!match || !(match->buttonstate & SDL_BUTTON_MASK(button)))) { /* This might be a button release from a transition between mouse messages and raw input. * See if there's another mouse source that already has that button down and use that. */ for (i = 0; i < mouse->num_sources; ++i) { source = &mouse->sources[i]; - if ((source->buttonstate & SDL_BUTTON(button))) { + if ((source->buttonstate & SDL_BUTTON_MASK(button))) { match = source; break; } @@ -966,10 +966,10 @@ static void SDL_PrivateSendMouseButton(Uint64 timestamp, SDL_Window *window, SDL // Figure out which event to perform if (down) { type = SDL_EVENT_MOUSE_BUTTON_DOWN; - buttonstate |= SDL_BUTTON(button); + buttonstate |= SDL_BUTTON_MASK(button); } else { type = SDL_EVENT_MOUSE_BUTTON_UP; - buttonstate &= ~SDL_BUTTON(button); + buttonstate &= ~SDL_BUTTON_MASK(button); } // We do this after calculating buttonstate so button presses gain focus diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c index aed0f644d..37bde7649 100644 --- a/src/test/SDL_test_common.c +++ b/src/test/SDL_test_common.c @@ -1018,12 +1018,12 @@ static void SDLTest_PrintButtonMask(char *text, size_t maxlen, SDL_MouseButtonFl int i; int count = 0; for (i = 1; i <= 32; ++i) { - const Uint32 flag = SDL_BUTTON(i); + const Uint32 flag = SDL_BUTTON_MASK(i); if ((flags & flag) == flag) { if (count > 0) { SDL_snprintfcat(text, maxlen, " | "); } - SDL_snprintfcat(text, maxlen, "SDL_BUTTON(%d)", i); + SDL_snprintfcat(text, maxlen, "SDL_BUTTON_MASK(%d)", i); ++count; } } diff --git a/src/video/uikit/SDL_uikitview.m b/src/video/uikit/SDL_uikitview.m index e433499f5..f01c0374f 100644 --- a/src/video/uikit/SDL_uikitview.m +++ b/src/video/uikit/SDL_uikitview.m @@ -238,7 +238,7 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick; int i; for (i = 1; i <= MAX_MOUSE_BUTTONS; ++i) { - if (event.buttonMask & SDL_BUTTON(i)) { + if (event.buttonMask & SDL_BUTTON_MASK(i)) { Uint8 button; switch (i) { @@ -294,7 +294,7 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick; int i; for (i = 1; i <= MAX_MOUSE_BUTTONS; ++i) { - if (event.buttonMask & SDL_BUTTON(i)) { + if (event.buttonMask & SDL_BUTTON_MASK(i)) { Uint8 button; switch (i) { diff --git a/src/video/wayland/SDL_waylandevents.c b/src/video/wayland/SDL_waylandevents.c index 2081c9bee..e71a20e68 100644 --- a/src/video/wayland/SDL_waylandevents.c +++ b/src/video/wayland/SDL_waylandevents.c @@ -740,9 +740,9 @@ static void pointer_handle_button_common(struct SDL_WaylandInput *input, uint32_ * long as any button is still down, the capture remains). */ if (state) { // update our mask of currently-pressed buttons - input->buttons_pressed |= SDL_BUTTON(sdl_button); + input->buttons_pressed |= SDL_BUTTON_MASK(sdl_button); } else { - input->buttons_pressed &= ~(SDL_BUTTON(sdl_button)); + input->buttons_pressed &= ~(SDL_BUTTON_MASK(sdl_button)); } // Don't modify the capture flag in relative mode. diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index 26e9fcfe8..d383dc23c 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -220,10 +220,10 @@ static void WIN_CheckWParamMouseButton(Uint64 timestamp, bool bwParamMousePresse } } - if (data->focus_click_pending & SDL_BUTTON(button)) { + if (data->focus_click_pending & SDL_BUTTON_MASK(button)) { // Ignore the button click for activation if (!bwParamMousePressed) { - data->focus_click_pending &= ~SDL_BUTTON(button); + data->focus_click_pending &= ~SDL_BUTTON_MASK(button); WIN_UpdateClipCursor(data->window); } if (WIN_ShouldIgnoreFocusClick(data)) { @@ -231,9 +231,9 @@ static void WIN_CheckWParamMouseButton(Uint64 timestamp, bool bwParamMousePresse } } - if (bwParamMousePressed && !(mouseFlags & SDL_BUTTON(button))) { + if (bwParamMousePressed && !(mouseFlags & SDL_BUTTON_MASK(button))) { SDL_SendMouseButton(timestamp, data->window, mouseID, button, true); - } else if (!bwParamMousePressed && (mouseFlags & SDL_BUTTON(button))) { + } else if (!bwParamMousePressed && (mouseFlags & SDL_BUTTON_MASK(button))) { SDL_SendMouseButton(timestamp, data->window, mouseID, button, false); } } @@ -651,10 +651,10 @@ static void WIN_HandleRawMouseInput(Uint64 timestamp, SDL_VideoData *data, HANDL } } - if (windowdata->focus_click_pending & SDL_BUTTON(button)) { + if (windowdata->focus_click_pending & SDL_BUTTON_MASK(button)) { // Ignore the button click for activation if (!down) { - windowdata->focus_click_pending &= ~SDL_BUTTON(button); + windowdata->focus_click_pending &= ~SDL_BUTTON_MASK(button); WIN_UpdateClipCursor(window); } if (WIN_ShouldIgnoreFocusClick(windowdata)) { diff --git a/test/testautomation_mouse.c b/test/testautomation_mouse.c index cf9ef4625..057822a57 100644 --- a/test/testautomation_mouse.c +++ b/test/testautomation_mouse.c @@ -17,11 +17,11 @@ static int mouseStateCheck(Uint32 state) { return (state == 0) || - (state == SDL_BUTTON(SDL_BUTTON_LEFT)) || - (state == SDL_BUTTON(SDL_BUTTON_MIDDLE)) || - (state == SDL_BUTTON(SDL_BUTTON_RIGHT)) || - (state == SDL_BUTTON(SDL_BUTTON_X1)) || - (state == SDL_BUTTON(SDL_BUTTON_X2)); + (state == SDL_BUTTON_MASK(SDL_BUTTON_LEFT)) || + (state == SDL_BUTTON_MASK(SDL_BUTTON_MIDDLE)) || + (state == SDL_BUTTON_MASK(SDL_BUTTON_RIGHT)) || + (state == SDL_BUTTON_MASK(SDL_BUTTON_X1)) || + (state == SDL_BUTTON_MASK(SDL_BUTTON_X2)); } /** diff --git a/test/testmanymouse.c b/test/testmanymouse.c index 017fbb285..4ef6ccb81 100644 --- a/test/testmanymouse.c +++ b/test/testmanymouse.c @@ -286,9 +286,9 @@ static void HandleMouseButton(SDL_MouseButtonEvent *event) } if (event->which == mouse_state->instance_id) { if (event->down) { - mouse_state->button_state |= SDL_BUTTON(event->button); + mouse_state->button_state |= SDL_BUTTON_MASK(event->button); } else { - mouse_state->button_state &= ~SDL_BUTTON(event->button); + mouse_state->button_state &= ~SDL_BUTTON_MASK(event->button); } } }