How-to: compiz-emerald water effect as a screen saver on KDE4.

These are two little scripts, assemble unprofessionally by myself, gleaning pieces of code, here and there. I honestly would prefer that those codes were rewritten, but they are working well.
I mostly want to demonstrate that it can be done easily with KDE4. Any improvement would be most welcome. Thank You.

I use OpenSUSE 13.2 AMD 64, KDE v 4.14.8, compiz-emerald.

That said, you will need **xdotool **to make this work, as it is:

zypper install xdotool

First, the start rain script: “rain”:


#!/bin/bash

while  -f ~/bin/.lock ]; do
sleep 0
done 
xdotool set_desktop 0 key shift+F9
touch ~/bin/.lock
sleep infinity
exit

Second, the stop rain script: “stoprain”:

#!/bin/bash

xdotool set_desktop 0 key shift+F9 && killall rain && rm ~/bin/.lock

Those scripts should be in the “/home/USER/bin” directory and must be executable:

cd ~/bin
chmod +x rain stoprain

To activate the “rain” script use KDE4’s Power Management settings:

KDE Menu/ Applications/ Configure Desktop/ Power Management/ Energy Saving:

Check the “Run Script” box, select run script “after” from the drop down and show the path to the start rain file (“rain”):

/home/**USER**/bin/rain

Next, link the “stoprain” script to a keyboard shortcut:

Right-click the KDE menu button, select “Edit applications…”.

The top entry is “Applications” click “New Item” and name it, in “General” tab fill up the “Command” line like so:

sh /home/**USER**/bin/stoprain

In the “Advance” tab select the “Current shortcut key”. Your choice, F4 worked for me.

That’s all for the installation.

Important:

When you re-log in, do not turn off the effect with the normal key binding( <Shift>F9),
use instead the F4 shortcut or the one you picked, otherwise the .lock file( see explanations bellow), still present,
will prevent the “rain” script from working again. If the effect is running when the scrip starts, everything will be reverse.
In that case too use “rm ~/bin/.lock”. Rebooting or logging out, won’t remove the file.

Also, when you test this script, set the “run script after” at a minimum of 2 minutes and
your
“screen locker( saver)” at least 1 minute more( 3 mins)
.
So the rain will start at 2 mins, screen saver at 5 mins.

For normal use, for example:

run script= 10 mins, screen locker( saver)= 11 mins, screen energy saving( Power down)= 20 mins.

This setup will get the rain to start at **10 **mins, screen locker( saver) at **21 **mins, screen energy saving at **30 **mins from the fist last input( keyboard or mice).
Because the real last input is when the script starts automaticaly, it equals two keyboard stokes and the coutdown restart.

Explanations:

In compiz-emerald, there are not two commands, like one to start and one to stop, the default binding “Toggle rain” ( <Shift>F9), both start and stop the effect,
in KDE’s power management, “Run Script after X minutes”, do not run only once, it’s repeated at the set interval, as long as the desktop is inactive.

If it wasn’t for the “rain” script .lock file,
the effect would be turn on and off, each time the “Run Script” delay is reached, plus, the screen would wake up. The “stoprain” script turn the effect off,
kill the proccess, before removing the .lock file for the next automatic utilization
of the “rain” script.

Tested on OpenSuse 13.2.

Enjoy!

Hi, I have updated my script, for full automatic operation. Tested in KDE 4.14.9.

It’s better in many ways:

Start and stop automatically.
Do not write or read from hard drive.
Show warnings with kdialog.
Screensaver fully integrated( unlock or lock, or both with a grace period for passwordless login)
DPMS integrated.
Every settings are easily adjustable.
Scripts are self explanatory.

There are three versions:

Script 1: Water effect + DPMS.
Script 2: Water effect with unlock screensaver + DPMS.
Script 3: Water effect with lock screensaver with or without grace period + DPMS.

