This commit is contained in:
Milarin 2024-02-09 20:32:02 +01:00
parent 399d484f6e
commit 283e7bd1fc
4 changed files with 0 additions and 157 deletions

View File

@ -1,21 +0,0 @@
package hypr
import (
"fmt"
"net"
"os"
)
func Execute(cmd string) error {
conn, err := net.Dial("unix", os.ExpandEnv("/tmp/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock"))
if err != nil {
return err
}
defer conn.Close()
if _, err := fmt.Fprintln(conn, cmd); err != nil {
return err
}
return nil
}

View File

@ -1,36 +0,0 @@
package hypr
import (
"encoding/json"
"os/exec"
"git.milar.in/milarin/slices"
)
func GetWindows() ([]*Window, error) {
cmd := exec.Command("hyprctl", "-j", "clients")
stdout, err := cmd.StdoutPipe()
if err != nil {
return nil, err
}
if err := cmd.Start(); err != nil {
return nil, err
}
windows := make([]*Window, 0, 5)
if err := json.NewDecoder(stdout).Decode(&windows); err != nil {
return nil, err
}
if err := cmd.Wait(); err != nil {
return nil, err
}
windows = slices.Filter(windows, func(w *Window) bool {
return w.PID != -1
})
return windows, nil
}

View File

@ -1,46 +0,0 @@
package hypr
import (
"bufio"
"context"
"net"
"os"
"strings"
"git.milar.in/milarin/channel"
"git.milar.in/milarin/slices"
)
func GetEventChannel(ctx context.Context, types ...EventType) (<-chan Event, error) {
conn, err := net.Dial("unix", os.ExpandEnv("/tmp/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock"))
if err != nil {
return nil, err
}
out := make(chan Event, 10)
go func() {
defer conn.Close()
<-ctx.Done()
}()
go func() {
defer close(out)
defer conn.Close()
sc := bufio.NewScanner(conn)
for sc.Scan() {
out <- parseEvent(sc.Text())
}
}()
if len(types) == 0 {
return out, nil
}
typeMap := slices.ToStructMap(slices.Map(types, strings.ToLower))
return channel.Filter(out, func(e Event) bool {
_, ok := typeMap[e.Type]
return ok
}), nil
}

View File

@ -1,54 +0,0 @@
package hypr
import (
"encoding/json"
"os/exec"
)
func GetWorkspaces() ([]*Workspace, error) {
cmd := exec.Command("hyprctl", "-j", "workspaces")
stdout, err := cmd.StdoutPipe()
if err != nil {
return nil, err
}
if err := cmd.Start(); err != nil {
return nil, err
}
workspaces := make([]*Workspace, 0, 5)
if err := json.NewDecoder(stdout).Decode(&workspaces); err != nil {
return nil, err
}
if err := cmd.Wait(); err != nil {
return nil, err
}
return workspaces, nil
}
func GetActiveWorkspace() (*Workspace, error) {
cmd := exec.Command("hyprctl", "-j", "activeworkspace")
stdout, err := cmd.StdoutPipe()
if err != nil {
return nil, err
}
if err := cmd.Start(); err != nil {
return nil, err
}
workspace := &Workspace{}
if err := json.NewDecoder(stdout).Decode(workspace); err != nil {
return nil, err
}
if err := cmd.Wait(); err != nil {
return nil, err
}
return workspace, nil
}