mirror of
https://codeberg.org/scip/swaycycle.git
synced 2025-12-17 12:31:05 +01:00
Compare commits
1 Commits
dependabot
...
enhancedeb
| Author | SHA1 | Date | |
|---|---|---|---|
| 640b0533b8 |
4
.github/workflows/release.yaml
vendored
4
.github/workflows/release.yaml
vendored
@@ -10,10 +10,10 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v5
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v6
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: 1.23.5
|
go-version: 1.23.5
|
||||||
|
|
||||||
|
|||||||
@@ -24,13 +24,6 @@ Add such a line to your sway config file (e.g. in `$HOME/.config/sway/config`):
|
|||||||
bindsym $mod+Tab exec ~/bin/swaycycle
|
bindsym $mod+Tab exec ~/bin/swaycycle
|
||||||
```
|
```
|
||||||
|
|
||||||
You may also add a second key binding to do the reverse, which is
|
|
||||||
sometimes very useful:
|
|
||||||
|
|
||||||
```default
|
|
||||||
bindsym $mod+Shift+Tab exec ~/bin/swaycycle --prev
|
|
||||||
```
|
|
||||||
|
|
||||||
## Debugging
|
## Debugging
|
||||||
|
|
||||||
You may call `swaycycle` in a terminal window on a workspace with at
|
You may call `swaycycle` in a terminal window on a workspace with at
|
||||||
|
|||||||
42
main.go
42
main.go
@@ -24,7 +24,6 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"sort"
|
|
||||||
|
|
||||||
"github.com/lmittmann/tint"
|
"github.com/lmittmann/tint"
|
||||||
"github.com/mattn/go-isatty"
|
"github.com/mattn/go-isatty"
|
||||||
@@ -43,7 +42,7 @@ const (
|
|||||||
|
|
||||||
LevelNotice = slog.Level(2)
|
LevelNotice = slog.Level(2)
|
||||||
|
|
||||||
VERSION = "v0.3.1"
|
VERSION = "v0.3.0"
|
||||||
|
|
||||||
IPC_HEADER_SIZE = 14
|
IPC_HEADER_SIZE = 14
|
||||||
IPC_MAGIC = "i3-ipc"
|
IPC_MAGIC = "i3-ipc"
|
||||||
@@ -56,7 +55,6 @@ const (
|
|||||||
var (
|
var (
|
||||||
Visibles = []*i3ipc.Node{}
|
Visibles = []*i3ipc.Node{}
|
||||||
CurrentWorkspace = ""
|
CurrentWorkspace = ""
|
||||||
Previous = false
|
|
||||||
Debug = false
|
Debug = false
|
||||||
Dumptree = false
|
Dumptree = false
|
||||||
Dumpvisibles = false
|
Dumpvisibles = false
|
||||||
@@ -72,7 +70,6 @@ const Usage string = `This is swaycycle - cycle focus through all visible window
|
|||||||
Usage: swaycycle [-vdDn] [-l <log>]
|
Usage: swaycycle [-vdDn] [-l <log>]
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-p, --prev cycle backward
|
|
||||||
-n, --no-switch do not switch windows
|
-n, --no-switch do not switch windows
|
||||||
-d, --debug enable debugging
|
-d, --debug enable debugging
|
||||||
-D, --dump dump the sway tree (needs -d as well)
|
-D, --dump dump the sway tree (needs -d as well)
|
||||||
@@ -85,7 +82,6 @@ Licensed under the terms of the GNU GPL version 3.
|
|||||||
`
|
`
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.BoolVarP(&Previous, "prev", "p", false, "cycle backward")
|
|
||||||
flag.BoolVarP(&Debug, "debug", "d", false, "enable debugging")
|
flag.BoolVarP(&Debug, "debug", "d", false, "enable debugging")
|
||||||
flag.BoolVarP(&Dumptree, "dump", "D", false, "dump the sway tree (needs -d as well)")
|
flag.BoolVarP(&Dumptree, "dump", "D", false, "dump the sway tree (needs -d as well)")
|
||||||
flag.BoolVarP(&Dumpvisibles, "dump-visibles", "", false, "dump a list of visible windows on current workspace (needs -d)")
|
flag.BoolVarP(&Dumpvisibles, "dump-visibles", "", false, "dump a list of visible windows on current workspace (needs -d)")
|
||||||
@@ -141,14 +137,8 @@ func main() {
|
|||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
id := 0
|
id := findNextWindow()
|
||||||
if Previous {
|
|
||||||
id = findPrevWindow()
|
|
||||||
slog.Debug("findPrevWindow", "nextid", id)
|
|
||||||
} else {
|
|
||||||
id = findNextWindow()
|
|
||||||
slog.Debug("findNextWindow", "nextid", id)
|
slog.Debug("findNextWindow", "nextid", id)
|
||||||
}
|
|
||||||
|
|
||||||
if id > 0 && !Notswitch {
|
if id > 0 && !Notswitch {
|
||||||
switchFocus(id, ipc)
|
switchFocus(id, ipc)
|
||||||
@@ -209,24 +199,6 @@ func findNextWindow() int {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func findPrevWindow() int {
|
|
||||||
vislen := len(Visibles)
|
|
||||||
if vislen == 0 {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
prevnode := Visibles[vislen-1].Id
|
|
||||||
|
|
||||||
for _, node := range Visibles {
|
|
||||||
if node.Focused {
|
|
||||||
return prevnode
|
|
||||||
}
|
|
||||||
prevnode = node.Id
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// actually switch focus using a swaymsg command
|
// actually switch focus using a swaymsg command
|
||||||
func switchFocus(id int, ipc *i3ipc.I3ipc) error {
|
func switchFocus(id int, ipc *i3ipc.I3ipc) error {
|
||||||
responses, err := ipc.RunContainerCommand(id, "focus")
|
responses, err := ipc.RunContainerCommand(id, "focus")
|
||||||
@@ -243,17 +215,11 @@ func switchFocus(id int, ipc *i3ipc.I3ipc) error {
|
|||||||
// iterate recursively over given node list extracting visible windows
|
// iterate recursively over given node list extracting visible windows
|
||||||
func recurseNodes(nodes []*i3ipc.Node) {
|
func recurseNodes(nodes []*i3ipc.Node) {
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
|
// we handle nodes and floating_nodes identical
|
||||||
|
node.Nodes = append(node.Nodes, node.FloatingNodes...)
|
||||||
|
|
||||||
if istype(node, workspace) {
|
if istype(node, workspace) {
|
||||||
if node.Name == CurrentWorkspace {
|
if node.Name == CurrentWorkspace {
|
||||||
//floating_nodes need to be sorted because
|
|
||||||
//order changes each time they are focused.
|
|
||||||
FloatVis := node.FloatingNodes
|
|
||||||
sort.Slice(FloatVis, func(i, j int) bool {
|
|
||||||
return FloatVis[i].Id < FloatVis[j].Id
|
|
||||||
})
|
|
||||||
//now we can handle nodes and floating_nodes identical
|
|
||||||
node.Nodes = append(node.Nodes, FloatVis...)
|
|
||||||
recurseNodes(node.Nodes)
|
recurseNodes(node.Nodes)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user