Skip to content

Commit

Permalink
Add pop_twice_to_wake and pop_twice_to_repeat functions (#1398)
Browse files Browse the repository at this point in the history
Following on from #1364

Haven't seen that PR change much over the past few weeks, I've been
using that functionality in my personal repo and it's been great so I
wanted to make sure other users got to try it out.

## Changes from #1364

 - Switched to tag at request of @pokey in review
   - This will prevent blocking on other pop commands
 - Added Module import to be able to define tag
 - Updated context matcher to look for `user.pop_twice_to_wake`
 - Dropped changes to mouse.py 

---

 - Merged with #1399 as per discussion in grooming session
 - Add explanation comments
 - Switch double pop time minimum  and maximum to a user.setting

---------

Co-authored-by: Guenther Schmitz <727316+gpunktschmitz@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Pokey Rule <755842+pokey@users.noreply.github.com>
Co-authored-by: Jeff Knaus <knaus.jeff@gmail.com>
  • Loading branch information
5 people authored Oct 27, 2024
1 parent 0a6a001 commit e78c752
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
44 changes: 44 additions & 0 deletions core/modes/sleep_mode_pop_twice_to_wake.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import time

from talon import Context, Module, actions, settings

ctx = Context()
mod = Module()

mod.tag("pop_twice_to_wake", desc="tag for enabling pop twice to wake in sleep mode")

mod.setting(
"double_pop_speed_minimum",
type=float,
desc="""Shortest time in seconds to accept a second pop to trigger additional actions""",
default=0.1,
)

mod.setting(
"double_pop_speed_maximum",
type=float,
desc="""Longest time in seconds to accept a second pop to trigger additional actions""",
default=0.3,
)

ctx.matches = r"""
mode: sleep
and tag: user.pop_twice_to_wake
"""

time_last_pop = 0


@ctx.action_class("user")
class UserActions:
def noise_trigger_pop():
# Since zoom mouse is registering against noise.register("pop", on_pop), let that take priority
if actions.tracking.control_zoom_enabled():
return
global time_last_pop
double_pop_speed_minimum = settings.get("user.double_pop_speed_minimum")
double_pop_speed_maximum = settings.get("user.double_pop_speed_maximum")
delta = time.perf_counter() - time_last_pop
if delta >= double_pop_speed_minimum and delta <= double_pop_speed_maximum:
actions.speech.enable()
time_last_pop = time.perf_counter()
30 changes: 30 additions & 0 deletions plugin/repeater/pop_twice_to_repeat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import time

from talon import Context, Module, actions, settings

ctx = Context()
mod = Module()

mod.tag("pop_twice_to_repeat", desc="tag for enabling pop twice to repeat")

ctx.matches = r"""
mode: command
and tag: user.pop_twice_to_repeat
"""

time_last_pop = 0


@ctx.action_class("user")
class UserActions:
def noise_trigger_pop():
# Since zoom mouse is registering against noise.register("pop", on_pop), let that take priority
if actions.tracking.control_zoom_enabled():
return
global time_last_pop
delta = time.perf_counter() - time_last_pop
double_pop_speed_minimum = settings.get("user.double_pop_speed_minimum")
double_pop_speed_maximum = settings.get("user.double_pop_speed_maximum")
if delta >= double_pop_speed_minimum and delta <= double_pop_speed_maximum:
actions.core.repeat_command()
time_last_pop = time.perf_counter()
15 changes: 15 additions & 0 deletions settings.talon
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ settings():
# Set the total number of command history lines to display
user.command_history_size = 50

# Set the time window size for to for pop_twice_to_sleep and pop_twice_to_repeat. By default, the pops must be more than 0.1 seconds apart and less then 0.3 seconds, to reduce false positives
user.double_pop_speed_minimum = 0.1
user.double_pop_speed_maximum = 0.3

# Uncomment to add a directory (relative to the Talon user dir) with additional
# .snippet files. Changing this setting requires a restart of Talon.
# user.snippets_dir = "snippets"
Expand Down Expand Up @@ -90,6 +94,17 @@ settings():
# See issue #688 for more detail: https://github.com/talonhub/community/issues/688
# tag(): user.mouse_cursor_commands_enable

# Uncomment below enable pop_twice_to_wake
# Without this tag noise_trigger_pop is usually associated with pop to click actions
# Enabling this tag disables other pop to click actions in sleep mode, including pop to click
# tag(): user.pop_twice_to_wake

# Uncomment below enable pop_twice_to_repeat
# Enabling this tag will repeat the last command when two pops are heard within the allotted time window
# Without this tag noise_trigger_pop is usually associated with pop to click actions
# Enabling this tag disables other pop to click actions in command mode, including pop to click
# tag(): user.pop_twice_to_repeat

# Uncomment the below to enable support for saying numbers without a prefix.
# By default you need to say "numb one" to write "1". If you uncomment this,
# you can say "one" to write "1".
Expand Down

0 comments on commit e78c752

Please sign in to comment.