Skip to content

Commit

Permalink
fix(compat): Update for new hyprland socket path, with fallback to /tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
pdf committed May 11, 2024
1 parent ca60d54 commit bc004e5
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions internal/hypripc/hypripc.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"net"
"os"
"path"
"regexp"
"strconv"
"strings"
Expand Down Expand Up @@ -193,7 +194,11 @@ func (h *HyprIPC) Dispatch(args ...string) error {
}

func (h *HyprIPC) send(args ...string) ([]byte, error) {
ctrl, err := net.Dial(`unix`, fmt.Sprintf("/tmp/hypr/%s/.socket.sock", os.Getenv(`HYPRLAND_INSTANCE_SIGNATURE`)))
sock, err := socketPath(`.socket.sock`)
if err != nil {
return nil, err
}
ctrl, err := net.Dial(`unix`, sock)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -314,7 +319,11 @@ func (h *HyprIPC) readloop() {

// New instantiates a new HyprIPC client
func New(log hclog.Logger) (*HyprIPC, error) {
evtConn, err := net.Dial(`unix`, fmt.Sprintf("/tmp/hypr/%s/.socket2.sock", os.Getenv(`HYPRLAND_INSTANCE_SIGNATURE`)))
sock, err := socketPath(`.socket2.sock`)
if err != nil {
return nil, err
}
evtConn, err := net.Dial(`unix`, sock)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -546,3 +555,19 @@ func hyprToEvent(name Event, value string) (*eventv1.Event, error) {
return eventv1.NewString(eventv1.EventKind_EVENT_KIND_UNSPECIFIED, value)
}
}

func socketPath(sock string) (string, error) {
s := path.Join(os.Getenv(`XDG_RUNTIME_DIR`), `hypr`, os.Getenv(`HYPRLAND_INSTANCE_SIGNATURE`), sock)
_, err := os.Stat(s)
if err == nil {
return s, nil
}

s = path.Join(`/tmp`, `hypr`, os.Getenv(`HYPRLAND_INSTANCE_SIGNATURE`), sock)
_, err = os.Stat(s)
if err != nil {
return ``, fmt.Errorf("hyprland socket not found: %w", err)
}

return s, nil
}

0 comments on commit bc004e5

Please sign in to comment.