diff --git a/core/cmd/dms/commands_screenshot.go b/core/cmd/dms/commands_screenshot.go index f068ee45..befc2ef5 100644 --- a/core/cmd/dms/commands_screenshot.go +++ b/core/cmd/dms/commands_screenshot.go @@ -217,9 +217,13 @@ func runScreenshot(config screenshot.Config) { } if config.Notify { + thumbData, thumbW, thumbH := bufferToRGBThumbnail(result.Buffer, 256) screenshot.SendNotification(screenshot.NotifyResult{ FilePath: filePath, Clipboard: config.Clipboard, + ImageData: thumbData, + Width: thumbW, + Height: thumbH, }) } } @@ -259,6 +263,51 @@ func writeImageToStdout(buf *screenshot.ShmBuffer, format screenshot.Format, qua } } +func bufferToRGBThumbnail(buf *screenshot.ShmBuffer, maxSize int) ([]byte, int, int) { + srcW, srcH := buf.Width, buf.Height + scale := 1.0 + if srcW > maxSize || srcH > maxSize { + if srcW > srcH { + scale = float64(maxSize) / float64(srcW) + } else { + scale = float64(maxSize) / float64(srcH) + } + } + + dstW := int(float64(srcW) * scale) + dstH := int(float64(srcH) * scale) + if dstW < 1 { + dstW = 1 + } + if dstH < 1 { + dstH = 1 + } + + data := buf.Data() + rgb := make([]byte, dstW*dstH*3) + + for y := 0; y < dstH; y++ { + srcY := int(float64(y) / scale) + if srcY >= srcH { + srcY = srcH - 1 + } + for x := 0; x < dstW; x++ { + srcX := int(float64(x) / scale) + if srcX >= srcW { + srcX = srcW - 1 + } + si := srcY*buf.Stride + srcX*4 + di := (y*dstW + x) * 3 + if si+2 < len(data) { + rgb[di+0] = data[si+2] // R + rgb[di+1] = data[si+1] // G + rgb[di+2] = data[si+0] // B + } + } + } + return rgb, dstW, dstH +} + func runScreenshotRegion(cmd *cobra.Command, args []string) { config := getScreenshotConfig(screenshot.ModeRegion) runScreenshot(config) diff --git a/core/internal/screenshot/notify.go b/core/internal/screenshot/notify.go index 40891b97..1ae675e9 100644 --- a/core/internal/screenshot/notify.go +++ b/core/internal/screenshot/notify.go @@ -21,6 +21,9 @@ const ( type NotifyResult struct { FilePath string Clipboard bool + ImageData []byte + Width int + Height int } func SendNotification(result NotifyResult) { @@ -36,8 +39,27 @@ func SendNotification(result NotifyResult) { } hints := map[string]dbus.Variant{} - if result.FilePath != "" && !result.Clipboard { - hints["image-path"] = dbus.MakeVariant(result.FilePath) + if len(result.ImageData) > 0 && result.Width > 0 && result.Height > 0 { + rowstride := result.Width * 3 + hints["image_data"] = dbus.MakeVariant(struct { + Width int32 + Height int32 + Rowstride int32 + HasAlpha bool + BitsPerSample int32 + Channels int32 + Data []byte + }{ + Width: int32(result.Width), + Height: int32(result.Height), + Rowstride: int32(rowstride), + HasAlpha: false, + BitsPerSample: 8, + Channels: 3, + Data: result.ImageData, + }) + } else if result.FilePath != "" { + hints["image_path"] = dbus.MakeVariant(result.FilePath) } summary := "Screenshot captured"