xscreensaver-aerial icon indicating copy to clipboard operation
xscreensaver-aerial copied to clipboard

Show same video in consecutive runs

Open curusarn opened this issue 5 years ago • 8 comments

Solves: https://github.com/graysky2/xscreensaver-aerial/issues/6

Goal:

  • Show the same video on multiple screens
  • Don't change the way how videos are chosen

Last used video is saved to $XDG_CONFIG_HOME/.atv4-previous[-4k].
If $XDG_CONFIG_HOME/.atv4-previous[-4k] was edited during the last 30 seconds then video from the previous run is used.
Otherwise, video is picked as usual.

I'm wondering if date is available everywhere. Especially the -r option.

curusarn avatar Mar 08 '19 00:03 curusarn

date is part of coreutils which is listed as a dependency.

curusarn avatar Mar 08 '19 00:03 curusarn

there is a race condition - script is launched for all screens and before any manages to pick the video, the other has already checked the $XDG_CONFIG_HOME/.atv4-previous. I will fix this.

curusarn avatar Mar 08 '19 13:03 curusarn

I'm still getting different images on multiple screens occasionally (about every 30 runs).

curusarn avatar Mar 08 '19 13:03 curusarn

Whole thing now works like this:

  1. wait until there is no lock file or until it gets too old (3s)
  2. write lock file
  3. goto 1) if someone have overwritten the lock
  4. use previous video (and return) if there is fresh enough $prev_used file
  5. continue normally

curusarn avatar Mar 08 '19 13:03 curusarn

It is still possible that different videos will be picked on multiple screens but the chance is pretty small.

curusarn avatar Mar 08 '19 13:03 curusarn

I have tested this on a dual monitor setup and I always didn't get a single case of different videos in about 100 runs.

curusarn avatar Mar 08 '19 13:03 curusarn

If the script is killed and the lock is left in place it expires in 3 seconds. So theoretically there could be a 3-second freeze in the following scenario:

  1. script creates a lock and is killed before picking a video
  2. script is immediately run again

Second run of the script would wait 3 seconds and then continue normally.

curusarn avatar Mar 08 '19 14:03 curusarn

I am currently using this. Thanks for sharing.

gmfricke avatar Aug 17 '20 16:08 gmfricke