LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices



Reply
 
Search this Thread
Old 11-20-2007, 11:32 AM   #1
BCarey
Senior Member
 
Registered: Oct 2005
Location: New Mexico
Distribution: Slackware
Posts: 1,490

Rep: Reputation: Disabled
lock screen before suspend with power button


I am using Slackware 12.0 with KDE on a HP zv5000 laptop and a 2.6.22 kernel. I use kpowersave for suspending and hibernating. Everything works fine, and I have it configured to lock the screen before either action. I would like to be able to suspend (to RAM) when I press the power button, so I edited "/etc/acpi/acpi_handler.sh" to suspend instead of shutdown the system. This also works fine, but I do not know how to get it to lock the screen first. I have tried adding "/usr/bin/kdesktop_lock --forcelock" to acpi_handler.sh before I call suspend, but it doesn't work (the command does work on its own, it just doesn't seem to have any effect in the script.

Does anyone know how I can do this?

Thanks,
Brian
 
Old 11-27-2007, 09:04 AM   #2
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 66
Moved to Slackware at posters request.
 
Old 11-27-2007, 09:28 AM   #3
zhoun
Member
 
Registered: Oct 2007
Location: anywhere
Distribution: slackware64 current & win7 64 on thinkpad X61
Posts: 104

Rep: Reputation: 18
Code:
USER="guo"
LOCKAPP="/usr/bin/kdesktop_lock --forcelock"
su ${USER} -c "${LOCKAPP}"
change the USER to your login name and try it.
 
Old 11-27-2007, 10:59 AM   #4
BCarey
Senior Member
 
Registered: Oct 2005
Location: New Mexico
Distribution: Slackware
Posts: 1,490

Original Poster
Rep: Reputation: Disabled
zhoun,

Thanks for the suggestion. Unfortunately it does not help and the behavior is the same.

Brian
 
Old 11-27-2007, 03:51 PM   #5
Alien_Hominid
Senior Member
 
Registered: Oct 2005
Location: Lithuania
Distribution: Hybrid
Posts: 2,247

Rep: Reputation: 53
Just a wild guess: maybe that kdesktop_lock isn't quick enough to lock the screen before actual suspend to RAM happens.
 
Old 11-27-2007, 05:17 PM   #6
BCarey
Senior Member
 
Registered: Oct 2005
Location: New Mexico
Distribution: Slackware
Posts: 1,490

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Alien_Hominid View Post
Just a wild guess: maybe that kdesktop_lock isn't quick enough to lock the screen before actual suspend to RAM happens.
I put a "sleep 5" in the script before the suspend command, and it appears that kdesktop_lock is not working at all in the script, even though it works fine if I just run it from the command line. Hmmm. At least this gives me a path to pursue. Thanks.

Brian
 
Old 11-27-2007, 05:19 PM   #7
BCarey
Senior Member
 
Registered: Oct 2005
Location: New Mexico
Distribution: Slackware
Posts: 1,490

Original Poster
Rep: Reputation: Disabled
BTW, This languished for a week in another LQ forum with no response. I get it moved to the Slackware forum this morning and I've got two responses already. Thanks, Slackers for a great forum.

Brian
 
Old 11-27-2007, 07:52 PM   #8
rg3
Member
 
Registered: Jul 2007
Distribution: Slackware Linux
Posts: 514

Rep: Reputation: Disabled
I bet kdesktop_lock needs to find the environment variables of a corresponding running KDE session for it to work, and they won't be available when it's called from acpid, which is launched at boot. In my system I suspend to ram by closing the laptop, so I have created a shell script that stops a couple of things, calls s2ram and then restores the things I stopped, and I have associated the LID button event to call that script. It's similar to what you do. To lock the screen before suspending, I do it by hand. It's very easy and not annoying if you set up a keyboard shortcut to do so, like I did with Ctrl+Alt+L. So when I want to suspend to RAM I press Ctrl+Alt+L and close the laptop. Piece of cake.
 
Old 11-27-2007, 08:23 PM   #9
zhoun
Member
 
Registered: Oct 2007
Location: anywhere
Distribution: slackware64 current & win7 64 on thinkpad X61
Posts: 104

Rep: Reputation: 18
Please try this again.

Code:
USER="guo"	
export XAUTHORITY="/home/${USER}/.Xauthority"	
LOCKAPP="/usr/bin/kdesktop_lock --forcelock"
su ${USER} -c "${LOCKAPP}"
Remember to change your login name.
I copy the code from my acpi scripts.
It worked fine for me with all thinkpad Fn functions.
 
