iye/lightsOn

gnome-screensaver?

goodevilgenius opened this issue · 17 comments

dbus-send --session --dest=org.gnome.ScreenSaver --type=method_call /org/gnome/ScreenSaver org.gnome.ScreenSaver.SimulateUserActivity does for gnome-screensaver what qdbus org.freedesktop.ScreenSaver /ScreenSaver SimulateUserActivity does for kscreensaver.

Should be pretty easy to add gnome-screensaver support with that.

iye commented

I tried something similar when i first wrote lightsOn and it didnt work. I dont remember the details, I should try again. What distribution are you using?

Sent from my Android phone with K-9 Mail. Please excuse my brevity.

Dan Jones notifications@github.com wrote:

dbus-send --session --dest=org.gnome.ScreenSaver --type=method_call /org/gnome/ScreenSaver org.gnome.ScreenSaver.SimulateUserActivity does for gnome-screensaver what qdbus org.freedesktop.ScreenSaver /ScreenSaver SimulateUserActivity does for kscreensaver.

Should be pretty easy to add gnome-screensaver support with that.


Reply to this email directly or view it on GitHub.

I'm using Ubuntu 12.04.

But I'm not actually using gnome-screensaver myself anymore. I switched to xscreensaver recently, but when I was using gnome-screensaver, that was the command I used to suspend it. Specifically, I did

while true
do
    dbus-send --session --dest=org.gnome.ScreenSaver --type=method_call /org/gnome/ScreenSaver org.gnome.ScreenSaver.SimulateUserActivity
    sleep 30
done

The GNOME 3 DBUS API for this has changed. Everything now seems to be in org.gnome.SessionManager, on the methods Inhibit() and UnInhibit(). Sadly, it doesn't seem that dbus-send will work for this. [Source]

In my fork of this repository I'm committing an addition for this. A python script invoked from lightsOn works for me. @iye Please let me know if you'd be interested in merging this feature.

iye commented

I don't like the idea of adding a python script. Frankly I like LightsOn as it is, a simple Bash script that does not require you to install any extra package. I get the feeling that this python script will work for some and not for others.
I will watch your fork anyway, if it looks nice I may change my mind.
The blog you mentions is pretty old, have you tried dbus method now?

Yep, I had the same problem and the DBUS method on my Cinnamon (GNOME 3-based) machine works that way. The machine respects the gnome-control-center's "Brightness and Lock" setting to turn the screen off when idle. Since it has a max of one hour, it'll still activate and shut off the screen even if lightsOn is delaying xscreensaver's DPMS activation.

The only known fix is to use a non-bash script to control the DBUS, or to remove /usr/bin/gnome-screensaver-command, but then you lose the ability to lock the screen from the Menu, or by Ctrl+Alt+L. I've removed gnome-screensaver, and right now my gnome-screensaver-command is a symlink to /usr/bin/xscreesaver-command to keep that lock feature. This seems to also be required for locking on wake-from-suspend.

Edit: Here's a roundup of how one can replace gnome-screensaver with xscreensaver. It's what I followed, and describes the Ctrl+Alt+L and lock screen behavior.

This version: https://github.com/hotice/lightsOn
works perfectly here (Ubuntu 12.04, gnome-classic).

@ribeirobreno Features are nice on that fork.. I was wanting a way for HTML5 fullscreen to work. Unfortunately, GNOME3 doesn't have org.gnome.ScreenSaver.SimulateUserActivity on the DBUS, so it seems it'll only work on GNOME2.

@appleYaks This is the output from my console:

ribeirobreno@ubuntu:~$ gnome-session --version
gnome-session 3.2.1

Interesting... could you try checking something? If you install D-Feet (sudo apt-get install d-feet) and open the program, then use the Session Bus tab to navigate on the left panel to org.gnome.ScreenSaver, then on the right panel open up the /org/gnome/ScreenSaver object path and the org.gnome.ScreenSaver interface, would you tell me whether you have SimulateUserActivity() as a method on that interface? I only have Lock() ... I know this sounds complicated but when you see the program you'll know what I mean. :)

Maybe it was removed in a newer 3.x version?
It can also be because i'm using the "classic" gnome... maybe it was enabled to ensure compatibility.

Just trying to start a new session with the "new" gnome, doesn't change the screenshot.

ss-20130410124244

iye commented

Just want to mention that I'm following your comments. I'm busy with my job and I don't have much free time but I will have some updates during the weekend.

@ribeirobreno That seems to be the case. Thanks for posting the screenshot. 👍

Here's mine:
Screenshot from 2013-04-11 13:51:35

On my machine the screensaver stuff seems to be in org.gnome.SessionManager. I'm using the Inhibit() method in a python script to keep gnome from starting its own screen dimming:
Screenshot from 2013-04-11 13:52:44

@iye Good to hear. Thanks for maintaining this script

@appleYaks You're welcome! :)
@iye I make @appleYaks words mine: Good to hear. Thanks for maintaining this script :)

