diff --git a/ReadMe.md b/ReadMe.md index d97c768..efc1a30 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -261,31 +261,43 @@ shell paste功能,即explorer里的CTRL+V一样的效果: ``` # 6. 类似neovide的光标移动效果 ``` -(pop-select/beacon-animation X Y W H TIMER STEP R G B) +(pop-select/beacon-animation X Y W H TIMER STEP R G B DIFF-MIN) +X: 坐标x值 +Y: 坐标y值 +W: 光标宽度 +H: 光标高度 +TIMER: 动画持续时间 +STEP: 动画持续时间按多少份处理 +R: 光标颜色RGB的R值 +G: 光标颜色RGB的G值 +B: 光标颜色RGB的B值 +DIFF-MIN: 坐标差值最小值,小于这个值就不显示动画,可以排除光标小范围移动时显示动画 ``` 配置参考: ``` (when (fboundp 'pop-select/beacon-animation) - (add-hook 'post-command-hook (lambda() - (ignore-errors - (let* ((p (window-absolute-pixel-position)) - (pp (point)) - (w (if (equal cursor-type 'bar) 1 - (if-let ((glyph (when (< pp (point-max)) - (aref (font-get-glyphs (font-at pp) pp (1+ pp)) 0)))) - (aref glyph 4) - (window-font-width)))) - (h (line-pixel-height)) - ) - (when p - (pop-select/beacon-animation (car p) ; x - (cdr p) ; y - w - h - 100 ; timer - 50 ; timer step - 233 86 120 ; r g b - ))))))) + (defun show-cursor-animation() + (ignore-errors + (let* ((p (window-absolute-pixel-position)) + (pp (point)) + (w (if (equal cursor-type 'bar) 1 + (if-let ((glyph (when (< pp (point-max)) + (aref (font-get-glyphs (font-at pp) pp (1+ pp)) 0)))) + (aref glyph 4) + (window-font-width)))) + (h (line-pixel-height)) + ) + (when p + (pop-select/beacon-animation (car p) ; x + (cdr p) ; y + w + h + 100 ; timer + 50 ; timer step + 233 86 120 ; r g b + 20 ; diff min,自己试验 + ))))) + (add-hook 'post-command-hook 'show-cursor-animation)) ``` 效果图: ![gif](gif/ani.gif) diff --git a/src/beacon.rs b/src/beacon.rs index 2b8774f..9bc073a 100644 --- a/src/beacon.rs +++ b/src/beacon.rs @@ -621,6 +621,7 @@ fn animation( r: u8, g: u8, b: u8, + diff_min: usize, ) -> Result<()> { unsafe { cursor_info_x = x; @@ -635,16 +636,20 @@ fn animation( } if cursor_info_x != cursor_info_prev_x || cursor_info_y != cursor_info_prev_y { - cursor_start_x = cursor_info_prev_x; - cursor_start_y = cursor_info_prev_y; - cursor_end_x = cursor_info_x; - cursor_end_y = cursor_info_y; - cursor_color_r = r; - cursor_color_g = g; - cursor_color_b = b; - ANIMATION_ARG_DURATION = timer; - ANIMATION_ARG_DURATION_STEP = step; - PostThreadMessageW(UI_THREAD_ID, WM_SHOW_ANIMATION, 0 as WPARAM, 0 as LPARAM); + if cursor_info_x.abs_diff(cursor_info_prev_x) >= diff_min + || cursor_info_y.abs_diff(cursor_info_prev_y) >= diff_min + { + cursor_start_x = cursor_info_prev_x; + cursor_start_y = cursor_info_prev_y; + cursor_end_x = cursor_info_x; + cursor_end_y = cursor_info_y; + cursor_color_r = r; + cursor_color_g = g; + cursor_color_b = b; + ANIMATION_ARG_DURATION = timer; + ANIMATION_ARG_DURATION_STEP = step; + PostThreadMessageW(UI_THREAD_ID, WM_SHOW_ANIMATION, 0 as WPARAM, 0 as LPARAM); + } cursor_info_prev_x = x; cursor_info_prev_y = y; cursor_info_prev_w = w;