summaryrefslogtreecommitdiffstats
path: root/mga-bg-res/mga-bg-res.sh
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2015-05-02 09:53:00 +0200
committerRémi Verschelde <rverschelde@gmail.com>2015-05-02 09:53:00 +0200
commit5682ab44e3ecca0a18404885bcfbf97b8762a89b (patch)
tree10ca46f93134fb36640b49353e9c578ef24ba8a5 /mga-bg-res/mga-bg-res.sh
parent3e6f62173f00b6f60050c07485948bfbbb4b59ba (diff)
downloadtheme-5682ab44e3ecca0a18404885bcfbf97b8762a89b.tar
theme-5682ab44e3ecca0a18404885bcfbf97b8762a89b.tar.gz
theme-5682ab44e3ecca0a18404885bcfbf97b8762a89b.tar.bz2
theme-5682ab44e3ecca0a18404885bcfbf97b8762a89b.tar.xz
theme-5682ab44e3ecca0a18404885bcfbf97b8762a89b.zip
Make mga-bg-res a systemd service that uses monitor-probe
Now runs as a systemd service with root privileges, therefore the mga-bg-res C binary is no longer needed. Uses monitor-probe to find the optimal resolution when X is not yet started, and handles cases where monitor-probe fails by defaulting to 4:3 aspect ratio.
Diffstat (limited to 'mga-bg-res/mga-bg-res.sh')
-rwxr-xr-xmga-bg-res/mga-bg-res.sh47
1 files changed, 47 insertions, 0 deletions
diff --git a/mga-bg-res/mga-bg-res.sh b/mga-bg-res/mga-bg-res.sh
new file mode 100755
index 0000000..db937cb
--- /dev/null
+++ b/mga-bg-res/mga-bg-res.sh
@@ -0,0 +1,47 @@
+#!/bin/bash
+
+bgpath="/usr/share/mga/backgrounds"
+theme="Mageia-Default"
+curlink=$(readlink $bgpath/default.jpg)
+
+# If the following tests bail out, default to 4:3 aspect ratio (e.g. 1024x768)
+res="1600x1200"
+
+# Search for the optimal background resolution according to the driver
+DRIVER=$(grep -A 6 'Device' /etc/X11/xorg.conf | grep 'Driver') # => Driver "DriverName"
+DRIVER=$(expr "$DRIVER" : '.*"\(.*\)"') # isolate driver's name
+if [ ! -z "$DRIVER" -a -e /usr/sbin/monitor-probe ]; then
+ res=$(exec /usr/sbin/monitor-probe $DRIVER | grep -m 1 ModeLine) # => ModeLine "1920x1080" ...
+ res=$(expr "$res" : '.*"\(.*\)".*') # isolate the resolution
+fi
+
+# Check if the symlink is already good
+if [ "$curlink" = "$bgpath/$theme-$res.jpg" ]; then
+ exit 1
+fi
+
+# Check if this is a supported resolution, if not, find the background with a similar aspect ratio
+if [ ! -e "$bgpath/$theme-$res.jpg" ]; then
+ width=$(echo $res | cut -f1 -d"x")
+ height=$(echo $res | cut -f2 -d"x")
+ # Bash only does integer arithmetic, we multiply everything by 1000 to workaround this
+ ratio=$((1000*$width/$height))
+ declare -A refRatios=( ["1250"]="1280x1024" ["1333"]="1600x1200" ["1600"]="1920x1200"
+ ["1667"]="1280x768" ["1707"]="1024x600" ["1778"]="1920x1080" )
+ for key in "${!refRatios[@]}"; do
+ if [ $(($ratio % $key)) -lt 25 -o $(($key % $ratio)) -lt 25 ]; then
+ res=${refRatios[$key]}
+ break
+ fi
+ done
+fi
+
+# Check again if the symlink does not already point to this new resolution
+# If not, create a new symlink
+if [ "$curlink" != "$bgpath/$theme-$res.jpg" ]; then
+ if [ -e "$bgpath/$theme-$res.jpg" ]; then
+ ln -sf $bgpath/$theme-$res.jpg $bgpath/default.jpg
+ else
+ echo -e "Could not find this file: $bgpath/$theme-$res.jpg.\nPlease check that the mageia-theme-Default package is properly installed, or disable the mga-bg-res systemd service if you do not want to force using the Mageia theme."
+ fi
+fi