Monday, June 22, 2009

Stop the WiFi Keyboard LED from Flashing

When I first installed Ubuntu on my Vostro 1500, I was very happy that the wireless card worked. Ordering the correct hardware is one thing, actually printing "Hello World" is another.

Two days later I was cursing the wireless worked. The wireless LED that is. It's a constant bright blue blinking light that's extremely annoying. After googling, I finally discovered that I could control it via the /sys file system:

# echo iphy0assoc > '/sys/class/leds/iwl-phy0:assoc/trigger'
# echo none > '/sys/class/leds/iwl-phy0:radio/trigger'
# echo none > '/sys/class/leds/iwl-phy0:RX/trigger'
# echo none > '/sys/class/leds/iwl-phy0:TX/trigger

Woot! The light turned off. For two seconds. Then was back again. Still bright, still blue, still blinking, still annoying. It took me a couple nights, but then I woke up. Haduh! Computers do the redundant really well! So I wrote a simple C program:

#include <unistd.h>

int main ( ) {
 while ( 1 ) {
  // loop endlessly

  system( "echo iphy0assoc > '/sys/class/leds/iwl-phy0:assoc/trigger'" );
  system( "echo none > '/sys/class/leds/iwl-phy0:radio/trigger'" );
  system( "echo none > '/sys/class/leds/iwl-phy0:RX/trigger'" );
  system( "echo none > '/sys/class/leds/iwl-phy0:TX/trigger'" );

  system( "echo 0 > '/sys/class/leds/iwl-phy0:radio/brightness'" );
  sleep( 2 ); // wait 2 seconds, before doing it again
 }
}

Basically, an endless loop, turning off the wifi led every 2 seconds. Compilation was easy:

$ gcc -Os -o turn_off_wifi_led turn_off_wifi_led.c

Now, the tricky part is that this must be run as root, and I don't want to have to run it manually every time I login. Luckily, our Unix engineers have thought of this: setuid

$ ll turn_off_wifi_led
-rwxr-xr-x 1 kevin kevin 6.3K 2009-06-22 01:59 turn_off_wifi_led

$ sudo chown root:kevin turn_off_wifi_led
$ sudo chmod 4755 turn_off_wifi_led
-rwsr-xr-x 1 root kevin 6.3K 2009-06-22 01:59 turn_off_wifi_led

Now, because it's setuid, and it's owned by root, no matter who executes the turn_off_wifi_led program, it will run with root privileges.

The last actions are to put it my bin folder, and to run it automatically when I log in:

$ mv turn_off_wifi_led ~/bin

Then go to System→Preferences→Startup Applications. Click 'Add' to make a new entry in the table:

Name:    Kill WiFi LED
Command: /home/kevin/bin/turn_off_wifi_led &
Comment: Turn off that damned annoying, always flashing, blue wifi LED.

Click Save, then Close. VoilĂ ! After logging back in, the annoying blue LED is off for good!

Saturday, February 16, 2008

Stop XFCE from Automatically Switching Windows to Different Desktops

My email reading and surfing habits follow a lazy model: I like to click on a link and load it in the background while I finish absorbing the current context (email, webpage, IRC snippet, etc.). When I'm finished with the current email or webpage, I then go back and check out what I clicked. This was all fine and dandy while I was using the Gnome desktop, but I recently changed to XFCE and some of the defaults are a little different.

The problem: I make use of multiple (virtual) desktops for splitting up my computing activities. I group my active applications together in the 2nd quadrant (think unit-circle quadrants) and my email in the 3rd quadrant. When I click a hyperlink in my email quadrant, XFCE moves my web browser to the 3rd quadrant. This is annoying.

I finally ascertained the appropriate action when I asked on the #xfce channel. The solution is a hidden option (so called since it is not yet accessible via the GUI) so it's terminal time. The option is activate_action=none and it gets put into ~/.config/xfce4/xfwm4/xfwm4rc.

$ echo activate_action=none >> ~/.config/xfce4/xfwm4/xfwm4rc

After restarting XFCE (otherwise known as logging out and back in), windows no longer switched desktops automatically! Exciting! Thanks #xfce!

I'm still not sure what was wrong with my google-fu, but after the fact, I finally found the documentation of this option in XFCE's svn repository. (Search for activate_action.)

activate_action=bring|switch|none When set to bring, the window manager to bring the window on the current workspace, switch will switch to the window's workspace, and none will simply do nothing but set the demand attention flag on the window.

Hello World

I am a geek, and every good geek starts off projects with the obligatory Hello, World! Hello, World.