-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathhyprctl.go
More file actions
70 lines (57 loc) · 1.97 KB
/
hyprctl.go
File metadata and controls
70 lines (57 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package wallutils
import (
"fmt"
"github.com/xyproto/env/v2"
)
// Hyprctl compatible windowmanager
type Hyprctl struct {
mode string
verbose bool
}
// Name returns the name of this window manager or desktop environment
func (h *Hyprctl) Name() string {
return "Hyprctl"
}
// ExecutablesExists checks if executables associated with this backend exists in the PATH
func (h *Hyprctl) ExecutablesExists() bool {
return which("hyprctl") != "" && which("hyprpaper") != ""
}
// Running examines environment variables to try to figure out if this backend is currently running.
func (h *Hyprctl) Running() bool {
return env.Contains("XDG_SESSION_DESKTOP", "Hyprland") || env.Contains("DESKTOP_SESSION", "hyprland")
}
// SetMode will set the current way to display the wallpaper (stretched, tiled etc)
func (h *Hyprctl) SetMode(mode string) {
h.mode = mode
}
// SetVerbose can be used for setting the verbose field to true or false.
// This will cause this backend to output information about what is is doing on stdout.
func (h *Hyprctl) SetVerbose(verbose bool) {
h.verbose = verbose
}
// SetWallpaper sets the desktop wallpaper, given an image filename.
// The image must exist and be readable.
func (h *Hyprctl) SetWallpaper(imageFilename string) error {
if !exists(imageFilename) {
return fmt.Errorf("no such file: %s", imageFilename)
}
// Set the wallpaper mode
mode := defaultMode
if h.mode != "" {
mode = h.mode
}
switch mode {
case "stretched", "center", "fill", "fit", "scale", "scaled", "stretch", "tile", "zoom", "zoomed":
mode = ""
default:
// Invalid and unrecognized desktop wallpaper mode
return fmt.Errorf("invalid desktop wallpaper mode for swaybg: %s", mode)
}
// preload the wallpaper image using hyprctl
err := run("hyprctl", []string{"hyprpaper", "preload", imageFilename}, h.verbose)
if err != nil {
return err
}
// reload the wallpaper image using hyprctl
return run("hyprctl", []string{"hyprpaper", "reload", ",\"" + imageFilename + "\""}, h.verbose)
}