]> git.eshelyaron.com Git - emacs.git/commitdiff
Add support for pinch events to NS
authorPo Lu <luangruo@yahoo.com>
Tue, 28 Dec 2021 06:05:32 +0000 (14:05 +0800)
committerPo Lu <luangruo@yahoo.com>
Tue, 28 Dec 2021 06:07:49 +0000 (14:07 +0800)
* 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.

lisp/face-remap.el
src/nsterm.m

index 67123ac7f82c109bb09b1cc8a2f69e755445e987..3440f4c9416d5ad7eceaf2574b7f8cdb5487cbcb 100644 (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
index 591e28f20b92a1117d4f1d572aa3d485e83f69d3..f79e271a989e3f41f3c61b98ea420bdb62c8aab2 100644 (file)
@@ -6821,6 +6821,42 @@ not_in_argv (NSString *arg)
   [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
 {