diff --git a/org-clock-waybar.el b/org-clock-waybar.el index 1d2bfac..0ff80cc 100644 --- a/org-clock-waybar.el +++ b/org-clock-waybar.el @@ -64,6 +64,14 @@ 'emacs-mule) "Coding system of the file `org-clock-waybar-filename'.") +(defsubst org-clock-waybar--get-task-title (task) + "Get the title of TASK." + (when task (substring-no-properties task))) + +(defsubst org-clock-waybar--get-task-category (task) + "Get the category of TASK." + (when task (get-text-property 0 'org-category task))) + (defun org-clock-waybar-tooltip () "The default tooltip to send to waybar." (when org-clock-current-task @@ -84,18 +92,16 @@ If CLOCKING-OUT is non-nil, `org-clock-current-task' will be treated as if it were nil; this is required because `org-clock-out' calls the hook functions before setting `org-clock-current-task' to nil." (let* ((task (if clocking-out nil org-clock-current-task)) - (category (when task (get-text-property 0 'org-category task))) - (title (when task (substring-no-properties task))) + (category (org-clock-waybar--get-task-title task)) + (title (org-clock-waybar--get-task-category task)) (tooltip (org-clock-waybar-tooltip)) (output (json-new-object))) (setq output (json-add-to-object output "text" - (if title - title - org-clock-waybar-not-clocked-in-text))) - (setq output (json-add-to-object output "alt" (if category category ""))) - (setq output (json-add-to-object output "tooltip" (if tooltip tooltip ""))) + (or title org-clock-waybar-not-clocked-in-text))) + (setq output (json-add-to-object output "alt" (or category ""))) + (setq output (json-add-to-object output "tooltip" (or tooltip ""))) (setq output (json-add-to-object output "class" "")) (setq output (json-add-to-object output "percentage" "")) (json-encode output)))