mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-05 21:15:38 -05:00
screenshot: clipboard by default
This commit is contained in:
@@ -19,8 +19,8 @@ var (
|
|||||||
ssQuality int
|
ssQuality int
|
||||||
ssOutputDir string
|
ssOutputDir string
|
||||||
ssFilename string
|
ssFilename string
|
||||||
ssClipboard bool
|
ssNoClipboard bool
|
||||||
ssNoFreeze bool
|
ssNoFile bool
|
||||||
ssNoNotify bool
|
ssNoNotify bool
|
||||||
ssStdout bool
|
ssStdout bool
|
||||||
)
|
)
|
||||||
@@ -43,12 +43,13 @@ Output format (--format):
|
|||||||
ppm - PPM format
|
ppm - PPM format
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
dms screenshot # Interactive region selection
|
dms screenshot # Region select, save file + clipboard
|
||||||
dms screenshot full # Full screen of focused output
|
dms screenshot full # Full screen of focused output
|
||||||
dms screenshot all # All screens combined
|
dms screenshot all # All screens combined
|
||||||
dms screenshot output -o DP-1 # Specific output
|
dms screenshot output -o DP-1 # Specific output
|
||||||
dms screenshot last # Last region (pre-selected)
|
dms screenshot last # Last region (pre-selected)
|
||||||
dms screenshot --clipboard # Copy to clipboard
|
dms screenshot --no-clipboard # Save file only
|
||||||
|
dms screenshot --no-file # Clipboard only
|
||||||
dms screenshot --cursor # Include cursor
|
dms screenshot --cursor # Include cursor
|
||||||
dms screenshot -f jpg -q 85 # JPEG with quality 85`,
|
dms screenshot -f jpg -q 85 # JPEG with quality 85`,
|
||||||
}
|
}
|
||||||
@@ -106,9 +107,9 @@ func init() {
|
|||||||
screenshotCmd.PersistentFlags().IntVarP(&ssQuality, "quality", "q", 90, "JPEG quality (1-100)")
|
screenshotCmd.PersistentFlags().IntVarP(&ssQuality, "quality", "q", 90, "JPEG quality (1-100)")
|
||||||
screenshotCmd.PersistentFlags().StringVarP(&ssOutputDir, "dir", "d", "", "Output directory")
|
screenshotCmd.PersistentFlags().StringVarP(&ssOutputDir, "dir", "d", "", "Output directory")
|
||||||
screenshotCmd.PersistentFlags().StringVar(&ssFilename, "filename", "", "Output filename (auto-generated if empty)")
|
screenshotCmd.PersistentFlags().StringVar(&ssFilename, "filename", "", "Output filename (auto-generated if empty)")
|
||||||
screenshotCmd.PersistentFlags().BoolVar(&ssClipboard, "clipboard", false, "Copy to clipboard instead of file")
|
screenshotCmd.PersistentFlags().BoolVar(&ssNoClipboard, "no-clipboard", false, "Don't copy to clipboard")
|
||||||
screenshotCmd.PersistentFlags().BoolVar(&ssNoFreeze, "no-freeze", false, "Don't freeze screen during region selection")
|
screenshotCmd.PersistentFlags().BoolVar(&ssNoFile, "no-file", false, "Don't save to file")
|
||||||
screenshotCmd.PersistentFlags().BoolVar(&ssNoNotify, "no-notify", false, "Don't show notification after capture")
|
screenshotCmd.PersistentFlags().BoolVar(&ssNoNotify, "no-notify", false, "Don't show notification")
|
||||||
screenshotCmd.PersistentFlags().BoolVar(&ssStdout, "stdout", false, "Output image to stdout (for piping to swappy, etc.)")
|
screenshotCmd.PersistentFlags().BoolVar(&ssStdout, "stdout", false, "Output image to stdout (for piping to swappy, etc.)")
|
||||||
|
|
||||||
screenshotCmd.AddCommand(ssRegionCmd)
|
screenshotCmd.AddCommand(ssRegionCmd)
|
||||||
@@ -126,8 +127,8 @@ func getScreenshotConfig(mode screenshot.Mode) screenshot.Config {
|
|||||||
config.Mode = mode
|
config.Mode = mode
|
||||||
config.OutputName = ssOutputName
|
config.OutputName = ssOutputName
|
||||||
config.IncludeCursor = ssIncludeCursor
|
config.IncludeCursor = ssIncludeCursor
|
||||||
config.Clipboard = ssClipboard
|
config.Clipboard = !ssNoClipboard
|
||||||
config.Freeze = !ssNoFreeze
|
config.SaveFile = !ssNoFile
|
||||||
config.Notify = !ssNoNotify
|
config.Notify = !ssNoNotify
|
||||||
config.Stdout = ssStdout
|
config.Stdout = ssStdout
|
||||||
|
|
||||||
@@ -184,18 +185,9 @@ func runScreenshot(config screenshot.Config) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Clipboard {
|
var filePath string
|
||||||
if err := copyImageToClipboard(result.Buffer, config.Format, config.Quality); err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "Error copying to clipboard: %v\n", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
if config.Notify {
|
|
||||||
screenshot.SendNotification(screenshot.NotifyResult{Clipboard: true})
|
|
||||||
}
|
|
||||||
fmt.Println("Screenshot copied to clipboard")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if config.SaveFile {
|
||||||
outputDir := config.OutputDir
|
outputDir := config.OutputDir
|
||||||
if outputDir == "" {
|
if outputDir == "" {
|
||||||
outputDir = screenshot.GetOutputDir()
|
outputDir = screenshot.GetOutputDir()
|
||||||
@@ -206,17 +198,30 @@ func runScreenshot(config screenshot.Config) {
|
|||||||
filename = screenshot.GenerateFilename(config.Format)
|
filename = screenshot.GenerateFilename(config.Format)
|
||||||
}
|
}
|
||||||
|
|
||||||
path := filepath.Join(outputDir, filename)
|
filePath = filepath.Join(outputDir, filename)
|
||||||
if err := screenshot.WriteToFile(result.Buffer, path, config.Format, config.Quality); err != nil {
|
if err := screenshot.WriteToFile(result.Buffer, filePath, config.Format, config.Quality); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Error writing file: %v\n", err)
|
fmt.Fprintf(os.Stderr, "Error writing file: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
fmt.Println(filePath)
|
||||||
if config.Notify {
|
|
||||||
screenshot.SendNotification(screenshot.NotifyResult{FilePath: path})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(path)
|
if config.Clipboard {
|
||||||
|
if err := copyImageToClipboard(result.Buffer, config.Format, config.Quality); err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "Error copying to clipboard: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
if !config.SaveFile {
|
||||||
|
fmt.Println("Copied to clipboard")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.Notify {
|
||||||
|
screenshot.SendNotification(screenshot.NotifyResult{
|
||||||
|
FilePath: filePath,
|
||||||
|
Clipboard: config.Clipboard,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func copyImageToClipboard(buf *screenshot.ShmBuffer, format screenshot.Format, quality int) error {
|
func copyImageToClipboard(buf *screenshot.ShmBuffer, format screenshot.Format, quality int) error {
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ type Config struct {
|
|||||||
OutputDir string
|
OutputDir string
|
||||||
Filename string
|
Filename string
|
||||||
Clipboard bool
|
Clipboard bool
|
||||||
Freeze bool
|
SaveFile bool
|
||||||
Notify bool
|
Notify bool
|
||||||
Stdout bool
|
Stdout bool
|
||||||
}
|
}
|
||||||
@@ -61,8 +61,8 @@ func DefaultConfig() Config {
|
|||||||
Quality: 90,
|
Quality: 90,
|
||||||
OutputDir: "",
|
OutputDir: "",
|
||||||
Filename: "",
|
Filename: "",
|
||||||
Clipboard: false,
|
Clipboard: true,
|
||||||
Freeze: true,
|
SaveFile: true,
|
||||||
Notify: true,
|
Notify: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user