News for hackers. Stuff that matters.
Re:Why Is It So Hard to Detect Keyup Events on Linux? by cryptonector on Sunday January 27, 2019 @01:13PM (#19012912)
Eh? No, no one can fix this. Oracle couldn't fix this in Solaris. Microsoft can't fix this either (in Windows, in Linux, not at all).

It's not a question of money, or managerial will-power. You're asking to boil a great lake, and if you have the money for it, you will almost certainly find better uses for it. There is no market demand for a "fix" here, so there cannot be any managerial will-power either.

Nor is this due to Unix being open source back in the 70s, because it simply wasn't open source (and save for the erstwhile OpenSolaris, it still isn't). It wasn't entirely a research vehicle either, as AT&T used Unix as the OS for its phone switches. VMS too could not have had this feature, and for the same reasons -- though I'm not familiar enough with VMS, I feel absolutely certain that VMS did not have this either. And the hardware terminals (they were all hardware terminals back then, as there were no graphical terminals in which to emulate a terminal) were decidedly not open-source, and their vendors were in it for the profit.

This, and all the wonky, hacky things to do with terminals, goes back to the way things were almost half a century ago, long long before "FOSS" even came to be.

Software business models have absolutely nothing to do with why you can't have key up events in ttys.

EDIT: And incidentally, windowing systems happened on the scene around 1984-1985. By 1987 even SVR2 had a windowing system in the AT&T Unix PC. But it was too late to retrofit key up events into ttys -- already by then there was over a decade of legacy, and hardware terminals continued to be a thing for some time yet. This is a crucial lesson in engineering: even relatively small amounts of legacy have profound effects on what is feasible, so often you have to get things right in the very beginning (precisely when it's hardest to get things right!).

Re:Why Is It So Hard to Detect Keyup Events on Linux? by zamalek on Sunday January 27, 2019 @02:26PM (#19013306)
> No, no one can fix this.

The nice thing about escape sequences is that they are ignored if not understood.

> Microsoft can't fix this either (in Windows

Because it's not an issue in Windows? The Windows console, as primitive as it is, supports monitoring the status of the keyboard (which can be used to infer key up events).

Re:Why Is It So Hard to Detect Keyup Events on Linux? by cryptonector on Sunday January 27, 2019 @03:03PM (#19013500)
MSFT is adding a pty driver and support for Unix-style applications.
Re:Why Is It So Hard to Detect Keyup Events on Linux? by bboreham on Monday January 28, 2019 @02:03PM (#19020112)
> The nice thing about escape sequences is that they are ignored if not understood.

This is not what I find when I press my arrow keys in a container terminal set up with no TERM variable. I get funky characters spewed across the input line.

Re:Why Is It So Hard to Detect Keyup Events on Linux? by ordu on Sunday January 27, 2019 @02:23PM (#19013289)
> No, no one can fix this.

I don't know about this mythical "one", but I can. I just see no reason to fix it.

It is not so hard to make a patch for a /usr/src/linux/drivers/tty/vt.c to make it accept one more esc-seqeuence which would switch terminal into special state, when terminal will send keyup and keydown escape sequences instead of raw-keys for each keypress. A week of tinkering with vt.c and viola, terminal can send keyup and keydown. (Plus maybe one more week to decide how to encode keyups and keydown the best, so ideally terminal would be useable even after wrong esc-sequence sent to it in the wrong time).

The right question is: and what? Why might I wish to do this? I might invent some application for this new feature, but I'm pretty sure I couldn't invent something useful what can't be done without keyup event.

Re:Why Is It So Hard to Detect Keyup Events on Linux? by derefr on Sunday January 27, 2019 @02:29PM (#19013325)
That doesn't fix it, on its own. You now also need to make every library and abstraction layer that the packages on your system use be aware of this new feature as well. Can an ncurses program now detect a keyup through this? Can a Docker PTY? Can the JVM? Etc.

In most of those cases, because of the historical precedent, these libraries/runtimes don't even have a concept of "keyup" for their TTY-like abstraction, so adding this to them may entail a bit more work than it sounds—especially if, like the JVM, they have a static interface/protocol built in to specify the API of a "TTY-like object", which cannot be changed, since third-parties have compiled code against it and expect that code to remain ABI-compatible with new versions of the runtime.

Re:Why Is It So Hard to Detect Keyup Events on Linux? by cryptonector on Sunday January 27, 2019 @02:51PM (#19013443)
Exactly. There's more to it. And yes, it can be done, literally, and I'm sure several participants in this thread could do it. But there's practically no demand, so it won't get done.
Re:Why Is It So Hard to Detect Keyup Events on Linux? by ordu on Sunday January 27, 2019 @03:02PM (#19013488)
> You now also need to make every library and abstraction layer that the packages on your system use be aware of this new feature as well.

No. You miss the point. I need to do nothing. I have no reason to do anything. Give me a reason and then we can discuss what I need to do. I need a rationale to do something, without rationale my work would be pointless and you might argue indefinitly that anything that I've done already is not enough.

Re:Why Is It So Hard to Detect Keyup Events on Linux? by derefr on Sunday January 27, 2019 @03:15PM (#19013542)
You are the one that said, above, that you could—and I quote—"fix this."

"This", in that phrase, stands for the problem in the OP post title—"it being so hard to detect keyup event on Linux."

And "on Linux", in the OP post, is a shorthand for "in all the arbitrary applications that exist in the Linux userland, or that one might choose to write in the Linux userland." (You can tell that it has this meaning, because under the more literal meaning of "on Linux"—working within the Linux kernel itself—it is already quite easy to detect keyup events.)

Obviously, fixing the entire Linux userland is an unbounded amount of work. That is precisely why the other commenters above are saying that it cannot be done. Not "done" as in "worked upon", but "done" as in "finished."

Re:Why Is It So Hard to Detect Keyup Events on Linux? by killjoywashere on Sunday January 27, 2019 @05:27PM (#19014129)
key-up could give you all sorts of interesting information: you could detect "false zeros" where there are extremely rapid up-down sequences suggestive of motor function disorders in the user (Parkinsonism, etc). You could test the forearm extensors. You could test motor units to exhaustion (hold key until press fails, the "keyup" event). We haven't even gotten to the spinal cord yet, so I'm pretty sure the frontal cortex could be engaged in all sorts of interesting 3rd order ways.
Re:Why Is It So Hard to Detect Keyup Events on Linux? by ordu on Sunday January 27, 2019 @08:38PM (#19014878)
Yes, but why might one want to do it in terminal? You can start Xorg server or Wayland and make it in graphics, where there are no such constraints.
Re:Why Is It So Hard to Detect Keyup Events on Linux? by mikeash on Sunday January 27, 2019 @04:32PM (#19013913)
There are terminal emulators that can display images, make clickable hyperlinks, track the mouse cursor, and dynamically update the title bar with custom text. None of that was possible in the 70s. To say that this is impossible is to ignore how terminal emulators have actually evolved over the years.
Re:Why Is It So Hard to Detect Keyup Events on Linux? by darkpuma on Sunday January 27, 2019 @05:12PM (#19014071)
A typical modern terminal emulator running under X will export WINDOWID that is the X id of the terminal emulator window. With this you could detect key-up events. I've never seen anybody do this though. The only uses of this I've ever seen are detecting when the terminal emulator goes out of focus and drawing images on top of the terminal emulator. I've not done a detailed survey, but I believe this used to be the most common way of displaying images "in" terminal emulators before terminal emulators started supporting inline images encoded as escape sequences (e.g. iterm2)

The problem with having the terminal emulator implement it is getting the terminal emulator to know when to insert these new key-up escape codes into the psuedo-terminal. The terminal emulator shouldn't send them to the psuedo-terminal when it's in raw mode, because every existing program that runs in raw mode won't know what to do with them. And inserting them into a cooked mode pty simply makes no sense. So it becomes clear that the terminal needs a "rawer than raw" (still bleeding?) mode, and some way for the program requesting bleeding mode to communicate that desire to the terminal emulator. Right now, that's not how the whole stack works. A program tells the psuedo-terminal (kernel) whether it wants raw or cooked mode, that's not something that terminal emulator is involved in.

You could potentially have a terminal emulator that accepts a proprietary "toggle bleeding mode" escape sequence, at which point the terminal emulator starts inserting key up escape codes into the pseudo-terminal which it assumes has been placed into raw mode appropriately. There's not really any technical reason this couldn't be done, but there's a strong "nobody needs this" social reason for why it hasn't been done. Sure, if you want responsive controls while play aalib quake in your terminal emulator across ssh, you'd want this. But who does that as anything other than a gimmick?

Re:Why Is It So Hard to Detect Keyup Events on Linux? by cryptonector on Sunday January 27, 2019 @05:21PM (#19014108)
Making links clickable requires no changes to the protocols spoken -- the emulator merely recognizes URIs. I know about mouse support. Updating title bars actually goes back a long time. Displaying images... I've never seen -- can you tell me about that?

I've actually outlined in this thread how to implement key up events, if that really was desired, in ttys, but I argue there's no real demand, and it won't happen. And it is impossible now in the sense that... the functionality does not exist.

Re:Why Is It So Hard to Detect Keyup Events on Linux? by mikeash on Sunday January 27, 2019 @05:42PM (#19014218)
I’m not just talking about clickable URLs, but actual hyperlinks where the visible title is different from the destination URL.

I don’t know what there is to tell about displaying images. There are terminal emulators that can display images inline when a program emits the image data properly.

I don’t understand your final sentence. How does it make sense to say that it’s impossible because it doesn’t currently exist? That’s like saying it’s impossible for me to drive because I’m not currently in a car. You didn’t say that nothing currently supports it, you said “no one can fix this.”

Re:Why Is It So Hard to Detect Keyup Events on Linux? by cryptonector on Sunday January 27, 2019 @05:52PM (#19014255)
I wrote this:

> So, yes, it's absolutely impossible to get key up events in tty context, and at this point it will almost certainly stay that way forever, as it's too late to retrofit terminal emulators, drivers, and applications to understand whatever protocol for communicating key up events. (The right way to do this would be to develop an escape sequence protocol that the tty/pty drivers could decode and turn events into out-of-band events to be delivered via ioctl()s, that way applications that don't care about key up events don't see them and don't need to be modified. But who is going to do all that work?)

So "it's impossible [right now]" and "it can be done" but "it's not gonna happen". Is that not a fair summary? Perhaps we can disagree as to the last part.

EDIT: Ah yes, further below I wrote this:

> Eh? No, no one can fix this. Oracle couldn't fix this in Solaris. Microsoft can't fix this either (in Windows, in Linux, not at all).

> It's not a question of money, or managerial will-power. You're asking to boil a great lake, and if you have the money for it, you will almost certainly find better uses for it. There is no market demand for a "fix" here, so there cannot be any managerial will-power either.

That's overbroad, yes. The fix I outlined is not as much as boiling great lakes.

Re:Why Is It So Hard to Detect Keyup Events on Linux? by mikeash on Sunday January 27, 2019 @07:22PM (#19014632)
I wouldn’t be at all surprised if it happened. I wouldn’t be surprised if it never happened, too, but I don’t think it’s at all a fair summary to say it definitely never will. It’s not at all reasonable to call it impossible, and Oracle, Microsoft, or random Linux developers could all do it if they felt like it.
Re:Why Is It So Hard to Detect Keyup Events on Linux? by cryptonector on Sunday January 27, 2019 @07:51PM (#19014721)
Fair enough.
Re:Why Is It So Hard to Detect Keyup Events on Linux? by LeoPanthera on Sunday January 27, 2019 @07:29PM (#19014656)
Terminals have been able to display images since the VT200:

https://en.wikipedia.org/wiki/Sixel

Re:Why Is It So Hard to Detect Keyup Events on Linux? by kevin_thibedeau on Sunday January 27, 2019 @09:35PM (#19015046)
Tektronix had graphical terminals in the 70's. Still emulated by xterm.
Re:Why Is It So Hard to Detect Keyup Events on Linux? by dfc on Sunday January 27, 2019 @05:59PM (#19014287)
The terminology, the terminal emulator from enlightenment, will display images and do other things tgat xterm never could:

https://www.enlightenment.org/about-terminology.md

Re:Why Is It So Hard to Detect Keyup Events on Linux? by darkpuma on Sunday January 27, 2019 @06:10PM (#19014348)
>things that xterm never could

Ah, but can terminology render tektronix vector graphics? :)

Re:Why Is It So Hard to Detect Keyup Events on Linux? by cryptonector on Sunday January 27, 2019 @06:42PM (#19014461)
Thanks!
Re:Why Is It So Hard to Detect Keyup Events on Linux? by darkpuma on Sunday January 27, 2019 @05:30PM (#19014148)
iterm2 supports inline images with a proprietary set of escape codes described here: https://www.iterm2.com/documentation-images.html

Incidentally if you ssh into an untrusted system using iterm2 (or otherwise get foreign escape codes going into iterm2, for instance if you cat the wrong file), I believe it's possible for that system to drop files into your ~/Downloads/ directory without prompting you.

It could be worse though, there used to be terminal emulators you could exploit by setting the title, because they weren't bounds checking correctly.

Re:Why Is It So Hard to Detect Keyup Events on Linux? by gnachman on Sunday January 27, 2019 @07:06PM (#19014570)
> No, no one can fix this

It's been solved twice, but I'd like to get that down to just once :)

https://sw.kovidgoyal.net/kitty/protocol-extensions.html#key...

https://gitlab.com/gnachman/iterm2/issues/7440

Re:Why Is It So Hard to Detect Keyup Events on Linux? by ironmagma on Sunday January 27, 2019 @01:29PM (#19012991)
There's a left out qualification here: "without breaking backwards compatibility". Sure, you can fix it, you just might have to change the entire stack a little bit and say goodbye to running all the programs currently out there. And then you can have a subsystem for backwards-compatibility, or in the worst case, a VM.
Re:Why Is It So Hard to Detect Keyup Events on Linux? by cryptonector on Sunday January 27, 2019 @01:48PM (#19013091)
There is a ton of value in legacy. Maintaining backwards compatibility is a big deal. At some point you end-of-life a feature, but you generally don't want to make breaking changes. The tty is probably going to be with us for many more years yet (decades), so I don't see it getting end-of-lifed.
Re:Why Is It So Hard to Detect Keyup Events on Linux? by ironmagma on Sunday January 27, 2019 @02:27PM (#19013313)
It is a big deal, but honestly as somewhat of a visionary I would rather see an open source platform that decided to cut ties with such a legacy system that causes short term pains in favor of longer term advantages. That transition has to happen at some point for a platform to become more versatile, and if it's put off indefinitely, that just resigns itself to being not the best possible platform it can be.
Re:Why Is It So Hard to Detect Keyup Events on Linux? by csande17 on Sunday January 27, 2019 @02:34PM (#19013353)
The thing you have to keep in mind is that once you start cutting ties with legacy systems, breaking changes will keep happening. Today, it's key-up events. Tomorrow, it'll be something else. And eventually, the new and shiny subsystem you introduced today will be considered legacy code by someone else, and it too will be tossed out and replaced.

In the end, you'll be choosing between a platform that requires you update every piece of software you maintain every six months and a platform that doesn't. And while the former might seem better from a pure-ideals perspective, the latter is vastly preferable for actual usage. (That's why so many people use Windows, and it's why I now run Linux on my MacBook.)

Re:Why Is It So Hard to Detect Keyup Events on Linux? by ironmagma on Sunday January 27, 2019 @02:58PM (#19013474)
That's an interesting perspective, but it seems unlikely that that is the main or even an important advantage Linux has over Windows. After all, you can't really run old Linux binaries on a new Linux system without strong determination and a lot of time. There are many others, including its (essentially) fully open source nature definitely being up there.
Re:Why Is It So Hard to Detect Keyup Events on Linux? by csande17 on Sunday January 27, 2019 @03:03PM (#19013499)
You're correct that this is not an advantage Linux has over Windows; both Windows and Linux strive to maintain strong backwards-compatibility guarantees. It's an advantage they both have over systems like macOS.

And while Windows maintains near-perfect binary compatibility (I've run programs on Windows 10 that were last compiled a decade ago), Linux instead has excellent source compatibility. I've successfully compiled and used decade-old Linux utilities with no problems.

This difference speaks to the different economic philosophies these platforms have. Microsoft expects you to buy software in a box at a store and use it forever. Linux expects you to use free software developed by volunteers. And Apple expects you to pay over and over again to avoid losing functionality.

Re:Why Is It So Hard to Detect Keyup Events on Linux? by cryptonector on Sunday January 27, 2019 @03:07PM (#19013512)
The Linux kernel is famous for trying really hard to maintain ABI backwards-compatibility.

In practice this means that statically-linked executables from a decade ago will run just fine on Linux today, at least as far as interactions with the kernel is concerned (interactions with other parts of the system, it depends). The same is not necessarily true of dynamically-linked applications because user-space libraries' maintainers are not as exacting about backwards-compatibility. Note that this is not an argument for static linking, at least not in its current form.

Re:Why Is It So Hard to Detect Keyup Events on Linux? by michaelmrose on Monday January 28, 2019 @01:04AM (#19015586)
You forgot to justify where you need to have interesting features in a tty instead of graphical environments where there is no such limitation.
Re:Why Is It So Hard to Detect Keyup Events on Linux? by csande17 on Sunday January 27, 2019 @02:30PM (#19013328)
> Sure, you can fix it, you just might have to [...] say goodbye to running all the programs currently out there.

One problem with doing this is that the only reason anyone uses Linux is to run programs that are currently out there. If Linux started to make breaking changes like this, people would switch to some other operating system that didn't break their software.

Sure, lots of people use macOS, and macOS breaks a bunch of APIs every year. But macOS users also buy expensive recurring subscriptions for every app they use, so Mac software companies can afford to employ developers to clean up after Apple every year. Linux doesn't have that; a lot of Linux software is either unmaintained or maintained by volunteer developers in their spare time.