From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alan Third Newsgroups: gmane.emacs.devel Subject: Touch events Date: Sat, 24 Jun 2017 09:53:35 +0100 Message-ID: <20170624085335.GA10629@breton.holly.idiocy.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="mYCpIKhGyMATD0i+" Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1498294439 19052 195.159.176.226 (24 Jun 2017 08:53:59 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 24 Jun 2017 08:53:59 +0000 (UTC) User-Agent: Mutt/1.7.2 (2016-11-26) To: Emacs-Devel devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jun 24 10:53:53 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dOgpE-0004by-En for ged-emacs-devel@m.gmane.org; Sat, 24 Jun 2017 10:53:52 +0200 Original-Received: from localhost ([::1]:38613 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dOgpJ-00033g-9z for ged-emacs-devel@m.gmane.org; Sat, 24 Jun 2017 04:53:57 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40785) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dOgp6-00032I-1C for emacs-devel@gnu.org; Sat, 24 Jun 2017 04:53:45 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dOgp4-0004sr-8g for emacs-devel@gnu.org; Sat, 24 Jun 2017 04:53:44 -0400 Original-Received: from mail-wr0-x22c.google.com ([2a00:1450:400c:c0c::22c]:34646) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dOgp3-0004sA-TR for emacs-devel@gnu.org; Sat, 24 Jun 2017 04:53:42 -0400 Original-Received: by mail-wr0-x22c.google.com with SMTP id 77so92826016wrb.1 for ; Sat, 24 Jun 2017 01:53:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=sender:date:from:to:subject:message-id:mime-version :content-disposition:content-transfer-encoding:user-agent; bh=l65r4Q3MfN6Xaekv1+C63DX6Xhgiq4t/0SYtGiN70+I=; b=khmbjlz5fC+qhylaSFsfvAmkV/6ChyZVUgMTvzTnlrvD7ZAUn1fahwxOHGQosF8eFP uODYIf02ASnzDx469cyJp+LvpbUhlK3HD7bEsPiT7+NCwQ8YxrdnPg5zy9i+E8654DMj lFYHLTxQ92l6Eahm6eL+yjnN8AGg5lGfq85jAL3ku5gCm+kwrZxePk8uU9vqtheBXrjD E63bE3pJrPw0g5ic3rU0+7mka+/n1ymYLLQSmpfrD5nnzgKqAfvzYlJzQ2NnkxnTOcaE CJZRpsLjUGCf62ix8PpWEv/n7KAN5UL1UlA+5mnqlvVg4L7VecR9SQiSLhxOJDbsZCHM rzBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:subject:message-id :mime-version:content-disposition:content-transfer-encoding :user-agent; bh=l65r4Q3MfN6Xaekv1+C63DX6Xhgiq4t/0SYtGiN70+I=; b=LHEAn7j0Lb213XQYQ1yXhQ4eSH3sjX6lHemPAxPOm4TY6BlxvS1VHDw0GZDvIsznzi bKQ+6cJ4fC5ja/mY6BhHOUYNToi+YvVl4Ru+jSXXoSTm3TDJDFsJ+sRfZUMW4m72FEV0 J533/LbaDbuNWAOOCHpixWSnppN1kwODqS8xoYnEXfTmVLrcr/8+L4y3Vt7ndybkrwJP RL9lwuM/8OFIOVP+tv3SOBpnIpTNRLi7MLLpUM96u9mhBQN1pU8dZHxTf8h6E5aQoyGl 1VXP6Dx/6l6pZpH6XmzffIz1hp3K5F+LRNjd09YgFniEZEV5bHlQ+W0Ipe78UFnr9ljo umTA== X-Gm-Message-State: AKS2vOxsKNPal/ugNvZAaqVGI0jH2lpjvsIVNuiYZoYtyGIlYMw89sx7 Y35lAlRO1q2nMtHPMp4= X-Received: by 10.28.27.72 with SMTP id b69mr7740036wmb.85.1498294418771; Sat, 24 Jun 2017 01:53:38 -0700 (PDT) Original-Received: from breton.holly.idiocy.org (ip6-2001-08b0-03f8-8129-80a8-1daf-cedd-5c40.holly.idiocy.org. [2001:8b0:3f8:8129:80a8:1daf:cedd:5c40]) by smtp.gmail.com with ESMTPSA id m63sm5006356wma.18.2017.06.24.01.53.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Jun 2017 01:53:37 -0700 (PDT) Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::22c X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:215928 Archived-At: --mYCpIKhGyMATD0i+ Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit 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 --mYCpIKhGyMATD0i+ Content-Type: text/plain; charset=us-ascii Content-Description: Test functions Content-Disposition: attachment; filename="tp.el" (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) --mYCpIKhGyMATD0i+ Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0001-Add-touch-events.patch" >From 0cc26156f8f13622073488ecee647bf6a656fee8 Mon Sep 17 00:00:00 2001 From: Alan Third 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 --mYCpIKhGyMATD0i+--