franciscolourenco / done

A fish-shell package to automatically receive notifications when long processes finish.
MIT License
766 stars 70 forks source link

Notifications not showing on Wayland due to focused window detection #134

Open chipbuster opened 1 year ago

chipbuster commented 1 year ago

Hey there!

I changed my desktop over from X11 to Wayland GNOME a few months back, and lost notifications in the process (though I didn't notice it initially because a bunch of other stuff had broken as well).

I got some time to poke around at it today, and it looks like done always thinks that the terminal window is focused due to the check on line 210.

Further investigation shows that on my system, done gets the focused window ID using the gdbus call, and that this command always evaluates to the same thing on my system. I've tried running that command myself and focusing various XWayland and native Wayland apps, and I seem to always get the same result:

❯ sleep 2 && gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell --method org.gnome.Shell.Eval 'global.display.focus_window.get_id()'
(false, '')

and adding print statements into the is_process_window_focused function seems to confirm that this is the only window ID that's ever produced:

Intial window is (false, '')
focused window is (false, '')

Unfortunately, at this point, my knowledge of GNOME + Wayland basically runs out---I have no idea what that gdbus command is doing, whether it's supposed to work that way, etc. If anyone has proposed fixes, I would be happy to test it out.

System info:

Arch Linux (versions below are as reported by Pacman) GNOME Version: 43-1 Wayland version:1.21.0-2 XWayland version: 22.1.6-1 Fish version: 3.5.1-1 done version: 1.16.5

real-or-random commented 1 year ago

I have the same issue.

The reason why this call does not work anymore is security: https://www.reddit.com/r/gnome/comments/pneza1/gdbus_call_for_moving_windows_not_working_in/?rdt=34178

Other apps, e.g., ActivityWatch, have this issue, too. See https://github.com/flexagoon/focused-window-dbus for an GNOME Shell Extension to solve this. This was written with ActivityWatch in mind, but it's general. However, I don't know if it's worth the hassle supporting that here.

done always thinks that the terminal window is focused due to the check on line 210.

As a first step, it may be simpler to disable that check on GNOME, or at least give an option to do so? I don't know, it's hard to imagine how annoying it is to always get notifications even when the window is focused. We'd need to try.

franciscolourenco commented 8 months ago

1.19.0 (release) added an option to enable notifications on Wayland while using the Kitty terminal. Thanks @jinliu!

vibhavsinha commented 8 months ago

As a workaround, it is possible to remove the focused window detection and have the notification displayed even if the window is in focus by commenting the check for that. I keep the duration to be longer at 10s, so it works for me on alacritty.

~/.config/fish/conf.d/done.fish

     function __done_ended --on-event fish_postexec
         set -l exit_status $status

         # backwards compatibility for fish < v3.0
         set -q cmd_duration; or set -l cmd_duration $CMD_DURATION

         if test $cmd_duration
             and test $cmd_duration -gt $__done_min_cmd_duration # longer than notify_duration
-            and not __done_is_process_window_focused # process pane or window not focused
+            # and not __done_is_process_window_focused # process pane or window not focused