This version works on Ubuntu 13.04 with Google Chrome (Pepper Flash Player):

#!/bin/bash
# lightsOn.sh
# Copyright (c) 2013 iye.cba at gmail com
# url: https://github.com/iye/lightsOn
# modified by Vincent
# This script is licensed under GNU GPL version 2.0 or above

flash_detection=0
mplayer_detection=0
vlc_detection=0
minitube_detection=0
gnome_mplayer_detection=0
smplayer_detection=0
totem_detection=0
chrome_detection=1
delay_progs=()

displays=""
while read id
do
    displays="$displays $id"
done < <(xvinfo | sed -n 's/^screen #\([0-9]\+\)$/\1/p')

# I think "pidof name" is better than "pgrep -lfc name |grep -wc name". It only output the PIDs when detects the process,
# but output nothing when no process.Most importantly, it is shorter.
if [ `pidof gnome-screensaver` ]; then        # Most desktop enviromments use gnome-screensaver.
    screensaver=gnome-screensaver
else
    screensaver=None
    echo "gnome-screensaver not detected"
fi

checkDelayProgs()
{
    for prog in "${delay_progs[@]}"; do
        if [ `pidof "$prog"` ]; then
            echo "Delaying the screensaver because a program on the delay list, \"$prog\", is running..."
            delayScreensaver
            break
        fi
    done
}

checkFullscreen()
{
    for display in $displays
    do
        activ_win_id=`DISPLAY=:0.${display} xprop -root _NET_ACTIVE_WINDOW`
        activ_win_id=${activ_win_id:40:9}
        if [ "$activ_win_id" = "0x0" ]; then   # Skip invalid window ids (It returns "0x0" when ScreenSaver is actived)
         continue
        fi
        isActivWinFullscreen=`DISPLAY=:0.${display} xprop -id $activ_win_id | grep _NET_WM_STATE_FULLSCREEN`
            if [ "$isActivWinFullscreen" ];then
                isAppRunning
                var=$?
                if [[ $var -eq 1 ]];then
                    delayScreensaver
                fi
            fi
    done
}

isAppRunning()
{
    #Get PID of active window, I think it makes the code easier. 
    activ_win_pid=`xprop -id $activ_win_id | grep "_NET_WM_PID(CARDINAL)"`
    activ_win_pid=${activ_win_pid##* }
    if [ $flash_detection == 1 ]; then
        if [[ `lsof -p $activ_win_pid | grep flashplayer.so` ]]; then    #  match all browers (which use libflashplayer.so , libpepflashplayer.so & operapluginwrapper-native)  #pgrep -lf "chrome --type=ppapi" for Chrome PAPI flash (implement later)
            return 1
        fi
    fi
    if [ $mplayer_detection == 1 ];then
        if [[ `ps p $activ_win_pid o comm=` = "mplayer" ]];then    # Which is more simple and accurate.
            return 1
        fi
    fi
    if [ $vlc_detection == 1 ];then
        if [[ `ps p $activ_win_pid o comm=` = "vlc" ]];then
            return 1
        fi
    fi
    if [ $minitube_detection == 1 ];then
        if [[ `ps p $activ_win_pid o comm=` = "minitube" ]];then
            return 1
        fi
    fi    
    if [ $gnome_mplayer_detection == 1 ];then                  # It is easy to add video player detection.
        if [[ `ps p $activ_win_pid o comm=` = "gnome-mplayer" ]];then
            return 1
        fi
    fi
    if [ $smplayer_detection == 1 ];then
        if [[ `ps p $activ_win_pid o comm=` = "smplayer" ]];then
            return 1
        fi
    fi
    if [ $totem_detection == 1 ];then
        if [[ `ps p $activ_win_pid o comm=` = "totem" ]];then
            return 1
        fi
    fi
    if [ $chrome_detection == 1 ];then
        if [[ `ps p $activ_win_pid o comm=` = "chrome" ]];then # check for google chrome
            return 1
        fi
    fi
    return 0
}

delayScreensaver()
{
    if [ "$screensaver" == "gnome-screensaver" ]; then
        dbus-send --session --dest=org.gnome.ScreenSaver --type=method_call /org/gnome/ScreenSaver org.gnome.ScreenSaver.SimulateUserActivity #check before, using d-feet (function still available on ubuntu 13.04)
    fi
}

delay=$1
if [ -z "$1" ];then
    delay=50
fi
if [[ $1 = *[^0-9]* ]]; then
    echo "The Argument \"$1\" is not valid, not an integer"
    echo "Please use the time in seconds you want the checks to repeat."
    echo "You want it to be ~10 seconds less than the time it takes your screensaver or DPMS to activate"
    exit 1
fi

while true
do
    checkDelayProgs
    checkFullscreen
    sleep $delay
done

exit 0

@vincent-t can you make the script compatible with xscreensaver? i am new and i couldn't figure it out myself. especially this part... "--dest=org.gnome.ScreenSaver"
i am running LXDE, thank you.

@vincent-t Okay, great. thank you very much.