Selaa lähdekoodia

add xscreensaver kiosk blog post

Thomas Buck 2 vuotta sitten
vanhempi
commit
fa3c889044
1 muutettua tiedostoa jossa 118 lisäystä ja 0 poistoa
  1. 118
    0
      input/blog/2022/2022_01_17_xscreensaver_kiosk.md

+ 118
- 0
input/blog/2022/2022_01_17_xscreensaver_kiosk.md Näytä tiedosto

@@ -0,0 +1,118 @@
1
+title: Blog
2
+post: XScreenSaver as TV decoration
3
+description: Script for placing fullscreen windows
4
+date: 2022-01-17
5
+---
6
+
7
+I got a new TV connected to my PC.
8
+Using xrandr, I made some simple scripts to switch between stand-alone or mirrored mode.
9
+To control media playback comfortably from the desktop monitor, I'm using the nifty little tool [squint](https://github.com/a-ba/squint/), auto-starting and killing it as needed from my aforementioned scripts.
10
+
11
+To show some pretty pictures on the TV, I also created the following (pretty hacky) script for moving [XScreenSaver](https://www.jwz.org/xscreensaver/) hacks fullscreen'ed to the TV.
12
+
13
+Maybe it helps someone else.
14
+
15
+<pre class="sh_sh">
16
+#!/bin/bash
17
+
18
+# tv-screen-saver
19
+#
20
+# Show random animations on only one monitor.
21
+#
22
+# Dependencies:
23
+#   - XScreenSaver
24
+#   - wmctrl
25
+#   - xdotool
26
+#
27
+# This script randomly selects a screensaver (hack) from XScreenSaver,
28
+# runs it, moves it to a specific location on the desktop,
29
+# fullscreens it, waits for 5mins, then kills the hack.
30
+# This process is repeated endlessly.
31
+#
32
+# Control the position where the window will be placed by editing the
33
+# MONITOR_PLACE below. The parameters are X-Pos,Y-Pos,Width,Height.
34
+# Use -1 to keep existing values.
35
+#
36
+# Hacks that should be skipped are listed in HACK_BLACKLIST below.
37
+#
38
+# The window focus will be saved and restored when opening a new hack.
39
+#
40
+# Bugs:
41
+# In the timespan of opening a new hack, some keypresses may go to the new
42
+# hack window, if you are currently typing.
43
+
44
+TIMEOUT=300
45
+MONITOR_PLACE="3000,-1,-1,-1"
46
+HACKS_DIR=/usr/lib/xscreensaver
47
+
48
+HACK_BLACKLIST=("xscreensaver-auth" "xscreensaver-getimage" "xscreensaver-getimage-file" "xscreensaver-getimage-video" "xscreensaver-gfx" "xscreensaver-gl-visual" "xscreensaver-systemd" "xscreensaver-text" "webcollage" "webcollage-helper" "vidwhacker")
49
+
50
+HACK_PID=0
51
+FOCUS_WIN=0
52
+
53
+# kill running screensaver when user exits with Ctrl+C
54
+trap graceful_exit INT
55
+
56
+# make sure screensavers can find required xscreensaver-text and other helpers
57
+PATH=$PATH:$HACKS_DIR
58
+
59
+get_random_hack() {
60
+    HACK_NAME=$(ls $HACKS_DIR | shuf -n 1)
61
+
62
+    # skip if on blacklist
63
+    for i in ${!HACK_BLACKLIST[@]};
64
+    do
65
+        if [ "$HACK_NAME" == "${HACK_BLACKLIST[$i]}" ]
66
+        then
67
+            get_random_hack
68
+            exit 0
69
+        fi
70
+    done
71
+
72
+    echo $HACK_NAME
73
+}
74
+
75
+put_on_tv() {
76
+    wmctrl -r 'from the XScreenSaver' -e 0,$MONITOR_PLACE
77
+    wmctrl -r 'from the XScreenSaver' -b toggle,fullscreen
78
+}
79
+
80
+save_window_focus() {
81
+    FOCUS_WIN=$(xdotool getactivewindow)
82
+}
83
+
84
+restore_window_focus() {
85
+    xdotool windowactivate $FOCUS_WIN
86
+}
87
+
88
+graceful_exit() {
89
+    if [ "$HACK_PID" -ne "0" ]
90
+    then
91
+        kill $HACK_PID
92
+    fi
93
+    exit 0
94
+}
95
+
96
+while true
97
+do
98
+    save_window_focus
99
+
100
+    # run new hack
101
+    HACK=$(get_random_hack)
102
+    echo "Running $HACK for $TIMEOUT seconds"
103
+    $HACKS_DIR/$HACK &
104
+    HACK_PID=$!
105
+
106
+    # wait for window to appear
107
+    sleep 0.2
108
+    put_on_tv
109
+
110
+    restore_window_focus
111
+
112
+    sleep $TIMEOUT
113
+    kill $HACK_PID
114
+
115
+    # wait a bit before starting next one
116
+    sleep 0.2
117
+done
118
+</pre>

Loading…
Peruuta
Tallenna