Skip to content

Commit

Permalink
Merge pull request #42773 from bruvzg/macos_inertia_32
Browse files Browse the repository at this point in the history
[macOS, 3.2] Suppress momentum scrolling after key press.
  • Loading branch information
akien-mga authored Oct 20, 2020
2 parents e78fbd9 + 6ea9ee5 commit 0181819
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions platform/osx/os_osx.mm
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ static void push_to_key_event_buffer(const OS_OSX::KeyEvent &p_event) {
static int mouse_y = 0;
static int button_mask = 0;
static bool mouse_down_control = false;
static bool ignore_momentum_scroll = false;

static Vector2 get_mouse_pos(NSPoint locationInWindow) {

Expand Down Expand Up @@ -1179,6 +1180,8 @@ static int remapKey(unsigned int key, unsigned int state) {

- (void)keyDown:(NSEvent *)event {

ignore_momentum_scroll = true;

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

- (void)flagsChanged:(NSEvent *)event {

ignore_momentum_scroll = true;

// Ignore all input if IME input is in progress
if (!imeInputEventInProgress) {
OS_OSX::KeyEvent ke;
Expand Down Expand Up @@ -1359,6 +1364,13 @@ - (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(deltaX, deltaY, [event modifierFlags]);
} else {
Expand Down

0 comments on commit 0181819

Please sign in to comment.