Skip to content

Commit 916ac4a

Browse files
authored
Merge pull request #716 from ychin/force_click
Support Force click gesture. Can now map <ForceClick> gesture in MacVim
2 parents 1868c4c + 4f518b1 commit 916ac4a

16 files changed

+42
-2
lines changed

runtime/doc/gui_mac.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,10 @@ Each gesture generates one of the following Vim pseudo keys:
633633
Generated when swiping three fingers across the trackpad in a
634634
vertical direction. (Not supported by the Apple Magic Mouse.)
635635

636+
*<ForceClick>*
637+
Generated when doing a Force click by pressing hard on a trackpad.
638+
(Only supported on trackpads that support Force Touch.)
639+
636640
You can map these keys like with any other key using the |:map| family of
637641
commands. For example, the following commands map left/right swipe to change
638642
to the previous/next tab in normal mode: >

runtime/doc/tags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3415,6 +3415,7 @@ $VIM_POSIX vi_diff.txt /*$VIM_POSIX*
34153415
<F7> term.txt /*<F7>*
34163416
<F8> term.txt /*<F8>*
34173417
<F9> term.txt /*<F9>*
3418+
<ForceClick> gui_mac.txt /*<ForceClick>*
34183419
<Help> helphelp.txt /*<Help>*
34193420
<Home> motion.txt /*<Home>*
34203421
<Insert> insert.txt /*<Insert>*

src/MacVim/MMBackend.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3004,6 +3004,7 @@ - (void)handleGesture:(NSData *)data
30043004
case MMGestureSwipeRight: string[5] = KE_SWIPERIGHT; break;
30053005
case MMGestureSwipeUp: string[5] = KE_SWIPEUP; break;
30063006
case MMGestureSwipeDown: string[5] = KE_SWIPEDOWN; break;
3007+
case MMGestureForceClick: string[5] = KE_FORCECLICK; break;
30073008
default: return;
30083009
}
30093010

src/MacVim/MMCoreTextView.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,11 @@ - (void)swipeWithEvent:(NSEvent *)event
556556
[helper swipeWithEvent:event];
557557
}
558558

559+
- (void)pressureChangeWithEvent:(NSEvent *)event
560+
{
561+
[helper pressureChangeWithEvent:event];
562+
}
563+
559564
- (NSMenu*)menuForEvent:(NSEvent *)event
560565
{
561566
// HACK! Return nil to disable default popup menus (Vim provides its own).

src/MacVim/MMTextView.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,11 @@ - (void)swipeWithEvent:(NSEvent *)event
795795
[helper swipeWithEvent:event];
796796
}
797797

798+
- (void)pressureChangeWithEvent:(NSEvent *)event
799+
{
800+
[helper pressureChangeWithEvent:event];
801+
}
802+
798803
- (NSMenu*)menuForEvent:(NSEvent *)event
799804
{
800805
// HACK! Return nil to disable NSTextView's popup menus (Vim provides its

src/MacVim/MMTextViewHelper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
- (void)mouseDragged:(NSEvent *)event;
6666
- (void)mouseMoved:(NSEvent *)event;
6767
- (void)swipeWithEvent:(NSEvent *)event;
68+
- (void)pressureChangeWithEvent:(NSEvent *)event;
6869
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender;
6970
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender;
7071
- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender;

src/MacVim/MMTextViewHelper.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,20 @@ - (void)swipeWithEvent:(NSEvent *)event
477477
[self sendGestureEvent:type flags:[event modifierFlags]];
478478
}
479479

480+
- (void)pressureChangeWithEvent:(NSEvent *)event
481+
{
482+
static BOOL inForceClick = NO;
483+
if (event.stage >= 2) {
484+
if (!inForceClick) {
485+
inForceClick = YES;
486+
487+
[self sendGestureEvent:MMGestureForceClick flags:[event modifierFlags]];
488+
}
489+
} else {
490+
inForceClick = NO;
491+
}
492+
}
493+
480494
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
481495
{
482496
NSPasteboard *pboard = [sender draggingPasteboard];

src/MacVim/MacVim.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ enum {
296296
MMGestureSwipeRight,
297297
MMGestureSwipeUp,
298298
MMGestureSwipeDown,
299+
MMGestureForceClick,
299300
};
300301

301302

src/edit.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,7 @@ edit(
12641264
case K_SWIPERIGHT:
12651265
case K_SWIPEUP:
12661266
case K_SWIPEDOWN:
1267+
case K_FORCECLICK:
12671268
break;
12681269
# endif
12691270
#endif
@@ -3896,7 +3897,7 @@ ins_compl_prep(int c)
38963897
|| c == K_MOUSELEFT || c == K_MOUSERIGHT
38973898
# ifdef FEAT_GUI_MACVIM
38983899
|| c == K_SWIPELEFT || c == K_SWIPERIGHT || c == K_SWIPEUP
3899-
|| c == K_SWIPEDOWN
3900+
|| c == K_SWIPEDOWN || c == K_FORCECLICK
39003901
# endif
39013902
)
39023903
return retval;

src/evalfunc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4744,6 +4744,7 @@ f_getchar(typval_T *argvars, typval_T *rettv)
47444744
|| n == K_SWIPERIGHT
47454745
|| n == K_SWIPEUP
47464746
|| n == K_SWIPEDOWN
4747+
|| n == K_FORCECLICK
47474748
# endif
47484749
)
47494750
{

src/ex_getln.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,7 @@ getcmdline(
14901490
case K_SWIPERIGHT:
14911491
case K_SWIPEUP:
14921492
case K_SWIPEDOWN:
1493+
case K_FORCECLICK:
14931494
goto cmdline_not_changed;
14941495
# endif
14951496
#endif /* FEAT_MOUSE */

