Last active
April 9, 2022 14:43
-
-
Save gwenhael-le-moine/af56062c84b944d17edb8d7b2f20810c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[...] | |
# Alt-tab | |
bindsym Mod1+tab exec ~/.config/sway/alttab.rb | |
#[...] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 ) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 :)