QLOOKアクセス解析

スポンサーサイト

上記の広告は1ヶ月以上更新のないブログに表示されています。
新しい記事を書く事で広告が消せます。

スポンサー広告  |  ↑Top

2012/12/05 (Wed) 09:30

Linux Mint 13 Lock Screen on Suspend Hibernate

Locking screen (requiring password) when suspend and/or hibernate on Linux Mint 13 should work by setting mateconf-editor, but it doesn't work properly. So I have created a script.

To start mateconf-editor, select "Menu" -> "All" -> "Configuration Editor" or type "mateconf-editor" from terminal.

Then select /apps/mate-power-manager/lock/suspend and check or uncheck suspend and hibernate as you like.

ConfigurationEditor-lock-1.png

But it doesn't work properly. To solve this problem, create a script as as bellow.

Details.

1. Startup editor.

sudo pluma /usr/lib/pm-utils/sleep.d/00lock-screen


2. Copy and paste the following script.

#!/bin/sh

# getXuser gets the X user belonging to the display in $displaynum.
# If you want the foreground X user, use getXconsole!
getXuser() {
        user=`pinky -fw | awk '{ if ($2 == ":'$displaynum'" || $(NF) == ":'$displaynum'" ) { print $1; exit; } }'`
        if [ x"$user" = x"" ]; then
                startx=`pgrep -n startx`
                if [ x"$startx" != x"" ]; then
                        user=`ps -o user --no-headers $startx`
                fi
        fi
        if [ x"$user" != x"" ]; then
                userhome=`getent passwd $user | cut -d: -f6`
                export XAUTHORITY=$userhome/.Xauthority
        else
                export XAUTHORITY=""
        fi
        export XUSER=$user
}

if pidof mate-screensaver > /dev/null; then
    for x in /tmp/.X11-unix/*; do
        displaynum=`echo $x | sed s#/tmp/.X11-unix/X##`
        getXuser;
        if [ x"$XAUTHORITY" != x"" ]; then
            SESSION_PID=`pgrep -U $XUSER -fx "mate-session|x-session-manager"`
            DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS= /proc/$SESSION_PID/environ | sed -e 's/DBUS_SESSION_BUS_ADDRESS=//')

            screensaver_lock=`sudo -u $XUSER DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS \
                            mateconftool-2 --get /apps/mate-screensaver/lock_enabled`
            use_screensaver_settings=`sudo -u $XUSER DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS \
                            mateconftool-2 --get /apps/mate-power-manager/lock/use_screensaver_settings`
            lock_suspend=`sudo -u $XUSER DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS \
                            mateconftool-2 --get /apps/mate-power-manager/lock/suspend`
            lock_hibernate=`sudo -u $XUSER DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS \
                            mateconftool-2 --get /apps/mate-power-manager/lock/hibernate`

            if [ "`sudo -u $XUSER DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS LANG=C mate-screensaver-command --time`" = \
                 "The screensaver is not currently active." ]; then
                is_screensaver_active="false"
            else
                is_screensaver_active="true"
            fi
            echo $is_screensaver_active

            case "$1" in
                suspend)
                    if [ $is_screensaver_active = "false" ]; then
                        if [ $use_screensaver_settings = "true" ] && [ $screensaver_lock = "true" ] ||
                           [ $use_screensaver_settings = "false" ] && [ $lock_suspend = "true" ]; then
                            sudo -u $XUSER DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS mate-screensaver-command --activate --lock
                        else
                            sudo -u $XUSER DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS mate-screensaver-command --activate
                        fi
                    else
                        if [ $use_screensaver_settings = "false" ] && [ $lock_suspend = "true" ]; then
                            sudo -u $XUSER DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS mate-screensaver-command --deactivate
                            sudo -u $XUSER DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS mate-screensaver-command --activate --lock
                        fi
                    fi
                ;;
                hibernate)
                    if [ $is_screensaver_active = "false" ]; then
                        if [ $use_screensaver_settings = "true" ] && [ $screensaver_lock = "true" ] ||
                           [ $use_screensaver_settings = "false" ] && [ $lock_hibernate = "true" ]; then
                            sudo -u $XUSER DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS mate-screensaver-command --activate --lock
                        else
                            sudo -u $XUSER DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS mate-screensaver-command --activate
                        fi
                    else
                        if [ $use_screensaver_settings = "false" ] && [ $lock_hibernate = "true" ]; then
                            sudo -u $XUSER DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS mate-screensaver-command --deactivate
                            sudo -u $XUSER DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS mate-screensaver-command --activate --lock
                        fi
                    fi
                ;;
                resume|thaw)
                    # nothing
                ;;
            esac
        fi
    done
fi


3. Change permission.

sudo chmod +x /usr/lib/pm-utils/sleep.d/00lock-screen



Then lock screen should work properly.
This program is FREE, but ABSOLUTELY NO WARRANTY.

コラム  |  トラックバック(0)  |  コメント(0)  |  ↑Top

Comment

コメントを投稿する


 管理者だけに表示  (非公開コメント投稿可能)

▲TOP

Trackback

この記事のトラックバックURL

→http://cyberbaba.blog57.fc2.com/tb.php/258-98837efb

この記事にトラックバックする(FC2ブログユーザー)

この記事へのトラックバック

▲TOP

 | HOME | 
上記広告は1ヶ月以上更新のないブログに表示されています。新しい記事を書くことで広告を消せます。