From 0ab80ac9c5a2d6b98ac1fce0866f0e26956442ec Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Tue, 23 Jul 2024 13:10:23 +0100 Subject: [PATCH] request: implement Binds --- request.go | 8 ++++++++ request_test.go | 10 ++++++++-- request_types.go | 26 +++++++++++++++++++++++--- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/request.go b/request.go index 2b9b2c9..12d1abc 100644 --- a/request.go +++ b/request.go @@ -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) { diff --git a/request_test.go b/request_test.go index c3312bc..6e5e922 100644 --- a/request_test.go +++ b/request_test.go @@ -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{}) } @@ -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)...) }) @@ -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) } diff --git a/request_types.go b/request_types.go index ba99931..efb6de4 100644 --- a/request_types.go +++ b/request_types.go @@ -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. @@ -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"`