Old 11-27-2007, 08:50 PM   #10
BCarey
Senior Member
 
Registered: Oct 2005
Location: New Mexico
Distribution: Slackware
Posts: 1,490

Original Poster
Rep: Reputation: Disabled
zhoun,

I added the additional line, still no dice.

rg3,

Which environment variables were you referring to?

Brian
 
Old 11-27-2007, 09:15 PM   #11
zhoun
Member
 
Registered: Oct 2007
Location: anywhere
Distribution: slackware64 current & win7 64 on thinkpad X61
Posts: 104

Rep: Reputation: 18
My /etc/acpi/acpi_handler.sh, just for reference.
I have no idea why it not work for you.

Code:
#!/bin/sh
#
# ACPI handler script default.sh
# Optimized for Thinkpad R52
#
# Copyright (c) Phillip Berndt, 2007
# Modified by Forever Steel, 2007-11-19, add Fn+Home, Fn+End function (Brightness Controll) 

## Configuration #####################################################
# X11 access for osd_cat and xset dpms
USER="guo"					# Main user of this PC
export XAUTHORITY="/home/guo/.Xauthority"	# X authority file
export DISPLAY="auto"				# Default display

# Screen saver
LOCKAPP="export LANG=zh_CN.gbk;/usr/bin/kdesktop_lock --forcelock"

# WLAN device driver
WLAN_MODULE="ipw3945"
WLAN_PARAMS=""
# or: WLAN_PARAMS="rtap_iface=1"

# Which application to run on "zoom" key
# In my case, start a network autoconfiguration tool AS ROOT!!
# You might want to use "su ${USER} -c <foo>" here
zoom_do() {
	xterm -title "Network autoconfiguration" -e /usr/local/lib/net/network &
}

# File for OSD disabling
OSD_DISABLE_FILE="/var/lib/misc/acpid_osd_disable"

## Help ##############################################################
# 
# Installation:
#  Copy to /etc/acpi/default.sh for acpid and symlink to tpb.sh to use it
#  as a callback script for tpb.
#  Run
#     echo enable,0xffff >/proc/acpi/ibm/hotkey
#     /usr/bin/tpb -d --callback="/etc/acpi/tpb/tpb.sh" -m on -x off
#  on startup.
#
# This script has the following configuration:
#  * F1: Change between performance and powersave govenor (CPU)
#  * F2: dpms force off (Blank screen)
#  * F3: Lock screen
#  * F4: Suspend to ram
#  * F5: Bluetooth on/off
#  * F7: VGA out on/off
#  * F8: LCD on/off
#  * F11: Deactivate OSD
#  * F12: Suspend to disk
#  * Change to performance on AC-plug-in
#  * Change to powersave on AC-unplug
#  * Hibernate on battery power < 5%
#  * Spindown HDD on lid close
#  * Poweroff after pressing the power button TWO times
#  * Load and unload wlan driver on "Access IBM" button
#
# You'll need the following tools to use all features:
#
#  * /usr/sbin/hibernate	Hibernate script
#  * /usr/sbin/radeontool	Radeon graphics settings
#  * /usr/bin/osd_cat		cat'like X11 tool
#  * /usr/bin/xset		Xset (Not installed by default with modular Xorg)
######################################################################

export PATH=/bin/mem:/bin:/usr/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/sbin

if [ "$(basename $0)" == "tpb.sh" ]; then
	ACTION="$1"
	PARAMETER="$2"
	logger "Got TPB Event: Action ${ACTION}, Parameter: ${PARAMETER}"
else
	GROUP="${1/\/*/}"
	ACTION="${1/*\//}"
	PARAMETER2="$2"
	PARAMETER3="$3"
	PARAMETER="$4"
	logger "Got ACPI Event: In Group ${GROUP} action ${ACTION}, Parameter: ${PARAMTER2} ${PARAMTER3} ${PARAMETER}"
fi

## Functions #########################################################
# OSD cat
if [ "${DISPLAY}" == "auto" ]; then
	X="$(ls /tmp/.X11-unix/X* | head -n1)";
	[ "${X}" != "" ] && export DISPLAY=":${X/\/tmp\/.X11-unix\/X/}"
fi

if [ "${DISPLAY}" != "auto" ] && which osd_cat &>/dev/null; then
	osd() {
		[ -f ${OSD_DISABLE_FILE} ] && return
		pkill osd_cat
		echo $@ | osd_cat -p bottom -A center -c green -O 1 -u black -f "-adobe-helvetica-bold-r-normal-*-*-320-*-*-p-*-iso8859-1" &
	}
