Skip to content

Commit

Permalink
Merge pull request #10 from thiagokokada/implement-more-commands
Browse files Browse the repository at this point in the history
request: implement SwitchXkbLayout
  • Loading branch information
thiagokokada authored Jul 26, 2024
2 parents 6ecc758 + a1fde7b commit e03703a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
20 changes: 18 additions & 2 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,11 @@ func unmarshalResponse[T any](response RawResponse, v *T) (T, error) {

err := json.Unmarshal(response, &v)
if err != nil {
return *v, fmt.Errorf("error during unmarshal: %w", err)
return *v, fmt.Errorf(
"error while unmarshal: %w, response: %s",
err,
response,
)
}
return *v, nil
}
Expand Down Expand Up @@ -478,7 +482,7 @@ func (c *RequestClient) Reload() (r Response, err error) {
}

// Set cursor command, similar to 'hyprctl setcursor'.
// Returns a [Response], that may be useful for further validations
// Returns a [Response], that may be useful for further validations.
func (c *RequestClient) SetCursor(theme string, size int) (r Response, err error) {
raw, err := c.doRequest("setcursor", fmt.Sprintf("%s %d", theme, size))
if err != nil {
Expand All @@ -488,6 +492,18 @@ func (c *RequestClient) SetCursor(theme string, size int) (r Response, err error
return response[0], err // should return only one response
}

// Set cursor command, similar to 'hyprctl switchxkblayout'.
// Returns a [Response], that may be useful for further validations.
// Param cmd can be either 'next', 'prev' or an ID (e.g: 0).
func (c *RequestClient) SwitchXkbLayout(device string, cmd string) (r Response, err error) {
raw, err := c.doRequest("switchxkblayout", fmt.Sprintf("%s %s", device, cmd))
if err != nil {
return r, err
}
response, err := parseAndValidateResponse(nil, raw)
return response[0], err // should return only one response
}

// Splash command, similar to 'hyprctl splash'.
func (c *RequestClient) Splash() (s string, err error) {
response, err := c.doRequest("splash")
Expand Down
11 changes: 11 additions & 0 deletions request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,17 @@ func TestSetCursor(t *testing.T) {
})
}

func TestSwitchXkbLayout(t *testing.T) {
// Need to find a keyboard, call Devices()
checkEnvironment(t)
devices, err := c.Devices()
assert.NoError(t, err)

testCommandR(t, func() (Response, error) {
return c.SwitchXkbLayout(devices.Keyboards[0].Name, "next")
})
}

func TestSplash(t *testing.T) {
testCommand(t, c.Splash, "")
}
Expand Down

0 comments on commit e03703a

Please sign in to comment.