From 8df1cd226d4e558829a9bea72a2efa55474523a0 Mon Sep 17 00:00:00 2001 From: Mihail Ivanchev Date: Thu, 23 Jan 2025 09:54:34 +0100 Subject: [PATCH] Escape special chars and some edge case fixes when showing the notification's details. --- util/notify/notify.lisp | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/util/notify/notify.lisp b/util/notify/notify.lisp index 19daf91..78e2316 100644 --- a/util/notify/notify.lisp +++ b/util/notify/notify.lisp @@ -53,20 +53,31 @@ (append fst (list "...")) fst))))) +(defun escape-special-chars (text) + (stumpwm::escape-caret text)) + (defun show-notification (app icon summary body) "Show the notification using standard STUMPWM::MESSAGE function" (declare (ignore app icon)) - (stumpwm:message "~A~A^0~% ~%~A~A^0" + ; Use ^[ and ^] to preserve the selected colors and include + ; the noop ^[^] between the color and the text to make sure + ; that the notification's texts' are separated from StumpWM's + ; color modifier. This becomes an issue when the text begins + ; with a digit. Also, escape all special chars in the texts + ; to make sure no funny things happen. + (stumpwm:message "^[~A^[^]~A^]~% ~%^[~A^[^]~A^]" *notify-server-title-color* - (rewrap-body - summary - :max-lines *notify-server-max-title-lines* - :show-ellipsis t) + (escape-special-chars + (rewrap-body + summary + :max-lines *notify-server-max-title-lines* + :show-ellipsis t)) *notify-server-body-color* - (rewrap-body - body - :max-lines *notify-server-max-body-lines* - :show-ellipsis t))) + (escape-special-chars + (rewrap-body + body + :max-lines *notify-server-max-body-lines* + :show-ellipsis t)))) (define-dbus-object notify-dbus-service (:path "/org/freedesktop/Notifications"))