-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2303 from carapace-sh/add-wl-mirror
added wl-mirror
- Loading branch information
Showing
3 changed files
with
127 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/carapace-sh/carapace" | ||
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/sway" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "wl-mirror", | ||
Short: "a simple Wayland output mirror client", | ||
Long: "https://github.com/Ferdi265/wl-mirror", | ||
Run: func(cmd *cobra.Command, args []string) {}, | ||
} | ||
|
||
func Execute() error { | ||
return rootCmd.Execute() | ||
} | ||
func init() { | ||
carapace.Gen(rootCmd).Standalone() | ||
|
||
rootCmd.Flags().StringP("backend", "b", "", "use a specific backend for capturing the screen") | ||
rootCmd.Flags().BoolP("freeze", "f", false, "freeze the current image on the screen") | ||
rootCmd.Flags().BoolP("fullscreen", "F", false, "open wl-mirror as fullscreen") | ||
rootCmd.Flags().String("fullscreen-output", "", "open wl-mirror as fullscreen on output O") | ||
rootCmd.Flags().BoolP("help", "h", false, "show this help") | ||
rootCmd.Flags().BoolP("invert-colors", "i", false, "invert colors in the mirrored screen") | ||
rootCmd.Flags().Bool("no-fullscreen", false, "open wl-mirror as a window (default)") | ||
rootCmd.Flags().Bool("no-fullscreen-output", false, "open wl-mirror as fullscreen on the current output (default)") | ||
rootCmd.Flags().Bool("no-invert-colors", false, "don't invert colors in the mirrored screen (default)") | ||
rootCmd.Flags().Bool("no-region", false, "capture the entire output (default)") | ||
rootCmd.Flags().Bool("no-show-cursor", false, "don't show the cursor on the mirrored screen") | ||
rootCmd.Flags().Bool("no-verbose", false, "disable debug logging (default)") | ||
rootCmd.Flags().StringP("region", "r", "", "capture custom region R") | ||
rootCmd.Flags().StringSliceP("scaling", "s", []string{}, "scaling mode") | ||
rootCmd.Flags().BoolP("show-cursor", "c", false, "show the cursor on the mirrored screen (default)") | ||
rootCmd.Flags().BoolP("stream", "S", false, "accept a stream of additional options on stdin") | ||
rootCmd.Flags().Bool("toggle-freeze", false, "toggle freeze state of screen capture") | ||
rootCmd.Flags().StringP("transform", "t", "", "apply custom transform T") | ||
rootCmd.Flags().Bool("unfreeze", false, "resume the screen capture after a freeze") | ||
rootCmd.Flags().BoolP("verbose", "v", false, "enable debug logging") | ||
rootCmd.Flags().BoolP("version", "V", false, "print version") | ||
|
||
carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{ | ||
"backend": carapace.ActionValuesDescribed( | ||
"auto", "automatically try the backends in order and use the first that works", | ||
"dmabuf", "use the wlr-export-dmabuf-unstable-v1 protocol to capture outputs", | ||
"screencopy", "use the wlr-screencopy-unstable-v1 protocol to capture outputs", | ||
), | ||
"fullscreen-output": carapace.ActionValues(), // TODO | ||
"scaling": carapace.ActionValuesDescribed( | ||
"fit", "scale to fit (default)", | ||
"cover", "scale to cover, cropping if needed", | ||
"exact", "only scale to exact multiples of the output size", | ||
"linear", "use linear scaling (default)", | ||
"nearest", "use nearest neighbor scaling", | ||
), | ||
"transform": carapace.ActionValuesDescribed( | ||
"normal", "no transformation", | ||
"flipX", "flip the X coordinate", | ||
"flipY", "flip the Y coordinate", | ||
"0cw", "apply a clockwise rotation", | ||
"90cw", "apply a clockwise rotation", | ||
"180cw", "apply a clockwise rotation", | ||
"270cw", "apply a clockwise rotation", | ||
"0ccw", "apply a counter-clockwise rotation", | ||
"90ccw", "apply a counter-clockwise rotation", | ||
"180ccw", "apply a counter-clockwise rotation", | ||
"270ccw", "apply a counter-clockwise rotation", | ||
|
||
"flipped", "flip the X coordinate", | ||
"0", "apply a clockwise rotation", | ||
"90", "apply a clockwise rotation", | ||
"180", "apply a clockwise rotation", | ||
"270", "apply a clockwise rotation", | ||
).UniqueList("-"), | ||
}) | ||
|
||
carapace.Gen(rootCmd).PositionalCompletion( | ||
sway.ActionOutputs(), // TODO other sources | ||
) | ||
} |
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,7 @@ | ||
package main | ||
|
||
import "github.com/carapace-sh/carapace-bin/completers/wl-mirror_completer/cmd" | ||
|
||
func main() { | ||
cmd.Execute() | ||
} |
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...) | ||
}) | ||
} |