Skip to content

Instantly share code, notes, and snippets.

@webflo-dev
Forked from SidharthArya/alttab
Created February 14, 2022 16:01
Show Gist options
  • Select an option

  • Save webflo-dev/84b84c3ffe7752926b9686f92dcc1cba to your computer and use it in GitHub Desktop.

Select an option

Save webflo-dev/84b84c3ffe7752926b9686f92dcc1cba to your computer and use it in GitHub Desktop.

Revisions

  1. @SidharthArya SidharthArya revised this gist May 15, 2020. 2 changed files with 3 additions and 3 deletions.
    2 changes: 1 addition & 1 deletion alttab
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ import subprocess

    direction=bool(sys.argv[1] == 't' or sys.argv[1] == 'T')
    swaymsg = subprocess.run(['swaymsg', '-t', 'get_tree'], stdout=subprocess.PIPE)
    data = json.load(swaymsg.stdout)
    data = json.loads(swaymsg.stdout)
    current = data["nodes"][1]["current_workspace"]
    workspace = int(data["nodes"][1]["current_workspace"])-1
    roi = data["nodes"][1]["nodes"][workspace]
    4 changes: 2 additions & 2 deletions config
    Original file line number Diff line number Diff line change
    @@ -1,2 +1,2 @@
    bindsym Mod1+tab exec ~/.config/sway/alttab next
    bindsym Mod1+shift+tab exec ~/.config/sway/alttab prev
    bindsym $mod+tab exec swaymsg [con_id=$(swaymsg -t get_tree | ~/.config/sway/alttab t)] focus
    bindsym $mod+shift+tab exec swaymsg [con_id=$(swaymsg -t get_tree | ~/.config/sway/alttab f)] focus
  2. @SidharthArya SidharthArya revised this gist Feb 20, 2020. 2 changed files with 12 additions and 13 deletions.
    21 changes: 10 additions & 11 deletions alttab
    Original file line number Diff line number Diff line change
    @@ -2,9 +2,12 @@

    import sys
    import json
    import subprocess

    direction=bool(sys.argv[1] == 't' or sys.argv[1] == 'T')
    data = json.load(sys.stdin)
    swaymsg = subprocess.run(['swaymsg', '-t', 'get_tree'], stdout=subprocess.PIPE)
    data = json.load(swaymsg.stdout)
    current = data["nodes"][1]["current_workspace"]
    workspace = int(data["nodes"][1]["current_workspace"])-1
    roi = data["nodes"][1]["nodes"][workspace]
    temp = roi
    @@ -22,23 +25,19 @@ def getPrevWindow():
    else:
    return len(windows)-1


    def makelist(temp):
    for i in range(len(temp["nodes"])):
    if temp["nodes"][i]["name"] is None:
    makelist(temp["nodes"][i])
    else:
    windows.append(temp["nodes"][i])
    for nodes in "floating_nodes", "nodes":
    for i in range(len(temp[nodes])):
    if temp[nodes][i]["name"] is None:
    makelist(temp[nodes][i])
    else:
    windows.append(temp[nodes][i])

    def focused(temp_win):
    for i in range(len(temp_win)):
    if temp_win[i]["focused"] == True:
    return i





    makelist(temp)
    # print(len(windows))
    focus = focused(windows)
    4 changes: 2 additions & 2 deletions config
    Original file line number Diff line number Diff line change
    @@ -1,2 +1,2 @@
    bindsym $mod+tab exec swaymsg [con_id=$(swaymsg -t get_tree | ~/.config/sway/alttab t)] focus
    bindsym $mod+shift+tab exec swaymsg [con_id=$(swaymsg -t get_tree | ~/.config/sway/alttab f)] focus
    bindsym Mod1+tab exec ~/.config/sway/alttab next
    bindsym Mod1+shift+tab exec ~/.config/sway/alttab prev
  3. @SidharthArya SidharthArya revised this gist Apr 9, 2019. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion alttab
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,6 @@

    import sys
    import json
    import subprocess

    direction=bool(sys.argv[1] == 't' or sys.argv[1] == 'T')
    data = json.load(sys.stdin)
  4. @SidharthArya SidharthArya created this gist Apr 9, 2019.
    50 changes: 50 additions & 0 deletions alttab
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    #!/usr/bin/env python3

    import sys
    import json
    import subprocess

    direction=bool(sys.argv[1] == 't' or sys.argv[1] == 'T')
    data = json.load(sys.stdin)
    workspace = int(data["nodes"][1]["current_workspace"])-1
    roi = data["nodes"][1]["nodes"][workspace]
    temp = roi
    windows = list()

    def getNextWindow():
    if focus < len(windows) - 1:
    return focus+1
    else:
    return 0

    def getPrevWindow():
    if focus > 0:
    return focus-1
    else:
    return len(windows)-1


    def makelist(temp):
    for i in range(len(temp["nodes"])):
    if temp["nodes"][i]["name"] is None:
    makelist(temp["nodes"][i])
    else:
    windows.append(temp["nodes"][i])

    def focused(temp_win):
    for i in range(len(temp_win)):
    if temp_win[i]["focused"] == True:
    return i





    makelist(temp)
    # print(len(windows))
    focus = focused(windows)
    if str(sys.argv[1]) == 't' or str(sys.argv[1]) == 'T':
    print(windows[getNextWindow()]["id"])
    else:
    print(windows[getPrevWindow()]["id"])

    2 changes: 2 additions & 0 deletions config
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    bindsym $mod+tab exec swaymsg [con_id=$(swaymsg -t get_tree | ~/.config/sway/alttab t)] focus
    bindsym $mod+shift+tab exec swaymsg [con_id=$(swaymsg -t get_tree | ~/.config/sway/alttab f)] focus