Skip to content

Commit 83d29c1

Browse files
committed
Wayland: Issue with mouse wheel coordinates
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
1 parent a6641c8 commit 83d29c1

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/app.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ struct Impl_App {
169169
uint32_t elapsedSinceLastTicker;
170170
iBool isRunning;
171171
iBool isRunningUnderWindowSystem;
172+
iBool isRunningUnderWayland;
172173
iBool isTextInputActive;
173174
iBool isDarkSystemTheme;
174175
iBool isSuspended;
@@ -1153,9 +1154,11 @@ static void init_App_(iApp *d, int argc, char **argv) {
11531154
migrateInternalUserDirToExternalStorage_App_(d);
11541155
#endif
11551156
#if defined (iPlatformLinux) && !defined (iPlatformAndroid) && !defined (iPlatformTerminal)
1156-
d->isRunningUnderWindowSystem = !iCmpStr(SDL_GetCurrentVideoDriver(), "x11") ||
1157-
!iCmpStr(SDL_GetCurrentVideoDriver(), "wayland");
1157+
d->isRunningUnderWayland = !iCmpStr(SDL_GetCurrentVideoDriver(), "wayland");
1158+
d->isRunningUnderWindowSystem = d->isRunningUnderWayland ||
1159+
!iCmpStr(SDL_GetCurrentVideoDriver(), "x11");
11581160
#else
1161+
d->isRunningUnderWayland = iFalse;
11591162
d->isRunningUnderWindowSystem = iTrue;
11601163
#endif
11611164
d->isTextInputActive = iFalse;
@@ -3011,6 +3014,10 @@ iBool isRunningUnderWindowSystem_App(void) {
30113014
return app_.isRunningUnderWindowSystem;
30123015
}
30133016

3017+
iBool isRunningUnderWayland_App(void) {
3018+
return app_.isRunningUnderWayland;
3019+
}
3020+
30143021
void setTextInputActive_App(iBool active) {
30153022
app_.isTextInputActive = active;
30163023
if (active) {

src/app.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ void refresh_App (void);
9292

9393
iBool isFinishedLaunching_App (void);
9494
iBool isRunningUnderWindowSystem_App(void);
95+
iBool isRunningUnderWayland_App (void);
9596
iBool isRefreshPending_App (void);
9697
iBool isLandscape_App (void);
9798
iLocalDef iBool isPortrait_App (void) { return !isLandscape_App(); }

src/ui/util.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
6161
#include <the_Foundation/math.h>
6262
#include <the_Foundation/path.h>
6363
#include <SDL_timer.h>
64+
#include <SDL_version.h>
6465

6566
iBool isCommand_SDLEvent(const SDL_Event *d) {
6667
return d->type == SDL_USEREVENT && d->user.code == command_UserEventCode;
@@ -106,13 +107,17 @@ iInt2 coord_MouseWheelEvent(const SDL_MouseWheelEvent *ev) {
106107
iWindow *win = get_Window(); /* may not be the focus window */
107108
#if !defined (iPlatformTerminal)
108109
if (isDesktop_Platform()) {
110+
# if SDL_VERSION_ATLEAST(2, 26, 0) && !defined(iPlatformApple)
111+
return coord_Window(win, ev->mouseX, ev->mouseY);
112+
# else
109113
/* We need to figure out where the mouse is in relation to the currently active window.
110114
It may be outside the actual focus window. */
111115
iInt2 mousePos, winPos;
112116
SDL_GetGlobalMouseState(&mousePos.x, &mousePos.y);
113117
SDL_GetWindowPosition(win->win, &winPos.x, &winPos.y);
114118
subv_I2(&mousePos, winPos);
115119
return coord_Window(win, mousePos.x, mousePos.y);
120+
# endif
116121
}
117122
#endif
118123
return mouseCoord_Window(win, ev->which);

0 commit comments

Comments
 (0)