Posts tagged ‘thinkpad’

Another Thinkpad script, volume.

I was missing my volume buttons on my thinkpad, I’m sure the default flavours of (XU|KU|U)buntu handle this nicely (can’t say I checked though ;). But since I run ion3 I get none of that fluffyness.

There are ofcourse already some onelines and scripts outthere that fix this problem, and I certainly copied from them what was useful, but I wanted my OSD feedback. So I wrote the following script, not fancy but it works.
It depends on the following packages:

  • perl
  • alsa-utils
  • xosd-bin

/usr/local/bin/ibmvolume.pl

#!/usr/bin/perl -w
use strict;
## Script made for Lenovo Thinkpad X61s
## for different cards you might need a different numid.

my $nvol  = '28';
my $nmute = '29';

my $volinfo  = `amixer cget numid=28`;
my $muteinfo = `amixer cget numid=29`;

my ($min, $max, $cur) =
    $volinfo =~ /.*min=(.+?),.*max=(.+?),.*values=([0-9]+).*/si;
my $per = int($cur / ($max / 100));

my ($mute)  = $muteinfo =~ /.*values=([a-z]+).*/si;
my $invmute = ($mute eq 'on') ? 'off' : 'on';

if($#ARGV < 0) {
    print "Min: $min, Max: $max, Cur: $cur($per%), Mute: $mute($invmute)\n";
    print "Usage: $0 (up|down|mute|show)\n";
    exit 1;
}

my $command = shift;

my %controls = (
    up   => "amixer -q cset numid=$nvol ".($cur+1),
    down => "amixer -q cset numid=$nvol ".($cur-1),
    mute => "amixer -q cset numid=$nmute $invmute",
);

system($controls{$command}) if $controls{$command};

my $cmute = ($command eq 'mute') ? $invmute : $mute;

my $font = '*-lucidatypewriter-bold-r-normal-sans-24-240-75-75-m-140-iso8859-1';

system("osd_cat -b percentage -f $font  -c green -A center -o 600 -d 1 -T 'Volume($cmute):' -P $per &");

Sadly the osd_cat tool can wait no shorter than 1 second, I would’ve liked something more like 0.5 second.

This now works from the commandline, taking commands like ‘up’, ‘down’, ‘mute’ and ’show’. Now one can use something like ‘xbindkeys’ to link it to key events like ‘XF86AudioRaiseVolume’ and ‘XF86AudioLowerVolume’.

But I just put the following code in my (lua) config for ion3:

~/.ion3/cfg_bindings.lua

defbindings("WMPlex.toplevel", {
    kpress("XF86AudioRaiseVolume", "ioncore.exec_on(_, '/usr/local/bin/ibmvolume.pl up')"),
    kpress("XF86AudioLowerVolume", "ioncore.exec_on(_, '/usr/local/bin/ibmvolume.pl down')"),
    kpress("XF86AudioMute", "ioncore.exec_on(_, '/usr/local/bin/ibmvolume.pl mute')"),
})

And don’t forget to reload ion3 afterwards :)

Simple but useful ACPI + Thinkpad script

I always got anoyed when X crashed, or hanged and I couldn’t do anything anymore, while I knew the rest of the system was still functional and I should be able to get my screen session back.

The ‘easy’ way for this would be to SSH into your workstation, but I like to keep sshd turned off on those machines. preferably no external services on workstations at all actually.

Now I have a Thinkpad, and Thinkpads have this ugly Thinkpad/Thinkvantage button, especially ugly in it’s inner workings, and because of that it’s useful here.

The Thinkvantage button is not a keyboard event (which at this point is controlled by a broken Xorg) but it’s polled by the ACPI daemon, which runs as root. So when you press the button, an ACPI event is generated, which can have scripts linked to them.

A quick fix would be to put ‘chvt 2′ in the /etc/acpi/thinkpad-thinkpad.sh script on debian. But I wanted a little more and  changed it to the following:

/etc/acpi/thinkpad-thinkpad.sh

#!/bin/sh
CURVT=`/bin/fgconsole`
NEXTVT=`expr $CURVT + 1`

if [ $NEXTVT -gt 8 ]; then
    NEXTVT=1
    echo "looped back to: $NEXTVT" >> /tmp/nextvt.log;
fi

echo "Current VT: $CURVT, Next VT: $NEXTVT" >> /tmp/nextvt.log
if [ "X$NEXTVT" eq "X" ]; then
    /bin/chvt 2;
else
    /bin/chvt $NEXTVT;
fi

So this actually loops through terminal 1 t/m 8, without needing the keyboard-driver.

(don’t forget to reload acpid after chaning any of the scripts).

Obscure mplayer problems

Since a little while now, I used to have the problem of the music skipping in mplayer. I guessed bad audio or crappy I/O, but I never noticed any errors anywhere.

What was happening was that when I moved my laptop, bumped against the laptop or table it was standing on it would skip or rewind the music. Sometimes a little, sometimes a lot.

Now I have a Thinkpad X40 and it only happened with mplayer, no other audio/video player.

Since yesterday I finally realised the problem after confirming it was related to me bumping against the table/laptop.

Continue reading ‘Obscure mplayer problems’ »