~tsdh/swayr

559bf941e546fa1ae4febc1ee89eafacc9a7678f — William Barsse 20 days ago f484eb0
Add a "nop" command

The "nop" command, as the name implies, doesn't do anything.

The change isn't entirely frivolous ;-) Sending a "nop" command
interrupts any in-progress "prev-next" sequence without any other side
effects. Until a sequence is interrupted, all next/prev-window commands
navigate the windows in the LRU order captured at the time of the
first command in the sequence.

A "nop" command can be useful if bound to a particular key _release_
event in Sway. For instance, if <Mod1-release> is bound to "nop" while
<Mod1-Tab> and <Mod1-Shift-Tab> are bound to the "prev/next-window"
commands, then releasing <Mod1> will be enough to refresh the LRU
sequence for the next use of these next/prev bindings. This behavior
feels more intuitive (at least to me) than the non-nop variation.

One caveat though: there is currently an [outstanding bug in sway on
release bindings](https://github.com/swaywm/sway/issues/6456) which
prevents the described scenario from working exactly as described
because the Tab/S-Tab key presses actually cancel the outstanding
release action. There is however also a (non-merged) PR available that
addresses the issue.
1 files changed, 4 insertions(+), 0 deletions(-)

M swayr/src/cmds.rs
M swayr/src/cmds.rs => swayr/src/cmds.rs +4 -0
@@ 67,6 67,9 @@ pub enum ConsiderWindows {

#[derive(clap::Parser, Debug, Deserialize, Serialize)]
pub enum SwayrCommand {
    /// No-operation. Interrupts any in-progress prev/next sequence but has
    /// no other effect
    Nop,
    /// Switch to next urgent window (if any) or to last recently used window.
    SwitchToUrgentOrLRUWindow,
    /// Switch to the given app (given by app_id or window class) if that's not


@@ 264,6 267,7 @@ pub fn exec_swayr_cmd(args: ExecSwayrCmdArgs) {
    }

    match args.cmd {
        SwayrCommand::Nop => {}
        SwayrCommand::SwitchToUrgentOrLRUWindow => {
            switch_to_urgent_or_lru_window(&*props.read().unwrap())
        }