1

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

0

1 Answer 1

3
+50

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.

3
  • Thanks for your precise answer. Gonna check this when i'll have the time ! Nov 18, 2023 at 15:38
  • Following your advice : CON_ID=$(swaymsg -t get_tree | jq '.nodes.[].nodes.[] | select(.name=="__i3_scratch").floating_nodes | last.id') [ "$CON_ID" = "null" ] || swaymsg [con_id=$CON_ID] scratchpad show That seems to work, in a sh. The last element of the json seems to be the last added Nov 18, 2023 at 22:07
  • I can even add , floating disable at the end, that's just perfection. No fifo cycling, no floating, just LIFO stack. Thank you a lot ! Nov 18, 2023 at 22:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .