From 99d980b5867b277d15d39731eb235bfa9695268e Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Fri, 23 Jul 2021 14:58:42 +0300 Subject: Window: Mouse wheel events vs. split mode Only process mouse wheel events on the root over which the mouse is currently. --- src/ui/window.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src/ui/window.c') diff --git a/src/ui/window.c b/src/ui/window.c index f71d8102..4bf42a30 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -957,10 +957,14 @@ iBool dispatchEvent_Window(iWindow *d, const SDL_Event *ev) { if (isCommand_SDLEvent(ev) && ev->user.data2 && ev->user.data2 != root) { continue; /* Not meant for this root. */ } - else if ((ev->type == SDL_KEYDOWN || ev->type == SDL_KEYUP || ev->type == SDL_TEXTINPUT) + if ((ev->type == SDL_KEYDOWN || ev->type == SDL_KEYUP || ev->type == SDL_TEXTINPUT) && d->keyRoot != root) { continue; /* Key events go only to the root with keyboard focus. */ } + if (ev->type == SDL_MOUSEWHEEL && !contains_Rect(rect_Root(root), + coord_MouseWheelEvent(&ev->wheel))) { + continue; /* Only process the event in the relevant split. */ + } setCurrent_Root(root); const iBool wasUsed = dispatchEvent_Widget(root->widget, ev); if (wasUsed) { @@ -1154,20 +1158,19 @@ iInt2 coord_Window(const iWindow *d, int x, int y) { return mulf_I2(init_I2(x, y), d->pixelRatio); } -iInt2 mouseCoord_Window(const iWindow *d) { -#if defined (iPlatformMobile) - /* At least on iOS the coordinates returned by SDL_GetMouseState() do no match up with - our touch coordinates on the Y axis (?). Maybe a pixel ratio thing? */ - iUnused(d); - return latestPosition_Touch(); -#else +iInt2 mouseCoord_Window(const iWindow *d, int whichDevice) { + if (whichDevice == SDL_TOUCH_MOUSEID) { + /* At least on iOS the coordinates returned by SDL_GetMouseState() do no match up with + our touch coordinates on the Y axis (?). Maybe a pixel ratio thing? */ + iUnused(d); + return latestPosition_Touch(); + } if (!d->isMouseInside) { return init_I2(-1000000, -1000000); } int x, y; SDL_GetMouseState(&x, &y); return coord_Window(d, x, y); -#endif } float uiScale_Window(const iWindow *d) { -- cgit v1.2.3