diff --git a/.fpm b/.fpm index 247b8cf..747df4e 100644 --- a/.fpm +++ b/.fpm @@ -3,5 +3,4 @@ --license agpl3 --description "Wallpaper manager for i3" --url "https://gitnet.fr/deblan/i3-wallpaper-manager" ---deb-recommends "feh" --maintainer "Simon Vieille " diff --git a/.gitea/issue_template/FEATURE_TEMPLATE.yml b/.gitea/issue_template/FEATURE_TEMPLATE.yml deleted file mode 100644 index 3d687c5..0000000 --- a/.gitea/issue_template/FEATURE_TEMPLATE.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: New feature -about: Use this template if you want to request a feature -title: "[FEATURE] " -labels: - - Kind/Enhancement -body: - - type: markdown - attributes: - value: | - Thanks for taking the time to fill out this feature request! - - - type: textarea - id: description - attributes: - label: Description - description: Describe the feature. - validations: - required: true - - - type: textarea - id: benefits - attributes: - label: Benefits - description: Describe the benefits of this feature. - validations: - required: true - - - type: textarea - id: extra - attributes: - label: More informations - description: If you want to share more things, this is here! - validations: - required: false diff --git a/.gitea/issue_template/ISSUE_TEMPLATE.yml b/.gitea/issue_template/ISSUE_TEMPLATE.yml deleted file mode 100644 index 0a703fd..0000000 --- a/.gitea/issue_template/ISSUE_TEMPLATE.yml +++ /dev/null @@ -1,63 +0,0 @@ -name: New issue -about: Use this template if you have a bug -title: "[Bug] " -labels: - - Kind/Bug -body: - - type: markdown - attributes: - value: | - Thanks for taking the time to fill out this bug report! - - - type: textarea - id: environment - attributes: - label: Environment - value: | - * i3 wallpaper manager version: - * i3-wm version: - * Operating system and version: - validations: - required: true - - - type: textarea - id: configuration - attributes: - label: Configuration - value: | - ``` - ``` - validations: - required: false - - - type: textarea - id: steps - attributes: - label: Steps to reproduce - description: How reproduce the bug? - validations: - required: false - - - type: textarea - id: resuts - attributes: - label: Observed Results - description: What happened? - validations: - required: false - - - type: textarea - id: expected - attributes: - label: Expected Results - description: What should happen? - validations: - required: false - - - type: textarea - id: extra - attributes: - label: More informations - description: If you want to share more things, this is here! - validations: - required: false diff --git a/.gitea/issue_template/QUESTION_TEMPLATE.yml b/.gitea/issue_template/QUESTION_TEMPLATE.yml deleted file mode 100644 index 30fd73c..0000000 --- a/.gitea/issue_template/QUESTION_TEMPLATE.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: New question -about: Use this template when you don't know how to do something -title: "[Question] " -body: - - type: markdown - attributes: - value: | - Thanks for taking the time to fill information. - - - type: textarea - id: environment - attributes: - label: Environment - value: | - * i3 wallpaper manager version: - * i3-wm version: - * Operating system and version: - validations: - required: true - - - type: textarea - id: question - attributes: - label: Question - validations: - required: true diff --git a/.gitea/issue_template/config.yml b/.gitea/issue_template/config.yml deleted file mode 100644 index d3fdf27..0000000 --- a/.gitea/issue_template/config.yml +++ /dev/null @@ -1,8 +0,0 @@ -blank_issues_enabled: true -contact_links: - - name: Documentation - url: https://gitnet.fr/deblan/i3-wallpaper-manager - about: Official documentation web site - - name: Ask a question in our Matrix room - about: If you prefer a chat-like conversation or in need for quick help, this might be an alternative to opening an issue. - url: https://matrix.to/#/!QDcaVhvLZlhptPkGVi:neutralnetwork.org?via=neutralnetwork.org diff --git a/CHANGELOG.md b/CHANGELOG.md index 7aab162..8ee4019 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,19 +1,5 @@ [Unreleased] -## v1.2.1 -### Added -- Add debian packaging deb-recommends -### Fixed -- Fix #1: add cache of latest command to not run wallpaper update when it's already up to date - -## v1.2.0 -### Added -- Add `callback` option - -## v1.1.1 -### Fixed -- Update wallpapers on start - ## v1.1.0 ### Changed - Refactoring diff --git a/README.md b/README.md index 4bfe0b1..ce80a89 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,12 @@ -# 🖥️ i3 Wallpaper Manager +# 🖥️ i3 wallpaper manager -**i3 Wallpaper Manager** is a command-line tool designed to change the wallpaper depending of active workspaces on [i3](https://i3wm.org/). This tool works on one or multiple screens. - - - -_Thanks [AZProductions](https://github.com/AZProductions/AbstractCollection/)!_ +**i3 wallpaper manager** is a command-line tool designed to change the wallpaper depending of active workspaces on [i3](https://i3wm.org/). ## 📗 How to install the project ### Dependencies -- [Feh](https://feh.finalrewind.org/) (by default) +- [Feh](https://feh.finalrewind.org/) ### Pre-compiled versions @@ -37,7 +33,7 @@ workspaces: "Name of the workspace 3": /home/alice/wallpapers/3.jpg ``` -Next, you simply need to run `i3-wallpaper-manager` and specify the path to the configuration file. +Next, you simply need to run `i3-wallpaper-manager` while specify the path to the configuration file. ```bash DISPLAY=:0 i3-wallpaper-manager /path/to/config.yaml @@ -46,25 +42,5 @@ DISPLAY=:0 i3-wallpaper-manager /path/to/config.yaml To run it when i3 starts, add this to your i3 configuration: ```bash -exec --no-startup-id DISPLAY=:0 i3-wallpaper-manager /path/to/config.yaml -``` - -If you wish to use a program other than `feh`, set the `callback` parameter by specifying the path to your script. - -```yaml -callback: /path/to/custom.sh -``` - -```bash -#!/bin/sh -# /path/to/custom.sh - -SCREEN_1="$1" -WALLPAPER_1="$2" - -SCREEN_2="$3" -WALLPAPER_2="$4" -# etc. - -# Do stuff... +exec_always DISPLAY=:0 i3-wallpaper-manager /path/to/config.yaml ``` diff --git a/callback.go b/callback.go deleted file mode 100644 index 270c942..0000000 --- a/callback.go +++ /dev/null @@ -1,19 +0,0 @@ -package main - -import ( - "os" - "os/exec" -) - -func CallbackUpdateWallpapers(callback string, files, screens []string) *exec.Cmd { - args := []string{} - - for key, file := range files { - args = append(args, screens[key], file) - } - - cmd := exec.Command(callback, args...) - cmd.Env = os.Environ() - - return cmd -} diff --git a/config.go b/config.go index e90166f..9e657cf 100644 --- a/config.go +++ b/config.go @@ -8,7 +8,6 @@ import ( type Config struct { Default string `yaml:"default"` - Callback string `yaml:"callback"` Workspaces map[string]string `yaml:"workspaces"` } diff --git a/config.yaml.example b/config.yaml.example index 0cf69eb..5e50253 100644 --- a/config.yaml.example +++ b/config.yaml.example @@ -3,4 +3,3 @@ workspaces: "Name of the workspace 1": /home/alice/wallpapers/1.jpg "Name of the workspace 2": /home/alice/wallpapers/2.jpg "Name of the workspace 3": /home/alice/wallpapers/3.jpg -# callback: /path/to/custom.sh diff --git a/event.go b/event.go new file mode 100644 index 0000000..d59241d --- /dev/null +++ b/event.go @@ -0,0 +1,14 @@ +package main + +import ( + "os/exec" +) + +func HandleFocusEvent(config Config) (*exec.Cmd, error) { + files, err := GetOutputsWallpapers(config) + if err != nil { + return nil, err + } + + return FehUpdateWallpapers(files) +} diff --git a/feh.go b/feh.go index 9e8b562..4884960 100644 --- a/feh.go +++ b/feh.go @@ -5,7 +5,7 @@ import ( "os/exec" ) -func FehUpdateWallpapers(files []string) *exec.Cmd { +func FehUpdateWallpapers(files []string) (*exec.Cmd, error) { args := []string{} for _, file := range files { @@ -15,5 +15,5 @@ func FehUpdateWallpapers(files []string) *exec.Cmd { cmd := exec.Command("feh", args...) cmd.Env = os.Environ() - return cmd + return cmd, cmd.Run() } diff --git a/main.go b/main.go index 81c8d3e..0c9e58a 100644 --- a/main.go +++ b/main.go @@ -16,21 +16,22 @@ func main() { } config, err := LoadConfiguration(os.Args[1]) - if err != nil { log.Printf("[ERROR] %s", err.Error()) os.Exit(1) } - var lastCommand string - - UpdateWallapers(config, &lastCommand) - for recv.Next() { event := recv.Event().(*i3.WorkspaceEvent) if event.Change == "focus" { - UpdateWallapers(config, &lastCommand) + cmd, err := HandleFocusEvent(config) + + if err != nil { + log.Printf("[ERROR] cmd=%s error=%s", cmd.String(), err.Error()) + } else { + log.Printf("[SUCCESS] cmd=%s", cmd.String()) + } } } } diff --git a/wallpaper.go b/wallpaper.go index bec24d4..3fe854e 100644 --- a/wallpaper.go +++ b/wallpaper.go @@ -1,9 +1,6 @@ package main import ( - "log" - "os/exec" - "go.i3wm.org/i3" ) @@ -18,12 +15,11 @@ func GetWorkspaceWallpaper(workspace string, config Config) string { return file } -func GetOutputsWallpapers(config Config) ([]string, []string, error) { +func GetOutputsWallpapers(config Config) ([]string, error) { files := []string{} - screens := []string{} outputs, err := i3.GetOutputs() if err != nil { - return files, screens, err + return files, err } for _, output := range outputs { @@ -32,40 +28,9 @@ func GetOutputsWallpapers(config Config) ([]string, []string, error) { if file != "" { files = append(files, file) - screens = append(screens, output.Name) } } } - return files, screens, nil -} - -func UpdateWallapers(config Config, lastCommand *string) { - files, screens, err := GetOutputsWallpapers(config) - if err != nil { - log.Printf("[ERROR] %s", err.Error()) - return - } - - var cmd *exec.Cmd - - if config.Callback == "" { - cmd = FehUpdateWallpapers(files) - } else { - cmd = CallbackUpdateWallpapers(config.Callback, files, screens) - } - - if cmd.String() == *lastCommand { - log.Printf("[INFO] wallapaper(s) already up to date") - return - } - - err = cmd.Run() - - if err != nil { - log.Printf("[ERROR] cmd=%s error=%s", cmd.String(), err.Error()) - } else { - log.Printf("[SUCCESS] cmd=%s", cmd.String()) - *lastCommand = cmd.String() - } + return files, nil }