Added script for Hyprland integration and updated README.md
This commit is contained in:
@@ -10,7 +10,7 @@ Of course it is not without usage, I will prepare the app to be hooked in Hyprla
|
|||||||
- SDL3
|
- SDL3
|
||||||
|
|
||||||
## Installations
|
## Installations
|
||||||
> As of now the only like-indented working implementation is for macOS.
|
> As of now the only like-indented working implementation is for macOS. Wayland ignores the desired window states (resize, position).
|
||||||
|
|
||||||
#### macOS
|
#### macOS
|
||||||
- `brew install sdl3`
|
- `brew install sdl3`
|
||||||
@@ -21,3 +21,8 @@ Of course it is not without usage, I will prepare the app to be hooked in Hyprla
|
|||||||
#### Linux
|
#### Linux
|
||||||
- `sudo pacman -S sdl3 --noconfirm`
|
- `sudo pacman -S sdl3 --noconfirm`
|
||||||
- `gcc SimpleImageViewer.c -o SimpleImageViewer -Wall -Werror -o3 $(pkg-config --cflags --libs sdl3) -lm` or with `clang`
|
- `gcc SimpleImageViewer.c -o SimpleImageViewer -Wall -Werror -o3 $(pkg-config --cflags --libs sdl3) -lm` or with `clang`
|
||||||
|
- when using Hyprland, move the scripts folder into your `~/.config/hypr/`
|
||||||
|
- in `simple-image-viewer-clipboard.sh`: set `viewer`, I placed my binary beside this script
|
||||||
|
- move the `hypr_simpleimageviewer.lua` file into `~/.config/hypr/`
|
||||||
|
- replace [USER] with your user
|
||||||
|
- add `require(hypr_simpleimageviewer)` at the top of your Hyprland config
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
hl.bind("SUPER + I", hl.dsp.exec_cmd("/home/[USER]/.config/hypr/scripts/simple-image-viewer-clipboard.sh"))
|
||||||
|
|
||||||
+94
@@ -0,0 +1,94 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
viewer=
|
||||||
|
|
||||||
|
notify() {
|
||||||
|
if [ -x /usr/bin/notify-send ]; then
|
||||||
|
/usr/bin/notify-send "SimpleImageViewer" "$1" || true
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
types=$(/usr/bin/wl-paste --list-types 2>/dev/null || true)
|
||||||
|
|
||||||
|
text_type=$(
|
||||||
|
printf '%s\n' "$types" | /usr/bin/awk '
|
||||||
|
/^text\/plain/ || $0 == "text/uri-list" || $0 == "UTF8_STRING" || $0 == "STRING" {
|
||||||
|
print
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
'
|
||||||
|
)
|
||||||
|
|
||||||
|
path=
|
||||||
|
if [ -n "$text_type" ]; then
|
||||||
|
path=$(
|
||||||
|
/usr/bin/wl-paste --no-newline --type "$text_type" 2>/dev/null | /usr/bin/awk '
|
||||||
|
{
|
||||||
|
sub(/^[[:space:]]+/, "")
|
||||||
|
sub(/[[:space:]]+$/, "")
|
||||||
|
if ($0 == "" || $0 == "copy" || $0 == "cut" || substr($0, 1, 1) == "#") next
|
||||||
|
sub(/^file:\/\//, "")
|
||||||
|
gsub(/%20/, " ")
|
||||||
|
sub(/^~/, ENVIRON["HOME"])
|
||||||
|
print
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
'
|
||||||
|
)
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$path" ] && [ -f "$path" ]; then
|
||||||
|
exec "$viewer" "$path"
|
||||||
|
fi
|
||||||
|
|
||||||
|
image_type=$(
|
||||||
|
printf '%s\n' "$types" | /usr/bin/awk '
|
||||||
|
$0 == "image/png" { found = $0; print; exit }
|
||||||
|
$0 == "image/jpeg" || $0 == "image/jpg" { found = $0; print; exit }
|
||||||
|
$0 == "image/bmp" || $0 == "image/x-bmp" { found = $0; print; exit }
|
||||||
|
$0 == "image/gif" { found = $0; print; exit }
|
||||||
|
$0 == "image/x-tga" || $0 == "image/tga" { found = $0; print; exit }
|
||||||
|
$0 == "image/x-portable-pixmap" || $0 == "image/x-portable-anymap" { found = $0; print; exit }
|
||||||
|
/^image\// && fallback == "" { fallback = $0 }
|
||||||
|
END { if (found == "" && fallback != "") print fallback }
|
||||||
|
'
|
||||||
|
)
|
||||||
|
|
||||||
|
if [ -z "$image_type" ]; then
|
||||||
|
notify "Clipboard contains neither an image path nor image data"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$image_type" in
|
||||||
|
image/png) ext=png ;;
|
||||||
|
image/jpeg | image/jpg) ext=jpg ;;
|
||||||
|
image/bmp | image/x-bmp) ext=bmp ;;
|
||||||
|
image/gif) ext=gif ;;
|
||||||
|
image/x-tga | image/tga) ext=tga ;;
|
||||||
|
image/x-portable-pixmap) ext=ppm ;;
|
||||||
|
image/x-portable-anymap) ext=pnm ;;
|
||||||
|
*) ext=img ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
tmpdir=$(/usr/bin/mktemp -d "${TMPDIR:-/tmp}/simple-image-viewer.XXXXXXXXXX")
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
/usr/bin/rm -rf "$tmpdir"
|
||||||
|
}
|
||||||
|
|
||||||
|
trap cleanup EXIT
|
||||||
|
trap 'exit 130' HUP INT TERM
|
||||||
|
|
||||||
|
image_path=$tmpdir/clipboard.$ext
|
||||||
|
if ! /usr/bin/wl-paste --type "$image_type" >"$image_path"; then
|
||||||
|
notify "Could not read image data from clipboard"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -s "$image_path" ]; then
|
||||||
|
notify "Clipboard image data is empty"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
"$viewer" "$image_path"
|
||||||
Reference in New Issue
Block a user