Skip to content

Commit

Permalink
request: implement Keyword and SetCursor
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagokokada committed Jul 22, 2024
1 parent 0fc6951 commit cfc2638
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 19 deletions.
48 changes: 33 additions & 15 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func (c *RequestClient) Request(request RawRequest) (response RawResponse, err e
return rbuf.Bytes(), nil
}

// Get option command, similar to 'hyprctl activewindow'.
// Active window command, similar to 'hyprctl activewindow'.
// Returns a [Window] object.
func (c *RequestClient) ActiveWindow() (w Window, err error) {
response, err := c.doRequest("activewindow")
Expand All @@ -227,7 +227,7 @@ func (c *RequestClient) ActiveWorkspace() (w Workspace, err error) {
return w, unmarshalResponse(response, &w)
}

// Get option command, similar to 'hyprctl clients'.
// Clients command, similar to 'hyprctl clients'.
// Returns a [Client] object.
func (c *RequestClient) Clients() (cl []Client, err error) {
response, err := c.doRequest("clients")
Expand All @@ -237,7 +237,7 @@ func (c *RequestClient) Clients() (cl []Client, err error) {
return cl, unmarshalResponse(response, &cl)
}

// Get option command, similar to 'hyprctl cursorpos'.
// Cursor position command, similar to 'hyprctl cursorpos'.
// Returns a [CursorPos] object.
func (c *RequestClient) CursorPos() (cu CursorPos, err error) {
response, err := c.doRequest("cursorpos")
Expand Down Expand Up @@ -268,6 +268,15 @@ func (c *RequestClient) GetOption(name string) (o Option, err error) {
return o, unmarshalResponse(response, &o)
}

// Keyword command, similar to 'hyprctl keyword'.
func (c *RequestClient) Keyword(params ...string) error {
response, err := c.doRequest("keyword", params...)
if err != nil {
return err
}
return c.validateResponse(nil, response)
}

// Kill command, similar to 'hyprctl kill'.
// Will NOT wait for the user to click in the window.
func (c *RequestClient) Kill() error {
Expand All @@ -278,7 +287,7 @@ func (c *RequestClient) Kill() error {
return c.validateResponse(nil, response)
}

// Kill command, similar to 'hyprctl monitors'.
// Monitors command, similar to 'hyprctl monitors'.
// Returns a [Monitor] object.
func (c *RequestClient) Monitors() (m []Monitor, err error) {
response, err := c.doRequest("monitors")
Expand All @@ -297,7 +306,25 @@ func (c *RequestClient) Reload() error {
return c.validateResponse(nil, response)
}

// Get option command, similar to 'hyprctl version'.
// Set cursor command, similar to 'hyprctl setcursor'.
func (c *RequestClient) SetCursor(theme string, size int) error {
response, err := c.doRequest("setcursor", fmt.Sprintf("%s %d", theme, size))
if err != nil {
return err
}
return c.validateResponse(nil, response)
}

// Splash command, similar to 'hyprctl splash'.
func (c *RequestClient) Splash() (s string, err error) {
response, err := c.doRequest("splash")
if err != nil {
return "", err
}
return string(response), nil
}

// Version command, similar to 'hyprctl version'.
// Returns a [Version] object.
func (c *RequestClient) Version() (v Version, err error) {
response, err := c.doRequest("version")
Expand All @@ -307,7 +334,7 @@ func (c *RequestClient) Version() (v Version, err error) {
return v, unmarshalResponse(response, &v)
}

// Get option command, similar to 'hyprctl workspaces'.
// Workspaces option command, similar to 'hyprctl workspaces'.
// Returns a [Workspace] object.
func (c *RequestClient) Workspaces() (w []Workspace, err error) {
response, err := c.doRequest("workspaces")
Expand All @@ -316,12 +343,3 @@ func (c *RequestClient) Workspaces() (w []Workspace, err error) {
}
return w, unmarshalResponse(response, &w)
}

// Get option command, similar to 'hyprctl splash'.
func (c *RequestClient) Splash() (s string, err error) {
response, err := c.doRequest("splash")
if err != nil {
return "", err
}
return string(response), nil
}
24 changes: 20 additions & 4 deletions request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ func TestGetOption(t *testing.T) {
}
}

func TestKeyword(t *testing.T) {
checkEnvironment(t)
err := c.Keyword("general:border_size 1", "general:border_size 5")
if err != nil {
t.Error(err)
}
}

func TestKill(t *testing.T) {
testCommand(t, c.Kill)
}
Expand All @@ -212,14 +220,22 @@ func TestReload(t *testing.T) {
testCommand(t, c.Reload)
}

func TestSetCursor(t *testing.T) {
checkEnvironment(t)
err := c.SetCursor("Nordzy-cursors", 32)
if err != nil {
t.Error(err)
}
}

func TestSplash(t *testing.T) {
testCommand1(t, c.Splash, "")
}

func TestWorkspaces(t *testing.T) {
testCommand1(t, c.Workspaces, []Workspace{})
}

func TestVersion(t *testing.T) {
testCommand1(t, c.Version, Version{})
}

func TestSplash(t *testing.T) {
testCommand1(t, c.Splash, "")
}

0 comments on commit cfc2638

Please sign in to comment.