Incorporate outfoxxed feedback

This commit is contained in:
David Heinemeier Hansson
2026-05-16 13:28:37 +02:00
parent 122adc6bb9
commit 3eda4948b2
4 changed files with 255 additions and 183 deletions
@@ -81,6 +81,12 @@ PopupWindow {
var window = target.QsWindow.window var window = target.QsWindow.window
if (!window) return if (!window) return
if (root.bar.position === "top" || root.bar.position === "bottom") {
localX = Math.max(root.margin, Math.min(localX, window.width - popupWidth - root.margin))
} else {
localY = Math.max(root.margin, Math.min(localY, window.height - popupHeight - root.margin))
}
var point = window.contentItem.mapFromItem(target, localX, localY) var point = window.contentItem.mapFromItem(target, localX, localY)
popupAnchor.rect.x = Math.round(point.x) popupAnchor.rect.x = Math.round(point.x)
popupAnchor.rect.y = Math.round(point.y) popupAnchor.rect.y = Math.round(point.y)
@@ -177,6 +177,7 @@ Item {
bar: root.bar bar: root.bar
owner: root owner: root
open: root.popupOpen open: root.popupOpen
margin: 6
contentWidth: 320 contentWidth: 320
contentHeight: layout.implicitHeight + 28 contentHeight: layout.implicitHeight + 28
@@ -55,6 +55,16 @@ Item {
return "'" + String(value).replace(/'/g, "'\\''") + "'" return "'" + String(value).replace(/'/g, "'\\''") + "'"
} }
function scriptPath(name) {
var base = omarchyPath || Quickshell.env("OMARCHY_PATH") || (Quickshell.env("HOME") + "/.local/share/omarchy")
return base + "/default/quickshell/omarchy-shell/scripts/" + name
}
function focusPicker() {
if (pickerWindowLoader.item && typeof pickerWindowLoader.item.focusCarousel === "function")
pickerWindowLoader.item.focusCarousel()
}
// Decode a base64-encoded UTF-8 string sent via IPC. Used for fields that // Decode a base64-encoded UTF-8 string sent via IPC. Used for fields that
// would otherwise carry embedded newlines or tabs (image rows, raw colors // would otherwise carry embedded newlines or tabs (image rows, raw colors
// JSON) which bash IPC arguments can't reliably round-trip. // JSON) which bash IPC arguments can't reliably round-trip.
@@ -249,7 +259,7 @@ Item {
root.select(root.selectedImageIndex(), true) root.select(root.selectedImageIndex(), true)
root.imagesLoaded = true root.imagesLoaded = true
root.opened = true root.opened = true
carousel.forceActiveFocus() root.focusPicker()
} }
function openSelector(nextImageDirs, nextImageRows, nextSelectedImage, nextSelectionFile, nextDoneFile, nextShowLabels, nextFilterable) { function openSelector(nextImageDirs, nextImageRows, nextSelectedImage, nextSelectionFile, nextDoneFile, nextShowLabels, nextFilterable) {
@@ -274,7 +284,7 @@ Item {
if (imageRows) { if (imageRows) {
loadRows(imageRows) loadRows(imageRows)
} else { } else {
loadImagesProc.output = "" loadImagesProc.requestSerial = requestSerial
loadImagesProc.running = true loadImagesProc.running = true
} }
} }
@@ -292,16 +302,15 @@ Item {
Process { Process {
id: loadImagesProc id: loadImagesProc
property string output: "" property int requestSerial: 0
command: ["bash", "-lc", "cache_dir=${XDG_CACHE_HOME:-$HOME/.cache}/omarchy/image-selector; while IFS= read -r dir; do [[ -n $dir && -d $dir ]] && find -L \"$dir\" -maxdepth 1 -type f \\( -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.png' -o -iname '*.gif' -o -iname '*.bmp' -o -iname '*.webp' \\) -print0; done <<< " + shellQuote(root.imageDirs) + " | sort -z | while IFS= read -r -d '' image; do hash=$(md5sum \"$image\" | cut -d ' ' -f 1); thumb=\"$cache_dir/$hash.jpg\"; [[ -f $thumb ]] || thumb=$image; printf '%s\\t%s\\n' \"$image\" \"$thumb\"; done"] command: [root.scriptPath("image-picker-list.sh"), root.imageDirs]
stdout: SplitParser { stdout: StdioCollector {
onRead: function(data) { waitForEnd: true
loadImagesProc.output += data + "\n" onStreamFinished: {
if (loadImagesProc.requestSerial === root.requestSerial)
root.loadRows(String(text || ""))
} }
} }
onExited: {
root.loadRows(output)
}
} }
// Lifecycle hooks invoked by omarchy-shell summon/hide. shell.summon(id, // Lifecycle hooks invoked by omarchy-shell summon/hide. shell.summon(id,
@@ -370,9 +379,19 @@ Item {
onExited: root.releaseNextDoneFile() onExited: root.releaseNextDoneFile()
} }
LazyLoader {
id: pickerWindowLoader
active: root.opened && root.imagesLoaded
onItemChanged: root.focusPicker()
PanelWindow { PanelWindow {
id: panel id: panel
visible: root.opened && root.imagesLoaded
function focusCarousel() {
carousel.forceActiveFocus()
}
visible: true
anchors { top: true; bottom: true; left: true; right: true } anchors { top: true; bottom: true; left: true; right: true }
color: "transparent" color: "transparent"
WlrLayershell.namespace: "omarchy-image-selector" WlrLayershell.namespace: "omarchy-image-selector"
@@ -586,3 +605,4 @@ Item {
} }
} }
} }
}
@@ -0,0 +1,45 @@
#!/bin/bash
image_dirs=${1:-}
cache_dir=${XDG_CACHE_HOME:-$HOME/.cache}/omarchy/image-selector
index_file="$cache_dir/index.tsv"
mkdir -p "$cache_dir"
thumbnail_for() {
local image="$1"
local signature hash thumbnail legacy_hash
signature=$(stat -Lc '%s:%Y' "$image") || return
hash=$(awk -F '\t' -v path="$image" -v sig="$signature" '$1 == path && $2 == sig { print $3; exit }' "$index_file" 2>/dev/null)
if [[ -z $hash ]]; then
hash=$(printf '%s\t%s' "$image" "$signature" | md5sum | cut -d ' ' -f 1)
fi
thumbnail="$cache_dir/$hash.jpg"
if [[ ! -f $thumbnail ]]; then
# Older on-demand picker code keyed fallback thumbnails by file content.
# Keep finding those if a user still has them cached.
legacy_hash=$(md5sum "$image" 2>/dev/null | cut -d ' ' -f 1)
[[ -n $legacy_hash && -f $cache_dir/$legacy_hash.jpg ]] && thumbnail="$cache_dir/$legacy_hash.jpg"
fi
if [[ -f $thumbnail ]]; then
printf '%s' "$thumbnail"
else
printf '%s' "$image"
fi
}
while IFS= read -r dir; do
[[ -n $dir && -d $dir ]] || continue
find -L "$dir" -maxdepth 1 -type f \
\( -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.png' -o -iname '*.gif' -o -iname '*.bmp' -o -iname '*.webp' \) \
-print0 2>/dev/null
done <<<"$image_dirs" | sort -z | while IFS= read -r -d '' image; do
thumbnail=$(thumbnail_for "$image")
[[ -n $thumbnail ]] || continue
printf '%s\t%s\n' "$image" "$thumbnail"
done