-
-
Save gwenhael-le-moine/af56062c84b944d17edb8d7b2f20810c to your computer and use it in GitHub Desktop.
#[...] | |
# Alt-tab | |
bindsym Mod1+tab exec ~/.config/sway/alttab.rb | |
#[...] |
#!/usr/bin/env ruby | |
def current_tag_focused_client_id | |
`swaymsg -t get_tree | jq --arg active_workspace $(swaymsg -t get_tree | jq '[ .nodes[] | .nodes ] | flatten | map({id, name, focused: [ .nodes | map(.focused) | reduce .[] as $item (false; . or $item) ] | .[0] }) | .[] | select(.focused) | .id') '[ .nodes[] | .nodes ] | flatten | .[] | select(.id == ($active_workspace | tonumber)) | .nodes | .[] | [ select(.focused == true) ] | .[] | .id'`.to_i | |
end | |
def current_tag_unfocused_clients_ids | |
`swaymsg -t get_tree | jq --arg active_workspace $(swaymsg -t get_tree | jq '[ .nodes[] | .nodes ] | flatten | map({id, name, focused: [ .nodes | map(.focused) | reduce .[] as $item (false; . or $item) ] | .[0] }) | .[] | select(.focused) | .id') '[ .nodes[] | .nodes ] | flatten | .[] | select(.id == ($active_workspace | tonumber)) | .nodes | .[] | [ select(.focused == false) ] | .[] | .id'`.split.map(&:to_i).sort | |
end | |
def focus_this_client( con_id ) | |
`swaymsg [con_id=#{con_id}] focus` unless con_id.nil? | |
end | |
def find_next_client_id( focused_client_id, unfocused_clients_ids ) | |
return focused_client_id if focused_client_id.nil? || unfocused_clients_ids.nil? || unfocused_clients_ids.empty? | |
next_client_id = unfocused_clients_ids.find { |i| i > focused_client_id } | |
next_client_id = unfocused_clients_ids.first if next_client_id.nil? | |
next_client_id | |
end | |
focus_this_client( find_next_client_id( current_tag_focused_client_id, current_tag_unfocused_clients_ids ) ) |
Don't really see the point in such a movement, when you perfectly can just move to each node with way precise control. But haven't really looked at the script just thinking of alt+tab windows behavior.
I don't want to think about which window I want to focus, just cycle through all windows of the current workspace. I rarely have more than 4 so quickly inputting Mod1-Tab multiple times is quicker than thinking "I want to go left" and remembering the correct binding of that precise action.
It has come to my attention that in fact this does the same:
bindsym Mod1+Tab focus right
I don't want to think about which window I want to focus, just cycle through all windows of the current workspace. I rarely have more than 4 so quickly inputting Mod1-Tab multiple times is quicker than thinking "I want to go left" and remembering the correct binding of that precise action.
Ah okay I see. I don't think that it is that hard to remember the binding for go left/right, but that seems personal preference.
bindsym Mod1+Tab focus right
Nice fix :D
I did the same thing but in bash, and it's lagging as hell :).
Did try bunch of switcher but can't find one just simply fast, switch windows on a focused workspace only, and switch on all kinds of windows.
Anyway your script lack of floating_nodes
, I think you don't intend to use floating windows, yes?
And how about nested windows? I guess that's why my switcher is so lag :)
I got real tired of having lost a sane alt-tab after switching to sway so I made this... thing. I'm not proud of it but it works as far as I can tell (which is about 1 hour of light use at the moment.)