-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package sway | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/carapace-sh/carapace" | ||
) | ||
|
||
type swayOutput struct { | ||
Name string | ||
Make string | ||
Modes []struct { | ||
Width int | ||
Height int | ||
Refresh int | ||
} | ||
} | ||
|
||
// ActionOutputs completes outputs | ||
func ActionOutputs() carapace.Action { | ||
return carapace.ActionExecCommand("swaymsg", "-t", "get_outputs")(func(output []byte) carapace.Action { | ||
var outputs []swayOutput | ||
if err := json.Unmarshal(output, &outputs); err != nil { | ||
return carapace.ActionMessage(err.Error()) | ||
} | ||
|
||
vals := make([]string, 0) | ||
for _, o := range outputs { | ||
description := o.Make | ||
if len(o.Modes) > 0 { | ||
description += fmt.Sprintf(" %vx%v @ %v Hz", o.Modes[0].Width, o.Modes[0].Height, float64(o.Modes[0].Refresh)/1000) | ||
} | ||
vals = append(vals, o.Name, description) | ||
} | ||
return carapace.ActionValuesDescribed(vals...) | ||
}) | ||
} |