else
	osd() {
		logger "OSD cat: $@"
	}
fi

# Suspend to ram
suspram() {
		# Prepare suspend (Power saving hacks)
		echo -n eject > /proc/acpi/ibm/bay
		ethtool -s eth0 wol d
		su ${USER} -c "${LOCKAPP}" 
		
		# Suspend
		sleep 1
		echo mem > /sys/power/state
		/etc/rc.d/rc.smartctl
}

## Handlers ##########################################################
if [ "${ACTION}" == "thinkpad" ]; then
	# Load wlan driver
	if [ -d /sys/module/${WLAN_MODULE} ]; then
		modprobe -r ${WLAN_MODULE}
		osd "${WLAN_MODULE} unloaded"
	else
		modprobe ${WLAN_MODULE} ${WLAN_PARAMS}
		osd "${WLAN_MODULE} loaded"
	fi
fi

if [ "${ACTION}" == "zoom" ]; then
	zoom_do
fi

# Closing the laptop (Or opening it ;))
if [ "${ACTION}" == "lid" ]; then
	if [ "$(cat /proc/acpi/button/lid/LID/state | grep open)" != "" ]; then
		# Enable the LCD
		xset dpms force on
		/etc/rc.d/rc.smartctl
	else
		# Immerdiately spindown the harddrive to prevent loosing data
		# due to drive problems. I'd prefer to power it down, but it
		# needs a very long time to power on again.
		xset dpms force off
		su ${USER} -c "${LOCKAPP}" &
		sync
		hdparm -y /dev/sda
		# when lid up, no event send, so add this
		if [ "$(cat /proc/acpi/button/lid/LID/state | grep open)" != "" ]; then
			# Enable the LCD
			xset dpms force on
			/etc/rc.d/rc.smartctl
		fi
	fi
fi

# Special IBM hotkeys
if [ "${ACTION}" == "hotkey" ]; then
	# Change speed
	if [ "${PARAMETER}" == "00001001" ]; then
		DO="performance"
		grep "performance" "/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor" &>/dev/null && DO="powersave"
		echo ${DO} > "/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"
		osd "Governor is now ${DO}"
	fi

	# Blank screen
	if [ "${PARAMETER}" == "00001002" ]; then
		xset dpms force off
	fi

	# Blank screen buton (Sleep instead)
	if [ "${PARAMETER}" == "00001003" ]; then
		#chvt 6
		xset dpms force off
		su ${USER} -c "${LOCKAPP}" &
	fi

	# Suspend-To-Ram on sleep
	if [ "${PARAMETER}" == "00001004" ]; then
		suspram
	fi

	# Bluetooth
	if [ "${PARAMETER}" == "00001005" ]; then
		DO="disable"
		grep -q "disabled" "/proc/acpi/ibm/bluetooth" && DO="enable"
		echo ${DO} > "/proc/acpi/ibm/bluetooth"
		osd "Bluetooth ${DO}d"
	fi

	# Display (External)
	if [ "${PARAMETER}" == "00001007" ]; then
		if /usr/local/sbin/radeontool dac | grep -q "looks on"; then
			/usr/local/sbin/radeontool dac off
			echo "crt_disable" > /proc/acpi/ibm/video
			osd "Video switch (off)"
		else
			/usr/local/sbin/radeontool dac on
			echo "crt_enable" > /proc/acpi/ibm/video
			osd "Video switch (on)"
		fi
	fi

	# Display (Internal)
	if [ "${PARAMETER}" == "00001008" ]; then
		if /usr/local/sbin/radeontool light | grep -q "looks on"; then
			/usr/local/sbin/radeontool light off
			osd "Internal video switch (off)"
		else
			/usr/local/sbin/radeontool light on
			osd "Internal video switch (on)"
		fi

	fi

	# (De)activate OSD
	if [ "${PARAMETER}" == "0000100b" ]; then
		if [ -f ${OSD_DISABLE_FILE} ]; then
			rm ${OSD_DISABLE_FILE}
			osd "OSD activated"
		else
			osd "OSD deactivated"
			touch ${OSD_DISABLE_FILE}
		fi
	fi

	# Hibernate button
	if [ "${PARAMETER}" == "0000100c" ]; then
		su ${USER} -c "${LOCKAPP}" &
		/usr/local/sbin/hibernate
		/etc/rc.d/rc.smartctl
	fi

	# Brightness up
	#if [ "${PARAMETER}" == "00001010" ]; then
	#	echo up > /proc/acpi/ibm/brightness
	#	xbacklight -inc 7
	#	level=$(cat /proc/acpi/ibm/brightness | grep level:)
	#	osd "${level}"
	#fi
	# Brightness down
	#if [ "${PARAMETER}" == "00001011" ]; then
	#	echo down > /proc/acpi/ibm/brightness
	#	xbacklight -dec 3
	#	level=$(cat /proc/acpi/ibm/brightness | grep level:)
	#	osd "${level}"
	#fi
