Skip to content

Commit

Permalink
request: implement Monitors and Workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagokokada committed Jul 22, 2024
1 parent 47cc9e1 commit 16a7d84
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
22 changes: 21 additions & 1 deletion request.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,16 @@ func (c *RequestClient) Kill() error {
return c.validateResponse(nil, response)
}

// Kill command, similar to 'hyprctl monitors'.
// Returns a [Monitor] object.
func (c *RequestClient) Monitors() (m []Monitor, err error) {
response, err := c.doRequest("monitors")
if err != nil {
return m, err
}
return m, unmarshalResponse(response, &m)
}

// Reload command, similar to 'hyprctl reload'.
func (c *RequestClient) Reload() error {
response, err := c.doRequest("reload")
Expand All @@ -288,7 +298,7 @@ func (c *RequestClient) Reload() error {
}

// Get option command, similar to 'hyprctl version'.
// Returns an [Version] object.
// Returns a [Version] object.
func (c *RequestClient) Version() (v Version, err error) {
response, err := c.doRequest("version")
if err != nil {
Expand All @@ -297,6 +307,16 @@ func (c *RequestClient) Version() (v Version, err error) {
return v, unmarshalResponse(response, &v)
}

// Get option command, similar to 'hyprctl workspaces'.
// Returns a [Workspace] object.
func (c *RequestClient) Workspaces() (w []Workspace, err error) {
response, err := c.doRequest("workspaces")
if err != nil {
return w, err
}
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")
Expand Down
11 changes: 11 additions & 0 deletions request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func testCommand1[T any](t *testing.T, command func() (T, error), v any) {
if reflect.DeepEqual(got, v) {
t.Error("got empty struct")
}
t.Log(got)
}

func TestPrepareRequests(t *testing.T) {
Expand Down Expand Up @@ -142,6 +143,7 @@ func TestRequest(t *testing.T) {
if len(response) == 0 {
t.Error("empty response")
}
t.Log(response)
}

func TestActiveWindow(t *testing.T) {
Expand Down Expand Up @@ -193,6 +195,7 @@ func TestGetOption(t *testing.T) {
if reflect.DeepEqual(got, Option{}) {
t.Error("got empty struct")
}
t.Log(got)
})
}
}
Expand All @@ -201,10 +204,18 @@ func TestKill(t *testing.T) {
testCommand(t, c.Kill)
}

func TestMonitors(t *testing.T) {
testCommand1(t, c.Monitors, []Monitor{})
}

func TestReload(t *testing.T) {
testCommand(t, c.Reload)
}

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

func TestVersion(t *testing.T) {
testCommand1(t, c.Version, Version{})
}
Expand Down
25 changes: 25 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,31 @@ type CursorPos struct {
Y int `json:"y"`
}

type Monitor struct {
Id int `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Make string `json:"make"`
Model string `json:"model"`
Serial string `json:"serial"`
Width int `json:"width"`
Height int `json:"height"`
RefreshRate float64 `json:"refreshRate"`
X int `json:"x"`
Y int `json:"y"`
ActiveWorkspace WorkspaceType `json:"activeWorkspace"`
SpecialWorkspace WorkspaceType `json:"specialWorkspace"`
Reserved []int `json:"reserved"`
Scale float64 `json:"scale"`
Transform int `json:"transform"`
Focused bool `json:"focused"`
DpmsStatus bool `json:"dpmsStatus"`
Vrr bool `json:"vrr"`
ActivelyTearing bool `json:"activelyTearing"`
CurrentFormat string `json:"currentFormat"`
AvailableModes []string `json:"availableModes"`
}

type Option struct {
Option string `json:"option"`
Int int `json:"int"`
Expand Down

0 comments on commit 16a7d84

Please sign in to comment.