ospfranco / sol

MacOS launcher & command palette
MIT License
1.92k stars 87 forks source link

Custom shortcuts #81

Closed cocoonkid closed 1 year ago

cocoonkid commented 1 year ago

[feature request] Add ctrl + space as hotkey (or actually make it fully customizable)

I run Contexts on cmd+space and my terminal on option+space.

Alfred works on ctrl+space but I cannot configure sol to work with this combo. I'd really like to use it instead of Alfred.

I was able to put Sol on ctrl+space via hammerspoon but it still reserves the cmd or option key for itself.

Thank you for consideration.

ospfranco commented 1 year ago

PRs welcome

cocoonkid commented 1 year ago

Thanks, I'd work on it but I'm still a noob and I'm not ready for tackling swift.

I researched a bit though https://n1ghtmare.github.io/2022-01-14/implement-a-keyboard-shortcuts-handler-in-typescript/

I then tried to fix it with hamerspoon. https://github.com/Hammerspoon/hammerspoon

I am successful in launching it and sometimes it works actually but most of the time it just gets into some kind of "hidden state"

here's the Lua code I'm using.

hs.hotkey.bind({"ctrl"}, "space", toggle_application("com.ospfranco.sol"))

function toggle_application(_app)
    return function()           
        local app = hs.application.applicationsForBundleID(_app)
        if app[1] == nill then
            hs.application.launchOrFocusByBundleID(_app)
        elseif app[1]:isFrontmost() then
            app[1]:hide()
        else
            app[1]:activate()
        end
    end 
end

I wonder if there's a way to capture the sol window on it's own.

cocoonkid commented 1 year ago

I propose adding an option to disable either/or Global Shortcut, Clipboard Shortcut, Scratchpad Shortcut.

cocoonkid commented 1 year ago

Ha, I was able to get it to work:

hs.hotkey.bind({"ctrl"}, "space", toggle_application("com.ospfranco.sol"))

function toggle_application(_app)
    return function()           
        local app = hs.application.applicationsForBundleID(_app)
        if app[1] == nill then
            hs.application.launchOrFocusByBundleID(_app)
        elseif app[1]:isFrontmost() then
            app[1]:hide()
        else
            app[1]:activate()
            app[1]:unhide()
            app[1]:setFrontmost(true)
        end
    end 
end

the native shortcut is set to cmd + space and does not interfere with Contexts.

cocoonkid commented 1 year ago

No, unfortunately not. It just takes a while longer now for the Sol window to become inaccessible.

Killing the Sol process makes it work again. I haven't yet been able to identify what triggers the inaccessibility.

Will report back as soon as I have stable workaround.

ospfranco commented 1 year ago

There is more happening when the window is shown than just activating it:

https://vscode.dev/github/ospfranco/sol/blob/dcdb7b7b34dba04ada467c77c60c1672cd400fd9/macos/sol-macOS/AppDelegate.swift#L181

You will probably not get around this with hammerspoon

ospfranco commented 1 year ago

Added Ctrl + Space to the list of selectable global shortcuts