Skip to content

Commit

Permalink
Merge branch 'main' into rpc_client
Browse files Browse the repository at this point in the history
  • Loading branch information
nriley authored Nov 23, 2024
2 parents 188476c + 5286e2b commit e6c8495
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 21 deletions.
13 changes: 1 addition & 12 deletions core/edit/insert_between.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from talon import Module, actions, app
from talon import Module, actions

mod = Module()

Expand All @@ -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"
)
11 changes: 9 additions & 2 deletions core/edit_text_file.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import subprocess
from pathlib import Path

from talon import Context, Module, app

Expand Down Expand Up @@ -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")
Expand All @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions plugin/mouse/mouse.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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")
Expand Down
21 changes: 19 additions & 2 deletions plugin/mouse/mouse_scroll.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import time
from typing import Literal

from talon import Context, Module, actions, app, cron, ctrl, imgui, settings, ui
Expand All @@ -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

Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)


Expand Down
3 changes: 3 additions & 0 deletions settings.talon
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit e6c8495

Please sign in to comment.