Skip to content

Commit

Permalink
Merge pull request #42772 from bruvzg/macos_inertia
Browse files Browse the repository at this point in the history
[macOS] Suppress momentum scrolling after key press.
  • Loading branch information
akien-mga authored Oct 20, 2020
2 parents 15ff276 + 801f0a0 commit 1810825
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions platform/osx/display_server_osx.mm
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@

#define DS_OSX ((DisplayServerOSX *)(DisplayServerOSX::get_singleton()))

static bool ignore_momentum_scroll = false;

static void _get_key_modifier_state(unsigned int p_osx_state, Ref<InputEventWithModifiers> r_state) {
r_state->set_shift((p_osx_state & NSEventModifierFlagShift));
r_state->set_control((p_osx_state & NSEventModifierFlagControl));
Expand Down Expand Up @@ -1304,6 +1306,8 @@ - (void)keyDown:(NSEvent *)event {
ERR_FAIL_COND(!DS_OSX->windows.has(window_id));
DisplayServerOSX::WindowData &wd = DS_OSX->windows[window_id];

ignore_momentum_scroll = true;

// Ignore all input if IME input is in progress
if (!imeInputEventInProgress) {
NSString *characters = [event characters];
Expand Down Expand Up @@ -1348,6 +1352,8 @@ - (void)keyDown:(NSEvent *)event {
}

- (void)flagsChanged:(NSEvent *)event {
ignore_momentum_scroll = true;

// Ignore all input if IME input is in progress
if (!imeInputEventInProgress) {
DisplayServerOSX::KeyEvent ke;
Expand Down Expand Up @@ -1507,6 +1513,14 @@ - (void)scrollWheel:(NSEvent *)event {
deltaY *= 0.03;
}

if ([event momentumPhase] != NSEventPhaseNone) {
if (ignore_momentum_scroll) {
return;
}
} else {
ignore_momentum_scroll = false;
}

if ([event phase] != NSEventPhaseNone || [event momentumPhase] != NSEventPhaseNone) {
sendPanEvent(window_id, deltaX, deltaY, [event modifierFlags]);
} else {
Expand Down

0 comments on commit 1810825

Please sign in to comment.