e6a1db213d66efdaec00469e58d4f9f3f2a78bd0

Author
bretello <bretello@users.noreply.github.com>
Committer
GitHub <noreply@github.com>
Date

Message

feat(bgnotify): add support to wayland (#12045)

Diff

 1diff --git a/plugins/bgnotify/bgnotify.plugin.zsh b/plugins/bgnotify/bgnotify.plugin.zsh
 2index ed2653aa8c74909b3360590eb56477095e92dc39..9ad989c0bd00d809c1b12e5494e32e30c186973a 100644
 3--- a/plugins/bgnotify/bgnotify.plugin.zsh
 4+++ b/plugins/bgnotify/bgnotify.plugin.zsh
 5@@ -59,11 +59,14 @@ function bgnotify_formatted {
 6   fi
 7 }
 8 
 9-# for macOS, output is "app ID, window ID" (com.googlecode.iterm2, 116)
10 function bgnotify_appid {
11   if (( ${+commands[osascript]} )); then
12+    # output is "app ID, window ID" (com.googlecode.iterm2, 116)
13     osascript -e 'tell application (path to frontmost application as text) to get the {id, id of front window}' 2>/dev/null
14-  elif (( ${+commands[xprop]} )); then
15+  elif [[ -n $WAYLAND_DISPLAY && ${+commands[swaymsg]} && ${+commands[jq]} ]]; then # wayland+sway
16+    # output is "app_id, container id" (Alacritty, 1694)
17+    swaymsg -t get_tree | jq '.. | select(.type?) | select(.focused==true) | {app_id, id} | join(", ")'
18+  elif [[ -n $DISPLAY && ${+commands[xprop]} ]]; then
19     xprop -root _NET_ACTIVE_WINDOW 2>/dev/null | cut -d' ' -f5
20   else
21     echo $EPOCHSECONDS
22@@ -71,7 +74,8 @@ function bgnotify_appid {
23 }
24 
25 function bgnotify {
26-  # $1: title, $2: message
27+  local title="$1"
28+  local message="$2"
29   if (( ${+commands[terminal-notifier]} )); then # macOS
30     local term_id="${bgnotify_termid%%,*}" # remove window id
31     if [[ -z "$term_id" ]]; then
32@@ -82,18 +86,22 @@ function bgnotify {
33     fi
34 
35     if [[ -z "$term_id" ]]; then
36-      terminal-notifier -message "$2" -title "$1" &>/dev/null
37+      terminal-notifier -message "$message" -title "$title" &>/dev/null
38     else
39-      terminal-notifier -message "$2" -title "$1" -activate "$term_id" -sender "$term_id" &>/dev/null
40+      terminal-notifier -message "$message" -title "$title" -activate "$term_id" -sender "$term_id" &>/dev/null
41     fi
42   elif (( ${+commands[growlnotify]} )); then # macOS growl
43-    growlnotify -m "$1" "$2"
44-  elif (( ${+commands[notify-send]} )); then # GNOME
45-    notify-send "$1" "$2"
46+    growlnotify -m "$title" "$message"
47+  elif (( ${+commands[notify-send]} )); then
48+    if [[ -n $ALACRITTY_WINDOW_ID ]]; then
49+        notify-send -i Alacritty "$title" "$message"
50+    else
51+        notify-send "$title" "$message"
52+    fi
53   elif (( ${+commands[kdialog]} )); then # KDE
54-    kdialog --title "$1" --passivepopup  "$2" 5
55+    kdialog --title "$title" --passivepopup  "$message" 5
56   elif (( ${+commands[notifu]} )); then # cygwin
57-    notifu /m "$2" /p "$1"
58+    notifu /m "$message" /p "$title"
59   fi
60 }
61