unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Touch events
@ 2017-06-24  8:53 Alan Third
  2017-06-24  9:33 ` martin rudalics
                   ` (2 more replies)
  0 siblings, 3 replies; 24+ messages in thread
From: Alan Third @ 2017-06-24  8:53 UTC (permalink / raw)
  To: Emacs-Devel devel

[-- Attachment #1: Type: text/plain, Size: 1126 bytes --]

I’ve created a small patch that adds some touch event handling to
Emacs. Currently it only works on macOS, but the same functionality is
available on GTK3, MS Windows and vanilla Xorg.

I wanted to know if I’m going about this the right way, or if it’s
even worth my while continuing.

I’ve created a number of new events: touch-scroll, touch-pinch, etc.,
that can be bound to functions. I’ve attached a simple script that
binds touch-pinch to the text-scale-increase/decrease functions.

BTW, how do you create a lisp float from C? I tried something like

    Lisp_Object delta;
    XSETFLOAT (delta, [event magnification]);

but it just complains that [event magnification] returns a double and
not void *.

NOTE: If you install this patch, scrolling with the touchpad will no
longer work on macOS (a real mousewheel will be fine, though). It
needs some effort to get it working, and my elisp skills aren’t up to
much. It either needs a compatibility function in lisp, or a way to
disable it and use the existing mousewheel code. It could be worth
trying to tie it into the new pixel scroll mode.
-- 
Alan Third

[-- Attachment #2: Test functions --]
[-- Type: text/plain, Size: 531 bytes --]

(defun touch--scroll (event)
  (interactive (list last-input-event))
  (message "%s" event)
  (set-window-vscroll (caadr event) (- (window-vscroll (caadr event) t)
				       (cadr (caddr event))) t))

(defun touch--pinch (event)
  (interactive (list last-input-event))
  (message "%s" event)
  (let ((delta (caddr event)))
    (cond ((> delta 0)
  	   (text-scale-increase delta))
	  ((< delta 0)
	   (text-scale-decrease (- delta))))))

(global-set-key [touch-pinch] 'touch--pinch)
(global-set-key [touch-scroll] 'touch--scroll)

[-- Attachment #3: 0001-Add-touch-events.patch --]
[-- Type: text/plain, Size: 6937 bytes --]

From 0cc26156f8f13622073488ecee647bf6a656fee8 Mon Sep 17 00:00:00 2001
From: Alan Third <alan@idiocy.org>
Date: Sat, 24 Jun 2017 09:36:03 +0100
Subject: [PATCH] Add touch events

---
 src/keyboard.c  | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/nsterm.m    | 66 +++++++++++++++++++++++++++++++++++++++++++++------------
 src/termhooks.h |  4 ++++
 3 files changed, 116 insertions(+), 13 deletions(-)

diff --git a/src/keyboard.c b/src/keyboard.c
index 55486c6d9a..8e1face509 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -4556,6 +4556,7 @@ static Lisp_Object accent_key_syms;
 static Lisp_Object func_key_syms;
 static Lisp_Object mouse_syms;
 static Lisp_Object wheel_syms;
+static Lisp_Object touch_syms;
 static Lisp_Object drag_n_drop_syms;
 
 /* This is a list of keysym codes for special "accent" characters.
@@ -5106,6 +5107,12 @@ static const char *const lispy_wheel_names[] =
   "wheel-up", "wheel-down", "wheel-left", "wheel-right"
 };
 
+static const char *const touch_names[] =
+{
+  "touch-scroll", "touch-pinch", "touch-rotate", "touch-swipe-up",
+  "touch-swipe-down", "touch-swipe-left", "touch-swipe-right"
+};
+
 /* drag-n-drop events are generated when a set of selected files are
    dragged from another application and dropped onto an Emacs window.  */
 static const char *const lispy_drag_n_drop_names[] =
@@ -5999,6 +6006,48 @@ make_lispy_event (struct input_event *event)
 	return list3 (head, position, files);
       }
 
+    case TOUCH_SCROLL_EVENT:
+      {
+	Lisp_Object position;
+	Lisp_Object head;
+        Lisp_Object deltas = event->arg;
+	struct frame *f = XFRAME (event->frame_or_window);
+
+	/* Ignore touch events that were made on frame that have
+	   been deleted.  */
+	if (! FRAME_LIVE_P (f))
+	  return Qnil;
+
+	position = make_lispy_position (f, event->x, event->y,
+					event->timestamp);
+
+        head = modify_event_symbol (0, event->modifiers, Qtouch_scroll, Qnil,
+                                    touch_names, &touch_syms, ASIZE (touch_syms));
+
+        return list3 (head, position, deltas);
+      }
+
+    case TOUCH_PINCH_EVENT:
+      {
+	Lisp_Object position;
+	Lisp_Object head;
+        Lisp_Object delta = event->arg;
+	struct frame *f = XFRAME (event->frame_or_window);
+
+	/* Ignore touch events that were made on frame that have
+	   been deleted.  */
+	if (! FRAME_LIVE_P (f))
+	  return Qnil;
+
+	position = make_lispy_position (f, event->x, event->y,
+					event->timestamp);
+
+        head = modify_event_symbol (1, event->modifiers, Qtouch_pinch, Qnil,
+                                    touch_names, &touch_syms, ASIZE (touch_syms));
+
+        return list3 (head, position, delta);
+      }
+
 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
     || defined (HAVE_NS) || defined (USE_GTK)
     case MENU_BAR_EVENT:
@@ -11054,6 +11103,14 @@ syms_of_keyboard (void)
   /* The values of Qevent_kind properties.  */
   DEFSYM (Qmouse_click, "mouse-click");
 
+  DEFSYM (Qtouch_scroll, "touch-scroll");
+  DEFSYM (Qtouch_pinch, "touch-pinch");
+  DEFSYM (Qtouch_rotate, "touch-rotate");
+  DEFSYM (Qtouch_swipe_up, "touch-swipe-up");
+  DEFSYM (Qtouch_swipe_down, "touch-swipe-down");
+  DEFSYM (Qtouch_swipe_left, "touch-swipe-left");
+  DEFSYM (Qtouch_swipe_right, "touch-swipe-right");
+
   DEFSYM (Qdrag_n_drop, "drag-n-drop");
   DEFSYM (Qsave_session, "save-session");
   DEFSYM (Qconfig_changed_event, "config-changed-event");
@@ -11190,6 +11247,8 @@ syms_of_keyboard (void)
   wheel_syms = Fmake_vector (make_number (ARRAYELTS (lispy_wheel_names)),
 			     Qnil);
   staticpro (&wheel_syms);
+  touch_syms = Fmake_vector (make_number (6), Qnil);
+  staticpro (&touch_syms);
 
   {
     int i;
diff --git a/src/nsterm.m b/src/nsterm.m
index bf83550b3d..00dc286feb 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -6392,24 +6392,36 @@ - (void)mouseDown: (NSEvent *)theEvent
 
   if ([theEvent type] == NSEventTypeScrollWheel)
     {
-      CGFloat delta = [theEvent deltaY];
-      /* Mac notebooks send wheel events w/delta =0 when trackpad scrolling */
-      if (delta == 0)
+      if ([theEvent hasPreciseScrollingDeltas])
         {
-          delta = [theEvent deltaX];
+          Lisp_Object dx, dy;
+          XSETINT (dx, [theEvent scrollingDeltaX]);
+          XSETINT (dy, [theEvent scrollingDeltaY]);
+
+          emacs_event->kind = TOUCH_SCROLL_EVENT;
+          emacs_event->arg = list2 (dx, dy);
+        }
+      else
+        {
+          CGFloat delta = [theEvent deltaY];
+          /* Mac notebooks send wheel events w/delta =0 when trackpad scrolling */
           if (delta == 0)
             {
-              NSTRACE_MSG ("deltaIsZero");
-              return;
+              delta = [theEvent deltaX];
+              if (delta == 0)
+                {
+                  NSTRACE_MSG ("deltaIsZero");
+                  return;
+                }
+              emacs_event->kind = HORIZ_WHEEL_EVENT;
             }
-          emacs_event->kind = HORIZ_WHEEL_EVENT;
-        }
-      else
-        emacs_event->kind = WHEEL_EVENT;
+          else
+            emacs_event->kind = WHEEL_EVENT;
 
-      emacs_event->code = 0;
-      emacs_event->modifiers = EV_MODIFIERS (theEvent) |
-        ((delta > 0) ? up_modifier : down_modifier);
+          emacs_event->code = 0;
+          emacs_event->modifiers = EV_MODIFIERS (theEvent) |
+            ((delta > 0) ? up_modifier : down_modifier);
+        }
     }
   else
     {
@@ -6555,6 +6567,34 @@ - (void)otherMouseDragged: (NSEvent *)e
 }
 
 
+- (void)magnifyWithEvent: (NSEvent *) e
+{
+  struct ns_display_info *dpyinfo = FRAME_DISPLAY_INFO (emacsframe);
+  NSPoint p = [self convertPoint: [e locationInWindow] fromView: nil];
+  Lisp_Object delta;
+
+  NSTRACE ("[EmacsView magnifyWithEvent:]");
+
+  [self deleteWorkingText];
+
+  if (!emacs_event)
+    return;
+
+  dpyinfo->last_mouse_frame = emacsframe;
+
+  XSETINT (delta, (int)([e magnification] * 100));
+
+  emacs_event->kind = TOUCH_PINCH_EVENT;
+  emacs_event->arg = delta;
+  emacs_event->modifiers = EV_MODIFIERS (e)
+    | EV_UDMODIFIERS (e);
+
+  XSETINT (emacs_event->x, lrint (p.x));
+  XSETINT (emacs_event->y, lrint (p.y));
+  EV_TRAILER (e);
+}
+
+
 - (BOOL)windowShouldClose: (id)sender
 {
   NSEvent *e =[[self window] currentEvent];
diff --git a/src/termhooks.h b/src/termhooks.h
index 14ec397346..07894c8154 100644
--- a/src/termhooks.h
+++ b/src/termhooks.h
@@ -120,6 +120,10 @@ enum event_kind
   HORIZ_WHEEL_EVENT,            /* A wheel event generated by a second
                                    horizontal wheel that is present on some
                                    mice. See WHEEL_EVENT.  */
+  TOUCH_SCROLL_EVENT,           /* A touchpad scroll event.  */
+  TOUCH_PINCH_EVENT,
+  TOUCH_SWIPE_EVENT,
+  TOUCH_ROTATE_EVENT,
 #ifdef HAVE_NTGUI
   LANGUAGE_CHANGE_EVENT,	/* A LANGUAGE_CHANGE_EVENT is
 				   generated when HAVE_NTGUI or on Mac OS
-- 
2.12.0


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: Touch events
  2017-06-24  8:53 Touch events Alan Third
@ 2017-06-24  9:33 ` martin rudalics
  2017-06-24  9:58   ` Alan Third
  2017-06-24 13:18 ` Clément Pit-Claudel
  2017-06-26 10:08 ` Anders Lindgren
  2 siblings, 1 reply; 24+ messages in thread
From: martin rudalics @ 2017-06-24  9:33 UTC (permalink / raw)
  To: Alan Third, Emacs-Devel devel

 > BTW, how do you create a lisp float from C?

Try make_float.

martin



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: Touch events
  2017-06-24  9:33 ` martin rudalics
@ 2017-06-24  9:58   ` Alan Third
  0 siblings, 0 replies; 24+ messages in thread
From: Alan Third @ 2017-06-24  9:58 UTC (permalink / raw)
  To: martin rudalics; +Cc: Emacs-Devel devel

On Sat, Jun 24, 2017 at 11:33:32AM +0200, martin rudalics wrote:
> > BTW, how do you create a lisp float from C?
> 
> Try make_float.

Thanks! That makes the text scaling a bit nicer.
-- 
Alan Third



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: Touch events
  2017-06-24  8:53 Touch events Alan Third
  2017-06-24  9:33 ` martin rudalics
@ 2017-06-24 13:18 ` Clément Pit-Claudel
  2017-06-24 17:00   ` Lars Ingebrigtsen
  2017-06-26 10:08 ` Anders Lindgren
  2 siblings, 1 reply; 24+ messages in thread
From: Clément Pit-Claudel @ 2017-06-24 13:18 UTC (permalink / raw)
  To: emacs-devel

On 2017-06-24 04:53, Alan Third wrote:
> I wanted to know if I’m going about this the right way, or if it’s
> even worth my while continuing.

I don't know about the first part. But for the second one: yes!
This looks great; thanks a lot for working on it (a nice benchmark for its generality would be how much of strokes-mode it can replace, btw).

Clément.



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: Touch events
  2017-06-24 13:18 ` Clément Pit-Claudel
@ 2017-06-24 17:00   ` Lars Ingebrigtsen
  2017-06-24 23:22     ` Alan Third
  0 siblings, 1 reply; 24+ messages in thread
From: Lars Ingebrigtsen @ 2017-06-24 17:00 UTC (permalink / raw)
  To: Clément Pit-Claudel; +Cc: emacs-devel

Clément Pit-Claudel <cpitclaudel@gmail.com> writes:

> On 2017-06-24 04:53, Alan Third wrote:
>> I wanted to know if I’m going about this the right way, or if it’s
>> even worth my while continuing.
>
> I don't know about the first part. But for the second one: yes!

Let me concur (on both of those points).  I'd love to get proper support
for touch events in Emacs.  For my touchey devices I currently have to
use a brittle series of external programs to translate touch events to
stuff Emacs can understand, and that's all rather boring.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: Touch events
  2017-06-24 17:00   ` Lars Ingebrigtsen
@ 2017-06-24 23:22     ` Alan Third
  2017-06-24 23:43       ` Clément Pit-Claudel
  0 siblings, 1 reply; 24+ messages in thread
From: Alan Third @ 2017-06-24 23:22 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: Clément Pit-Claudel, emacs-devel

On Sat, Jun 24, 2017 at 07:00:09PM +0200, Lars Ingebrigtsen wrote:
> Clément Pit-Claudel <cpitclaudel@gmail.com> writes:
> 
> > On 2017-06-24 04:53, Alan Third wrote:
> >> I wanted to know if I’m going about this the right way, or if it’s
> >> even worth my while continuing.
> >
> > I don't know about the first part. But for the second one: yes!
> 
> Let me concur (on both of those points).  I'd love to get proper support
> for touch events in Emacs.  For my touchey devices I currently have to
> use a brittle series of external programs to translate touch events to
> stuff Emacs can understand, and that's all rather boring.

Currently I’m only implementing the basic multitouch gestures that all
the systems seem to share:

  - scroll/pan
  - swipe
  - pinch
  - rotate

I could pass on *all* touch events, not just gestures, but I’m worried
it will result in a deluge of ‘<touch-event> is undefined’ messages
whenever the touchpad/touchscreen is used. Passing on all touch events
might be what’s needed to work up a touch version of strokes.el,
though.

(I think swipe may be a touch‐screen only thing as I can’t get it to
work using my touchpad, it just seems to result in scrolling. Or maybe
it’s just not what I think it is.)

-- 
Alan Third



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: Touch events
  2017-06-24 23:22     ` Alan Third
@ 2017-06-24 23:43       ` Clément Pit-Claudel
  2017-06-25  0:04         ` Lars Ingebrigtsen
  2017-06-25 19:22         ` Stefan Monnier
  0 siblings, 2 replies; 24+ messages in thread
From: Clément Pit-Claudel @ 2017-06-24 23:43 UTC (permalink / raw)
  To: Alan Third, Lars Ingebrigtsen; +Cc: emacs-devel

On 2017-06-24 19:22, Alan Third wrote:
> I could pass on *all* touch events, not just gestures, but I’m worried
> it will result in a deluge of ‘<touch-event> is undefined’ messages
> whenever the touchpad/touchscreen is used.

Would binding these events to #'ignored in the global map work?

Clément.



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: Touch events
  2017-06-24 23:43       ` Clément Pit-Claudel
@ 2017-06-25  0:04         ` Lars Ingebrigtsen
  2017-06-25 10:40           ` Alan Third
  2017-06-25 19:22         ` Stefan Monnier
  1 sibling, 1 reply; 24+ messages in thread
From: Lars Ingebrigtsen @ 2017-06-25  0:04 UTC (permalink / raw)
  To: Clément Pit-Claudel; +Cc: Alan Third, emacs-devel

Clément Pit-Claudel <cpitclaudel@gmail.com> writes:

> Would binding these events to #'ignored in the global map work?

Doing something like that would be right thing, I think.  We want to be
able to react to events like "three fingered swipe to the left", but
there should be no errors if nothing has bound that event.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: Touch events
  2017-06-25  0:04         ` Lars Ingebrigtsen
@ 2017-06-25 10:40           ` Alan Third
  2017-06-25 16:56             ` Clément Pit-Claudel
  0 siblings, 1 reply; 24+ messages in thread
From: Alan Third @ 2017-06-25 10:40 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: Clément Pit-Claudel, emacs-devel

On Sun, Jun 25, 2017 at 02:04:54AM +0200, Lars Ingebrigtsen wrote:
> Clément Pit-Claudel <cpitclaudel@gmail.com> writes:
> 
> > Would binding these events to #'ignored in the global map work?
> 
> Doing something like that would be right thing, I think.  We want to be
> able to react to events like "three fingered swipe to the left", but
> there should be no errors if nothing has bound that event.

It’s good to know we can do that.

I’ve had a look, though, and while macOS lets me access the full range
of touch events, GTK3 doesn’t seem to. I don’t know anything about it
really, so it may be possible to grab them directly from XOrg, which,
again, I know nothing about.

And I’ve not even looked at MS Windows—I don’t have a Windows build
environment.

So, anyway, I’ll try to get the gestures working in NS and at least
one Free platform (probably GTK3 unless someone else fancies giving it
a go), and then I’ll see where we can go from there.

-- 
Alan Third



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: Touch events
  2017-06-25 10:40           ` Alan Third
@ 2017-06-25 16:56             ` Clément Pit-Claudel
  2017-06-25 17:04               ` Noam Postavsky
  2017-06-25 17:10               ` martin rudalics
  0 siblings, 2 replies; 24+ messages in thread
From: Clément Pit-Claudel @ 2017-06-25 16:56 UTC (permalink / raw)
  To: Alan Third, Lars Ingebrigtsen; +Cc: emacs-devel

On 2017-06-25 06:40, Alan Third wrote:
> So, anyway, I’ll try to get the gestures working in NS and at least
> one Free platform (probably GTK3 unless someone else fancies giving it
> a go), and then I’ll see where we can go from there.

Thanks for your work! This is a very exciting development.

One question: currently, Emacs doesn't expose mouse motion events.  The code/docs say that it's because it generates too many events, but there are legitimate uses for that (such as showing info in the echo area or the modeline when the pointer is above a particular screen region).

The only trick I know of is to use show-help-function, which requires jumping through a bunch of annoying hoops.  Maybe now is a good time to add an option to propagate these events to lisp? Maybe there should be a high-frequency-events list of symbols that includes which events should be propagated to Lisp? One pour (add-to-list 'high-frequency-events 'mouse-motion) to enable them, for example.

Cheers,
Clément.



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: Touch events
  2017-06-25 16:56             ` Clément Pit-Claudel
@ 2017-06-25 17:04               ` Noam Postavsky
  2017-06-25 17:10               ` martin rudalics
  1 sibling, 0 replies; 24+ messages in thread
From: Noam Postavsky @ 2017-06-25 17:04 UTC (permalink / raw)
  To: Clément Pit-Claudel; +Cc: Alan Third, Lars Ingebrigtsen, Emacs developers

On Sun, Jun 25, 2017 at 12:56 PM, Clément Pit-Claudel
<cpitclaudel@gmail.com> wrote:

> One question: currently, Emacs doesn't expose mouse motion events.  The code/docs say that it's because it generates too many events, but there are legitimate uses for that (such as showing info in the echo area or the modeline when the pointer is above a particular screen region).
>
> The only trick I know of is to use show-help-function, which requires jumping through a bunch of annoying hoops.  Maybe now is a good time to add an option to propagate these events to lisp? Maybe there should be a high-frequency-events list of symbols that includes which events should be propagated to Lisp? One pour (add-to-list 'high-frequency-events 'mouse-motion) to enable them, for example.

Perhaps you are looking for `track-mouse'?



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: Touch events
  2017-06-25 16:56             ` Clément Pit-Claudel
  2017-06-25 17:04               ` Noam Postavsky
@ 2017-06-25 17:10               ` martin rudalics
  2017-06-25 18:09                 ` Clément Pit-Claudel
  1 sibling, 1 reply; 24+ messages in thread
From: martin rudalics @ 2017-06-25 17:10 UTC (permalink / raw)
  To: Clément Pit-Claudel, Alan Third, Lars Ingebrigtsen; +Cc: emacs-devel

 > The only trick I know of is to use show-help-function, which requires
 > jumping through a bunch of annoying hoops.  Maybe now is a good time
 > to add an option to propagate these events to lisp? Maybe there should
 > be a high-frequency-events list of symbols that includes which events
 > should be propagated to Lisp? One pour (add-to-list
 > 'high-frequency-events 'mouse-motion) to enable them, for example.

Why can't you use ‘track-mouse’ for that?  Disregarding the fact that
movements below the smallest character size will not be propagated by
e.g. XTmouse_position anyway.

martin




^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: Touch events
  2017-06-25 17:10               ` martin rudalics
@ 2017-06-25 18:09                 ` Clément Pit-Claudel
  0 siblings, 0 replies; 24+ messages in thread
From: Clément Pit-Claudel @ 2017-06-25 18:09 UTC (permalink / raw)
  To: martin rudalics, Alan Third, Lars Ingebrigtsen; +Cc: emacs-devel

On 2017-06-25 13:10, martin rudalics wrote:
>> The only trick I know of is to use show-help-function, which requires
>> jumping through a bunch of annoying hoops.  Maybe now is a good time
>> to add an option to propagate these events to lisp? Maybe there should
>> be a high-frequency-events list of symbols that includes which events
>> should be propagated to Lisp? One pour (add-to-list
>> 'high-frequency-events 'mouse-motion) to enable them, for example.
> 
> Why can't you use ‘track-mouse’ for that?  Disregarding the fact that
> movements below the smallest character size will not be propagated by
> e.g. XTmouse_position anyway.

I wasn't aware of that variable :)
Thanks!



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: Touch events
  2017-06-24 23:43       ` Clément Pit-Claudel
  2017-06-25  0:04         ` Lars Ingebrigtsen
@ 2017-06-25 19:22         ` Stefan Monnier
  1 sibling, 0 replies; 24+ messages in thread
From: Stefan Monnier @ 2017-06-25 19:22 UTC (permalink / raw)
  To: emacs-devel

>> I could pass on *all* touch events, not just gestures, but I’m worried
>> it will result in a deluge of ‘<touch-event> is undefined’ messages
>> whenever the touchpad/touchscreen is used.
> Would binding these events to #'ignored in the global map work?

No need for that: just use function-key-map to translate [touch-event]
to [] (and this will only happen when there's no binding using
touch-event).


        Stefan




^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: Touch events
  2017-06-24  8:53 Touch events Alan Third
  2017-06-24  9:33 ` martin rudalics
  2017-06-24 13:18 ` Clément Pit-Claudel
@ 2017-06-26 10:08 ` Anders Lindgren
  2017-06-26 18:28   ` Alan Third
  2017-06-27 20:08   ` Alan Third
  2 siblings, 2 replies; 24+ messages in thread
From: Anders Lindgren @ 2017-06-26 10:08 UTC (permalink / raw)
  To: Alan Third; +Cc: Emacs-Devel devel

[-- Attachment #1: Type: text/plain, Size: 1777 bytes --]

Hi!

This looks great, I just can't wait to start using it! I can imagine a
number of uses for it already -- I would like to bind zoom and pinch to
show and hide documentation.

Anyway, the "mac" port, maintained by YAMAMOTO Mitsuharu have had support
for this for some time. It uses the names `swipe-left/right/up/down',
`magnify-up/down', and `rotate-left/right' -- I guess it would be a good
idea for us to use the same names and conventions, to avoid confusing users.

    -- Anders

On Sat, Jun 24, 2017 at 10:53 AM, Alan Third <alan@idiocy.org> wrote:

> I’ve created a small patch that adds some touch event handling to
> Emacs. Currently it only works on macOS, but the same functionality is
> available on GTK3, MS Windows and vanilla Xorg.
>
> I wanted to know if I’m going about this the right way, or if it’s
> even worth my while continuing.
>
> I’ve created a number of new events: touch-scroll, touch-pinch, etc.,
> that can be bound to functions. I’ve attached a simple script that
> binds touch-pinch to the text-scale-increase/decrease functions.
>
> BTW, how do you create a lisp float from C? I tried something like
>
>     Lisp_Object delta;
>     XSETFLOAT (delta, [event magnification]);
>
> but it just complains that [event magnification] returns a double and
> not void *.
>
> NOTE: If you install this patch, scrolling with the touchpad will no
> longer work on macOS (a real mousewheel will be fine, though). It
> needs some effort to get it working, and my elisp skills aren’t up to
> much. It either needs a compatibility function in lisp, or a way to
> disable it and use the existing mousewheel code. It could be worth
> trying to tie it into the new pixel scroll mode.
> --
> Alan Third
>

[-- Attachment #2: Type: text/html, Size: 2271 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: Touch events
  2017-06-26 10:08 ` Anders Lindgren
@ 2017-06-26 18:28   ` Alan Third
  2017-06-28  8:25     ` John Wiegley
  2017-06-27 20:08   ` Alan Third
  1 sibling, 1 reply; 24+ messages in thread
From: Alan Third @ 2017-06-26 18:28 UTC (permalink / raw)
  To: Anders Lindgren; +Cc: Emacs-Devel devel

On Mon, Jun 26, 2017 at 12:08:12PM +0200, Anders Lindgren wrote:
> Anyway, the "mac" port, maintained by YAMAMOTO Mitsuharu have had support
> for this for some time. It uses the names `swipe-left/right/up/down',
> `magnify-up/down', and `rotate-left/right' -- I guess it would be a good
> idea for us to use the same names and conventions, to avoid confusing users.

Drat! Wish I’d known about this before. I’ve completed that part of the
code and have gone in a quite different direction. I suppose it
wouldn’t be too much work to go back and change it.

I not too sure about the event names, though. Magnify in particular is
an Apple specific term, afaik.

What I’ve done so far is available on scratch/touch, if anyone wants a look.
-- 
Alan Third



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: Touch events
  2017-06-26 10:08 ` Anders Lindgren
  2017-06-26 18:28   ` Alan Third
@ 2017-06-27 20:08   ` Alan Third
  2017-06-28  9:40     ` Anders Lindgren
  1 sibling, 1 reply; 24+ messages in thread
From: Alan Third @ 2017-06-27 20:08 UTC (permalink / raw)
  To: Anders Lindgren; +Cc: Emacs-Devel devel

On Mon, Jun 26, 2017 at 12:08:12PM +0200, Anders Lindgren wrote:
> Anyway, the "mac" port, maintained by YAMAMOTO Mitsuharu have had support
> for this for some time. It uses the names `swipe-left/right/up/down',
> `magnify-up/down', and `rotate-left/right' -- I guess it would be a good
> idea for us to use the same names and conventions, to avoid confusing users.

I’ve just pushed a change to use these event names to scratch/touch.

I’ve kept a separate ‘touch-scroll’ event as the mac port just embeds
that into the mouse-wheel events, but I feel there’s an argument to be
made that they should be handled differently.

If anyone feels otherwise, please let me know.
-- 
Alan Third



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: Touch events
  2017-06-26 18:28   ` Alan Third
@ 2017-06-28  8:25     ` John Wiegley
  2017-06-28 15:14       ` raman
  0 siblings, 1 reply; 24+ messages in thread
From: John Wiegley @ 2017-06-28  8:25 UTC (permalink / raw)
  To: Alan Third; +Cc: Anders Lindgren, Emacs-Devel devel

>>>>> "AT" == Alan Third <alan@idiocy.org> writes:

AT> I not too sure about the event names, though. Magnify in particular is an
AT> Apple specific term, afaik.

As much as I appreciate Yamamoto-san's forward thinking on this feature, I
wouldn't feel compelled to maintain a similar nomeclature. Pick whatever you
feel would best suit a GNU project running on a GNU system.

-- 
John Wiegley                  GPG fingerprint = 4710 CF98 AF9B 327B B80F
http://newartisans.com                          60E1 46C4 BD1A 7AC1 4BA2



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: Touch events
  2017-06-27 20:08   ` Alan Third
@ 2017-06-28  9:40     ` Anders Lindgren
  2017-06-28 17:23       ` James Nguyen
  2017-06-28 21:06       ` Alan Third
  0 siblings, 2 replies; 24+ messages in thread
From: Anders Lindgren @ 2017-06-28  9:40 UTC (permalink / raw)
  To: Alan Third; +Cc: Emacs-Devel devel

[-- Attachment #1: Type: text/plain, Size: 1137 bytes --]

>
> I’ve kept a separate ‘touch-scroll’ event as the mac port just embeds
> that into the mouse-wheel events, but I feel there’s an argument to be
> made that they should be handled differently.
>

One thing that has annoyed me with the existing mouse-wheel events is that
macOS sends implements a kind of inertia, resulting is a sequence of events
a few seconds after I've stopped scrolling. Furthermore, if I have pressed,
say, shift while scrolling and release the shift key while the extra events
are arriving, the remaning events are treated as though they were
unshifted, possibly executing a different Emacs command.

It would be good to be able to get a single event for swipe commands (even
though the inertia is useful for some commands).

    -- Anders

Ps. In the package https://github.com/Lindydancer/multicolumn I've
implemented support for moving to next/prev/first/last window using
horizontal swipes. To get around the extra events passed by the macOS, I'm
using timers to silence scroll events for a while after a command has been
handled, which clearly isn't a good technical solution.

[-- Attachment #2: Type: text/html, Size: 1508 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: Touch events
  2017-06-28  8:25     ` John Wiegley
@ 2017-06-28 15:14       ` raman
  2017-06-28 20:50         ` Alan Third
  0 siblings, 1 reply; 24+ messages in thread
From: raman @ 2017-06-28 15:14 UTC (permalink / raw)
  To: Alan Third; +Cc: Anders Lindgren, Emacs-Devel devel

John Wiegley <jwiegley@gmail.com> writes:


Also it would be nice to think ahead and build something that works on
tablets and phones, AKA keyboardless devices. 

Emacs on those devices in turn might well offer an interesting
experimental platform for testing out different touch input mechanisms
---  given Emacs' long history of smart completion across different contexts.

>>>>>> "AT" == Alan Third <alan@idiocy.org> writes:
>
> AT> I not too sure about the event names, though. Magnify in particular is an
> AT> Apple specific term, afaik.
>
> As much as I appreciate Yamamoto-san's forward thinking on this feature, I
> wouldn't feel compelled to maintain a similar nomeclature. Pick whatever you
> feel would best suit a GNU project running on a GNU system.

-- 



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: Touch events
  2017-06-28  9:40     ` Anders Lindgren
@ 2017-06-28 17:23       ` James Nguyen
  2017-06-28 21:06       ` Alan Third
  1 sibling, 0 replies; 24+ messages in thread
From: James Nguyen @ 2017-06-28 17:23 UTC (permalink / raw)
  To: Anders Lindgren; +Cc: Alan Third, Emacs-Devel devel

[-- Attachment #1: Type: text/plain, Size: 1456 bytes --]

+1, I’ve noticed that too (especially with the pixel-scroll-mode on OSX). The extra inertia from scrolling causes Emacs to scroll up/down uncontrollably for 300-400 ms after every scroll.

> On Jun 28, 2017, at 2:40 AM, Anders Lindgren <andlind@gmail.com> wrote:
> 
> I’ve kept a separate ‘touch-scroll’ event as the mac port just embeds
> that into the mouse-wheel events, but I feel there’s an argument to be
> made that they should be handled differently.
> 
> One thing that has annoyed me with the existing mouse-wheel events is that macOS sends implements a kind of inertia, resulting is a sequence of events a few seconds after I've stopped scrolling. Furthermore, if I have pressed, say, shift while scrolling and release the shift key while the extra events are arriving, the remaning events are treated as though they were unshifted, possibly executing a different Emacs command.
> 
> It would be good to be able to get a single event for swipe commands (even though the inertia is useful for some commands).
> 
>     -- Anders
> 
> Ps. In the package https://github.com/Lindydancer/multicolumn <https://github.com/Lindydancer/multicolumn> I've implemented support for moving to next/prev/first/last window using horizontal swipes. To get around the extra events passed by the macOS, I'm using timers to silence scroll events for a while after a command has been handled, which clearly isn't a good technical solution.


[-- Attachment #2: Type: text/html, Size: 2362 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: Touch events
  2017-06-28 15:14       ` raman
@ 2017-06-28 20:50         ` Alan Third
  2017-09-03  9:14           ` Alan Third
  0 siblings, 1 reply; 24+ messages in thread
From: Alan Third @ 2017-06-28 20:50 UTC (permalink / raw)
  To: raman; +Cc: Anders Lindgren, Emacs-Devel devel

On Wed, Jun 28, 2017 at 08:14:33AM -0700, raman wrote:
> Also it would be nice to think ahead and build something that works on
> tablets and phones, AKA keyboardless devices. 
> 
> Emacs on those devices in turn might well offer an interesting
> experimental platform for testing out different touch input mechanisms
> ---  given Emacs' long history of smart completion across different contexts.

I’ve been looking into the Xorg side of touch events and it doesn’t
have built‐in gesture support, so I think I’ll have to code that
myself. I was thinking it could maybe be worth passing the touch
events up to lisp and doing gesture recognition in it. That would, I
think, also allow us to handle touch screen devices better as we
wouldn’t have to rely on mouse emulation.

The downside is that my lisp skills are woeful and on platforms where
touch gestures ARE available, we might end up with differing behaviour
from native apps.

The best of both worlds would be if we’re able to fire off input
events from within lisp code, which would let us transparently emulate
system touch gestures where they’re not available, while still having
access to all touch events. I don’t know if that’s possible.

The other option, I suppose, is to pass gesture events from C, and
also pass the basic touch events to lisp. That might be easier.

I need to build an Xorg dev system and try digging into this stuff.
-- 
Alan Third



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: Touch events
  2017-06-28  9:40     ` Anders Lindgren
  2017-06-28 17:23       ` James Nguyen
@ 2017-06-28 21:06       ` Alan Third
  1 sibling, 0 replies; 24+ messages in thread
From: Alan Third @ 2017-06-28 21:06 UTC (permalink / raw)
  To: Anders Lindgren; +Cc: Emacs-Devel devel

On Wed, Jun 28, 2017 at 11:40:13AM +0200, Anders Lindgren wrote:
> >
> > I’ve kept a separate ‘touch-scroll’ event as the mac port just embeds
> > that into the mouse-wheel events, but I feel there’s an argument to be
> > made that they should be handled differently.
> >
> 
> One thing that has annoyed me with the existing mouse-wheel events is that
> macOS sends implements a kind of inertia, resulting is a sequence of events
> a few seconds after I've stopped scrolling. Furthermore, if I have pressed,
> say, shift while scrolling and release the shift key while the extra events
> are arriving, the remaning events are treated as though they were
> unshifted, possibly executing a different Emacs command.

What makes scrolling with the trackpad on macOS so awkward is that
Cocoa is expecting the application to implement smooth scrolling, so
it sends events at a fairly high frequency. These events have pixel
based deltas, which are very often less than one line‐height.

Emacs sends one wheel up/down event per NS event, which results in far
more scrolling than expected.

The correct way to handle it is to add up the deltas until they exceed
one line‐height, and then scroll the relevant number of lines. I’ve
tried to implement something like that in lisp/touch.el in the
scratch/touch branch.

The other part of this is momentum. We should probably add a
customisation option to ignore events from the momentum phase. I
wouldn’t want to always ignore them, because people might expect Emacs
to scroll the same as other macOS apps. Especially if pixel scrolling
is available.

> It would be good to be able to get a single event for swipe commands (even
> though the inertia is useful for some commands).
>
> Ps. In the package https://github.com/Lindydancer/multicolumn I've
> implemented support for moving to next/prev/first/last window using
> horizontal swipes. To get around the extra events passed by the macOS, I'm
> using timers to silence scroll events for a while after a command has been
> handled, which clearly isn't a good technical solution.

Cocoa has a ‘swipe’ gesture separate from the normal scrolling
gesture. I don’t know what the difference is as I haven’t seen the
swipe gesture events showing up in my emacs yet, and I can’t find any
description of them online. It’s possible they’re a three‐finger
gesture, which are normally intercepted by the WM. I believe you can
turn the interception off.
-- 
Alan Third



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: Touch events
  2017-06-28 20:50         ` Alan Third
@ 2017-09-03  9:14           ` Alan Third
  0 siblings, 0 replies; 24+ messages in thread
From: Alan Third @ 2017-09-03  9:14 UTC (permalink / raw)
  To: Emacs-Devel devel

On Wed, Jun 28, 2017 at 09:50:27PM +0100, Alan Third wrote:
> I’ve been looking into the Xorg side of touch events and it doesn’t
> have built‐in gesture support, so I think I’ll have to code that
> myself. I was thinking it could maybe be worth passing the touch
> events up to lisp and doing gesture recognition in it. That would, I
> think, also allow us to handle touch screen devices better as we
> wouldn’t have to rely on mouse emulation.

I finally got round to looking at this properly and have very quickly
realised it’s probably beyond me. In order to receive touch events we
need to migrate to XInput2, which seems to be completely different
from XInput1.

I don’t know how much work would be involved as I have no experience
with X programming, but I suspect it’s quite a lot.

I also don’t know if it would introduce compatibility issues with
older versions of X.
-- 
Alan Third



^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2017-09-03  9:14 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-24  8:53 Touch events Alan Third
2017-06-24  9:33 ` martin rudalics
2017-06-24  9:58   ` Alan Third
2017-06-24 13:18 ` Clément Pit-Claudel
2017-06-24 17:00   ` Lars Ingebrigtsen
2017-06-24 23:22     ` Alan Third
2017-06-24 23:43       ` Clément Pit-Claudel
2017-06-25  0:04         ` Lars Ingebrigtsen
2017-06-25 10:40           ` Alan Third
2017-06-25 16:56             ` Clément Pit-Claudel
2017-06-25 17:04               ` Noam Postavsky
2017-06-25 17:10               ` martin rudalics
2017-06-25 18:09                 ` Clément Pit-Claudel
2017-06-25 19:22         ` Stefan Monnier
2017-06-26 10:08 ` Anders Lindgren
2017-06-26 18:28   ` Alan Third
2017-06-28  8:25     ` John Wiegley
2017-06-28 15:14       ` raman
2017-06-28 20:50         ` Alan Third
2017-09-03  9:14           ` Alan Third
2017-06-27 20:08   ` Alan Third
2017-06-28  9:40     ` Anders Lindgren
2017-06-28 17:23       ` James Nguyen
2017-06-28 21:06       ` Alan Third

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).