>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