diff --git a/runtime/doc/gui_mac.txt b/runtime/doc/gui_mac.txt index 89f16785ea..9351b55dd7 100644 --- a/runtime/doc/gui_mac.txt +++ b/runtime/doc/gui_mac.txt @@ -633,6 +633,10 @@ Each gesture generates one of the following Vim pseudo keys: Generated when swiping three fingers across the trackpad in a vertical direction. (Not supported by the Apple Magic Mouse.) + ** + Generated when doing a Force click by pressing hard on a trackpad. + (Only supported on trackpads that support Force Touch.) + You can map these keys like with any other key using the |:map| family of commands. For example, the following commands map left/right swipe to change to the previous/next tab in normal mode: > diff --git a/runtime/doc/tags b/runtime/doc/tags index a00037931d..57d6c6462e 100644 --- a/runtime/doc/tags +++ b/runtime/doc/tags @@ -3415,6 +3415,7 @@ $VIM_POSIX vi_diff.txt /*$VIM_POSIX* term.txt /** term.txt /** term.txt /** + gui_mac.txt /** helphelp.txt /** motion.txt /** insert.txt /** diff --git a/src/MacVim/MMBackend.m b/src/MacVim/MMBackend.m index ce0d62f70b..2146fb53ee 100644 --- a/src/MacVim/MMBackend.m +++ b/src/MacVim/MMBackend.m @@ -3004,6 +3004,7 @@ - (void)handleGesture:(NSData *)data case MMGestureSwipeRight: string[5] = KE_SWIPERIGHT; break; case MMGestureSwipeUp: string[5] = KE_SWIPEUP; break; case MMGestureSwipeDown: string[5] = KE_SWIPEDOWN; break; + case MMGestureForceClick: string[5] = KE_FORCECLICK; break; default: return; } diff --git a/src/MacVim/MMCoreTextView.m b/src/MacVim/MMCoreTextView.m index fa391d3ca7..841c92b2b8 100644 --- a/src/MacVim/MMCoreTextView.m +++ b/src/MacVim/MMCoreTextView.m @@ -556,6 +556,11 @@ - (void)swipeWithEvent:(NSEvent *)event [helper swipeWithEvent:event]; } +- (void)pressureChangeWithEvent:(NSEvent *)event +{ + [helper pressureChangeWithEvent:event]; +} + - (NSMenu*)menuForEvent:(NSEvent *)event { // HACK! Return nil to disable default popup menus (Vim provides its own). diff --git a/src/MacVim/MMTextView.m b/src/MacVim/MMTextView.m index aa16b5f1ff..2b7dbca6f9 100644 --- a/src/MacVim/MMTextView.m +++ b/src/MacVim/MMTextView.m @@ -795,6 +795,11 @@ - (void)swipeWithEvent:(NSEvent *)event [helper swipeWithEvent:event]; } +- (void)pressureChangeWithEvent:(NSEvent *)event +{ + [helper pressureChangeWithEvent:event]; +} + - (NSMenu*)menuForEvent:(NSEvent *)event { // HACK! Return nil to disable NSTextView's popup menus (Vim provides its diff --git a/src/MacVim/MMTextViewHelper.h b/src/MacVim/MMTextViewHelper.h index bb3d3dd5b5..c5b5858a94 100644 --- a/src/MacVim/MMTextViewHelper.h +++ b/src/MacVim/MMTextViewHelper.h @@ -65,6 +65,7 @@ - (void)mouseDragged:(NSEvent *)event; - (void)mouseMoved:(NSEvent *)event; - (void)swipeWithEvent:(NSEvent *)event; +- (void)pressureChangeWithEvent:(NSEvent *)event; - (BOOL)performDragOperation:(id )sender; - (NSDragOperation)draggingEntered:(id )sender; - (NSDragOperation)draggingUpdated:(id )sender; diff --git a/src/MacVim/MMTextViewHelper.m b/src/MacVim/MMTextViewHelper.m index 838bbeb059..ea3ee42615 100644 --- a/src/MacVim/MMTextViewHelper.m +++ b/src/MacVim/MMTextViewHelper.m @@ -477,6 +477,20 @@ - (void)swipeWithEvent:(NSEvent *)event [self sendGestureEvent:type flags:[event modifierFlags]]; } +- (void)pressureChangeWithEvent:(NSEvent *)event +{ + static BOOL inForceClick = NO; + if (event.stage >= 2) { + if (!inForceClick) { + inForceClick = YES; + + [self sendGestureEvent:MMGestureForceClick flags:[event modifierFlags]]; + } + } else { + inForceClick = NO; + } +} + - (BOOL)performDragOperation:(id )sender { NSPasteboard *pboard = [sender draggingPasteboard]; diff --git a/src/MacVim/MacVim.h b/src/MacVim/MacVim.h index ad09586ed1..118dac889c 100644 --- a/src/MacVim/MacVim.h +++ b/src/MacVim/MacVim.h @@ -296,6 +296,7 @@ enum { MMGestureSwipeRight, MMGestureSwipeUp, MMGestureSwipeDown, + MMGestureForceClick, }; diff --git a/src/edit.c b/src/edit.c index 7f3f2619db..7683ad0141 100644 --- a/src/edit.c +++ b/src/edit.c @@ -1264,6 +1264,7 @@ edit( case K_SWIPERIGHT: case K_SWIPEUP: case K_SWIPEDOWN: + case K_FORCECLICK: break; # endif #endif @@ -3896,7 +3897,7 @@ ins_compl_prep(int c) || c == K_MOUSELEFT || c == K_MOUSERIGHT # ifdef FEAT_GUI_MACVIM || c == K_SWIPELEFT || c == K_SWIPERIGHT || c == K_SWIPEUP - || c == K_SWIPEDOWN + || c == K_SWIPEDOWN || c == K_FORCECLICK # endif ) return retval; diff --git a/src/evalfunc.c b/src/evalfunc.c index f6034ee974..d8b89aa821 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -4744,6 +4744,7 @@ f_getchar(typval_T *argvars, typval_T *rettv) || n == K_SWIPERIGHT || n == K_SWIPEUP || n == K_SWIPEDOWN + || n == K_FORCECLICK # endif ) { diff --git a/src/ex_getln.c b/src/ex_getln.c index befb05ee59..b228ce88c5 100644 --- a/src/ex_getln.c +++ b/src/ex_getln.c @@ -1490,6 +1490,7 @@ getcmdline( case K_SWIPERIGHT: case K_SWIPEUP: case K_SWIPEDOWN: + case K_FORCECLICK: goto cmdline_not_changed; # endif #endif /* FEAT_MOUSE */ diff --git a/src/keymap.h b/src/keymap.h index 69b59e401e..264889feee 100644 --- a/src/keymap.h +++ b/src/keymap.h @@ -277,6 +277,7 @@ enum key_extra , KE_SWIPERIGHT = 103 /* Swipe trackpad right */ , KE_SWIPEUP = 104 /* Swipe trackpad up */ , KE_SWIPEDOWN = 105 /* Swipe trackpad down */ + , KE_FORCECLICK = 106 /* Force click on trackpad */ #endif }; @@ -486,6 +487,7 @@ enum key_extra # define K_SWIPERIGHT TERMCAP2KEY(KS_EXTRA, KE_SWIPERIGHT) # define K_SWIPEUP TERMCAP2KEY(KS_EXTRA, KE_SWIPEUP) # define K_SWIPEDOWN TERMCAP2KEY(KS_EXTRA, KE_SWIPEDOWN) +# define K_FORCECLICK TERMCAP2KEY(KS_EXTRA, KE_FORCECLICK) #endif /* Bits for modifier mask */ diff --git a/src/message.c b/src/message.c index 90f8e55601..fc9f2ea309 100644 --- a/src/message.c +++ b/src/message.c @@ -1207,6 +1207,7 @@ wait_return(int redraw) # ifdef FEAT_GUI_MACVIM || c == K_SWIPELEFT || c == K_SWIPERIGHT || c == K_SWIPEUP || c == K_SWIPEDOWN + || c == K_FORCECLICK # endif #endif ); diff --git a/src/misc1.c b/src/misc1.c index 3279817c52..52a560afee 100644 --- a/src/misc1.c +++ b/src/misc1.c @@ -3654,6 +3654,7 @@ get_keystroke(void) || n == K_SWIPERIGHT || n == K_SWIPEUP || n == K_SWIPEDOWN + || n == K_FORCECLICK # endif ) { diff --git a/src/misc2.c b/src/misc2.c index 36ea45cbf4..70c86b811c 100644 --- a/src/misc2.c +++ b/src/misc2.c @@ -2520,6 +2520,7 @@ static struct key_name_entry {K_SWIPERIGHT, (char_u *)"SwipeRight"}, {K_SWIPEUP, (char_u *)"SwipeUp"}, {K_SWIPEDOWN, (char_u *)"SwipeDown"}, + {K_FORCECLICK, (char_u *)"ForceClick"}, #endif {0, NULL} /* NOTE: When adding a long name update MAX_KEY_NAME_LEN. */ diff --git a/src/normal.c b/src/normal.c index 4d3ad7f46a..653b7b50ec 100644 --- a/src/normal.c +++ b/src/normal.c @@ -3865,7 +3865,7 @@ add_to_showcmd(int c) K_X1MOUSE, K_X1DRAG, K_X1RELEASE, K_X2MOUSE, K_X2DRAG, K_X2RELEASE, K_CURSORHOLD, # ifdef FEAT_GUI_MACVIM - K_SWIPELEFT, K_SWIPERIGHT, K_SWIPEUP, K_SWIPEDOWN, + K_SWIPELEFT, K_SWIPERIGHT, K_SWIPEUP, K_SWIPEDOWN, K_FORCECLICK, # endif 0 };