lxde / lxterminal

VTE terminal emulator written in GTK
GNU General Public License v2.0
161 stars 57 forks source link

WINDOWID variable not being set makes it impossible to figure out last active/focused shell #58

Open wknapik opened 6 years ago

wknapik commented 6 years ago

Terminal emulators like aterm, konsole, mate-terminal, sakura, urxvt, xfce4-terminal and xterm set the WINDOWID environment variable to the window id of the window corresponding to the shell.

For terminal emulators that have the same child process in each window, like xfce4-terminal, that variable makes it possible to figure out which shell in one of those windows was used last.

Lxterminal, like xfce4-terminal, has the same child process in each window, but lacks the WINDOWID variable. This matters in cases like this one, for instance https://github.com/wknapik/lastcwd, where the user wants to figure out the last CWD (the README explains the WINDOWID problem in more detail).

There is no feasible workaround, because WINDOWID has to be set after the window is created, but will not show up in /proc/pid/environ if set after the window/shell is spawned, so this has to be done by lxterminal - no wrapper, or profile script can solve this, at least as far as I can tell.

It seems like it would be trivial to implement, would not cause any problems and would put lxterminal in line with classic terminal emulators like xterm and urxvt.

wknapik commented 6 years ago

Discussion about the same issue in gnome-terminal: https://gitlab.gnome.org/GNOME/gnome-terminal/issues/17

Lyle-Tafoya commented 4 years ago

I'm developing some software which is intended to be run in terminal emulators and requires the Window id as part of a solution to detect key release events. By far the most reliable way to obtain the Window id that I know of is to read the WINDOWID environment variable. Other possibilities I have investigated require some assumptions to be made that I know will not always hold up.

Most major terminal emulators set this environment variable (ie. xterm, urxvt, konsole, xfce4-terminal, mate-terminal, kitty, alacritty, sakura, etc...), with gnome terminal being one of the only exceptions I am aware of. Their reasoning basically boils down to "we don't like this because it's 'hacky'". I don't find their reasoning to be satisfactory at all. All the concerns they raise are issues that developers like myself who wish to leverage the variable should be worrying about and not really issues that the terminal emulator developers themselves need to worry about. There are some inherent limitations in terminal emulator technology that sometimes require hacky solutions to solve. It's unfortunate, but also undeniably true.

Is this something you would consider adding?

LourensVeen commented 3 years ago

I've been trying out LXTerminal recently, and I've noticed that vim does not set the tab title to the file name in LXTerminal as it does in mate-terminal. If I look up the window id using xwininfo and manually set WINDOWID then it works as expected.

It is possible to work around this issue by having vim use an escape sequence to set the tab title, but this leaves it unable to restore the previous tab title on shutdown, since it cannot get the original value using an escape sequence, only via an X11 call.