diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/firefox-io-slayer (renamed from src/firefox-io-slayer-redux) | 0 | ||||
-rwxr-xr-x | src/firestart | 40 | ||||
-rwxr-xr-x | src/firestartx | 58 | ||||
-rw-r--r-- | src/ioslay@.service | 3 |
4 files changed, 100 insertions, 1 deletions
diff --git a/src/firefox-io-slayer-redux b/src/firefox-io-slayer index fe54e37..fe54e37 100755 --- a/src/firefox-io-slayer-redux +++ b/src/firefox-io-slayer | |||
diff --git a/src/firestart b/src/firestart new file mode 100755 index 0000000..5cc1c92 --- /dev/null +++ b/src/firestart | |||
@@ -0,0 +1,40 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | UNIT=firefox@$DISPLAY | ||
4 | |||
5 | if systemctl --user is-active "$UNIT" >/dev/null | ||
6 | then | ||
7 | echo "Attemping to contact existing Firefox instance." >&2 | ||
8 | # Ask the existing firefox to open a new window. | ||
9 | |||
10 | # Firefox does not include an official API to do this in a way that | ||
11 | # is not racy. If we merely do this: | ||
12 | # | ||
13 | # exec firefox "$@" | ||
14 | # | ||
15 | # ...then the unit could become inactive after our check, in which | ||
16 | # case this launches a new firefox outside the container! | ||
17 | # | ||
18 | # So instead, we launch the same command using a systemd container | ||
19 | # that prevents Firefox from forking off a new process. | ||
20 | # | ||
21 | # Well, actually, we let it fork off _one_ process, since otherwise | ||
22 | # it segfaults. But this _does_ happen to prevent it starting a new | ||
23 | # firefox instance! Firefox safely segfaults if it is limited this | ||
24 | # way while trying to start a new instance. | ||
25 | # | ||
26 | # A more "correct" approach is available here: | ||
27 | # https://github.com/ayosec/findfox | ||
28 | exec systemd-run \ | ||
29 | --user \ | ||
30 | --property Environment="DISPLAY=$DISPLAY" \ | ||
31 | --property Environment=XAUTHORITY="$XAUTHORITY" \ | ||
32 | --property TasksMax=2 \ | ||
33 | --wait \ | ||
34 | --pipe \ | ||
35 | -q \ | ||
36 | -- /bin/sh -c 'exec firefox "$@"' sh "$@" | ||
37 | else | ||
38 | systemctl --user reset-failed "$UNIT" 2>/dev/null | ||
39 | systemctl --user start "$UNIT" | ||
40 | fi | ||
diff --git a/src/firestartx b/src/firestartx new file mode 100755 index 0000000..636fc84 --- /dev/null +++ b/src/firestartx | |||
@@ -0,0 +1,58 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | get_new_display() | ||
4 | { | ||
5 | for ((n=1; n<99; ++n)) | ||
6 | do | ||
7 | if [ ! -e /tmp/.X$n-lock ] | ||
8 | then | ||
9 | NEW_DISPLAY=:$n | ||
10 | return | ||
11 | fi | ||
12 | done | ||
13 | false | ||
14 | } | ||
15 | |||
16 | get_new_display || exit | ||
17 | |||
18 | if [ $# = 0 ] | ||
19 | then | ||
20 | set -- firestart | ||
21 | fi | ||
22 | |||
23 | # TITLE=$* # lol, startx doesn't support arguments with spaces | ||
24 | TITLE=$1 | ||
25 | TITLE= # blank title documents the screen grab keys in the title | ||
26 | |||
27 | if [ "$1" != firestart ] | ||
28 | then | ||
29 | USE_XINIT=y | ||
30 | fi | ||
31 | |||
32 | if [ "$USE_XINIT" ] | ||
33 | then | ||
34 | set -x | ||
35 | case "$1" in | ||
36 | /*) ;; | ||
37 | *) f1=$(which "$1") || exit | ||
38 | shift | ||
39 | set -- "$f1" "$@" | ||
40 | ;; | ||
41 | esac | ||
42 | xinit "$@" -- $(which Xephyr) "$NEW_DISPLAY" -resizeable -p 0 -terminate ${TITLE:+ -title "$TITLE"} | ||
43 | else | ||
44 | set -x | ||
45 | dpi=$(xrdb -query | sed -n -e 's/^Xft.dpi:[ \t]*//p') | ||
46 | startx -- "$(which Xephyr)" "$NEW_DISPLAY" \ | ||
47 | -resizeable \ | ||
48 | -p 0 \ | ||
49 | -terminate \ | ||
50 | ${TITLE:+ -title "$TITLE"} \ | ||
51 | ${dpi:+ -dpi "$dpi"} \ | ||
52 | & | ||
53 | if [ $# -gt 0 ] | ||
54 | then | ||
55 | DISPLAY=$NEW_DISPLAY "$@" & | ||
56 | fi | ||
57 | wait | ||
58 | fi | ||
diff --git a/src/ioslay@.service b/src/ioslay@.service index 1a00bd4..11db192 100644 --- a/src/ioslay@.service +++ b/src/ioslay@.service | |||
@@ -1,5 +1,6 @@ | |||
1 | [Unit] | 1 | [Unit] |
2 | Description = Kill firefox when it spins the disk | 2 | Description = Kill firefox when it spins the disk |
3 | Requires = firefox@%I | ||
3 | 4 | ||
4 | [Service] | 5 | [Service] |
5 | ExecStart = /usr/local/bin/firefox-io-slayer-redux %I | 6 | ExecStart = /usr/local/bin/firefox-io-slayer %I |