9 Commits

Author SHA1 Message Date
a0f85e4d90 add badges 2025-11-10 20:10:46 +01:00
16ba4846d4 make linter happy 2025-11-10 20:06:43 +01:00
80cb994396 fix i3ipc dep 2025-11-10 19:59:14 +01:00
c7f85508f4 moving to codeberg 2025-11-10 19:54:27 +01:00
dependabot[bot]
85a1e6530c Bump actions/checkout from 4 to 5 (#5) 2025-09-19 07:56:48 +02:00
feba0f3580 bump version 2025-08-25 09:53:53 +02:00
2fbb3ebc59 add doc about prev flag 2025-08-25 09:53:40 +02:00
T.v.Dein
8e48b42bad enhance window switch debugging (#4) 2025-08-25 09:02:14 +02:00
kkvark
7a5657b778 add --prev option and sort floating_nodes (#3)
* add --prev option
* sort floating_nodes to avoid skipping floating windows
2025-08-25 08:59:21 +02:00
7 changed files with 199 additions and 101 deletions

View File

@@ -1,87 +0,0 @@
name: build-release
on:
push:
tags:
- "v*.*.*"
jobs:
release:
name: Build Release Assets
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.23.5
- name: Build the executables
run: ./mkrel.sh swaycycle ${{ github.ref_name}}
- name: List the executables
run: ls -l ./releases
- name: Upload the binaries
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.ref_name }}
file: ./releases/*
file_glob: true
- name: Build Changelog
id: github_release
uses: mikepenz/release-changelog-builder-action@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
mode: "PR"
configurationJson: |
{
"template": "#{{CHANGELOG}}\n\n**Full Changelog**: #{{RELEASE_DIFF}}",
"pr_template": "- #{{TITLE}} (##{{NUMBER}}) by #{{AUTHOR}}\n#{{BODY}}",
"empty_template": "- no changes",
"categories": [
{
"title": "## New Features",
"labels": ["add", "feature"]
},
{
"title": "## Bug Fixes",
"labels": ["fix", "bug", "revert"]
},
{
"title": "## Documentation Enhancements",
"labels": ["doc"]
},
{
"title": "## Refactoring Efforts",
"labels": ["refactor"]
},
{
"title": "## Miscellaneus Changes",
"labels": []
}
],
"ignore_labels": [
"duplicate", "good first issue", "help wanted", "invalid", "question", "wontfix"
],
"label_extractor": [
{
"pattern": "(.) (.+)",
"target": "$1"
},
{
"pattern": "(.) (.+)",
"target": "$1",
"on_property": "title"
}
]
}
- name: Create Release
uses: softprops/action-gh-release@v2
with:
body: ${{steps.github_release.outputs.changelog}}

65
.goreleaser.yaml Normal file
View File

@@ -0,0 +1,65 @@
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
version: 2
before:
hooks:
- go mod tidy
gitea_urls:
api: https://codeberg.org/api/v1
download: https://codeberg.org
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- freebsd
archives:
- formats: [tar.gz]
# this name template makes the OS and Arch compatible with the results of `uname`.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}_{{ .Tag }}
# use zip for windows archives
format_overrides:
- goos: windows
formats: [zip]
- goos: linux
formats: [tar.gz,binary]
files:
- src: "*.md"
strip_parent: true
- src: Makefile.dist
dst: Makefile
wrap_in_directory: true
changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
groups:
- title: Improved
regexp: '^.*?(feat|add|new)(\([[:word:]]+\))??!?:.+$'
order: 0
- title: Fixed
regexp: '^.*?(bug|fix)(\([[:word:]]+\))??!?:.+$'
order: 1
- title: Changed
order: 999
release:
header: "# Release Notes"
footer: >-
---
Full Changelog: [{{ .PreviousTag }}...{{ .Tag }}](https://codeberg.org/scip/swaycycle/compare/{{ .PreviousTag }}...{{ .Tag }})

36
.woodpecker/build.yaml Normal file
View File

@@ -0,0 +1,36 @@
matrix:
platform:
- linux/amd64
goversion:
- 1.24
labels:
platform: ${platform}
steps:
build:
when:
event: [push]
image: golang:${goversion}
commands:
- go get
- go build
linter:
when:
event: [push]
image: golang:${goversion}
commands:
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.5.0
- golangci-lint --version
- golangci-lint run ./...
depends_on: [build]
test:
when:
event: [push]
image: golang:${goversion}
commands:
- go get
- go test -v -cover
depends_on: [build,linter]

15
.woodpecker/release.yaml Normal file
View File

@@ -0,0 +1,15 @@
# build release
labels:
platform: linux/amd64
steps:
goreleaser:
image: goreleaser/goreleaser
when:
event: [tag]
environment:
GITEA_TOKEN:
from_secret: DEPLOY_TOKEN
commands:
- goreleaser release --clean --verbose

18
Makefile.dist Normal file
View File

@@ -0,0 +1,18 @@
# -*-make-*-
.PHONY: install all
tool = rpn
PREFIX = /usr/local
UID = root
GID = 0
all:
@echo "Type 'sudo make install' to install the tool."
@echo "To change prefix, type 'sudo make install PREFIX=/opt'"
install:
install -d -o $(UID) -g $(GID) $(PREFIX)/bin
install -d -o $(UID) -g $(GID) $(PREFIX)/share/doc
install -o $(UID) -g $(GID) -m 555 $(tool) $(PREFIX)/sbin/
install -o $(UID) -g $(GID) -m 444 *.md $(PREFIX)/share/doc/

View File

@@ -1,3 +1,7 @@
[![status-badge](https://ci.codeberg.org/api/badges/15562/status.svg)](https://ci.codeberg.org/repos/15562)
[![License](https://img.shields.io/badge/license-GPL-blue.svg)](https://codeberg.org/scip/swaycycle/raw/branch/main/LICENSE)
[![Go Report Card](https://goreportcard.com/badge/codeberg.org/scip/epuppy)](https://goreportcard.com/report/codeberg.org/scip/swaycycle)
# swaycycle
Cycle through all visible windows on a sway[fx] workspace including
@@ -9,7 +13,7 @@ the tool to `ALT-tab` and there you go.
## Installation
Download the binary for your architecture from the [release
page](https://github.com/TLINDEN/swaycycle/releases) and copy to
page](https://codeberg.org/scip/swaycycle/releases) and copy to
some location within your `$PATH`.
To build the tool from source, checkout the repo and execute
@@ -24,6 +28,13 @@ Add such a line to your sway config file (e.g. in `$HOME/.config/sway/config`):
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
You may call `swaycycle` in a terminal window on a workspace with at
@@ -69,7 +80,7 @@ best way for me to forget to do something.
In order to report a bug, unexpected behavior, feature requests or to
submit a patch, please open an issue on github:
https://github.com/tlinden/swaycycle/issues.
https://codeberg.org/scip/swaycycle/issues.
## See also
@@ -87,7 +98,7 @@ T.v.Dein <tom AT vondein DOT org>
## Project homepage
https://github.com/tlinden/swaycycle
https://codeberg.org/scip/swaycycle
## Copyright and License

62
main.go
View File

@@ -18,12 +18,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package main
import (
"errors"
"fmt"
"io"
"log"
"log/slog"
"os"
"runtime/debug"
"sort"
"github.com/lmittmann/tint"
"github.com/mattn/go-isatty"
@@ -42,7 +44,7 @@ const (
LevelNotice = slog.Level(2)
VERSION = "v0.3.0"
VERSION = "v0.3.1"
IPC_HEADER_SIZE = 14
IPC_MAGIC = "i3-ipc"
@@ -55,6 +57,7 @@ const (
var (
Visibles = []*i3ipc.Node{}
CurrentWorkspace = ""
Previous = false
Debug = false
Dumptree = false
Dumpvisibles = false
@@ -70,6 +73,7 @@ const Usage string = `This is swaycycle - cycle focus through all visible window
Usage: swaycycle [-vdDn] [-l <log>]
Options:
-p, --prev cycle backward
-n, --no-switch do not switch windows
-d, --debug enable debugging
-D, --dump dump the sway tree (needs -d as well)
@@ -78,10 +82,10 @@ Options:
-v, --version show program version
Copyleft (L) 2025 Thomas von Dein.
Licensed under the terms of the GNU GPL version 3.
`
Licensed under the terms of the GNU GPL version 3.`
func main() {
flag.BoolVarP(&Previous, "prev", "p", false, "cycle backward")
flag.BoolVarP(&Debug, "debug", "d", false, "enable debugging")
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)")
@@ -108,7 +112,11 @@ func main() {
if err != nil {
log.Fatalf("Failed to open logfile %s: %s", Logfile, err)
}
defer file.Close()
defer func() {
if err := file.Close(); err != nil {
log.Fatalf("failed to close log file: %s", err)
}
}()
setupLogging(file)
} else {
setupLogging(os.Stdout)
@@ -137,11 +145,19 @@ func main() {
os.Exit(0)
}
id := findNextWindow()
slog.Debug("findNextWindow", "nextid", id)
id := 0
if Previous {
id = findPrevWindow()
slog.Debug("findPrevWindow", "nextid", id)
} else {
id = findNextWindow()
slog.Debug("findNextWindow", "nextid", id)
}
if id > 0 && !Notswitch {
switchFocus(id, ipc)
if err := switchFocus(id, ipc); err != nil {
log.Fatalf("%s", err)
}
}
}
@@ -149,7 +165,7 @@ func main() {
// its visible windows, store them in the global var Visibles
func processJSON(sway *i3ipc.Node) error {
if !istype(sway, root) && len(sway.Nodes) == 0 {
return fmt.Errorf("Invalid or empty JSON structure")
return errors.New("invalid or empty JSON structure")
}
if Dumptree {
@@ -199,11 +215,29 @@ func findNextWindow() int {
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
func switchFocus(id int, ipc *i3ipc.I3ipc) error {
responses, err := ipc.RunContainerCommand(id, "focus")
if err != nil {
log.Fatalf("failed to send focus command to container %d: %w (%s)",
log.Fatalf("failed to send focus command to container %d: %s (%s)",
id, responses[0].Error, err)
}
@@ -215,11 +249,17 @@ func switchFocus(id int, ipc *i3ipc.I3ipc) error {
// iterate recursively over given node list extracting visible windows
func recurseNodes(nodes []*i3ipc.Node) {
for _, node := range nodes {
// we handle nodes and floating_nodes identical
node.Nodes = append(node.Nodes, node.FloatingNodes...)
if istype(node, workspace) {
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)
return
}