Add support for pinch events to NS

* lisp/face-remap.el (text-scale-pinch): Remove mistaken
assumption that angle is always 1.0 at the beginning of
a sequence.

* src/nsterm.c (- magnifyWithEvent): New function.
This commit is contained in:
Po Lu 2021-12-28 14:05:32 +08:00
parent 036e88ce2f
commit 208ae993ba
2 changed files with 37 additions and 2 deletions

View file

@ -417,8 +417,7 @@ a top-level keymap, `text-scale-increase' or
(with-selected-window window
(when (and (zerop dx)
(zerop dy)
(zerop angle)
(equal scale 1.0))
(zerop angle))
(setq text-scale--pinch-start-scale
(if text-scale-mode text-scale-mode-amount 0)))
(text-scale-set

View file

@ -6821,6 +6821,42 @@ - (void)otherMouseDragged: (NSEvent *)e
[self mouseMoved: e];
}
#ifdef NS_IMPL_COCOA
- (void) magnifyWithEvent: (NSEvent *) event
{
NSPoint pt = [self convertPoint: [event locationInWindow] fromView: nil];
static CGFloat last_scale;
NSTRACE ("[EmacsView magnifyWithEvent]");
if (emacs_event)
{
emacs_event->kind = PINCH_EVENT;
emacs_event->modifiers = EV_MODIFIERS (event);
XSETINT (emacs_event->x, lrint (pt.x));
XSETINT (emacs_event->y, lrint (pt.y));
XSETFRAME (emacs_event->frame_or_window, emacsframe);
if ([event phase] == NSEventPhaseBegan)
{
last_scale = 1.0 + [event magnification];
emacs_event->arg = list4 (make_float (0.0),
make_float (0.0),
make_float (last_scale),
make_float (0.0));
}
else
/* Report a tiny change so that Lisp code doesn't think this
is the beginning of an event sequence. This is the best we
can do because NS doesn't report pinch events in as much
detail as XInput 2 or GTK+ do. */
emacs_event->arg = list4 (make_float (0.01),
make_float (0.0),
make_float (last_scale += [event magnification]),
make_float (0.0));
EV_TRAILER (event);
}
}
#endif
- (BOOL)windowShouldClose: (id)sender
{