Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
labi-le committed May 14, 2024
2 parents 496aa06 + d8ba6ca commit 8930db2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type ed struct {
}

func main() {
c := client.NewClient(os.Getenv("HYPRLAND_INSTANCE_SIGNATURE"))
c := client.MustClient(os.Getenv("HYPRLAND_INSTANCE_SIGNATURE"))
e := &ed{}
client.Subscribe(c, e, client.EventActiveLayout)
}
Expand Down
31 changes: 25 additions & 6 deletions ipc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"encoding/json"
"errors"
"io"
"log"
"net"
"os"
"reflect"
"strings"
)
Expand All @@ -25,15 +27,33 @@ type ReceivedData struct {
type IPCClient struct {
conn net.Conn
wconn *net.UnixAddr
sign string
}

func NewClient(sign string) *IPCClient {
if sign == "" {
func MustClient(sign string) *IPCClient {
readsock := "/tmp/hypr/" + sign + "/.socket2.sock"
writesock := "/tmp/hypr/" + sign + "/.socket.sock"

_, exist := os.Stat(readsock)
_, wexist := os.Stat(writesock)
if exist == nil && wexist == nil {
return NewClient(
readsock,
writesock,
)
}
xdg := os.Getenv("XDG_RUNTIME_DIR")
return NewClient(
xdg+"/hypr/"+sign+"/.socket2.sock",
xdg+"/hypr/"+sign+"/.socket.sock",
)
}

func NewClient(readSock, writeSock string) *IPCClient {
if readSock == "" || writeSock == "" {
panic("sign is empty")
}

conn, err := net.Dial("unix", "/tmp/hypr/"+sign+"/.socket2.sock")
conn, err := net.Dial("unix", readSock)
if err != nil {
panic(err)
}
Expand All @@ -42,9 +62,8 @@ func NewClient(sign string) *IPCClient {
conn: conn,
wconn: &net.UnixAddr{
Net: "unix",
Name: "/tmp/hypr/" + sign + "/.socket.sock",
Name: writeSock,
},
sign: sign,
}
}

Expand Down
3 changes: 2 additions & 1 deletion ipc_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package client

import (
"os"
"reflect"
"testing"
)

var ipctest = NewClient("fe7b748eb668136dd0558b7c8279bfcd7ab4d759_1714258749")
var ipctest = MustClient(os.Getenv("HYPRLAND_INSTANCE_SIGNATURE"))

func Test_ipc_Clients(t *testing.T) {
got, err := ipctest.Clients()
Expand Down
13 changes: 8 additions & 5 deletions ipc_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,14 @@ type Devices struct {
}

type Version struct {
Branch string `json:"branch"`
Commit string `json:"commit"`
Dirty bool `json:"dirty"`
CommitMessage string `json:"commit_message"`
Flags []interface{} `json:"flags"`
Branch string `json:"branch"`
Commit string `json:"commit"`
Dirty bool `json:"dirty"`
CommitMessage string `json:"commit_message"`
CommitDate string `json:"commit_date"`
Tag string `json:"tag"`
Commits string `json:"commits"`
Flags []string `json:"flags"`
}

type CursorPos struct {
Expand Down

0 comments on commit 8930db2

Please sign in to comment.