The problem though, as you may or may not know, is that the svg parser we use in Linux, which is librsvg, does not support animation. And that's a pity, because imagine the possibilities.
I suppose for some, stuff like animated icons, wallpapers and such need to be chucked on the big horror hill of bloat, but you know, others like some playful graphical elements in their gui.
However, the Firefox browser uses an svg parser which DOES support animated svg, so I figured that perhaps it would be a nice idea to set up the Firefox browser as a screensaver. And this became my project.
Now, understand, I know nothing about scripting, so what I did mostly is look on the Internet for people who do know, and were willing to demonstrate and make available the things I was looking for.
So what did I want?
1. A script that would open my Firefox browser, put it in full screen, and then load what I wanted to load.
2. A script in my Startup folder that would track the computers idle time (time passed without any activity), and then after a given amount of time give the command to run the script that opens Firefox and loads what I want.
3. An svg animation that runs in Firefox indefinitely.
Because this is more a proof of concept than anything else, I kind of did it quick and dirty. Those of you that are more actively involved in system modification and maintenance would undoubtably have done it more cleanly, but I just wanted to make it work.
So, first things first. A script to open the browser and load something specific.
I created a file in the root called simplescreensaver, and it only contained one line:
Code: Select all
#!/bin/sh
firefox "my-documents/screensaver01.html"
What I want though, is not only that it loads the page, but I also want Firefox to go into fullscreen mode.
You might be able to achieve that by changing the configuration of Firefox so that it would always open in fullscreen mode, but of course I don't want that. I only want it to do that when it kicks in as a screensaver.
To normally get Firefox to go to real fullscreen, you need to have your mouse in the browser window and press F11 on your keyboard. So what I need is something that tells my system this is happening, and what I discovered is that something like that exists, and that it is called xdotool. Xdotool tells your system that certain keys are pressed or your mouse behaves a certain way. Very handy.
So I found a Ubuntu repository which had a version for me (Puppy Precise), installed it, and after some experimenting, my script looked like this:
Code: Select all
#!/bin/sh
firefox -fullscreen & sleep 4
xdotool mousemove 720 450
xdotool click 1
xdotool key F11
firefox "my-documents/screensaver01.html"
Now all we have to do is make a script that will activate itself at startup, monitor the time passed without any activity, and execute our simplescreensaver script after a given time period.
If you want a script to automatically be excuted at startup, you can place it in a folder in root, which is conveniently named Startup.
So I created a script called screensavestart and placed it in the Startup folder. The script had to have some way of monitoring time passed without activity, and for this purpose, I discovered, another utility exists, which is called xprintidle. So I looked for the correct package online and installed it.
Since I had no idea how to cook up a script that would do what I wanted, I just looked on the Internet until I found something that I could use.
This is the little script that does the trick:
Code: Select all
#!/bin/bash
#Check if X is idle. Timer set to 5 minutes.
export DISPLAY=:0
idletime=0
while [ $idletime -le 300000 ]
do
echo "Idle Time is: $idletime milliseconds"
sleep 1
idletime=$(xprintidle)
done
/root/simplescreensaver
You might think this would be enough, but then you would be forgetting something very important. The thing is, you see, that the screensavestart script will keep on running and tracking idle time even while the screensaver is active. And so it will also ask the simplescreensaver script to execute again after a certain amount of time, and then, of course, another instance of Firefox running your screensaver would start, and this would repeat itself over and over until your system completely freezes.
And we do not want that.
So what we need is something that tells your simplescreensaver script that Firefox is already running. We do that with the grep command. That also means we have to make a conditional statement in our simplescreensaver script.
So, going back to the simplescreensaver script in root, these are the changes made:
Code: Select all
#!/bin/sh
SERVICE='firefox'
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
echo "eq 0 - firefox running - do nothing"
else
firefox -fullscreen & sleep 4
xdotool mousemove 720 450
xdotool click 1
xdotool key F11
firefox "my-documents/screensaver01.html"
fi
Now, of course, you could have Firefox running on your computer and you could be walking your dog or unplugging the sink or conducting an opera hoping that a screensaver would activate itself in your absence. In that case you would be unlucky.
Okay, now we want something to appear in Firefox that does something screensaver-like.
First, we make the html page in the my-documents folder, called screensaver01.html.
Here's the html code for that:
Code: Select all
<HTML>
<HEAD>
<TITLE>SVG screensaver</TITLE>
<style type="text/css">
#centered_div {width: 350px; height: 350px; position: absolute; top: 50%; left: 50%; margin-top: -175px; margin-left: -175px;}</style>
</HEAD>
<BODY BGCOLOR="#000">
<!-- HTML Code -->
<div id="centered_div">
<img src="animation.svg" />
</div>
</BODY>
</HTML>
My animation, aptly named animation.svg, is in the same my-documents folder, and this is the code:
Code: Select all
<svg xmlns="http://www.w3.org/2000/svg" width="350" height="350">
<path d="M0 0h350v350H0z"/>
<path d="M161 0l-33-57-74-4L0 0l7 81 62 41 62-27 6-66-58-46L0 0l-41 70 25 70 66 14 43-50-20-71L0 0l-75 33-20 71 44 50 65-14 26-70L0 0l-80-17-58 46 6 66 61 27 62-41L0 0l-55-61-74 4-34 57 34 57 74 3L0 0l-9-81-62-41-61 26-6 67 58 46L0 0l40-70-26-70-65-15-44 50 20 72L0 0l73-33 20-72-43-50-66 15-25 70L0 0l79 17 58-46-6-67-62-26L7-81 0 0l54 60 74-3z" fill="#ddf" fill-rule="evenodd" stroke="#444" stroke-width="5" transform="translate(175 175)">
<animateTransform attributeName="transform" attributeType="XML" begin="0s" dur="10s" type="rotate" from="0 0 0" to="36 0 0" repeatCount="indefinite" additive="sum"/>
<animateTransform attributeName="transform" attributeType="XML" type="scale" from="1" to=".05" begin="0s" dur="120s" repeatCount="indefinite" additive="sum"/>
<animate attributeName="stroke" begin="0s" dur="30s" repeatCount="indefinite" values="#fff;#000;#fff"/>
<animate attributeName="fill" begin="0s" dur="30s" repeatCount="indefinite" values="#000;#fff;#000"/>
</path>
</svg>
Besides, it's not really important, because you could, if you prefer, make something else in your screensaver01.html page, like a css/jquery slidehow. The point is that you can now use your browser as a rudimentary screensaver.
If I really knew what I was doing, I'd make it so Firefox would unload at any renewed activity, but like I said, this is more like a proof of concept for me, plus, I'm a total dork when it comes to scripting.