fi


# Battery actions
if [ "${GROUP}" == "battery" ]; then
	# $ACTION is the battery i.e. BAT0
	# Get remaining capacity
	capacityPercent=$(/usr/bin/acpitool -b | grep \#$[${ACTION/*[A-Z]/} + 1] | egrep -o [0-9.]+% | egrep -o ^[0-9]+)

	# OSD info
	osd "Battery Event: ${capacityPercent}%"

	# Hibernate on low battery
	if [ "${capacityPercent}" -lt 5 ]; then
		/usr/local/sbin/hibernate -f
	fi
fi

# Brightness button
if [ "${ACTION}" == "video" ]; then
	if [ "${PARAMETER3}" == "00000086" ]; then
		echo up > /proc/acpi/ibm/brightness
		xbacklight -inc 7
		level=$(cat /proc/acpi/ibm/brightness | grep level:)
		osd "${level}"
	fi
	if [ "${PARAMETER3}" == "00000087" ]; then
		echo down > /proc/acpi/ibm/brightness
		xbacklight -dec 3
		level=$(cat /proc/acpi/ibm/brightness | grep level:)
		osd "${level}"
	fi
fi

# Power button
if [ "${ACTION}" == "power" ]; then
	if [ ! -e /var/run/poweroff ]; then
		date "+%s" > /var/run/poweroff
	else
		DIFF=$[ $(date "+%s") - $(cat "/var/run/poweroff") ]
		date "+%s" > /var/run/poweroff

		if [ ${DIFF} -lt 5 ]; then
			/sbin/poweroff
		fi
	fi
fi

# AC Control
if [ "${ACTION}" == "ac_adapter" ]; then
	if [ "`cat /proc/acpi/ac_adapter/AC/state | grep on-line`" != "" ]; then
		echo -n "performance" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
		osd "Powering from AC"
	else
		echo -n "powersave" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
		osd "Powering from Battery"
	fi
fi
 
Old 11-27-2007, 09:27 PM   #12
zhoun
Member
 
Registered: Oct 2007
Location: anywhere
Distribution: slackware64 current & win7 64 on thinkpad X61
Posts: 104

Rep: Reputation: 18
Or you can monitor the acpi log file:
/var/log/acpid

If error happens, it will be logged in this file.
 
Old 11-27-2007, 11:46 PM   #13
BCarey
Senior Member
 
Registered: Oct 2005
Location: New Mexico
Distribution: Slackware
Posts: 1,490

Original Poster
Rep: Reputation: Disabled
Thank you all, especially zhoun. I have a solution. This is the relevant section of my acpi_handler.sh:

Code:
export DISPLAY=":0"
/usr/bin/kdesktop_lock --forcelock &
sleep 3
/usr/lib/hal/scripts/hal-system-power-suspend
Comments:

1. I do not need the "export XAUTHORITY" line because I do "xhost +localhost". If I didn't, then the "export XAUTHORITY" line is necessary

2. The ampersand after the kdesktop_lock command is necessary or it will not suspend until I unlocked the display

3. The sleep 3 line is necessary or it will not lock until after the system is resumed, allowing a brief glimpse of the screen display

4. If you do not have the root password, then the "su..." line from zhoun's post is necessary.

Thanks again for all the help.

Brian

Last edited by BCarey; 11-28-2007 at 10:51 PM.
 
Old 11-28-2007, 12:04 AM   #14
zhoun
Member
 
Registered: Oct 2007
Location: anywhere
Distribution: slackware64 current & win7 64 on thinkpad X61
Posts: 104

Rep: Reputation: 18
You got it!

Your comments is clear and will help other people.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Lock screen (requiring password to unlock) when resuming from suspend theoldman Linux - Laptop and Netbook 2 12-17-2009 10:35 PM
suspend seems to only lock the screen ??? sirmonkey Fedora 2 03-04-2007 10:10 PM
lock button cant work yet ! black Linux - Newbie 3 11-22-2003 05:41 AM
lock button refuse to work ? black Linux - Newbie 2 11-09-2003 03:27 AM
Needs to push power button to power off? danpin Linux - Newbie 5 10-21-2003 09:08 PM


All times are GMT -5. The time now is 10:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration