Skip to content

Commit

Permalink
Wayland: Issue with mouse wheel coordinates
Browse files Browse the repository at this point in the history
Apply the fix suggested by @shurizzle in #669, requiring SDL 2.26+.

This does not apply on macOS because the wheel events are dispatched
by custom event handling code (due to trackpad swipe handling) and
therefore don't have the mouse coordinates included.

IssueID #612
IssueID #669
  • Loading branch information
skyjake committed Aug 28, 2024
1 parent a6641c8 commit 83d29c1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ struct Impl_App {
uint32_t elapsedSinceLastTicker;
iBool isRunning;
iBool isRunningUnderWindowSystem;
iBool isRunningUnderWayland;
iBool isTextInputActive;
iBool isDarkSystemTheme;
iBool isSuspended;
Expand Down Expand Up @@ -1153,9 +1154,11 @@ static void init_App_(iApp *d, int argc, char **argv) {
migrateInternalUserDirToExternalStorage_App_(d);
#endif
#if defined (iPlatformLinux) && !defined (iPlatformAndroid) && !defined (iPlatformTerminal)
d->isRunningUnderWindowSystem = !iCmpStr(SDL_GetCurrentVideoDriver(), "x11") ||
!iCmpStr(SDL_GetCurrentVideoDriver(), "wayland");
d->isRunningUnderWayland = !iCmpStr(SDL_GetCurrentVideoDriver(), "wayland");
d->isRunningUnderWindowSystem = d->isRunningUnderWayland ||
!iCmpStr(SDL_GetCurrentVideoDriver(), "x11");
#else
d->isRunningUnderWayland = iFalse;
d->isRunningUnderWindowSystem = iTrue;
#endif
d->isTextInputActive = iFalse;
Expand Down Expand Up @@ -3011,6 +3014,10 @@ iBool isRunningUnderWindowSystem_App(void) {
return app_.isRunningUnderWindowSystem;
}

iBool isRunningUnderWayland_App(void) {
return app_.isRunningUnderWayland;
}

void setTextInputActive_App(iBool active) {
app_.isTextInputActive = active;
if (active) {
Expand Down
1 change: 1 addition & 0 deletions src/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ void refresh_App (void);

iBool isFinishedLaunching_App (void);
iBool isRunningUnderWindowSystem_App(void);
iBool isRunningUnderWayland_App (void);
iBool isRefreshPending_App (void);
iBool isLandscape_App (void);
iLocalDef iBool isPortrait_App (void) { return !isLandscape_App(); }
Expand Down
5 changes: 5 additions & 0 deletions src/ui/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
#include <the_Foundation/math.h>
#include <the_Foundation/path.h>
#include <SDL_timer.h>
#include <SDL_version.h>

iBool isCommand_SDLEvent(const SDL_Event *d) {
return d->type == SDL_USEREVENT && d->user.code == command_UserEventCode;
Expand Down Expand Up @@ -106,13 +107,17 @@ iInt2 coord_MouseWheelEvent(const SDL_MouseWheelEvent *ev) {
iWindow *win = get_Window(); /* may not be the focus window */
#if !defined (iPlatformTerminal)
if (isDesktop_Platform()) {
# if SDL_VERSION_ATLEAST(2, 26, 0) && !defined(iPlatformApple)
return coord_Window(win, ev->mouseX, ev->mouseY);
# else
/* We need to figure out where the mouse is in relation to the currently active window.
It may be outside the actual focus window. */
iInt2 mousePos, winPos;
SDL_GetGlobalMouseState(&mousePos.x, &mousePos.y);
SDL_GetWindowPosition(win->win, &winPos.x, &winPos.y);
subv_I2(&mousePos, winPos);
return coord_Window(win, mousePos.x, mousePos.y);
# endif
}
#endif
return mouseCoord_Window(win, ev->which);
Expand Down

0 comments on commit 83d29c1

Please sign in to comment.