diff --git a/dispatch.go b/dispatch.go index cf1dc72..816eb76 100644 --- a/dispatch.go +++ b/dispatch.go @@ -6,11 +6,11 @@ import ( "strings" ) -func (i *Instance) Dispatch(cmd string) (io.ReadCloser, error) { +func (i *Client) Dispatch(cmd string) (io.ReadCloser, error) { return readSocketRaw(i.SocketPath(), strings.NewReader(fmt.Sprintf("dispatch %s", cmd))) } -func (i *Instance) DispatchExpectOK(cmd string) error { +func (i *Client) DispatchExpectOK(cmd string) error { str, err := readSocketString(i.SocketPath(), strings.NewReader(fmt.Sprintf("dispatch %s", cmd))) if err != nil { return err diff --git a/get_instances.go b/get_clients.go similarity index 73% rename from get_instances.go rename to get_clients.go index efb8116..5ead515 100644 --- a/get_instances.go +++ b/get_clients.go @@ -12,7 +12,7 @@ import ( "git.milar.in/milarin/slices" ) -func GetInstance(signature string) (*Instance, error) { +func GetClient(signature string) (*Client, error) { lockFilePath := fmt.Sprintf("/tmp/hypr/%s.lock", signature) file, err := os.Open(lockFilePath) @@ -33,38 +33,38 @@ func GetInstance(signature string) (*Instance, error) { return nil, err } - return &Instance{ + return &Client{ Signature: signature, PID: pid, WaylandSocket: lines[1], }, nil } -func GetDefaultInstance() (*Instance, error) { +func GetDefaultClient() (*Client, error) { signature, ok := os.LookupEnv("HYPRLAND_INSTANCE_SIGNATURE") if !ok { return nil, errors.New("default instance not found because HYPRLAND_INSTANCE_SIGNATURE is not set") } - return GetInstance(signature) + return GetClient(signature) } -func GetInstances() ([]*Instance, error) { +func GetClients() ([]*Client, error) { entries, err := os.ReadDir("/tmp/hypr") if err != nil { return nil, err } entries = slices.Filter(entries, fs.DirEntry.IsDir) - instances := make([]*Instance, 0, len(entries)) + clients := make([]*Client, 0, len(entries)) for _, entry := range entries { - instance, err := GetInstance(entry.Name()) + client, err := GetClient(entry.Name()) if err != nil { fmt.Println(err) continue } - instances = append(instances, instance) + clients = append(clients, client) } - return instances, nil + return clients, nil } diff --git a/getters.go b/getters.go index 82cf179..565f5f7 100644 --- a/getters.go +++ b/getters.go @@ -4,30 +4,30 @@ import ( "strings" ) -func (i *Instance) GetActiveWindow() (*Window, error) { +func (i *Client) GetActiveWindow() (*Window, error) { return readSocket[*Window](i.SocketPath(), strings.NewReader("j/activewindow")) } -func (i *Instance) GetActiveWorkspace() (*Workspace, error) { +func (i *Client) GetActiveWorkspace() (*Workspace, error) { return readSocket[*Workspace](i.SocketPath(), strings.NewReader("j/activeworkspace")) } -func (i *Instance) GetBinds() ([]*Bind, error) { +func (i *Client) GetBinds() ([]*Bind, error) { return readSocket[[]*Bind](i.SocketPath(), strings.NewReader("j/binds")) } -func (i *Instance) GetWindows() ([]*Window, error) { +func (i *Client) GetWindows() ([]*Window, error) { return readSocket[[]*Window](i.SocketPath(), strings.NewReader("j/clients")) } -func (i *Instance) GetCursorPos() (Point, error) { +func (i *Client) GetCursorPos() (Point, error) { return readSocket[Point](i.SocketPath(), strings.NewReader("j/cursorpos")) } -func (i *Instance) GetMonitors() ([]*Monitor, error) { +func (i *Client) GetMonitors() ([]*Monitor, error) { return readSocket[[]*Monitor](i.SocketPath(), strings.NewReader("j/monitors")) } -func (i *Instance) GetWorkspaces() ([]*Workspace, error) { +func (i *Client) GetWorkspaces() ([]*Workspace, error) { return readSocket[[]*Workspace](i.SocketPath(), strings.NewReader("j/workspaces")) } diff --git a/model_instance.go b/model_instance.go index 6efa34b..877e811 100644 --- a/model_instance.go +++ b/model_instance.go @@ -5,21 +5,21 @@ import ( "fmt" ) -type Instance struct { +type Client struct { Signature string `json:"instance"` PID int `json:"pid"` WaylandSocket string `json:"wl_socket"` } -func (i Instance) String() string { - data, _ := json.MarshalIndent(i, "", "\t") +func (c Client) String() string { + data, _ := json.MarshalIndent(c, "", "\t") return string(data) } -func (i Instance) SocketPath() string { - return fmt.Sprintf("/tmp/hypr/%s/.socket.sock", i.Signature) +func (c Client) SocketPath() string { + return fmt.Sprintf("/tmp/hypr/%s/.socket.sock", c.Signature) } -func (i Instance) EventSocketPath() string { - return fmt.Sprintf("/tmp/hypr/%s/.socket2.sock", i.Signature) +func (c Client) EventSocketPath() string { + return fmt.Sprintf("/tmp/hypr/%s/.socket2.sock", c.Signature) } diff --git a/subscribe_event.go b/subscribe_event.go index 8a3ec6c..d42df32 100644 --- a/subscribe_event.go +++ b/subscribe_event.go @@ -8,7 +8,7 @@ import ( "git.milar.in/milarin/slices" ) -func (i *Instance) Subscribe(ctx context.Context, events ...EventType) (<-chan Event, error) { +func (i *Client) Subscribe(ctx context.Context, events ...EventType) (<-chan Event, error) { r, err := readSocketRaw(i.EventSocketPath(), strings.NewReader("")) if err != nil { return nil, err