Wednesday, October 17, 2007

E17 profiles

I finally got around to playing with E17 profiles, which are located under the 'Advanced' section of the Configuration Panel. I kinda figured that, the E guys being who they are, I could use these to toggle between CPU-eating animated backgrounds/icons and normal static backgrounds when the laptop is running on battery or A/C power. I was right!

I put the following script in /usr/local/bin/e17_switch_profile.sh :
#!/usr/bin/env bash

# Switch e17 profile based on arg1

# 1. Check if E17 is running
if [ `ps ax | grep enlightenment | grep -v 'grep' | wc -l` -eq 0 ]
then
# no enlightenment running
exit 0
fi

# 2. Make sure E_IPC_SOCKET is set
if [ -z "$E_IPC_SOCKET" ]
then
# we are called from outside of e17
E_IPC_SOCKET=`ls -a /tmp/enlightenment-*/disp-*`
if [ -z "$E_IPC_SOCKET" ]
then
# something wrong with enlightenment!
echo "Cannot set E_IPC_SOCKET!" >> /dev/stderr
exit 0
fi
E_IPC_SOCKET=${E_IPC_SOCKET%|*}
fi

# 3. Get username to switch to
if [ $# -gt 0 ]
then
profile="$1"
else
# switch to default
profile="default"
fi

# 4. Switch enlightenment user!
E_IPC_SOCKET="$E_IPC_SOCKET" enlightenment_remote -default-profile-set $profile
This has the usage `e17_switch_profile.sh profile_name`, with 'default' being used when no profile name is provided.

I then modified /etc/acpi/power.sh as follows:

function laptop_mode_enable {
# Local Changes ---------------------------
/usr/local/bin/e17_profile_switch.sh battery
telinit 4
# -----------------------------------------

$LAPTOP_MODE start
# <...DETAILS OMITTED...>
}

function laptop_mode_disable {
# <...DETAILS OMITTED...>
$LAPTOP_MODE stop

# Local Changes ---------------------------
telinit 2
/usr/local/bin/e17_profile_switch.sh ac
# -----------------------------------------
}
There are three changes from the Ubuntu default:
  1. LAPTOP_MODE is enabled (see /etc/laptop_mode/laptop_mode.conf )
  2. The battery runlevel is 4, while the A/C runlevel is 2 (the default)
  3. The e17_profile_switch is called to set the profile to either 'battery' or 'ac'
Obviously the remaining step is to create those two profiles in E17, and set them up accordingly.

The runlevel trick is one I've been using for awhile: I modify one of the existing runlevels to kill off unnecessary daemons, and optionally to run shell scripts (placed in init.d of course) to do things like change the hard drive spin-down time or the CPU frequency governor. Note that laptop-mode-tools provides this latter capability, so my current battery runlevel just kills off services that aren't that important:
bash# ls -1 /etc/rc4.d
K19cupsys
K20apport
K20dirmngr
K20hplip
K20ntop
K20privoxy
K20pulseaudio
K20rsync
K20ssh
K20stunnel4
K20tor
K20udftools
K25bluetooth
K30mpd
K89anacron
K89atd
K89cron
K99avahi
K99dbus
K99networking
Some of these may seem strange choices, but I tend to not use the net when on battery (usually I'm holed up at a coffee shop coding), and likewise I avoid resource-intensive applications (Open Office, KDE, multimedia, etc). If I really want to stretch the battery life I'll kill X, but Acroread and Firefox are a bit useful for consulting documentation.

No comments:

Post a Comment