Free Software

Software Engineering with FOSS and Linux

Dealing with mouse and touchpad freezes in Linux

Sometimes the desktop in several Linux distributions freezes for no apparent reason; active windows can still be used, and the mouse pointer can be moved around, but clicking is impossible. Furthermore, your touchpad can no longer be controlled; the ‘Touchpad’ tab disappears from the System / Preferences / Mouse menu. Even if mouse functionality eventually returns, the touchpad remains uncontrollable. This extremely annoying bug occurs randomly and may last for a couple of seconds, or until you restart your X server.

If you check your system’s log after such an event (/var/log/messages) you will notice a few entries similar to these:

Sep  9 09:38:15 umbra kernel: [ 4939.006198] psmouse.c: DualPoint TouchPad at isa0060/serio1/input0 lost sync at byte 1
Sep  9 09:38:15 umbra kernel: [ 4939.012220] psmouse.c: DualPoint TouchPad at isa0060/serio1/input0 - driver resynched.

Basically this indicates an IRQ conflict between your mouse and your touchpad. This is a Linux kernel bug (I am currently using 2.6.28) and as such it affects most distributions. An easy way to recover both mouse and touchpad functionality without having to restart your X server is restarting the mouse driver. Run the following commands on a terminal window:

sudo rmmod psmouse
sudo modprobe psmouse

If there is no terminal window open, you can use one of the following:

  • In Gnome or KDE, press Alt + F2, type gnome-terminal and press Enter
  • Press Control + Alt + F1, login with your username and password, type the commands, then press Control + Alt + F7 to get back to X

Hopefully a future kernel release will fix this problem for good.

September 9, 2009 Posted by | linux | , , , , , , , | 33 Comments

Selecting language of multilingual web sites

Multilingual sites will usually offer a way to their users to switch between languages of the content, either through a link in their pages or through the configuration of user preferences. For first-time visitors, however, a site needs a way to determine their prefered language(s). The standard way to identify this is by inspecting the Accept-Language HTTP header sent to the site by the user’s browser.

According to the HTTP 1.1 Specification, the Accept-Language header can be used to assign a weight to each language, determining the users’ prefered order of natural languages of multilingual content. For example,

Accept-Language: el,en;q=0.5,fr;q=0.4

means that the user prefers Greek content, but if it is not available then English and French are also acceptable, with English having a higher priority.

You can parse the Accept-Language header to determine the appropriate language. Although a simple parsing can be used in most cases, addressing the gritty details of the specification can be a bit tricky. Here is an implementation of the parsing algorithm in PHP. It might be an overkill, but it gives you a pretty good idea:


<?
$default_lang 
"en";

function sort_descending_weights$a$b )
{
    
# Each array element is a (lang,weight) pair
    
if ( $a] != $b] )
    {
        return ( 
$a] < $b] ) ? : -1;
    }

    # If two languages have the same weight, then we might want to impose 
    # our own precedence. Put your own ordering code here. For simplicity, we
    # just assume that the default language takes priority.
    
if ( $a] == $default_lang ) return -1;
    else if ( 
$b] == $default_lang ) return 1;
    else return 
0;
}

function is_language_available$lang )
{
    return 
true;
}

function get_prefered_language( )
{
    global 
$default_lang;
    
    
# If no Accept_Language header exists, use the site's default language
    
if ( !in_array'HTTP_ACCEPT_LANGUAGE'$_SERVER ) ) 
    {
        return 
$default_lang;
    }

    # Parse the header. A * indicates any language not explicitly specified
    
$h $_SERVER'HTTP_ACCEPT_LANGUAGE' ];
    
$list explode","$h );
    if ( 
count$list ) == ) return $default_lang;
    
$prefs = array();
    foreach ( 
$list as $langs )
    {
        
$tmp explode";q="$langs );
        
$lang $tmp];
        
$weight count$tmp ) == 1.0 $tmp];
        
array_push$prefs, array( $lang$weight ) );
    }

    # The specification doesn't enforce weight to be in descending order.
    # Sort the parsed values.
    
usort$prefssort_descending_weights );    

    # Pick an available language. is_language_available() is a stub.
    
foreach ( $prefs as $pref )
    {
        list( 
$lang$weight ) = $pref;
        if ( 
is_language_available$lang ) ) return $lang;
    }
    return 
$default_lang;
}    

echo get_prefered_language();
?>


In Firefox 3.0, users may specify their prefered content languages in the Preferences / Content / Languages Menu:

prefs lang

For ease of use, exact weights don’t need to be specified. When users change the order of the languages in the list, the browser will calculate and send the appropriate weights in the HTTP request.

September 3, 2009 Posted by | Programming | , , , , , | 4 Comments

4 + 1 ways to celebrate the Software Freedom Day

With the Software Freedom Day fast approaching, the Free Software Foundation and communities across the world are planning their activities and are preparing to celebrate and promote Free Software in their region. Joining your local community and partaking to its activities is strongly suggested; however, here are some ideas for individual promotion of Free Software:

  • Spread the word. Mention it to your family, your friends, your colleagues, your classmates. You may be surprised by how many people may begin to care after they actually hear about a new idea. You will find that the “people don’t care about this kind of stuff” is a common misconception; many people do care and will often seek ways to help.
  • Make a T-shirt. Select a logo of your favorite Free Software application or organization and print it on a T-shirt. Wear it in public. Some will see. Some will be curious. Some will care.
  • Promote it in your virtual community. Blog it, digg it, twit it, post it on Facebook. If you play a game, talk about it in the game. If you run a game, announce it to your players. For example, here is the announcement planned for an online game I’m currently coding for:
    Today we celebrate the Software Freedom Day; we celebrate the freedom in our
    virtual world, a world made possible by Free Software. Our code is built on
    Free Software and has been powered by and running on Free Software for 17 years
    now. Our thanks to those who allowed us to revive and enjoy Dragonlance for
    all this time.
  • Use it as a chance to get involved in activities related to software freedom. You don’t need to be a programmer to help; you can help with translations, bug reports, or even activities not related to software at all: map your neighborhood using OpenStreetMap, upload your art to the Open Clip Art Library, publish your digital content under an appropriate Creative Commons License.

Maybe the most important thing you can do that day is learn more about Software Freedom and reflect on how it applies to you and your community. Checkout The Free Software Definition, learn Why Schools Should Use Exclusively Free Software and understand why Your Freedom Needs Free Software. Don’t take these at face value; think about them, and form your own opinion. Then act.

September 2, 2009 Posted by | Free Software | , , | 16 Comments