Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions runtime/doc/gui_mac.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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: >
Expand Down
1 change: 1 addition & 0 deletions runtime/doc/tags
Original file line number Diff line number Diff line change
Expand Up @@ -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>*
Expand Down
1 change: 1 addition & 0 deletions src/MacVim/MMBackend.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
5 changes: 5 additions & 0 deletions src/MacVim/MMCoreTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
5 changes: 5 additions & 0 deletions src/MacVim/MMTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/MacVim/MMTextViewHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions src/MacVim/MMTextViewHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 <NSDraggingInfo>)sender
{
NSPasteboard *pboard = [sender draggingPasteboard];
Expand Down
1 change: 1 addition & 0 deletions src/MacVim/MacVim.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ enum {
MMGestureSwipeRight,
MMGestureSwipeUp,
MMGestureSwipeDown,
MMGestureForceClick,
};


Expand Down
3 changes: 2 additions & 1 deletion src/edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,7 @@ edit(
case K_SWIPERIGHT:
case K_SWIPEUP:
case K_SWIPEDOWN:
case K_FORCECLICK:
break;
# endif
#endif
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/evalfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
{
Expand Down
1 change: 1 addition & 0 deletions src/ex_getln.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 2 additions & 0 deletions src/keymap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down Expand Up @@ -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 */
Expand Down
1 change: 1 addition & 0 deletions src/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down
1 change: 1 addition & 0 deletions src/misc1.c
Original file line number Diff line number Diff line change
Expand Up @@ -3654,6 +3654,7 @@ get_keystroke(void)
|| n == K_SWIPERIGHT
|| n == K_SWIPEUP
|| n == K_SWIPEDOWN
|| n == K_FORCECLICK
# endif
)
{
Expand Down
1 change: 1 addition & 0 deletions src/misc2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
2 changes: 1 addition & 1 deletion src/normal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down