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

OS X Scroll Momentum #2176

Closed
SDLBugzilla opened this issue Feb 11, 2021 · 6 comments · Fixed by #10740
Closed

OS X Scroll Momentum #2176

SDLBugzilla opened this issue Feb 11, 2021 · 6 comments · Fixed by #10740
Assignees
Milestone

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

Reported in version: 2.0.4
Reported for operating system, platform: Mac OS X 10.11, All

Comments on the original bug report:

On 2016-05-26 10:33:00 +0000, Martijn Courteaux wrote:

It turns out I don't receive the usual inertia scroll events in OS X. I get regular scroll events, but not the ones caused by momentum, which should be managed by the OS, I believe.

I'm not 100% sure, but I think this is an OS X feature, and not really a feature of a GUI library of Apple. So I suspect that SDL is retrieving these scroll events in a special alternative way?

If someone fixes this (maybe me within a couple of months), is it a good idea to add flag that indicates that these events are caused by momentum? Something like:

int SDL_Event.wheel.momentum

On 2016-05-27 17:04:29 +0000, Alex Szpakowski wrote:

it's explicitly disabled in SDL's code ( https://hg.libsdl.org/SDL/file/7cbfd97f1430/src/video/cocoa/SDL_cocoaevents.m#l327 ).

I'm not positive about the reason why, but I suspect it's because scroll momentum is unwanted in a lot of games.

On 2016-05-27 18:00:32 +0000, Martijn Courteaux wrote:

Aha, nice. I am most likely about to change this for my application. (I'm building an application, with a GUI where scrolling through lists etc feels more natural with momentum, using SDL instead of a game.) So, do you want me to contribute these changes to the SDL repository?

If so, how would you prefer seeing this implemented? I see three options:

  • Enable it by default, and indicate wether scroll events are caused by momentum or are regular scroll events. (This breaks compatibility with existing games, because these games will all start receiving unwanted scroll momentum events as regular SDL_MOUSEWHEELEVENTS.)

  • Second option is to make this some sort of configuration option when initialising SDL. I'm not sure wether OS X allows to change this settings more than once, but if that is possible, it would also be possible to provide a function to change behaviour. Something like: SDL_AllowScrollMomentumEvents(SDL_Bool); Of course, this in combination with the flag that a scroll event is caused by momentum or not. This is also backwards compatible.

  • Third option: create a new type of SDL_Event that will represent scroll momentum events. I don't like this approach, but is backwards compatible.

Personally, I like the second option the most. But if this won't be contributed to the SDL repository, I can go with the first option, since I want momentum events, whatsoever.

Thanks!

On 2016-05-31 21:17:56 +0000, Martijn Courteaux wrote:

I fixed it using another way. Super easy hack: create a OS X specific file ending in the .mm extension and make a function in it like this:

void OSX_HACK_enable_scroll_momentum()
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSDictionary *appDefaults = [NSDictionary dictionaryWithObject:@"YES" forKey:@"AppleMomentumScrollSupported"];
[defaults registerDefaults:appDefaults];
}

And of course call it.

On 2017-08-12 02:20:36 +0000, Sam Lantinga wrote:

Great hack!

I'm closing the bug since in general game developers don't want this for game control.

On 2019-08-23 13:24:20 +0000, Martijn Courteaux wrote:

The new hack is:

[[NSUserDefaults standardUserDefaults]
setBool: YES forKey: @"AppleMomentumScrollSupported"];

@SDLBugzilla SDLBugzilla added bug wontfix This will not be worked on labels Feb 11, 2021
@cblc
Copy link

cblc commented Mar 20, 2024

@mcourteaux , I'm not having success in using your hack for enabling scroll momentum. From what part of the code should you call that function? Just after SDL_Init() ?

@mcourteaux
Copy link

@mcourteaux , I'm not having success in using your hack for enabling scroll momentum. From what part of the code should you call that function? Just after SDL_Init() ?

Indeed, I was calling it right after SDL_Init(). I haven't tested this in a while on my MacBook so I can't confirm this still works, but that's where the call to that code is...

For the record, I have one file macos.mm containing:

#import <Foundation/Foundation.h>

void MACOS_enable_scroll_momentum() {
    [[NSUserDefaults standardUserDefaults]
    setBool: YES forKey: @"AppleMomentumScrollSupported"];
}

Good luck!

@mcourteaux
Copy link

mcourteaux commented Mar 20, 2024

Make sure you have SDL_INIT_EVENTS included in the bitmask to the SDL_Init() call.

@cblc
Copy link

cblc commented Mar 20, 2024

Thank you very much @mcourteaux !! Yes, it works, I made a dumb mistake but now it works perfectly. Thanks!

@slouken slouken added this to the 3.2.0 milestone Mar 20, 2024
@slouken
Copy link
Collaborator

slouken commented Mar 20, 2024

I'm going to reopen this for SDL 3.0, we can add a hint to enable momentum scrolling.

@slouken slouken reopened this Mar 20, 2024
@cblc
Copy link

cblc commented Mar 20, 2024

Yes, while I agree games don't want momentum, however, non-games are likely to prefer it (at least in my case, I do). And not only when panning through a 2D image/drawing, but even when 3D panning in a 3D scene: the Trackpad in the Mac feels weird when momentum is disabled (except in games, of course).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants