From 878eb11346ebab1660182cf9e0638be21744936b Mon Sep 17 00:00:00 2001 From: MitchMarq42 Date: Fri, 11 Aug 2023 19:37:10 -0800 Subject: [PATCH] Refactor `notibox--get-position` and add stack positions --- notibox.el | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/notibox.el b/notibox.el index 31195a3..f678797 100644 --- a/notibox.el +++ b/notibox.el @@ -48,21 +48,32 @@ (defvar notibox-padding 30) (defvar alert-fade-time 5); seconds, also provided by `alert' package (defvar notibox--refresh-delay 0.1) ; seconds. Probably don't change this one. -(defun notibox--get-position () - "Return the starting coordinate at which to place the notibox, as cons." - (let* ((parent-width (frame-pixel-width)) +(defun notibox--get-position (&optional stackdepth) + "Return the starting coordinate at which to place the next notibox, as cons. + +If STACKDEPTH is non-nil and nonzero, return a position that far down." + (let* ( + (stackdepth (or stackdepth 0)) + (parent-width (frame-pixel-width)) (child-width (* notibox-width (shr-string-pixel-width " "))) (parent-height (frame-pixel-height)) - (child-height (* notibox-height (line-pixel-height)))) - (pcase notibox-corner - ('topleft (cons notibox-padding notibox-padding)) - ('topright (cons (- parent-width (+ child-width notibox-padding)) - notibox-padding)) - ('bottomleft (cons notibox-padding - (- parent-height (+ child-height notibox-padding)))) - ('bottomright (cons - (- parent-width (+ child-width notibox-padding)) - (- parent-height (+ child-height notibox-padding))))))) + (child-height (* notibox-height (line-pixel-height))) + (padded-height (+ child-height notibox-padding)) + (x-justify (pcase notibox-corner + ((or 'topleft 'bottomleft) notibox-padding) + ((or 'topright 'bottomright) + (- parent-width (+ child-width notibox-padding))))) + (y-justify (pcase notibox-corner + ((or 'topleft 'topright) notibox-padding) + ((or 'bottomleft 'bottomright) + (- parent-height (+ child-height notibox-padding))))) + (y-direction (pcase notibox-corner + ((or 'topleft 'topright) #'+) + ((or 'bottomleft 'bottomright) #'-))) + (y-coord (funcall y-direction y-justify (* stackdepth child-height))) + ) + (cons x-justify y-coord) + )) ;; (notibox--get-position) (defun notibox--prepare-buffer (title body)