0

I'm implementing a screensaver system that would wait for user input on a tty, and, in the event that it didn't get any, would play a screensaver until input is received.

How would I efficiently tap the user input to the tty (for example /dev/pts/1)?

5
  • 3
    "If I have two terminals and write cat /proc/<pid of other terminal>/fd/0, I get results that are sketchy at best." I'll say! Why are you doing this? This seems really not the way to solve interprocess communications. But without knowing what you actually want to achieve, it's hard to advise. See the Wikipedia article on the XY Problem. Commented Dec 7, 2023 at 14:36
  • @MarcusMüller the end goal is to have a program that sees (or at least is aware of) every byte sent to either a process's std like /proc/<pid>/fd/* or a device like /dev/pts/1. I'd very much prefer that this does not require root. Commented Dec 7, 2023 at 14:57
  • Let's dig a slight bit deeper! What do you need that for? And consoles are completely different beasts than stdin, so, you're raising more questions here, even! Please try to give more applications context. As it's currently written, it really is impossible to find a solution to your problem. Commented Dec 7, 2023 at 14:58
  • A screensaving system that would listen in for user input in that process/tty, and, in the event that it doesn't get any, would play a screensaver. Commented Dec 7, 2023 at 14:59
  • 1
    ah, OK, this is extremely far from what you've asked for :D can you please edit your question to explain this screensaver system, and what it should precisely do? This feels like you need to implement a pseudo-TTY (or use an existing implementation of one), but I'm not sure. Commented Dec 7, 2023 at 15:04

1 Answer 1

0

So, this is really mostly about PTYs, not std input: key presses in a running process aren't usually standard input!

So, what you need is a pseudo-TTY emulator that will both deal with inputs as well keep a timer for how long nothing has happened on screen.

tmux can do that. Install tmux, and create a tmux.conf in ~/.config/tmux, containing (at least) the following (60 s screensaver delay)

set -g lock-command "the program you want to be screensaver. It has to quit when a key is pressed, but that's your problem to implement" set -g lock-after-time 60 

You can then run your "main" program as

tmux new yourprogram 

(or just use tmux as usual, see numerous tmux tutorials)

Using reptyr you can migrate an already program to a tmux session; haven't tried whether the inactivity detection still works.

5
  • It doesn't seem to be working. tmux looks fine, no errors or anything, but it doesn't execute pipes.sh after 5, 10, or 60 seconds. Also, tmux seems to have like a low refresh rate on my virtual console, and flickers every now and then. Commented Dec 7, 2023 at 15:45
  • that's unusual! Commented Dec 7, 2023 at 15:50
  • Is there an alternative to tmux, like something that would connect to a process like reptyr and give screensaver support, or would one have to be made? Commented Dec 7, 2023 at 15:56
  • I'd first look into what your pipes.sh does. tmux is very widely used and usually pretty low on bugs. Handling all kinds of PTYs can get very error-prone. Commented Dec 7, 2023 at 16:07
  • pipes.sh works fine when I run it manually. The same problem arises when I change it to `set -g lock-command "wall message". It just doesn't execute the command. Commented Dec 7, 2023 at 16:22

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.