From f229710d41e85752bc1a835bae56c055a62813d9 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Sun, 3 Apr 2022 09:59:14 +0800 Subject: [PATCH] Implement new DND features on GNUstep * lisp/term/ns-win.el (ns-drag-n-drop): Handle special `lambda' drag-n-drop events. * src/nsterm.m: ([EmacsView wantsPeriodicDraggingUpdates]): ([EmacsView draggingUpdated:]): New functions. --- lisp/term/ns-win.el | 41 ++++++++++++++++++++++------------------- src/nsterm.m | 31 +++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 19 deletions(-) diff --git a/lisp/term/ns-win.el b/lisp/term/ns-win.el index da6c5adee22..065ca235b40 100644 --- a/lisp/term/ns-win.el +++ b/lisp/term/ns-win.el @@ -508,25 +508,28 @@ unless the current buffer is a scratch buffer." Switch to a buffer editing the last file dropped, or insert the string dropped into the current buffer." (interactive "e") - (let* ((window (posn-window (event-start event))) - (arg (car (cdr (cdr event)))) - (type (car arg)) - (operations (car (cdr arg))) - (objects (cdr (cdr arg))) - (string (mapconcat 'identity objects "\n"))) - (set-frame-selected-window nil window) - (raise-frame) - (setq window (selected-window)) - (cond ((or (memq 'ns-drag-operation-generic operations) - (memq 'ns-drag-operation-copy operations)) - ;; Perform the default/copy action. - (dolist (data objects) - (dnd-handle-one-url window 'private (if (eq type 'file) - (concat "file:" data) - data)))) - (t - ;; Insert the text as is. - (dnd-insert-text window 'private string))))) + (if (eq (car-safe (cdr-safe (cdr-safe event))) 'lambda) + (dnd-handle-movement (event-start event)) + (let* ((window (posn-window (event-start event))) + (arg (car (cdr (cdr event)))) + (type (car arg)) + (operations (car (cdr arg))) + (objects (cdr (cdr arg))) + (string (mapconcat 'identity objects "\n"))) + (set-frame-selected-window nil window) + (raise-frame) + (setq window (selected-window)) + (goto-char (posn-point (event-start event))) + (cond ((or (memq 'ns-drag-operation-generic operations) + (memq 'ns-drag-operation-copy operations)) + ;; Perform the default/copy action. + (dolist (data objects) + (dnd-handle-one-url window 'private (if (eq type 'file) + (concat "file:" data) + data)))) + (t + ;; Insert the text as is. + (dnd-insert-text window 'private string)))))) (global-set-key [drag-n-drop] 'ns-drag-n-drop) diff --git a/src/nsterm.m b/src/nsterm.m index fd56094c28b..f4c1e08925c 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -8056,6 +8056,37 @@ not_in_argv (NSString *arg) return YES; } +- (BOOL) wantsPeriodicDraggingUpdates +{ + return YES; +} + +- (NSDragOperation) draggingUpdated: (id ) sender +{ + struct input_event ie; + NSPoint position; + int x, y; + + EVENT_INIT (ie); + ie.kind = DRAG_N_DROP_EVENT; + + /* Get rid of mouse face. */ + [self mouseExited: [[self window] currentEvent]]; + + position = [self convertPoint: [sender draggingLocation] + fromView: nil]; + x = lrint (position.x); + y = lrint (position.y); + + XSETINT (ie.x, x); + XSETINT (ie.y, y); + XSETFRAME (ie.frame_or_window, emacsframe); + ie.arg = Qlambda; + ie.modifiers = 0; + + kbd_buffer_store_event (&ie); + return NSDragOperationGeneric; +} -(BOOL)performDragOperation: (id ) sender { -- 2.39.2