Open ojhaujjwal opened 8 years ago
It appears that not every terminal sets the WINDOWID
environment variable.
Terminator and gnome-terminal
, for example, set it correctly, while Guake and Terminix do not.
I came up with a raw solution based on xdotool
, but I don't know if it is in line with @dschep's thoughts; relying on external binaries is not always a welcome choice, especially if such binaries are not installed by default on most systems.
Also extensive testing is required, as this is more of a temporary hack rather than a solution.
Hmm, yeah I've seen other tools that do this sort of thing using xdotool
. I'd prefer not having additional dependencies, but I wouldn't be opposed to using it if available, and falling back to $WINDOWID
.
Hrmm.. actually, isn't xdotoo getactivewindow
the same as the xprop
command ntfy uses? WINDOWID
is the ID of the window the command is running in, regardless of focus. Good to know that there's an issue with Guake & Gnome-Terminal, but I'm afraid xdotool
isn't the answer 😢
In theory both refer to the same attribute, but with the said terminals I've only managed to get a WindowID by using xdotool
... There's probably another attribute hidden somewhere in /proc
.
Hit the same issue. Solved it by returning False
from is_focused()
. Will see how that turns out for me ;). On a side note, having that configurable in .config would make things easier for other potentially deficient terminals.
@zamber But won't you get notified even if the terminal is focused, that way?
@zamber hmm yeah, I should make the ntfy done --background-only
and ntfy shell-integration --foreground-too
options configurable via the config file.
@nmaggioni yup.
I switched to Terminology recently and it appears to not set WINDOWID
either.
The last version of terminator does not set $WINDOWID
either
$ pacman -Qi terminator
Name : terminator
Version : 1.90-1
Perhaps, this could be of help? http://stackoverflow.com/questions/2250757/is-there-a-linux-command-to-determine-the-window-ids-associated-with-a-given-pro
Welp. seems Gnome terminal no longer sets WINDOWID either. gonna play with the xdotool solution.
Doh. per my previous comment xdotool doesn't work. Not sure how to do this :cry:
Potential fix for getting the terminals WINDOWID
wmctrl -lp | grep $PPID # but in python and recursively since ntfy/python's ppid is bash
still not great bc gnome-terminal for example has many windows for the same pid
I just installed guake
$ guake
Guake not running, starting it
Guake Terminal 3.2.1
VTE 0.50.2
Gtk 3.22.29
System doesn't support transparency
can't bind show-focus key
and xdotool seems to work...
$ xdotool getactivewindow
33554447
$ xdotool getmouselocation --shell | grep WINDOW
WINDOW=33554447
Right. but isn't xdotool getactivewindow
the equivalent of xprop -root '\t$0' _NET_ACTIVE_WINDOW
? Ie: it gets the current active window. WINDOWID
is window ID of the terminal that ntfy is running in. Its needed because to determine focus you have to compare the current window id with ntfy's terminal's window id.
It works very nicely on normal terminal but, I get an error on guake terminal.