Support Force click gesture. Can now map <ForceClick> gesture in MacVim

Can now map "<ForceClick>" similar to "<SwipeLeft/Right/Up/Down>"
gestures. Require a Mac that has a touchpad that supports Force Touch to
work.

Close #672
This commit is contained in:
Yee Cheng Chin
2018-07-29 05:01:08 -07:00
parent 1868c4cdac
commit 4f518b1996
16 changed files with 42 additions and 2 deletions
+4
View File
@@ -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.)
*<ForceClick>*
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: >
+1
View File
@@ -3415,6 +3415,7 @@ $VIM_POSIX vi_diff.txt /*$VIM_POSIX*
<F7> term.txt /*<F7>*
<F8> term.txt /*<F8>*
<F9> term.txt /*<F9>*
<ForceClick> gui_mac.txt /*<ForceClick>*
<Help> helphelp.txt /*<Help>*
<Home> motion.txt /*<Home>*
<Insert> insert.txt /*<Insert>*
+1
View File
@@ -3004,6 +3004,7 @@ extern GuiFont gui_mch_retain_font(GuiFont font);
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;
}
+5
View File
@@ -556,6 +556,11 @@ defaultAdvanceForFont(NSFont *font)
[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).
+5
View File
@@ -795,6 +795,11 @@
[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
+1
View File
@@ -65,6 +65,7 @@
- (void)mouseDragged:(NSEvent *)event;
- (void)mouseMoved:(NSEvent *)event;
- (void)swipeWithEvent:(NSEvent *)event;
- (void)pressureChangeWithEvent:(NSEvent *)event;
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender;
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender;
- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender;
+14
View File
@@ -477,6 +477,20 @@ KeyboardInputSourcesEqual(TISInputSourceRef a, TISInputSourceRef b)
[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 <NSDraggingInfo>)sender
{
NSPasteboard *pboard = [sender draggingPasteboard];
+1
View File
@@ -296,6 +296,7 @@ enum {
MMGestureSwipeRight,
MMGestureSwipeUp,
MMGestureSwipeDown,
MMGestureForceClick,
};
+2 -1
View File
@@ -1264,6 +1264,7 @@ doESCkey:
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;
+1
View File
@@ -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
)
{
+1
View File
@@ -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 */
+2
View File
@@ -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 */
+1
View File
@@ -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
);
+1
View File
@@ -3654,6 +3654,7 @@ get_keystroke(void)
|| n == K_SWIPERIGHT
|| n == K_SWIPEUP
|| n == K_SWIPEDOWN
|| n == K_FORCECLICK
# endif
)
{
+1
View File
@@ -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. */
+1 -1
View File
@@ -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
};