aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPo Lu2022-07-26 05:41:25 +0000
committerPo Lu2022-07-26 05:42:42 +0000
commit2bc6d8283189bcbbf9bceeac5013b9e41a511222 (patch)
tree85a119ef690ab01d0690c4e605dd272cf1b1fc2b
parentf6040018c5e281ee31a3e499f43f29fbf1e817e9 (diff)
downloademacs-2bc6d8283189bcbbf9bceeac5013b9e41a511222.tar.gz
emacs-2bc6d8283189bcbbf9bceeac5013b9e41a511222.zip
Handle modifiers during Haiku DND wheel movement
* lisp/term/haiku-win.el (haiku-dnd-modifier-mask) (haiku-dnd-wheel-modifier-type): New functions. (haiku-handle-drag-wheel): Use them. * lisp/x-dnd.el (x-dnd-modifier-mask): Remove outdated comment. * src/haikuselect.c (haiku_note_drag_wheel): Pass modifiers to wheel function. (syms_of_haikuselect): Update doc strings.
-rw-r--r--lisp/term/haiku-win.el62
-rw-r--r--lisp/x-dnd.el1
-rw-r--r--src/haikuselect.c13
3 files changed, 63 insertions, 13 deletions
diff --git a/lisp/term/haiku-win.el b/lisp/term/haiku-win.el
index 9d9c31970dc..a16169d477f 100644
--- a/lisp/term/haiku-win.el
+++ b/lisp/term/haiku-win.el
@@ -489,19 +489,56 @@ Return the number of clicks that were made in quick succession."
489 489
490(defvar haiku-drag-wheel-function) 490(defvar haiku-drag-wheel-function)
491 491
492(defun haiku-handle-drag-wheel (frame x y horizontal up) 492(defun haiku-dnd-modifier-mask (mods)
493 "Return the internal modifier mask for the Emacs modifier state MODS.
494MODS is a single symbol, or a list of symbols such as `shift' or
495`control'."
496 (let ((mask 0))
497 (unless (consp mods)
498 (setq mods (list mods)))
499 (dolist (modifier mods)
500 (cond ((eq modifier 'shift)
501 (setq mask (logior mask ?\S-\0)))
502 ((eq modifier 'control)
503 (setq mask (logior mask ?\C-\0)))
504 ((eq modifier 'meta)
505 (setq mask (logior mask ?\M-\0)))
506 ((eq modifier 'hyper)
507 (setq mask (logior mask ?\H-\0)))
508 ((eq modifier 'super)
509 (setq mask (logior mask ?\s-\0)))
510 ((eq modifier 'alt)
511 (setq mask (logior mask ?\A-\0)))))
512 mask))
513
514(defun haiku-dnd-wheel-modifier-type (flags)
515 "Return the modifier type of an internal modifier mask.
516FLAGS is the internal modifier mask of a turn of the mouse wheel."
517 (let ((modifiers (logior ?\M-\0 ?\C-\0 ?\S-\0
518 ?\H-\0 ?\s-\0 ?\A-\0)))
519 (catch 'type
520 (dolist (modifier mouse-wheel-scroll-amount)
521 (when (and (consp modifier)
522 (eq (haiku-dnd-modifier-mask (car modifier))
523 (logand flags modifiers)))
524 (throw 'type (cdr modifier))))
525 nil)))
526
527(defun haiku-handle-drag-wheel (frame x y horizontal up modifiers)
493 "Handle wheel movement during drag-and-drop. 528 "Handle wheel movement during drag-and-drop.
494FRAME is the frame on top of which the wheel moved. 529FRAME is the frame on top of which the wheel moved.
495X and Y are the frame-relative coordinates of the wheel movement. 530X and Y are the frame-relative coordinates of the wheel movement.
496HORIZONTAL is whether or not the wheel movement was horizontal. 531HORIZONTAL is whether or not the wheel movement was horizontal.
497UP is whether or not the wheel moved up (or left)." 532UP is whether or not the wheel moved up (or left).
533MODIFIERS is the internal modifier mask of the wheel movement."
498 (when (not (equal haiku-last-wheel-direction 534 (when (not (equal haiku-last-wheel-direction
499 (cons horizontal up))) 535 (cons horizontal up)))
500 (setq haiku-last-wheel-direction 536 (setq haiku-last-wheel-direction
501 (cons horizontal up)) 537 (cons horizontal up))
502 (when (consp haiku-dnd-wheel-count) 538 (when (consp haiku-dnd-wheel-count)
503 (setcar haiku-dnd-wheel-count 0))) 539 (setcar haiku-dnd-wheel-count 0)))
504 (let ((function (cond 540 (let ((type (haiku-dnd-wheel-modifier-type modifiers))
541 (function (cond
505 ((and (not horizontal) (not up)) 542 ((and (not horizontal) (not up))
506 mwheel-scroll-up-function) 543 mwheel-scroll-up-function)
507 ((not horizontal) 544 ((not horizontal)
@@ -512,14 +549,27 @@ UP is whether or not the wheel moved up (or left)."
512 (t (if mouse-wheel-flip-direction 549 (t (if mouse-wheel-flip-direction
513 mwheel-scroll-left-function 550 mwheel-scroll-left-function
514 mwheel-scroll-right-function)))) 551 mwheel-scroll-right-function))))
515 (timestamp (time-convert nil 1000))) 552 (timestamp (time-convert nil 1000))
553 (amt 1))
554 (cond ((and (eq type 'hscroll)
555 (not horizontal))
556 (setq function (if (not up)
557 mwheel-scroll-left-function
558 mwheel-scroll-right-function)))
559 ((and (eq type 'global-text-scale))
560 (setq function 'global-text-scale-adjust
561 amt (if up 1 -1)))
562 ((and (eq type 'text-scale))
563 (setq function 'text-scale-adjust
564 amt (if up 1 -1))))
516 (when function 565 (when function
517 (let ((posn (posn-at-x-y x y frame))) 566 (let ((posn (posn-at-x-y x y frame)))
518 (when (windowp (posn-window posn)) 567 (when (windowp (posn-window posn))
519 (with-selected-window (posn-window posn) 568 (with-selected-window (posn-window posn)
520 (funcall function 569 (funcall function
521 (or (and (not mouse-wheel-progressive-speed) 1) 570 (* amt
522 (haiku-note-wheel-click (car timestamp)))))))))) 571 (or (and (not mouse-wheel-progressive-speed) 1)
572 (haiku-note-wheel-click (car timestamp)))))))))))
523 573
524(setq haiku-drag-wheel-function #'haiku-handle-drag-wheel) 574(setq haiku-drag-wheel-function #'haiku-handle-drag-wheel)
525 575
diff --git a/lisp/x-dnd.el b/lisp/x-dnd.el
index 10fd9e5dac3..bdfe444bc1d 100644
--- a/lisp/x-dnd.el
+++ b/lisp/x-dnd.el
@@ -708,7 +708,6 @@ MODS is a single symbol, or a list of symbols such as `shift' or
708 (unless (consp mods) 708 (unless (consp mods)
709 (setq mods (list mods))) 709 (setq mods (list mods)))
710 (dolist (modifier mods) 710 (dolist (modifier mods)
711 ;; TODO: handle virtual modifiers such as Meta and Hyper.
712 (cond ((eq modifier 'shift) 711 (cond ((eq modifier 'shift)
713 (setq mask (logior mask 1))) ; ShiftMask 712 (setq mask (logior mask 1))) ; ShiftMask
714 ((eq modifier 'control) 713 ((eq modifier 'control)
diff --git a/src/haikuselect.c b/src/haikuselect.c
index 268d8b1ec92..7eb93a2754d 100644
--- a/src/haikuselect.c
+++ b/src/haikuselect.c
@@ -1062,8 +1062,9 @@ haiku_note_drag_wheel (struct input_event *ie)
1062 if (!NILP (Vhaiku_drag_wheel_function) 1062 if (!NILP (Vhaiku_drag_wheel_function)
1063 && (haiku_dnd_allow_same_frame 1063 && (haiku_dnd_allow_same_frame
1064 || XFRAME (ie->frame_or_window) != haiku_dnd_frame)) 1064 || XFRAME (ie->frame_or_window) != haiku_dnd_frame))
1065 safe_call (6, Vhaiku_drag_wheel_function, ie->frame_or_window, 1065 safe_call (7, Vhaiku_drag_wheel_function, ie->frame_or_window,
1066 ie->x, ie->y, horizontal ? Qt : Qnil, up ? Qt : Qnil); 1066 ie->x, ie->y, horizontal ? Qt : Qnil, up ? Qt : Qnil,
1067 make_int (ie->modifiers));
1067 1068
1068 redisplay_preserve_echo_area (35); 1069 redisplay_preserve_echo_area (35);
1069} 1070}
@@ -1149,12 +1150,12 @@ These are only called if a connection to the Haiku display was opened. */);
1149 1150
1150 DEFVAR_LISP ("haiku-drag-wheel-function", Vhaiku_drag_wheel_function, 1151 DEFVAR_LISP ("haiku-drag-wheel-function", Vhaiku_drag_wheel_function,
1151 doc: /* Function called upon wheel movement while dragging a message. 1152 doc: /* Function called upon wheel movement while dragging a message.
1152If non-nil, it is called with 5 arguments when the mouse wheel moves 1153If non-nil, it is called with 6 arguments when the mouse wheel moves
1153while a drag-and-drop operation is in progress: the frame where the 1154while a drag-and-drop operation is in progress: the frame where the
1154mouse moved, the frame-relative X and Y positions where the mouse 1155mouse moved, the frame-relative X and Y positions where the mouse
1155moved, whether or not the wheel movement was horizontal, and whether 1156moved, whether or not the wheel movement was horizontal, whether or
1156or not the wheel moved up (or left, if the movement was 1157not the wheel moved up (or left, if the movement was horizontal), and
1157horizontal). */); 1158keyboard modifiers currently held down. */);
1158 Vhaiku_drag_wheel_function = Qnil; 1159 Vhaiku_drag_wheel_function = Qnil;
1159 1160
1160 DEFSYM (QSECONDARY, "SECONDARY"); 1161 DEFSYM (QSECONDARY, "SECONDARY");