src/keymap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ enum key_extra
277277
, KE_SWIPERIGHT = 103 /* Swipe trackpad right */
278278
, KE_SWIPEUP = 104 /* Swipe trackpad up */
279279
, KE_SWIPEDOWN = 105 /* Swipe trackpad down */
280+
, KE_FORCECLICK = 106 /* Force click on trackpad */
280281
#endif
281282
};
282283

@@ -486,6 +487,7 @@ enum key_extra
486487
# define K_SWIPERIGHT TERMCAP2KEY(KS_EXTRA, KE_SWIPERIGHT)
487488
# define K_SWIPEUP TERMCAP2KEY(KS_EXTRA, KE_SWIPEUP)
488489
# define K_SWIPEDOWN TERMCAP2KEY(KS_EXTRA, KE_SWIPEDOWN)
490+
# define K_FORCECLICK TERMCAP2KEY(KS_EXTRA, KE_FORCECLICK)
489491
#endif
490492

491493
/* Bits for modifier mask */

src/message.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,7 @@ wait_return(int redraw)
12071207
# ifdef FEAT_GUI_MACVIM
12081208
|| c == K_SWIPELEFT || c == K_SWIPERIGHT
12091209
|| c == K_SWIPEUP || c == K_SWIPEDOWN
1210+
|| c == K_FORCECLICK
12101211
# endif
12111212
#endif
12121213
);

src/misc1.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3654,6 +3654,7 @@ get_keystroke(void)
36543654
|| n == K_SWIPERIGHT
36553655
|| n == K_SWIPEUP
36563656
|| n == K_SWIPEDOWN
3657+
|| n == K_FORCECLICK
36573658
# endif
36583659
)
36593660
{

src/misc2.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2520,6 +2520,7 @@ static struct key_name_entry
25202520
{K_SWIPERIGHT, (char_u *)"SwipeRight"},
25212521
{K_SWIPEUP, (char_u *)"SwipeUp"},
25222522
{K_SWIPEDOWN, (char_u *)"SwipeDown"},
2523+
{K_FORCECLICK, (char_u *)"ForceClick"},
25232524
#endif
25242525
{0, NULL}
25252526
/* NOTE: When adding a long name update MAX_KEY_NAME_LEN. */

src/normal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3865,7 +3865,7 @@ add_to_showcmd(int c)
38653865
K_X1MOUSE, K_X1DRAG, K_X1RELEASE, K_X2MOUSE, K_X2DRAG, K_X2RELEASE,
38663866
K_CURSORHOLD,
38673867
# ifdef FEAT_GUI_MACVIM
3868-
K_SWIPELEFT, K_SWIPERIGHT, K_SWIPEUP, K_SWIPEDOWN,
3868+
K_SWIPELEFT, K_SWIPERIGHT, K_SWIPEUP, K_SWIPEDOWN, K_FORCECLICK,
38693869
# endif
38703870
0
38713871
};

0 commit comments

Comments
 (0)