1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-05-12 15:29:43 -04:00

screenshot: respect XDG_PICTURES_DIR

fixes #2383
This commit is contained in:
bbedward
2026-05-11 10:00:21 -04:00
parent b192b5f779
commit 676219bc09
3 changed files with 38 additions and 39 deletions

View File

@@ -9,10 +9,8 @@ import (
"io"
"os"
"path/filepath"
"strings"
"time"
"github.com/AvengeMedia/DankMaterialShell/core/internal/log"
"github.com/AvengeMedia/DankMaterialShell/core/internal/utils"
)
@@ -105,7 +103,7 @@ func GetOutputDir() string {
return dir
}
if xdgPics := getXDGPicturesDir(); xdgPics != "" {
if xdgPics := utils.XDGPicturesDir(); xdgPics != "" {
screenshotDir := filepath.Join(xdgPics, "Screenshots")
if err := os.MkdirAll(screenshotDir, 0o755); err == nil {
return screenshotDir
@@ -113,42 +111,12 @@ func GetOutputDir() string {
return xdgPics
}
if home := os.Getenv("HOME"); home != "" {
if home, err := os.UserHomeDir(); err == nil {
return home
}
return "."
}
func getXDGPicturesDir() string {
userConfigDir, err := os.UserConfigDir()
if err != nil {
log.Error("failed to get user config dir", "err", err)
return ""
}
userDirsFile := filepath.Join(userConfigDir, "user-dirs.dirs")
data, err := os.ReadFile(userDirsFile)
if err != nil {
return ""
}
for _, line := range strings.Split(string(data), "\n") {
if len(line) == 0 || line[0] == '#' {
continue
}
const prefix = "XDG_PICTURES_DIR="
if !strings.HasPrefix(line, prefix) {
continue
}
path := strings.Trim(line[len(prefix):], "\"")
expanded, err := utils.ExpandPath(path)
if err != nil {
return ""
}
return expanded
}
return ""
}
func WriteToFile(buf *ShmBuffer, path string, format Format, quality int) error {
return WriteToFileWithFormat(buf, path, format, quality, uint32(FormatARGB8888))
}