fresh2dev / zellij-autolock

autolock Zellij when certain processes open.
MIT License
48 stars 2 forks source link

bug: toggle floating does not properly unlock #7

Open JonnyLoughlin opened 1 month ago

JonnyLoughlin commented 1 month ago

zellij --version: zellij 0.41.0

Terminal version: foot version: 1.18.1 +pgo +ime +graphemes -assertions

Operating system: Linux 6.10.10-arch1-1 #1 SMP PREEMPT_DYNAMIC x86_64 GNU/Linux

Issue description

When toggling floating panes in a window that is locked by a program defined in triggers, the ui is not unlocked.

Minimal reproduction

Zellij Config:

plugins {
    autolock location="file:/home/jonny/.config/zellij/zellij-autolock.wasm" {
        triggers "nvim"
    }
}

keybinds {
    normal {
        bind "Enter" {
            WriteChars "\u{000D}";
            MessagePlugin "autolock" {};
        }
    }
    shared_except "normal" "locked" {
        bind "Esc" { SwitchToMode "Normal"; }
    }
    // Standard Mode Bindings
    shared_except "locked" {
        bind "Alt ." { SwitchToMode "Locked"; }
        // Floating Settings
        bind "Alt o" { ToggleFloatingPanes; }
    }
}
  1. Open two panes
  2. Open Neovim in one pane
    • :!zellij action move-focus-or-tab right moves focus and unlocks the ui.
    • :!zellij action toggle-floating-panes opens the floating pane but the ui is still locked.

Other relevant information

Thanks for the work on this! I tried taking a swing at getting this fixed but its been a few years since I've even touched Rust and I've never done much with it. Maybe I am not correctly configuring for this use case so any help would be great!

theol0403 commented 3 weeks ago

Can you just do bind "Alt o" { ToggleFloatingPanes; SwitchToMode "Normal"; }.

Or equivalently :!zellij action toggle-floating-panes && zellij action switch-mode normal

JonnyLoughlin commented 2 weeks ago

Can you just do bind "Alt o" { ToggleFloatingPanes; SwitchToMode "Normal"; }.

Or equivalently :!zellij action toggle-floating-panes && zellij action switch-mode normal

That works for swapping into floating panes mode but if I'd swap back to Neovim, Zellij wouldn't autolock again. My workaround for now is just adding the following to my zellij config and manually unlocking if I need to when floating panes are toggled on.

locked {
    bind "Alt o" { ToggleFloatingPanes; }
}
fresh2dev commented 1 week ago

Thanks for the report and the suggested workaround. This seems to be an inherited limitation in the Zellij API. Aram hasn't cut a Zellij release in a while, but has been hard at work on it. I'll revisit this after the next Zellij release.

fresh2dev commented 1 week ago

FWIW, when opening a floating pane from within [Neo]vim using the companion plugin, zellij.vim, the floating window is opened in "Normal" mode (unlocked). This also has the helpful effect of opening the floating window in Vim's current working directory.

I have this in my Zellij config.kdl:

    shared_except "locked" {
        /* Put keybindings here if they conflict with Vim or others. */
        ...
        bind "Alt t" { ToggleFloatingPanes; }
        bind "Alt o" { NewPane "Down"; }
        bind "Alt v" { NewPane "Right"; }
        ...
    }

and this in my .vimrc:

" Open floating Zellij pane with `Alt+f`.
execute "set <M-t>=\ef"
noremap <M-t> :ZellijNewPane<CR>

" Open Zellij pane below with `Alt+t`.
execute "set <M-o>=\et"
noremap <M-o> :ZellijNewPaneSplit<CR>

" Open Zellij pane to the right with `Alt+v`.
execute "set <M-v>=\ev"
noremap <M-v> :ZellijNewPaneVSplit<CR>

These configs result in the desired behavior, when using [Neo]vim at least.