espanso / espanso

Cross-platform Text Expander written in Rust
https://espanso.org
GNU General Public License v3.0
10k stars 277 forks source link

Investigate SYNTHETIC_KB_ID property to mitigate debouncers interactions on macOS #618

Open montchr opened 3 years ago

montchr commented 3 years ago

I'm a new espanso user and have not yet gotten it working properly.

Each time I type a trigger, the replacement activates, however only the last character in the trigger is replaced. All other characters remain.

For example, when I type :espanso, the result is :espansHi there!. After the replacement, if I press backspace, I get :espansHi there:espanso.

Here is my entire config, located at ~/.config/espanso/default.yml:

# espanso configuration file

matches:
  # Simple text replacement
  - trigger: ":espanso"
    replace: "Hi there!"

OS: macOS Big Sur 11.2.2 Espanso version: 0.7.3

I haven't yet installed any packages from Espanso Hub.

I've tried numerous approaches to solving the problem, none of which had any visible effect:

Here's the result of espanso dump:

ConfigSet {
    default: Configs {
        name: "default",
        parent: "self",
        filter_title: "",
        filter_class: "",
        filter_exec: "",
        log_level: 0,
        conflict_check: false,
        ipc_server_port: 34982,
        worker_ipc_server_port: 34983,
        use_system_agent: true,
        config_caching_interval: 800,
        word_separators: [
            ' ',
            ',',
            '.',
            '?',
            '!',
            '\r',
            '\n',
            '\u{16}',
        ],
        toggle_key: ALT,
        toggle_interval: 230,
        preserve_clipboard: true,
        passive_match_regex: "(?P<name>:\\p{L}+)(/(?P<args>.*)/)?",
        passive_arg_delimiter: '/',
        passive_arg_escape: '\\',
        passive_key: OFF,
        passive_delay: 100,
        enable_passive: false,
        enable_active: true,
        undo_backspace: true,
        paste_shortcut: Default,
        backspace_limit: 3,
        restore_clipboard_delay: 300,
        secure_input_watcher_enabled: true,
        secure_input_watcher_interval: 5000,
        post_inject_delay: 100,
        secure_input_notification: true,
        backend: Inject,
        exclude_default_entries: false,
        show_notifications: true,
        show_icon: true,
        fast_inject: true,
        backspace_delay: 0,
        inject_delay: 0,
        auto_restart: true,
        matches: [
            Match {
                triggers: [
                    ":espanso",
                ],
                content: Text(
                    TextContent {
                        replace: "Hi there!",
                        vars: [],
                        _has_vars: false,
                    },
                ),
                word: false,
                passive_only: false,
                propagate_case: false,
                force_clipboard: false,
                is_html: false,
                _trigger_sequences: [
                    [
                        Char(
                            ':',
                        ),
                        Char(
                            'e',
                        ),
                        Char(
                            's',
                        ),
                        Char(
                            'p',
                        ),
                        Char(
                            'a',
                        ),
                        Char(
                            'n',
                        ),
                        Char(
                            's',
                        ),
                        Char(
                            'o',
                        ),
                    ],
                ],
            },
        ],
        global_vars: [],
        modulo_path: None,
        wait_for_modifiers_release: false,
    },
    specific: [],
}

And the results of espanso log:

❯ espanso log
05:25:20 [ INFO] espanso version 0.7.3
05:25:20 [ INFO] using config path: /Users/chrismontgomery/.config/espanso
05:25:20 [ INFO] using package path: /Users/chrismontgomery/Library/Application Support/espanso/packages
05:25:20 [ INFO] spawning worker process...
05:25:20 [ INFO] Binded to IPC unix socket: /Users/chrismontgomery/Library/Application Support/espanso/espanso.sock
05:25:20 [ INFO] initializing worker process...
05:25:20 [ INFO] Status icon already initialized, skipping.
05:25:20 [ INFO] Status icon (disabled) already initialized, skipping.
05:25:20 [ INFO] Initializing EspansoNotifyHelper in /Users/chrismontgomery/Library/Application Support/espanso
05:25:20 [ INFO] EspansoNotifyHelper already initialized, skipping.
05:25:20 [ INFO] Binded to IPC unix socket: /Users/chrismontgomery/Library/Application Support/espanso/worker.sock
05:25:21 [ INFO] Using modulo at "/usr/local/bin/modulo"
05:25:21 [ INFO] Created Modulo APP stub at: "/Users/chrismontgomery/Library/Application Support/espanso/Modulo.app/Contents/MacOS/modulo"
05:25:21 [ INFO] worker is running!
05:25:21 [ INFO] watching for changes in path: /Users/chrismontgomery/.config/espanso
federico-terzi commented 3 years ago

Hey @montchr,

I'm really sorry you experienced this problem! My first bet is that some debouncing software is interfering with espanso, but I noticed you already tried disabling them to see if that could help...

Try to play with the backspace_delay option, starting from value 1000 and gradually lowering it down. Also make sure your default.yml file does not contain other options (so that we can diagnose the problem a bit better):

backspace_delay: 1000

matches:
  - trigger: ":espanso"
    replace: "Hi there!"

Let me know if that helps!

Cheers :)

montchr commented 3 years ago

I apologize – it seems I didn't disable debounce-mac properly (I wish launchctl provided better feedback about whether its commands were successful or not). This time around, I followed debounce-mac's uninstallation instructions and Espanso worked! Thank you for your help. Now I get to have some fun actually using Espanso :)

montchr commented 3 years ago

@federico-terzi That said, I would still like to be able to use the debouncer. https://github.com/toothbrush/debounce-mac/issues/1 indicates that tool should only affect non-synthetic keystrokes. Why might espanso be affected by a debouncer since it's not a physical keyboard?

In debounce-mac, I see that it checks for the value of SYNTHETIC_KB_ID before debouncing. Do you know if there's any way to get espanso and this debouncer working nicely together?

https://github.com/toothbrush/debounce-mac/blob/1acd5a0fd3a53c8e5ee277cf787b095f05f10957/debounce.m#L16

federico-terzi commented 3 years ago

Hey @montchr,

Thank you for the investigation! I would surely like to support debouncers as well. I didn't know about the SYNTHETIC_KB_ID, this might be really helpful

I'll reopen this issue to keep track of it! Perhaps, we might be able to include this one in #594

Cheers :)

smeech commented 8 months ago

This is now a rather old issue. Is it still a problem with the recent release?