diff --git a/core/edit/insert_between.py b/core/edit/insert_between.py index ba957cde74..75885092fb 100644 --- a/core/edit/insert_between.py +++ b/core/edit/insert_between.py @@ -1,4 +1,4 @@ -from talon import Module, actions, app +from talon import Module, actions mod = Module() @@ -10,14 +10,3 @@ def insert_between(before: str, after: str): actions.insert(before + after) for _ in after: actions.edit.left() - - # This is deprecated, please use insert_between instead. - def insert_cursor(text: str): - """Insert a string. Leave the cursor wherever [|] is in the text""" - if "[|]" in text: - actions.user.insert_between(*text.split("[|]", 1)) - else: - actions.insert(text) - app.notify( - "insert_cursor is deprecated, please update your code to use insert_between" - ) diff --git a/core/edit_text_file.py b/core/edit_text_file.py index cab76c9635..a064230884 100644 --- a/core/edit_text_file.py +++ b/core/edit_text_file.py @@ -1,5 +1,6 @@ import os import subprocess +from pathlib import Path from talon import Context, Module, app @@ -72,7 +73,9 @@ def edit_text_file(path): class MacActions: def edit_text_file(path): # -t means try to open in a text editor. - open_with_subprocess(path, ["/usr/bin/open", "-t", path]) + open_with_subprocess( + path, ["/usr/bin/open", "-t", Path(path).expanduser().resolve()] + ) @linuxctx.action_class("self") @@ -81,7 +84,11 @@ def edit_text_file(path): # we use xdg-open for this even though it might not open a text # editor. we could use $EDITOR, but that might be something that # requires a terminal (eg nano, vi). - open_with_subprocess(path, ["/usr/bin/xdg-open", path]) + try: + open_with_subprocess(path, ["xdg-open", Path(path).expanduser().resolve()]) + except FileNotFoundError: + app.notify(f"xdg-open missing. Could not open file for editing: {path}") + raise # Helper for linux and mac. diff --git a/plugin/mouse/mouse.py b/plugin/mouse/mouse.py index 5ee4db412c..9e63cdf61c 100644 --- a/plugin/mouse/mouse.py +++ b/plugin/mouse/mouse.py @@ -1,4 +1,4 @@ -from talon import Context, Module, actions, clip, ctrl, settings, ui +from talon import Context, Module, actions, ctrl, settings, ui from talon_plugins import eye_zoom_mouse mod = Module() @@ -84,13 +84,13 @@ def mouse_sleep(): def copy_mouse_position(): """Copy the current mouse position coordinates""" - position = ctrl.mouse_pos() - clip.set_text(repr(position)) + x, y = actions.mouse_x(), actions.mouse_y() + actions.clip.set_text(f"{x}, {y}") def mouse_move_center_active_window(): - """move the mouse cursor to the center of the currently active window""" + """Move the mouse cursor to the center of the currently active window""" rect = ui.active_window().rect - ctrl.mouse_move(rect.left + (rect.width / 2), rect.top + (rect.height / 2)) + actions.mouse_move(rect.center.x, rect.center.y) @ctx.action_class("user") diff --git a/plugin/mouse/mouse_scroll.py b/plugin/mouse/mouse_scroll.py index 0c68311e60..856445afea 100644 --- a/plugin/mouse/mouse_scroll.py +++ b/plugin/mouse/mouse_scroll.py @@ -1,3 +1,4 @@ +import time from typing import Literal from talon import Context, Module, actions, app, cron, ctrl, imgui, settings, ui @@ -7,6 +8,7 @@ scroll_job = None gaze_job = None scroll_dir: Literal[-1, 1] = 1 +scroll_start_ts: float = 0 hiss_scroll_up = False control_mouse_forced = False @@ -32,6 +34,12 @@ default=80, desc="The default amount used when scrolling continuously", ) +mod.setting( + "mouse_continuous_scroll_acceleration", + type=float, + default=1, + desc="The maximum (linear) acceleration factor when scrolling continuously. 1=constant speed/no acceleration", +) mod.setting( "mouse_enable_hiss_scroll", type=bool, @@ -159,7 +167,7 @@ def noise_trigger_hiss(active: bool): def mouse_scroll_continuous(new_scroll_dir: Literal[-1, 1]): - global scroll_job, scroll_dir, continuous_scroll_mode + global scroll_job, scroll_dir, scroll_start_ts, continuous_scroll_mode if eye_zoom_mouse.zoom_mouse.state != eye_zoom_mouse.STATE_IDLE: return @@ -170,10 +178,13 @@ def mouse_scroll_continuous(new_scroll_dir: Literal[-1, 1]): cron.cancel(scroll_job) scroll_job = None continuous_scroll_mode = "" + # Issuing a scroll in the reverse direction resets acceleration else: scroll_dir = new_scroll_dir + scroll_start_ts = time.perf_counter() else: scroll_dir = new_scroll_dir + scroll_start_ts = time.perf_counter() continuous_scroll_mode = "scroll down continuous" scroll_continuous_helper() scroll_job = cron.interval("16ms", scroll_continuous_helper) @@ -184,7 +195,13 @@ def mouse_scroll_continuous(new_scroll_dir: Literal[-1, 1]): def scroll_continuous_helper(): scroll_amount = settings.get("user.mouse_continuous_scroll_amount") - y = scroll_amount * scroll_dir / 10 + acceleration_setting = settings.get("user.mouse_continuous_scroll_acceleration") + acceleration_speed = ( + 1 + min((time.perf_counter() - scroll_start_ts) / 0.5, acceleration_setting - 1) + if acceleration_setting > 1 + else 1 + ) + y = scroll_amount * acceleration_speed * scroll_dir / 10 actions.mouse_scroll(y) diff --git a/settings.talon b/settings.talon index 443252eb3d..3a8fba3ce4 100644 --- a/settings.talon +++ b/settings.talon @@ -24,6 +24,9 @@ settings(): # Set the scroll amount for continuous scroll/gaze scroll user.mouse_continuous_scroll_amount = 80 + # Set the maximum acceleration factor when scrolling continuously. 1=constant speed/no acceleration. + user.mouse_continuous_scroll_acceleration = 1 + # If `true`, stop continuous scroll/gaze scroll with a pop user.mouse_enable_pop_stops_scroll = true