diff --git a/core/modes/sleep_mode_pop_twice_to_wake.py b/core/modes/sleep_mode_pop_twice_to_wake.py new file mode 100644 index 0000000000..2fe45f938e --- /dev/null +++ b/core/modes/sleep_mode_pop_twice_to_wake.py @@ -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() diff --git a/plugin/repeater/pop_twice_to_repeat.py b/plugin/repeater/pop_twice_to_repeat.py new file mode 100644 index 0000000000..48ca816e7b --- /dev/null +++ b/plugin/repeater/pop_twice_to_repeat.py @@ -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() diff --git a/settings.talon b/settings.talon index 644ac46dcd..443252eb3d 100644 --- a/settings.talon +++ b/settings.talon @@ -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" @@ -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".