Showing sway scratchpad windows in LIFO order

I mainly use the sway scratchpad to hide the windows I don’t want to be in my workspaces : terminal windows like jupyter or rygel servers, Transmission, etc.

However, the showing order for scratchpad is FIFO, which I’d like to turn into a LIFO order.

I think that would be more useful : the last hidden window is most likely to be the window you need, not the terminal you’ve hidden a long time ago for any reason.

Is there any way to change the showing order ?

Thanks

Asked By: Arnaud Feldmann

||

In Sway, the scratchpad operates as a stack with a First-In, First-Out (FIFO) order, as you’ve noted. There isn’t a built-in feature to reverse this order to Last-In, First-Out (LIFO), but you can work around this limitation with a custom script or by using specific commands.

Here are a couple of methods you might consider:

  • Custom Scripting:

    You can write a script that utilizes swaymsg to query the list of scratchpad windows and then focuses on the most recently sent window. This script would need to parse the output of swaymsg -t get_tree, find the windows in the scratchpad, and then use swaymsg [criteria] focus to focus the most recently added window.

  • Manual Selection:

    Instead of relying on the automatic order, you could use a keybinding to select which scratchpad window to show. For example, you can define a mode in your Sway configuration that lists all scratchpad windows and allows you to pick one.

    Here is an example of how you might implement manual selection:

    # Enter the scratchpad selection mode
    bindsym $mod+minus mode "scratchpad_selection"
    
    # Define the scratchpad selection mode
    mode "scratchpad_selection" {
        bindsym $key1 [criteria for window 1] scratchpad show, mode "default"
        bindsym $key2 [criteria for window 2] scratchpad show, mode "default"
        # ... More keybindings for each window
        bindsym Escape mode "default"
    }
    

    This is just a template and would require you to manually update your Sway configuration every time you add a new frequently used scratchpad window. However, it gives you direct control over which window to show.

Focus the Most Recently Used (MRU) Window: You can focus the most recently used window by iterating over the windows in the scratchpad and selecting the one with the most recent activity. This may require more complex scripting to determine which window was last used.

As Sway and i3 are controlled through their IPC (Inter-Process Communication) interface, these customizations typically involve external scripting. If you’re not already familiar with scripting in a language like bash or Python, you may need to spend some time learning to implement these workarounds effectively.

Answered By: Kristtof V88
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.