Skip to content

Commit

Permalink
v0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pancsta committed Jun 3, 2024
1 parent 71fd645 commit 047d664
Show file tree
Hide file tree
Showing 21 changed files with 1,671 additions and 449 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/releaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: goreleaser

on:
push:
tags:
- 'v*'

permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
-
name: Set up Go
uses: actions/setup-go@v4
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@ go.work
/.dev
/sway-yast
/test.sh
/data.txt
/data.txt

/dist
19 changes: 19 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
builds:
- id: "sway-yast"
main: "./cmd/sway-yast/main.go"
binary: "sway-yast"
goos:
- linux
goarch:
- 386
- amd64
- arm64
goarm:
- 7

release:
github:
owner: pancsta
name: sway-yast
draft: true
replace_existing_draft: true
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## v0.1.0
- mouse follows focus
- pick space
- pick win
- run path
- live config changes

## v0.0.1
- initial release
179 changes: 151 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,84 @@
# sway-yast

**Y**et **A**nother **S**way **T**ab is a single-binary alt+tab clone (Most Recently Used) window switcher for [Sway WM](https://github.com/swaywm/sway).

![Dark mode](./assets/dark.png)
![Light mode](./assets/light.png)

## Features

1. Daemon (IPC & RPC) architecture, filesystem-free
2. Uses `fzf`, works in the terminal
3. Renders a popup using `foot` (optional)
4. Dark mode support (optional)<br />
Checks `gsettings get org.gnome.desktop.interface color-scheme`
5. Shows workspaces and outputs (especially headless)
6. 1-hand compatible keystrokes

## Usage

1. Install<br />
`go install github.com/pancsta/sway-yast@latest`
Sway **Y**et **A**nother **S**way **T**ab is a text-based window switcher which mimics alt+tab behavior (Most Recently Used order)
for [Sway WM](https://github.com/swaywm/sway).


| Dark Mode | Light Mode |
|------------------------------------------|------------------------------------------|
| ![Dark mode](./assets/dark.png) | ![Light mode](./assets/light.png) |

```text
$ sway-yast --help
Usage:
sway-yast [flags]
sway-yast [command]
Available Commands:
completion Generate the autocompletion script for the specified shell
config Change the config of a running daemon process
daemon Start tracking focus in sway
fzf Run fzf with a list of windows
fzf-path Run fzf with a list of executable files from PATH
fzf-pick-space Run fzf with a list of workspaces to pick
fzf-pick-win Run fzf with a list of windows to pick
help Help about any command
mru-list Print a list of MRU window IDs
path Show the +x files from PATH using foot
pick-space Show the workspace picker using foot
pick-win Show the window picker using foot
switcher Show the switcher window using foot
Flags:
-h, --help help for sway-yast
--version Print version and exit
Use "sway-yast [command] --help" for more information about a command.
```

```text
$ sway-yast daemon --help
Start tracking focus in sway
Usage:
sway-yast daemon [flags]
Flags:
--autoconfig Automatic configuration of layout (default true)
--default-keybindings Add default keybindings
-h, --help help for daemon
--mouse-follows-focus Calls 'input ... map_to_output OUTPUT' on each focus
```

## features

- daemon (IPC & RPC) architecture, filesystem-free
- uses `fzf` so it works in the terminal
- renders a floating popup using `foot` (optional)
- dark mode support (optional)<br />
checks `gsettings get org.gnome.desktop.interface color-scheme`
- 1-hand keystrokes
- [mouse follows focus](#mouse-follows-focus) mode (optional)
- additional features (popups)
- move a workspace to the current output
- move a window to the current workspace
- run anything in your `PATH`
- general MRU watcher via `mru-list`

## usage

1. Install using either<br />
- binary from [the releases page](https://github.com/pancsta/sway-yast/releases/latest)
- `go install github.com/pancsta/sway-yast@latest`
- `git clone && go mod tidy && go build`
2. Start the daemon<br />
`sway-yast daemon`
3. Add a binding (optional)<br />
`swaymsg bindsym alt+tab exec sway-yast switcher`
4. Run in the terminal (optional)<br />
`sway-yast daemon --default-keystrokes`
3. Use directly in the terminal (optional)<br />
`sway-yast fzf`
5. Press `alt+tab`
4. Press `alt+tab`

## Key bindings
## keystrokes

Normal mode:

Expand Down Expand Up @@ -57,11 +108,83 @@ Example - switch to Krusader by name:
- `k`, `r`, `u`
- `enter`

## Configuration
### default keystrokes

Various ways to get the default keybindings.

```bash
$ sway-yast daemon --default-keybindings
```

```bash
# shell
swaymsg bindsym alt+tab exec sway-yast switcher
swaymsg bindsym mod4+o exec sway-yast pick-space
swaymsg bindsym mod4+p exec sway-yast pick-win
swaymsg bindsym mod4+d exec sway-yast path
```

```text
# config
bindsym alt+tab exec sway-yast switcher
bindsym $mod+o exec sway-yast pick-space
bindsym $mod+p exec sway-yast pick-win
bindsym $mod+d exec sway-yast path
```

## mouse follows focus

```bash
$ sway-yast daemon --mouse-follows-focus
```

Using `input map_to_output`, traps the relative cursor inside the currently focused output. Changing focus moves the cursor between outputs (thus the name). Useful for VNC screens on separate machines. When combined with [waycorner](https://github.com/AndreasBackx/waycorner), it creates a synergy-like effect.

### waycorner config example

```toml
# HEADLESS-1 (right screen)
[pro5-left]
enter_command = [ "sway-pointer-output", "2" ]
locations = ["left"]
[pro5-left.output]
description = ".*output 1.*"

# HEADLESS-2 (left screen)
[mini6-right]
enter_command = [ "sway-pointer-output", "1" ]
locations = ["right"]
[mini6-right.output]
description = ".*output 2.*"
```

## configuration

See the [top config section in internal/pkg/daemon.go](internal/pkg/daemon.go), modify and `go build cmd/sway-yast/*.go`.

## additional features (popups)

### move a workspace to the current output

![move workspace](assets/move-workspace.png)

### move a window to the current workspace

![move window](assets/move-window.png)

### run anything in your `PATH`

![path runner](assets/path-runner.png)

## troubleshooting

`env YAST_LOG=1 sway-yast`

## changelog

See the [config section in main.go](main.go), modify and `go build`.
See [CHANGELOG.md](CHANGELOG.md).

## Kudos
## kudos

- [applist.py](https://github.com/davxy/dotfiles/blob/main/_old/sway/applist.py)
- [sway-fzfify](https://github.com/ldelossa/sway-fzfify)
Expand Down
Binary file modified assets/dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/grafana-dashboard-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/grafana-dashboard-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/move-window.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/move-workspace.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/path-runner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
129 changes: 129 additions & 0 deletions cmd/sway-yast/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package main

import (
"fmt"
"io"
"log"
"os"

"github.com/pancsta/sway-yast/internal/cmd"
"github.com/pancsta/sway-yast/internal/daemon"
"github.com/spf13/cobra"
)

func main() {
// TODO --status (PID, config, windows count)
// TODO readme, screenshots
// TODO auto bind default shortcuts via --bind-default-keys
// alt+tab, cmd+o, cmd+p
// TODO include desktop shortcuts in "path" (Name, Exe)
// - ~/.local/share/applications
// - /usr/share/applications
if os.Getenv("YAST_LOG") == "" {
log.SetOutput(io.Discard)
}
cmdDaemon := &cobra.Command{
Use: "daemon",
Short: "Start tracking focus in sway",
Run: func(cmd *cobra.Command, args []string) {
mouseFollow, _ := cmd.Flags().GetBool("mouse-follows-focus")
autoconfig, _ := cmd.Flags().GetBool("autoconfig")
defaultKeybindings, _ := cmd.Flags().GetBool("default-keybindings")
d := &daemon.Daemon{
MouseFollowsFocus: mouseFollow,
Autoconfig: autoconfig,
DefaultKeybindings: defaultKeybindings,
}
if mouseFollow {
log.Println("Mouse follows focus enabled")
}
d.Start()
},
}
// TODO extract
cmdDaemon.Flags().Bool("mouse-follows-focus", false,
"Calls 'input ... map_to_output OUTPUT' on each focus")
cmdDaemon.Flags().Bool("autoconfig", true,
"Automatic configuration of layout")
cmdDaemon.Flags().Bool("default-keybindings", false,
"Add default keybindings")

cmdList := &cobra.Command{
Use: "mru-list",
Short: "Print a list of MRU window IDs",
Run: func(cmd *cobra.Command, args []string) {
fmt.Print(daemon.RemoteCall("Daemon.RemoteWinList", daemon.RPCArgs{}))
},
}

cmdFzf := &cobra.Command{
Use: "fzf",
Short: "Run fzf with a list of windows",
Run: cmd.CmdFzf,
}

cmdFzfPickWin := &cobra.Command{
Use: "fzf-pick-win",
Short: "Run fzf with a list of windows to pick",
Run: cmd.CmdFzfPickWin,
}

cmdFzfPickSpace := &cobra.Command{
Use: "fzf-pick-space",
Short: "Run fzf with a list of workspaces to pick",
Run: cmd.CmdFzfPickSpace,
}

cmdFzfPath := &cobra.Command{
Use: "fzf-path",
Short: "Run fzf with a list of executable files from PATH",
Run: cmd.CmdFzfPath,
}

cmdSwitcher := &cobra.Command{
Use: "switcher",
Short: "Show the switcher window using foot",
Run: cmd.CmdSwitcher,
}

cmdPickWin := &cobra.Command{
Use: "pick-win",
Short: "Show the window picker using foot",
Run: cmd.CmdPickWin,
}

cmdPickSpace := &cobra.Command{
Use: "pick-space",
Short: "Show the workspace picker using foot",
Run: cmd.CmdPickSpace,
}

cmdPath := &cobra.Command{
Use: "path",
Short: "Show the +x files from PATH using foot",
Run: cmd.CmdPath,
}

cmdConfig := &cobra.Command{
Use: "config",
Short: "Change the config of a running daemon process",
Run: cmd.CmdConfig,
}
// TODO extract
cmdConfig.Flags().Bool("mouse-follows-focus", false,
"Calls 'input ... map_to_output OUTPUT' on each focus")

var rootCmd = &cobra.Command{
Use: "sway-yast",
Run: cmd.CmdRoot,
}
rootCmd.AddCommand(cmdDaemon, cmdList, cmdFzf, cmdSwitcher, cmdFzfPickWin, cmdPickWin, cmdConfig, cmdFzfPickSpace,
cmdPickSpace, cmdPath, cmdFzfPath)
rootCmd.Flags().Bool("version", false,
"Print version and exit")

err := rootCmd.Execute()
if err != nil {
log.Fatal("cobra error:", err)
}
}
Loading

0 comments on commit 047d664

Please sign in to comment.