*(https://vimeo.com/133905548).

These scripts are set to start after one minute for testing purposes, DPMS after two minutes.

Script 1:

#!/bin/bash
# Script for automatic activation/deactivation of compiz's water effect + DPMS. G.N. July 2015.
while true
do idle_time=$(qdbus org.freedesktop.ScreenSaver /ScreenSaver GetSessionIdleTime)
   if ((idle_time > 60000)); then # Activation delay in milliseconds. Edit to your needs, along line 42.

         kdialog --passivepopup "Water Effect Activation in 5 Secondes" 5; # Warning delay. Edit along line 8 and 18.
             for i in {1..5}; # Edit last number only, along line 7 and 18.
             do idle_time=$(qdbus org.freedesktop.ScreenSaver /ScreenSaver GetSessionIdleTime)
                                if ((idle_time < 1001)); then # Input devices reaction time. Do not change.
                                   break
                                fi
                               sleep 1 # Input devices reaction time and counter unit. Do not change.
                             done

                   idle_time=$(qdbus org.freedesktop.ScreenSaver /ScreenSaver GetSessionIdleTime)

                  if ((idle_time > 5000)); then # In milliseconds. Early warning delay. Edit along line 7 and 8.
                        xdotool key shift+F9;
                        else kdialog --passivepopup "Water Effect Cancellation" 1;
                  fi
                        sleep 1 # Do not change.

                     if ((idle_time > 999)); then # Do not change.
              while true
                        do idle_time=$(qdbus org.freedesktop.ScreenSaver /ScreenSaver GetSessionIdleTime)
# ______________________________________________________________________________________
                              if ((idle_time > 120000 & 121000 < idle_time)); then      # DPMS Section:
                                    xset dpms force off                                 # In milliseconds, edit to your
                              fi                                                        # needs, add 1000 to 2nd number.
# ______________________________________________________________________________________# This section can be comment out.

                           if ((idle_time < 1001)); then # Input devices reaction time. Do not change.
                                 xdotool key shift+F9;
                                 kdialog --passivepopup "Water Effect Deactivation, Please Wait..." 5;
                                 break
                           fi
                          sleep 1 # Input devices reaction time and counter unit. Do not change.
                        done
                     fi
   fi
  sleep 15 # In seconds or followed by m for minutes(e.g. 5m), should be 1/4 of line 5 "Activation delay"
done
  

Script 2:

#!/bin/bash
# Script for automatic activation/deactivation of compiz's water effect with screensaver + DPMS. G.N. July 2015.
while true
do idle_time=$(qdbus org.freedesktop.ScreenSaver /ScreenSaver GetSessionIdleTime)
   if ((idle_time > 60000)); then # Activation delay in milliseconds. Edit to your needs, along line 45.

         kdialog --passivepopup "Screensaver Activation in 5 Secondes" 5; # Warning delay. Edit along line 8 and 18.
             for i in {1..5}; # Edit last number only, along line 7 and 18.
                             do idle_time=$(qdbus org.freedesktop.ScreenSaver /ScreenSaver GetSessionIdleTime)
                                if ((idle_time < 1001)); then # Input devices reaction time. Do not change.
                                   break
                                fi
                               sleep 1 # Input devices reaction time and counter unit. Do not change.
                             done

                  idle_time=$(qdbus org.freedesktop.ScreenSaver /ScreenSaver GetSessionIdleTime)

                  if ((idle_time > 5000)); then # In milliseconds. Early warning delay. Edit along line 7 and 8.
                        xdotool key shift+F9;
                        qdbus org.freedesktop.ScreenSaver /ScreenSaver Lock;
                        else kdialog --passivepopup "Screensaver Cancellation" 1;
                  fi
                        sleep 1 # Do not change.

                     if ((idle_time > 999)); then # Do not change.
              while true
                        do idle_time=$(qdbus org.freedesktop.ScreenSaver /ScreenSaver GetSessionIdleTime)
# ______________________________________________________________________________________
                              if ((idle_time > 120000 & 121000 < idle_time)); then      # DPMS Section:
                                    xset dpms force off                                 # In milliseconds, edit to your
                              fi                                                        # needs, add 1000 to 2nd number.
# ______________________________________________________________________________________# This section can be comment out.

                           if ((idle_time < 1001)); then # Input devices reaction time. Do not change.
                                 qdbus org.kde.plasma-overlay /MainApplication quit;
                                 sleep .2
                                 xdotool key shift+F9;
                                 kdialog --passivepopup "Water Effect Deactivation, Please Wait..." 5;
                                 break
                           fi
                          sleep .8 # Input devices reaction time and counter unit. Do not change.
                        done
                     fi
   fi
  sleep 15 # In seconds or followed by m for minutes(e.g. 5m), should be 1/4 of line 5 "Activation delay".
done
  

Script 3:

#!/bin/bash
# Script for automatic activation/deactivation of compiz's water effect with screensaver and Locker + DPMS. G.N. July 2015.
while true
do idle_time=$(qdbus org.freedesktop.ScreenSaver /ScreenSaver GetSessionIdleTime)
   if ((idle_time > 60000)); then # Activation delay in milliseconds. Edit to your needs, along line 57.
   
         kdialog --passivepopup "Screen-Locker Activation in 5 Secondes" 5; # Early warning delay. Edit along line 8 and 18.
             for i in {1..5}; # Edit last number only, along line 7 and 18.
                             do idle_time=$(qdbus org.freedesktop.ScreenSaver /ScreenSaver GetSessionIdleTime)
                                if ((idle_time < 1001)); then # Input devices reaction time. Do not change.
                                   break
                                fi
                                   sleep 1 # Input devices reaction time and counter unit. Do not change.
                             done

                  idle_time=$(qdbus org.freedesktop.ScreenSaver /ScreenSaver GetSessionIdleTime)

                  if ((idle_time > 5000)); then # In milliseconds. Early warning delay. Edit along line 7 and 8.
                        xdotool key shift+F9;
                        qdbus org.freedesktop.ScreenSaver /ScreenSaver Lock;
                        else kdialog --passivepopup "Screen-Locker Cancellation" 1;
                  fi
                        sleep 1 # Do not change.

                     if ((idle_time > 999)); then # Do not change.
# __________________________________________________________________________________________________
        for i in {1..10}; # Edit last number only.                                                  # Screensaver Section:
                 do idle_time=$(qdbus org.freedesktop.ScreenSaver /ScreenSaver GetSessionIdleTime)  # Passwordless grace
                     if ((idle_time < 1001)); then # Do not change.                                 # period in secounds,
                           qdbus org.kde.plasma-overlay /MainApplication quit;                      # now set at 10. Edit
                           sleep .2 # Do not change.                                                # to your needs.
                           break                                                                    #
                     fi                                                                             # This section can be
                           sleep .8 # Do not change.                                                # comment out.
                 done                                                                               # 
# __________________________________________________________________________________________________#

              while true
                        do idle_time=$(qdbus org.freedesktop.ScreenSaver /ScreenSaver GetSessionIdleTime)
# ______________________________________________________________________________________
                              if ((idle_time > 120000 & 121000 < idle_time)); then      # DPMS Section:
                                    xset dpms force off                                 # In milliseconds, edit to your
                              fi                                                        # needs, add 1000 to 2nd number.
# ______________________________________________________________________________________# This section can be comment out.

                            if ((idle_time < 1001)); then # Input devices reaction time. Do not change.
                                 if  "`qdbus org.freedesktop.ScreenSaver /ScreenSaver GetActive`" = "false" ]; then
                                    xdotool key shift+F9;
                                    kdialog --passivepopup "Water Effect Deactivation, Please Wait..." 5;
                                    break
                                 fi
                            fi
                           sleep 1 # Input devices reaction time and counter unit. Do not change.
                        done 
                     fi
   fi
  sleep 15 # In seconds or followed by m for minutes(e.g. 5m), should be 1/4 of line 5 "Activation delay".
