the new and improved!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
3.6 KiB

#!/usr/bin/env sh
":"; exec emacs --quick --script "$0" "$@" # -*- mode: emacs-lisp; -*-
;;; hyprchan but it's in elisp
(load-file "~/.config/emacs.mitch/elabiasu.el")
(elabiasu-ensure-package 'f)
(elabiasu-ensure-package 'dash)
(require 'f)
(require 'dash)
(defvar waifudir "~/.local/share/waifus/")
(defvar wallpapers "~/.local/share/backgrounds/")
(defvar cachedir "~/.cache/hyprchan/")
(defvar logosrc "/usr/share/hyprland/hyprland.png")
(defvar splash (string-trim (shell-command-to-string "hyprctl splash")))
(defun get-dimensions (image)
"Return the dimensions of IMAGE as cons `(x . y)'."
(--> image
(shell-command-to-string (format "file %s" it))
(split-string it "," nil " ")
(--filter (string-match-p (rx (+ num) (? " ") "x" (? " ") (+ num)) it) it)
(--remove (string-match-p "density" it) it)
(car it)
(split-string it "x" nil " ")
(--map (string-to-number it) it)
(cons (car it) (cadr it)))
;; select the background image
(defvar canvas.src.fullname (--> (f-files wallpapers)
(--filter (string-match-p (rx (* any) "." (or "jpg" "png")) it) it)
(seq-random-elt it)
(defvar canvas.fullname canvas.src.fullname)
(defvar canvas.x (car (get-dimensions canvas.fullname)))
(defvar canvas.y (cdr (get-dimensions canvas.fullname)))
(defvar waifu.src.fullname (--> (f-files waifudir)
(--filter (string-match-p ".*.png" it) it)
(seq-random-elt it)
(defvar waifu.position.x) ; initialize these so we can `setq' them later
(defvar waifu.position.y) ; initialize these so we can `setq' them later
(defvar waifu.basename (file-name-base waifu.src.fullname))
(defvar waifu.maxdim (round (* canvas.x 0.25)))
(defvar waifu.cachefile (expand-file-name (format "%s-%s.png" waifu.basename waifu.maxdim) cachedir))
;; debug
(message waifu.src.fullname)
;; adding waifu to image
(if (not (file-exists-p waifu.cachefile))
(shell-command (format "magick %s -resize %s %s" waifu.src.fullname waifu.maxdim waifu.cachefile))
(message "waifu already exists, yay!"))
(defvar waifu.height (car (get-dimensions waifu.cachefile)))
(defvar waifu.width (cdr (get-dimensions waifu.cachefile)))
;; feet of waifu go at `canvas.x'
;; head of waifu goes at `canvas.x' minus `waifu.height'
(setq waifu.position.x (- canvas.x waifu.height))
;; center of waifu goes at 2/3 * `canvas.y'
;; center of waifu = `waifu-width' / 2
(setq waifu.position.y (- (* canvas.y (/ 2.0 3.0)) (/ waifu.width 2)))
;; shrink hyprland logo to proper scale
(defvar logo.src logosrc) ; it made sense in the powershell version okay
(defvar logo.src.basename (file-name-base logo.src))
(defvar logo.maxdim (round (* canvas.x 0.25)))
(defvar logo.start.x) ; init now, setq later
(defvar logo.start.y) ; init now, setq later
(defvar logo.cachefile (expand-file-name (format "%s-%s.png" logo.src.basename logo.maxdim) cachedir))
(if (not (file-exists-p logo.cachefile))
(shell-command (format "magick %s -resize %s %s" logo.src logo.maxdim logo.cachefile))
(message "logo already exists, yay!"))
(defvar logo.x (car (get-dimensions logo.cachefile)))
(defvar logo.y (cdr (get-dimensions logo.cachefile)))
;; coordinate to paste logo on bg
(setq logo.start.x (round (* canvas.x 0.2)))
(setq logo.start.y (round (- (* canvas.y 0.5) (* logo.y 0.5))))
(defvar splashthickness (/ canvas.x 50.0))
(defvar magickcmd (format
"convert %s -gravity South -pointsize %s -fill '#f0f0f0' -annotate 0 '%s' -page +%s+%s %s -page +%s+%s %s -flatten ~/.config/hypr/hyprchan.jpg"
logo.start.x logo.start.y
waifu.position.x waifu.position.y
(shell-command magickcmd)