Skip to content

Commit

Permalink
pop-select/beacon-animation添加差值参数,可以排除小范围移动
Browse files Browse the repository at this point in the history
  • Loading branch information
lynnux committed Aug 17, 2023
1 parent 3819cbc commit 2e1a0ff
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 31 deletions.
54 changes: 33 additions & 21 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
25 changes: 15 additions & 10 deletions src/beacon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ fn animation(
r: u8,
g: u8,
b: u8,
diff_min: usize,
) -> Result<()> {
unsafe {
cursor_info_x = x;
Expand All @@ -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;
Expand Down

0 comments on commit 2e1a0ff

Please sign in to comment.