done
  

Correction:

line 41 of script 2 and line 34 of script 3, “sleep .8” should be instead “sleep 1”.

Sorry

Hi, if you want to use the last two scripts with openSuse 42.1 and Plasma 5, you will need to replace:

qdbus org.kde.plasma-overlay /MainApplication quit;

By:

sudo  loginctl unlock-sessions;

In order to sudo without a password for loginctl exclusively, add this to your /etc/sudoers file:

YourUserName YourDomainName = (root) NOPASSWD: /usr/bin/loginctl

You may also want to add this to the first script if you use the included DPMS mode.:

sleep .1

At line 34, between “if ((idle_time < 1001)); then” and “xdotool key shift+F9;”, like so:

if ((idle_time < 1001)); then  # Input devices reaction time. Do not change.
      sleep .1
      xdotool key shift+F9;

Regards

Cool efect, cool video too. Congratulations!

Hi, this is my latest script.

Features:
#########
Fast, precise, reliable and efficient
The wiper is optional
Remote locking and unlocking of the session via ssh is built-in
Configuration script included

Required:
#########
xdotool
xinput
libnotify-tools
procps
/dev/shm/ must exist
top command should be stock(But the script can be adjusted)

Optional:
#########
Can “sudo loginctl unlock-sessions”, without supplying a password.
If not, turn Login screen off as a whole or enter 0 at the password-less duration question.

This script is simple, but is divided into multiple files.
It won’t do modifications to your system, other than create a folder in /dev/shm/ called RAIN_SCRIPT-SHM
and temporally change DPMS(Configure Desktop/Power Management/Energy Saving) setting, if you stop the script, reapply it manually(turn off/apply and on/apply) or logout and login.

*** You will need to make few small adjustements before starting it(See README). ***

Xinput is used to detect user inputs, it also temporally disable the keyboard and mouse to prevent user from interfering with xdotool.
Time keeping is done with inotifywait, not with qdbus as in previous versions.
Dbus-monitor listen passively for dbus screensaver “ActiveChanged” signal.
All moving parts, if I may say so, are written to RAM.

This script was done using openSuse 42.1 and Plasma 5, it may work on other environments with minor modifications.

Install:
########
Copy the “water-effect” folder in your home directory, copy “myrain” and “session” in your home bin folder.

Starting:
#########

Select your background and turn off Kde’s Screen-Locker.
If you type “myrain” in a terminal, you will see:

Usage: myrain [start|stop|restart|info|config]

Type:

myrain config

Always use myrain to start, stop or restart the script.

If you have troubles at first, always restart the script(myrain restart) and make sure the wiper is not running in the background(Wiper is Ctrl+F8, rain is Ctrl+F9).

Here is the link:

http://s000.tinyupload.com/?file_id=73529536755176271696

Click on: rain_script.tar.gz

Your comments or questions are most welcome.