Skip to content

Commit

Permalink
request: implement Binds
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagokokada committed Jul 23, 2024
1 parent 2f43acd commit 0ab80ac
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
8 changes: 8 additions & 0 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,14 @@ func (c *RequestClient) ActiveWorkspace() (w Workspace, err error) {
return w, unmarshalResponse(response, &w)
}

func (c *RequestClient) Binds() (b []Bind, err error) {
response, err := c.doRequest("binds")
if err != nil {
return b, err
}
return b, unmarshalResponse(response, &b)
}

// Clients command, similar to 'hyprctl clients'.
// Returns a [Client] object.
func (c *RequestClient) Clients() (cl []Client, err error) {
Expand Down
10 changes: 8 additions & 2 deletions request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ func TestActiveWorkspace(t *testing.T) {
testCommandS(t, c.ActiveWorkspace, Workspace{})
}

func TestBinds(t *testing.T) {
testCommandS(t, c.Binds, []Bind{})
}

func TestClients(t *testing.T) {
testCommandS(t, c.Clients, []Client{})
}
Expand All @@ -165,9 +169,8 @@ func TestDispatch(t *testing.T) {
})

if testing.Short() {
t.Skip("skipping slow test")
t.Skip("skip slow test")
}

testCommandRR(t, func() (RawResponse, error) {
return c.Dispatch(genParams("exec kitty", 40)...)
})
Expand Down Expand Up @@ -196,6 +199,9 @@ func TestKeyword(t *testing.T) {
}

func TestKill(t *testing.T) {
if testing.Short() {
t.Skip("skip test that kill windows")
}
testCommandRR(t, c.Kill)
}

Expand Down
26 changes: 23 additions & 3 deletions request_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package hyprland

import "net"

// Indicates the version where the structs are up-to-date
// Indicates the version where the structs are up-to-date.
const HYPRLAND_VERSION = "0.41.2"

// Represents a raw request that is passed for Hyprland's socket.
type RawRequest []byte

// Represents a raw response returned from the Hyprland's socket.
type RawResponse []byte

// RequestClient is the main struct from hyprland-go.
Expand All @@ -17,8 +19,26 @@ type RequestClient struct {
conn *net.UnixAddr
}

// Try to keep struct fields in the same order as the output for `hyprctl` for
// sanity.
// Unmarshal structs for requests.
// Try to keep struct fields in the same order as the output for `hyprctl -j`
// for sanity.

type Bind struct {
Locked bool `json:"locked"`
Mouse bool `json:"mouse"`
Release bool `json:"release"`
Repeat bool `json:"repeat"`
NonConsuming bool `json:"non_consuming"`
HasDescription bool `json:"has_description"`
ModMask int `json:"modmask"`
SubMap string `json:"submap"`
Key string `json:"key"`
KeyCode int `json:"keycode"`
CatchAll bool `json:"catch_all"`
Description string `json:"description"`
Dispatcher string `json:"dispatcher"`
Arg string `json:"arg"`
}

type Client struct {
Address string `json:"address"`
Expand Down

0 comments on commit 0ab80ac

Please sign in to comment.