Skip to content

Commit

Permalink
Automate reloading display configuration (#122)
Browse files Browse the repository at this point in the history
This allows Frame to handle display reconfiguration without a restart.

Features:

1. If there is no `display` option set, then when Frame runs it is set to a default
2. When the `display` option is set:
2.1. With Miral < 3.8 Frame is restarted and will load the new display configuration
2.2. With Miral 3.8 Frame is not restarted and will attempt to reload
3. When the display option is unset, the configuration is cleared and Frame restarted

Note: there is (still) no validation of the configuration being set

Fixes: #20
  • Loading branch information
AlanGriffiths committed Jan 27, 2023
1 parent ae5a6a9 commit f0e4565
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
28 changes: 28 additions & 0 deletions scripts/bin/initialise-display-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/sh
set -eu

wait_for()
{
until
until
inotifywait --event create "$(dirname "$1")"&
inotify_pid=$!
[ -e "$1" ] || sleep 2 && [ -e "$1" ]
do
wait "${inotify_pid}"
done
kill "${inotify_pid}"
[ -O "$1" ]
do
sleep 1
done
}

display_file="$SNAP_DATA/frame.display"

wait_for "${display_file}"

if [ -z "$(snapctl get display)" ] && ! grep "DO NOT EDIT THIS FILE BY HAND" "${display_file}"
then
snapctl set display="$(cat "${display_file}")"
fi
6 changes: 6 additions & 0 deletions scripts/bin/run-daemon
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#!/bin/sh
set -eux

display_file="$SNAP_DATA/frame.display"
if [ -z "$(snapctl get display)" ]
then
initialise-display-config&
fi

exec nohup "$@"
7 changes: 4 additions & 3 deletions snap/hooks/configure
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ EOT
mv "${display_file}" "${display_file}.save" || true
mv "${display_temp}" "${display_file}"
chmod a+r "${display_file}"
let config_changes+=1
! [ -e "${SNAP}/miral-lt-3.8" ] || ((config_changes+=1))
else
rm "${display_temp}"
fi
else
elif grep "DO NOT EDIT THIS FILE BY HAND" "${display_file}" &> /dev/null; then
mv "${display_file}" "${display_file}.save" || true
((config_changes+=1))
fi

# config_file
Expand Down Expand Up @@ -86,7 +87,7 @@ if ! diff "${config_temp}" "${config_file}" > /dev/null; then
mv "${config_file}" "${config_file}.save" || true
mv "${config_temp}" "${config_file}"
chmod a+r "${config_file}"
let config_changes+=1
((config_changes+=1))
else
rm "${config_temp}"
fi
Expand Down
11 changes: 11 additions & 0 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ parts:
scripts:
plugin: dump
source: scripts
stage-packages:
- inotify-tools

anon-shm-preload:
source: https://github.com/MirServer/anon-shm-preload.git
Expand All @@ -168,3 +170,12 @@ parts:
find . -type f,l -exec rm -f $SNAPCRAFT_PRIME/usr/lib/${SNAPCRAFT_ARCH_TRIPLET}/{} \;
rm -fr "$SNAPCRAFT_PRIME/usr/lib/${SNAPCRAFT_ARCH_TRIPLET}/dri"
rm -fr "$SNAPCRAFT_PRIME/usr/share/"{bug,doc,doc-base,drirc.d,glvnd,libdrm,lintian,man}
# Back compatibility fix until MirAL 3.8 is released
miral_version=`LANG=C apt-cache policy libmiral-dev | sed -rne 's/^\s+Candidate:\s+([0-9]*\.[0-9])\..+$/\1/p'`
if [ ${miral_version%.*} -eq 3 ] && [ ${miral_version#*.} -lt 8 ]
then
touch $SNAPCRAFT_PRIME/miral-lt-3.8
else
rm -f $SNAPCRAFT_PRIME/miral-lt-3.8
fi

0 comments on commit f0e4565

Please sign in to comment.