09.12.2010

Update to tablet-mode

Update: I've released yet another version of the package. It fixes the same bug as described below again (but now it really works! ;) ). The problem was a variable substitution in the Tcl "switch" statement (and some other flaws that I somehow didn't notice before). Version 1.4.0 is available via my Launchpad PPA and can be downloaded by the usual means.


I've released a new version of my tablet-mode package (see my article on my PPA if You don't know what I'm talking about).
Yesterday I wanted to use my notebook as a tablet and noticed that the touch function was not turned off as it was supposed to be. It turned out that the IDs of my Wacom devices (finger, stylus, eraser) had changed and were no longer the ones I had in my /etc/tablet-mode/tablet-mode.conf. Today I checked again and they were back to normal. Now to not have You change the values in the configuration file every now and then (and then have You change them back again shortly after), I changed the behavior of the script so that it does no longer require numeric IDs in the configuration but rather requires string identifiers like "Wacom ISDv4 E3 Pen stylus". It then looks up the corresponding numeric IDs by itself every time it is run.
Another problem that I fixed was that the script didn't even use the values from the configuration file at all. Due to a wrong variable name, the finger device always had the same numeric ID, no matter what You had in Your config file. The result was that when the device had another ID than 11 on Your system, the touch function was not turned off when entering tablet mode and the touch device was not rotated when rotating Your screen.
So, if You have the package installed, just update to the latest version and if not, You can safely install it :)

05.12.2010

Screen brightness

Changing the screen brightness can extend the battery life by a considerable amount, so this a quite important thing concerning laptops. Unfortunately, that functionality is broken. On my laptop with Ubuntu, I am unable to change the display brightness by the usual means. The buttons do create a reaction, but that reactions merely consists of the GNOME Power Manager displaying a notification with a bar that changes. Nothing happens to my display.
Additionally, every time I press one of the keys, that bar increases or decreases by two steps instead of one. So when I keep the button pressed for about 4-5 seconds, that notification keeps blinking for about 10-15 seconds before finally disappearing.
And now the good part: I found a solution :)
I managed to get the brightness keys working. I am able to change the brightness by an arbitrary amount upon a key press, yet so far I was unable to make that annoying notification disappear.
Thanks to some post in some forum (unfortunately I remember neither the author nor the forum), I got to know the location of a node on the /sys filesystem where the brightness can be changed by echoing numbers into it.
(Note: You need root access to write files in /etc/acpi/).
  1. Create a script to be executed upon pressing one of the brightness keys. Mine is named brightness.sh and is placed in /etc/acpi/.
    Code:
    #! /bin/bash

    # pressing the buttons generates 2 events, so we need to ignore one
    if [ "$2" != "LCD" ]
    then
        exit 0
    fi
    # get brightness
    CURRENT_BRIGHTNESS="$(sudo setpci -s 00:02.0 F4.B | tr "[a-z]" "[A-Z]")"
    # to upper case
    CURRENT_BRIGHTNESS="$(echo "$CURRENT_BRIGHTNESS" | tr "[a-z]" "[A-Z]")"
    # add/substract 16
    case "$3" in
        "00000086")
            OP="+"
            ;;
        "00000087")
            OP="-"
            ;;
        *)
            exit 0
    esac
    NEW_BRIGHTNESS="$(echo "obase=16;ibase=16;$CURRENT_BRIGHTNESS $OP 10" | bc)"
    # check boundaries
    if [ "$(echo "ibase=16; $NEW_BRIGHTNESS < F" | bc)" -eq 1 ] then     NEW_BRIGHTNESS="F" elif [ "$(echo "ibase=16; $NEW_BRIGHTNESS > FF" | bc)" -eq 1 ]
    then
        NEW_BRIGHTNESS="FF"
    fi
    # set brightness
    setpci -s 00:02.0 F4.B=$NEW_BRIGHTNESS
    The script changes the brightness in steps of 10. You can change this amount by changing the number in line 23 (NEW_BRIGHTNESS=...). The brightness is a number between 0 and 255 and is read and saved as a hexadecimal number (0 to FF).
  2. Make the script executable.
    Code:
    $ chmod +x /etc/acpi/brightness.sh
  3. Create an ACPI event handler to execute the script upon pressing one of the brightness keys. I called it brightness and placed it in /etc/acpi/events/.
    Code:
    # /etc/acpi/events/brightness
    # Calls /etc/acpi/brightness.sh to change screen brightness upon key press
    # Author: Frederik Möllers

    event=video
    action=/etc/acpi/brightness.sh %e
  4. Make acpid reload its configuration for the changes to take effect.
    Code:
    $ reload acpid

When pressing Your brightness keys, You display brightness should change now. The bar will still appear and display something wrong and will probably annoy You, but I haven't found out yet how to kill that thing. If it's not working, You can try to check wether the ACPI events are the correct ones (the script reacts on video LCD 00000086 00000000 and video LCD 00000087 00000000 - acpi_listen can tell You what events are generated by Your keys) and wether the call to setpci does the operation on the right card (lspci is Your friend, Your intel onBoard graphics card should have ID 00:02.0). If Your system has different values, just change them in the script and feel free to tell me so I can generalize the script and put a note on that here.

Warning: Never set Your brightness to 0! This is not only useless (You can't see anything because a value of 0 really means to completely turn off the light panel), but it will also kill Your system, forcing You to do a hard reset. You will be unable to change the brightness back to a positive number, even if You enter the correct command blindly. My script will not do this, but if You want to tinker around for Yourself, always keep this in mind!

That's it! You're done!

29.11.2010

Switchable graphics and power consumption

Update: The switch seems to work reliably for me now. I switched to the ATI card, restarted X, used it, switched back and restarted X again. The procedure worked without problems. If I find time I will probably write a small program to switch the graphics card similar to the one I wrote for screen rotation.

It is completed! Switchable graphics are supported by the Linux kernel!
The usage is pretty simple. You have 2 graphics cards installed in the system. Thus, You need drivers for both of them. For the tm2-1090eg this means You need to make sure that both the radeon and the intel module are loaded after You booted up Your laptop. If one of them does not appear in the output of lsmod, there's something wrong or You blacklisted is. How to cope with that is not covered in this guide.
Starting with some-kernel-version, there is a node in the sysfs, specifically in /sys/kernel/debug/, which is called vgaswitcheroo. This neat little thing gives us the possibility to switch the graphics adapter at runtime and also to turn off the idle one.
(As root) You can write different 3 values into the switch at /sys/kernel/debug/vgaswitcheroo/switch using:
Code:
$ echo <value> > /sys/kernel/debug/vgaswitcheroo/switch
The values are:
  1. OFF - This one is simple. It turns off the video adapter which is currently unused. It is of high value, though. I noticed that upon turning off my ATI card, the battery lifetime actually increased by a factor of 5! Before using this, I could use my laptop for about an hour before the batteries went dry and now I am able to hack on it for around 5 hours without a break. At the end of this article I will present an upstart script to automatically turn off the ATI card on startup (I can't think of a reason to use the ATI card on Linux. According to other people, the drivers don't work well and there is no need for 3D acceleration at all.).
  2. DDIS - Switch to the discrete graphics card (the ATI one). This requires a restart of the X server to take effect and the whole switching is buggy on my system. Every one or two switches, the system completely crashes and I need to hard-reboot my laptop. However, it may work for some people and may work for everyone in the near future, so I included it here as well.
  3. DIGD - Switch to the integrated graphics card (the Intel one). The same restrictions and errors apply as for the previous value.
You can also read the state of the switch:
Code:
$ cat /sys/kernel/debug/vgaswitcheroo/switch
So far so good. Now as I mentioned, the ATI card is practically useless unless You want to play games (and even then I heard it's not really making things look good). If You want to turn it off, You may copy the following script (name it ati-disable.conf and place it in /etc/init as root, of course).
Code:
# ati-disable - Disable ATI graphics card
#
# Disable the dedicated ATI graphics card to save power.

description "Disable ATI graphics card"
author "Frederik Möllers"

start on started gdm

script
    if [ -w /sys/kernel/debug/vgaswitcheroo/switch ]
    then
        echo "OFF" > /sys/kernel/debug/vgaswitcheroo/switch
    fi
end script
Upon reboot, Your ATI card should be turned off. You can check if it is by using the cat command from above.

That's it! You're done!

13.11.2010

Fred.deb

Update: There is a note on bugs at the end of the article.

Yay, I forged my first package! And I got my own PPA (personal package archive) at Launchpad!
The first package I made is based on my article on screen rotation. It contains the script itself (an improved version), the upstart script to map the keycodes and a configuration file (/etc/tablet-mode/tablet-mode.conf) to centrally configure the needed values.
Here's what You need to do if You want to use it (You need root access for most of the tasks):
  1. Add the PPA to Your sources:
    Code:
    add-apt-repository ppa:fredfredfred/ppa
  2. Refresh Your package list:
    Code:
    apt-get update
  3. Install the package:
    Code:
    apt-get install tablet-mode
  4. As told in the message during installation, You need to take a look at the configuration file, /etc/tablet-mode/tablet-mode.conf. Either use the comments from the file or have a look at my first article on this subject to find out the values You need. The values provided in the sample should work on an HP TouchSmart tm2-1090eg notebook, You only have to uncomment the last 2 lines to enable the keycode:scancode mapping upon system start.
  5. Bind the scan codes to rotatescreen tableton and rotatescreen tabletoff, as described in the other article.
That's it! You're done!

Bugs: If You turn the screen, put it down and then hibernate Your laptop, turn the screen back and power it back on, the screen is upside down as is the tablet orientation. I will not fix this, since I cannot. Upon resuming from suspend, there is no way for me to check which position the display is in. Use the console commands rotatescreen tableton and rotatescreen tabletoff to switch between the modes manually (or use the GUI).

07.11.2010

CPU governors and power supply status

Update: As announced, this script collection has been incorporated into my PPA as a package. Check it out here.

As promised, here's an article on CPU governors. As You might know by now, I use Ubuntu on my laptop. Unfortunately, it was kind of useless (until now) if I didn't plug in the power supply, since the battery was drained in less than an our of work (using nothing more than a text editor, kile). The problem source: The system doesn't change the cpu governor when the power cord is plugged out. Thus, the ondemand governor is used instead of the powersave one.
Luckily, there's an easy way to cope with this. The ACPI daemon acpid can be taught to execute arbitrary code upon any ACPI event. That means You can use it to automatically change the CPU governor depending on Your power supply status. Here's how it works:
  1. Create a script to change the CPU governor. You can use mine, too:
    Code:
    #! /bin/bash

    # Note: AC connection is in:
    # /sys/devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0003:00/power_supply/AC/online
    # 0 is disconnected, 1 is connected

    # If no arguments are passed, print governors
    if [ -z "$1" ]
    then
       for MYCPU in /sys/devices/system/cpu/cpu[0-9]*
       do :
          echo "$(basename $MYCPU): $(cat ${MYCPU}/cpufreq/scaling_governor)"
       done
       echo "Available (on cpu0): $(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors)"
       exit 0
    fi

    # Bring governor in control
    if [ "$UID" -ne "0" ]
    then
       echo "Error: Must be run as root!"
       exit 1
    fi
    echo -n "Handling over control to $1 governor... "
    if [ "$1" == "conservative" -o "$1" == "powersave" -o "$1" == "performance" -o "$1" == "ondemand" ]
    then
       for MYCPU in /sys/devices/system/cpu/cpu[0-9]*
       do :
          echo "$1" > ${MYCPU}/cpufreq/scaling_governor
       done
    # userspace governor needs speed argument
    elif [ "$1" == "userspace" ]
    then
       if [ "$2" -gt "0" ]
       then
          for MYCPU in /sys/devices/system/cpu/cpu[0-9]*
          do :
             echo "$1" > ${MYCPU}/cpufreq/scaling_governor
             echo "$(expr $2 \* 1000)" > ${MYCPU}/cpufreq/scaling_setspeed
          done
       else
          echo "userspace governor needs speed argument > 0!"
       fi
    else
       echo "Unknown governor: '$1'"
       exit 1
    fi
    echo "done"
    Make the script executable and place it somewhere, e.g. in /usr/local/bin. You can also use the script manually from the command line, e.g. with sudo cpufreq performance if You feel like You need everything Your computer got.
  2. Create a script for the acpid and place it in /etc/acpi (the script must be executable). Mine is called powersave.sh and looks like this:
    Code:
    #! /bin/bash

    # Called by /etc/acpi/events/powersave
    # Calls cpufreq script to set cpu governor
    # Author: Frederik Möllers

    if [ "$4" -eq 0 ]
    then
       /usr/local/bin/cpufreq powersave
    else
       /usr/local/bin/cpufreq ondemand
    fi
  3. Create a rule for the acpid and place it in /etc/acpi/events. Mine is called powersave and looks like this:
    Code:
    # /etc/acpi/events/powersave
    # Calls /etc/acpi/powersave to set cpu governor when ac adapter status changes
    # Author: Frederik Möllers

    event=ac_adapter
    action=/etc/acpi/powersave.sh %e
  4. Make acpid reload its configuration (as root):
    Code:
    $ reload acpid
  5. You might think You're done now, but actually You've only finished half of the job yet. When the system boots up, there will be no ACPI event telling acpid the status of Your power supply. Thus, if You boot with the power cord plugged out, Your system will still use the ondemand governor. To deal with that, You can create an upstart script which sets the CPU governor depending on the status of the power supply. Create a file /etc/init/cpufreq.conf (or with any other filename, but keep the .conf extension!) and fill it with something like the following.
    Code:
    # cpufreq
    #
    # Sets CPU governor to ondemand if AC is plugged in and powersave if not
    # Default is performance which is kind of overkill.

    description "CPU frequency scaling"
    author "Frederik Möllers"

    start on (virtual-filesystems and local-filesystems)

    script
       if [ "$(cat /sys/devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0003:00/power_supply/AC/online)" -eq 0 ]
       then
          sudo /usr/local/bin/cpufreq powersave
       else
          sudo /usr/local/bin/cpufreq ondemand
       fi
    end script
    WARNING: Depending on Your system, the path (/sys/devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0003:00/) on the /sys filesystem where the status of Your power supply can be found, may differ from the one I use. It shouldn't be miles away, but especially the number following ACPI may be another one on other laptop. You might need to search for the power_supply directory manually and change the path.
  6. You're almost done! Since the default CPU governor is performance which, as I said in my script, is kind of overkill, Ubuntu ships with an init-script to set the governor to ondemand upon startup. This, however, collides with the upstart script You just created, so You need to disable that init-script (as root):
    Code:
    $ update-rc.d ondemand disable
    This will safely disable the ondemand script but will still offer You the chance to turn it back on if You ever want to revert the changes You made.
That's it! You're done!

05.11.2010

Automatic screen rotation on HP touchsmart notebooks

Update 3: Apparently the python script which is advertised on some sites got more attention than it had when I first read about it and has even been set up as a Launchpad project. The huge CPU overhead has been taken care of (it's now event-based) and it supports more than just one laptop model. I haven't tried a new version of the script, but I guess it does the job just as fine as my script does (I can't tell which script is better). Feel free to test out both ways, I'd be happy to hear of some comparisons!

Update 2: There's a new article on this topic. I've managed to build a package out of the stuff I wrote here and made it available in my Launchpad PPA. It should be much easier to just install and configure it than to follow this whole guide. Here's the direct link to the article:
http://linuxquirks.blogspot.com/2010/11/freddeb.html

Update: According to feedback, this solution is not yet guaranteed to work, even for similar laptops. Feel free to test it and report any errors (helps me a lot), though. I will try to create an installable package out of all this, but this will take some time.

As I wrote in an earlier article, I possess an HP touchsmart tm2-1090eg notebook whichcan be turned into a tablet PC. Since the automatic screen rotation is not working out-of-the-box on Ubuntu and since I couldn't get the rotate-screen-button on the right side of the display to work yet, I've been getting by with a hand-written script. I wrote a Tcl/Tk program which uses xrandr and xsetwacom to rotate the screen according to my wishes.
By request of Felix, the first person to write a comment to this blog :), I looked into possibilities to automatically rotate the screen upon turning the display. I thought that since I managed to write an ACPI handler for CPU frequency scaling depending on the status of the power supply (there will be a post on this, too), I might give it a try. And guess what? I did it!
Unfortunately, my first guess was wrong. Turning around the display and putting it on top of the keyboard didn't create any ACPI events. However, I noticed some strange noise on dmesg:
atkbd serio0: Use 'setkeycodes e058 ' to make it known
atkbd serio0: Unknown key pressed (translated set 2, code 0xd9 on isa0060/serio0).
atkbd serio0: Use 'setkeycodes e059 ' to make it known.
atkbd serio0: Unknown key released (translated set 2, code 0xd9 on isa0060/serio0).

Hell yes, dmesg even told me what to do! Here's what I did:
  1. Find out the scan code - turn the display, put it down, pull it back up and inspect the messages:
    Code:
    $ dmesg
    There should be some messages like the ones I received. The first one is the key code from putting down the display, the second one is the code from pulling it back up.
    Note: If You don't get any messages like those, chances are that Your kernel already knows the keys. Try to bind something to them using the GNOME "Keyboard Shortcuts" or see if they generate key events by using xev.
  2. Find out which key code is available for mapping. There's no patented way for doing this. I just tried out some codes and looked what the GNOME "Keyboard Shortcuts" called the code. For me, the codes 220 and 221 worked well, since there is no button issuing these codes.
  3. Create an upstart script to set the keycodes on system startup. Setting the codes is not persistens, so You have to do it after each reboot. Use an upstart script to accomplish the job. As root, create a file /etc/init/tablet-mode.conf and put something like this inside:
    Code:
    # tablet-mode
    #
    # Map key codes to the scan codes emitted by the display when putting it down on
    # the keyboard.

    description "Tablet PC mode"
    author "Frederik Möllers"

    start on local-filesystems

    script
        setkeycodes e058 220
        setkeycodes e059 221
    end script
  4. Create a program to rotate the screen. Basically You just need to use xrandr to rotate the screen and xsetwacom to turn the tablet orientation. You can also use my Tcl/Tk program (requires wish to run, install the package if You want to use it) which also offers a GUI to use manually. Put the following code in a file (e.g. /usr/local/bin/rotatescreen, make it executable and You can call it with rotatescreen tableton and rotatescreen tabletoff. It not only turns the display and the tablet orientation but also disables the touch mode. This prevents the cursor from jumping around when You write with the stylus and touch the display with Your hand. Of course, You can customize the Tcl/Tk program to fit Your wishes. Even if You're not experienced in Tcl or Tk, the syntax should be quite easy. So here's the code:
    Code:
    #! /bin/bash
    #\
    exec wish "$0" "$@"

    proc rotate_0 {} {
       exec xrandr --output LVDS1 --rotate normal
       exec xsetwacom --set 11 rotate NONE
       exec xsetwacom --set 12 rotate NONE
       exec xsetwacom --set 13 rotate NONE
    }

    proc rotate_90 {} {
       exec xrandr --output LVDS1 --rotate left
       exec xsetwacom --set 11 rotate CCW
       exec xsetwacom --set 12 rotate CCW
       exec xsetwacom --set 13 rotate CCW
    }

    proc rotate_180 {} {
       exec xrandr --output LVDS1 --rotate inverted
       exec xsetwacom --set 11 rotate HALF
       exec xsetwacom --set 12 rotate HALF
       exec xsetwacom --set 13 rotate HALF
    }

    proc rotate_270 {} {
       exec xrandr --output LVDS1 --rotate right
       exec xsetwacom --set 11 rotate CW
       exec xsetwacom --set 12 rotate CW
       exec xsetwacom --set 13 rotate CW
    }

    proc touch_on {} {
       exec xsetwacom --set 11 Touch on
    }

    proc touch_off {} {
       exec xsetwacom --set 11 Touch off
    }

    proc quit {} {
       destroy .
       exit
    }

    if {$argc > 0} {
       switch "[lindex $argv 0]" {
          "0" {
             rotate_0
          }
          "90" {
             rotate_90
          }
          "180" {
             rotate_180
          }
          "270" {
             rotate_270
          }
          "tableton" {
             rotate_180
             touch_off
          }
          "tabletoff" {
             rotate_0
             touch_on
          }
          default {
             puts "Cannot rotate [lindex $argv 0] degrees!"
          }
       }
       exit
    }

    wm title . "Screen rotation"
    wm geometry . +605+300
    frame .deg
    button .deg.0 -text "0°" -command "rotate_0; quit"
    button .deg.90 -text "90°" -command "rotate_90; quit"
    button .deg.180 -text "180°" -command "rotate_180; quit"
    button .deg.270 -text "270°" -command "rotate_270; quit"
    pack .deg.0 .deg.90 .deg.180 .deg.270 -in .deg -pady 3 -side top
    frame .touch
    button .touch.ton -text "Touch on" -command "touch_on; quit"
    button .touch.toff -text "Touch off" -command "touch_off; quit"
    pack .touch.ton .touch.toff -in .touch -pady 3 -side top
    button .cancel -text "Cancel" -command "quit"
    pack .deg .touch .cancel -pady 6 -side top
    bind . "rotate_0; quit"
    bind . "rotate_90; quit"
    bind . "rotate_180; quit"
    bind . "rotate_270; quit"
    bind . "quit"
    bind . "quit"
    bind . "quit"
  5. Bind the keys to the program using GNOME "Keyboard Shortcuts" (or the equivalent for Your desktop manager). Create a binding with the command rotatescreen tableton and one with the command rotatescreen tabletoff and set the bindings by turning Your display, putting it down and pulling it back up.

Thanks again to Felix who told me to search for a way. I had already given up on this and didn't think I would find a way to get the screen rotation to work automatically.

That's it! You're done!

30.10.2010

HP touchsmart notebook, Intel Centrino Wireless N-1000 and no wifi

I recently tried to use my wifi card the first time on Ubuntu 10.10. I noticed that I couldn't connect to any wifi network, no matter what mode the network was (a/b/g/n) or what encryption it used. I looked around and found Ubuntu Bug #630748 and the related Kernel bug #16691 which I thought had something to do with my issue.
I couldn't be more wrong.
It turned out I couldn't get a wifi connection, because bluetooth was disabled using that small GNOME Bluetooth indicator. While bluetooth was disabled, my wifi card was able to list networks and NetworkManager could try connecting to one, however, it never succeeded. dmesg spit out some messages like "direct probe to (access point MAC address) timed out" and after some time even "iwlagn 0000:03:00.0: Microcode SW error detected. Restarting 0x2000000.".
Thanks to Zander Hill's comment in my bug report #663298, I found out that by enabling bluetooth, I could connect to wifi networks again with no problems.

So if You ever run into connectivity problems, feel free to try out everything completely unrelated to Your wifi card just to be sure.

"Modern" touchpads V2

Ubuntu 10.10 came out about 2 weeks ago. There were no big changes, at least no visibly remarkable ones. However, some things that worked in 10.04 stopped working in Maverick. One example are the new Synaptic ClickPads integrated into many of the newer notebooks such as my HP TouchSmart tm2-1090eg. According to the comments in Bug #582809, the psmouse driver module does not correctly recognize the ClickPad and treats it as a "regular" Synaptics Touchpad. Fortunately, someone going by the name of "pauls" uploaded a patched source archive for the psmouse module and posted a detailed guide how to install the new module.
I tried it and it works™!
Here's how (copied from pauls' comment in the linked bug report):
Note: You need root privileges to do most of the things
  1. Download the patched source archive
    Code:
    $ wget https://bugs.launchpad.net/ubuntu/+source/linux/+bug/582809/+attachment/1675262/+files/psmouse-2.6.35-22-generic-patched.tar.bz2
  2. Unpack the source to /usr/src/
    Code:
    $ tar -xjv -C /usr/src/ -f psmouse-2.6.35-22-generic-patched.tar.bz2
  3. Install dkms
    Code:
    $ apt-get install dkms
  4. Add the source to dkms, build it and install the module
    Code:
    $ dkms add -m psmouse -v 2.6.35-22-generic
    $ dkms build -m psmouse -v 2.6.35-22-generic
    $ dkms install -m psmouse -v 2.6.35-22-generic
  5. Reboot.
You can always check wether the module is installed using
Code:
$ dkms status -m psmouse -v 2.6.35-22-generic
If the module is not installed, You can use the steps again to rebuild and reinstall it.
You can also remove the module when a fixed kernel has been released:
Code:
$ sudo dkms uninstall -m psmouse -v 2.6.35-22-generic
$ sudo dkms remove -m psmouse -v 2.6.35-22-generic --all
For more information, updates and troubleshooting, consult the bug report and its comments.
That's it! You're done!

15.09.2010

"Modern" touchpads

My new laptop has a fancy new touchpad. The buttons are part of the pad themselves. The whole pad is a button, the action depends on where you press it down. The only thing that separates the buttons from the rest of the touchpad is a small white line (so basically nothing). The touchpad supports multitouch, which works quite well on Windows but doesn't work at all on Linux. When staying on the "button area" with one finger while trying to move the cursor with another finger, the result is a jumping pointer which does everything but move the way I want it to. I finally found a workaround.
This has been tested on my Synaptics touchpad and I have no idea wether it works for anyone else.
  1. Check your synclient values and save them somewhere.
    Code:
    $ synclient -l > synclient-values
  2. Make the touchpad area smaller so that moving the finger over the buttons doesn't move the cursor.
    Code:
    $ synclient AreaBottomEdge=<value>
    where <value> is a value between the values of BottomEdge and TopEdge. Experiment with the values until you reach the optimal result. Mine was 3836
  3. Change the value of JumpyCursorThreshold. I have no idea what exactly this value is or what exact effect changes on this value have. I only know that setting this value to 100 made my pointer much calmer than before.
    Code:
    $ synclient JumpyCursorThreshold=100
    You may find that other values provide better results for Your laptop and Your touchpad. Feel free to experiment, You can always reset the values either manually or by rebooting.
You can write a shell script and add it to Your startup programs if You want to keep the settings.
Hint: It is not possible to rotate Your touchpad orientation (could be useful if screen can be rotated), since synclient prevents You from setting values for BottomEdge that are smaller than the value of TopEdge and so on...
Hint 2: It is also impossible to change the area of the buttons. If You need to always press the bottom 0.1mm of the touchpad to perform a click, You better get used to it (or write a patch for the synaptics driver).
That's it! You're done!

28.08.2010

Ubuntu on a tablet computer

I installed Ubuntu on my new HP TouchSmart tm2-1090eg laptop. It has a cool tablet function (including a pen). Using the pen works out-of-the-box with Ubuntu 10.04. However, using the thumb-button as a right mouse click, does not. Another flaw is that the pressure curve of the pen (the curve which describes the way the default pressure on the tablet is translated into pressure of brushes in the gimp or whatever) sucks really hard. It's like an on-off-switch, but has nothing to do with pressure. Here is how to fix both things:
  1. Fix the thumb button: Edit the file /usr/lib/X11/xorg.conf.d/10-wacom.conf and in the first InputClass-Section, add the Option:
    Code:
    Option "Button2" "3"
  2. For the pressure curve, edit the same file and add something to the same section. Try out the following options (restarting X every time to see the effect) and choose the one You like the most:
    Code:
    Option "PressCurve" "0,75,25,100" # softest
    Option "PressCurve" "0,50,50,100"
    Option "PressCurve" "0,25,75,100"
    Option "PressCurve" "0,0,100,100 # linear (default)"
    Option "PressCurve" "25,0,100,75"
    Option "PressCurve" "50,0,100,50"
    Option "PressCurve" "75,0,100,25 # firmest"
    For interested users: The numbers describe a bezier curve and You can also change the values of the options via the command-line-tool xsetwacom. By using xsetwacom, the changes take effect immediately, but will be reset upon machine reboot (or driver reload).
Another side note: I managed to get the thumb button working like in Windows (only acts as right click if held down and then pressing the pen on the screen), but I don't know how and I didn't manage to save that behavior. If You know how to do this, tell me!
That's it! You're done!

No ttys after update

I installed ubuntu on a brand new laptop. I got it to work. I downloaded updates. My ttys (Ctrl-Alt-F[1-6]) were gone. Wtf? Now guess why. No, it had nothing to do with the new video card driver I installed. It didn't have anything to do with kernel modules at all.
I found the solution in some forum. I'm glad I tested it, because from what the text said, the problem that guy had fixed was something else than what I had experienced.

  1. Update the configuration for Your initrd. Edit (create if it doesn't exist) the file /etc/initramfs-tools/conf.d/splash and insert (or change if the key already exists): FRAMEBUFFER=y. Quick'n'Dirty:
    Code:
    $ echo "FRAMEBUFFER=y" >> /etc/initramfs-tools/conf.d/splash
  2. Rebuild your initrd with the new configuration:
    Code:
    $ update-initramfs -u
  3. Reboot.
  4. Look at the beautiful ttys in awe.

That's it! You're done!

UPDATE: It seems like You have to run update-initramfs every time You update Your kernel, since the initrd from the package is prebuilt without the FRAMEBUFFER=y option.
UPDATE 2: I sometimes lose my ttys even though I rebuild the initrd. No idea why.

gnome-terminal background transparency

When using gnome-terminal with unmodified settings (which means unmodified terminal profile, unmodified gnome theme and compiz activated), You might notice that the background of the terminal is slightly transparent. This is the case even if though "Solid background" is selected in the profile preferences. Wonder why? gconf is at it again! Want the background to be really solid?
/apps/gnome-terminal/profiles/Default/use_theme_background must be set to false:
Code:
$ gconftool-2 -t bool -s /apps/gnome-terminal/profiles/Default/use_theme_background false
That's it! You're done!

03.07.2010

Silence! I kill Your sound card!

It took me half a week to notice that my brand new Ubuntu installation had no sound. Turns out the driver module was loaded with the wrong option. In case You ran into the same problem (sound card was detected, everything seems fine except that there's nothing coming out of the speakers) and provided that You have an HD Audio card, here's how to get the sound back (You need to run most of the commands as root or with sudo):
  1. Determine Your sound chip
    Code:
    $ cat /proc/asound/card*/codec* | grep Codec
    Depending on Your hardware, You may get multiple lines of output (e.g. one for a modem and one for the sound card). I presume You're able to find out which one is the sound chip.
  2. Find out what options are available for the kernel module. These can be found in /usr/share/doc/alsa-base/driver/HD-Audio-Models.txt.gz. If You can't find Your specific card or are not sure which one to take, You'll have to try out some of them, especially the generic ones (like 3stack).
  3. Find out which kernel module is responsible for Your sound card.
    Code:
    $ lsmod | grep snd_page_alloc
    It's the one on the right side next to snd_pcm, mine was snd_hda_intel, for example.
  4. As root, add a line options <kernel module name> model=<model name from step 2>, to /etc/modeprobe.d/options, e.g.
    Code:
    $ echo "options snd_hda_intel model=3stack-dig" >> /etc/modprobe.d/options
That's it! You're done!

15.05.2010

Speaker trouble

For approximately 2 weeks I was searching for a way to turn off the PC speaker on my laptop. Everytime I shut down or rebooted while being logged in as root, the machine gave a loud beep. There was no pcspkr module loaded which I could blacklist.
The solution was easier than I could have imagined.
Use
Code:
$ alsamixer
on the command line and mute the Beep track.
That's it! You're done!

I feel stupid now.

23.04.2010

Ctrl-Alt-Backspace

This is nothing You won't find easily with Google, but for convenience it's here, too:
By default, the Ctrl-Alt-Backspace key combo does... nothing. In order to have it kill the X server (that's what it used to do in the good ol' times), simply use the GNOME menu and go to "System"->"Preferences"->"Keyboard"->"Layout">"Options..."->"Key sequence to kill the X server" and mark the entry.
That's it! You're done (already)!

UPDATE: There is a key in the gconf database which controls this behaviour. The preferences set this key. However, changing the value of the key for the gdm user does not enable Ctrl-Alt-Backspace during the login screen.
A workaround is to just use Alt-SysRq-K (Secure Access Key) instead of Ctrl-Alt-Backspace. The effect in GDM/GNOME is the same, as the SAK combo kills every process on the active tty.

19.04.2010

Smartcards and SSH

The standard openssh packages shipped with Ubuntu 10.04 provide no support for smartcards. In order to get either the ssh-agent or ssh itself to accept a smartcard (such as the Aladdin eToken), I needed to recompile the whole package. I have no idea why the developers included no apparent support for smartcards in the distribution, installing the necessary packages doesn't make it possible to use them in any application I know.
Here's how to get support for smartcards in openssh:
  1. Set up a directory to download and compile the sources in.
  2. If You haven't already, make sure the "Source code" checkbox is checked in software-properties-gtk or You have the right deb-src lines in Your /etc/apt/sources.list. After doing so, don't forget to execute apt-get update to update the package lists.
  3. Install all the required packages:
    Code:
    $ apt-get install build-essential libopenct1 libopensc2 libopensc2-dev openct opensc
    $ apt-get build-dep openssh
    In order to be able to use opensc as a normal user, You have to add Your regular account to the scard user group:
    Code:
    $ adduser <username> scard
    You might have to start a new shell/terminal or even log out and back in to apply the change.
  4. Now download the package into the directory You created. You can do this as an unprivileged user (I would recommend to do so). Change into the directory and execute:
    Code:
    $ apt-get source openssh
    You should now have 2 .tar.gz files, 1 .dsc file and a source directory named openssh-<version number>. Change into the directory.
  5. Make sure openssh will be compiled with smartcard support. In the debian subdirectory, there's a file named rules. This file specifies what options are passed to configure when the package is compiled. Edit the file and insert the following line:
    Code:
    confflags += --with-opensc
    The best place would be behind the first block of confflags += ... statements, titled "Common build options.", as it's essential to insert it before the line saying
    Code:
    confflags_udeb := $(confflags)
  6. Now You can compile the package. Make sure You are in the source code root directory (openssh-<version number>) and execute
    Code:
    $ debuild -us -uc
    This will build the package without signing the package itself or the .changes file.
  7. If You now go back into the directory You created (should be 1 above Your current directory), You should see several new .deb packages. Install these (for this you need root access again)
    Code:
    $ dpkg -i *.deb
  8. You're almost done. If you use GNOME, You need to stop the gnome-keyring from breaking Your ssh-agent. Doing this from command line is a pain in the arse, so just use the "Startup Applications" menu entry under "System"->"Preferences". Use the tool to disable the "SSH Key Agent". If You don't use GNOME, You just wasted Your time reading this step.
  9. Now log out and back in to make sure Your ssh-agent is killed. If You don't use GNOME, You also need to make sure it is running at all (most desktop managers start it automatically, but if You only use a console, You need to configure it Yourself).
  10. You should now be able to list the smartcard devices with
    Code:
    $ opensc-tool -l
    Ignore any error messages that might appear, it should still work just fine. 2 OpenCT reader (detached) will appear by default and if You plugged in a smartcard, it should show up as such. Use
    Code:
    $ ssh-add -s0
    (or substitute 0 with the reader number if it is different) to add Your private key to the ssh-agent.
One last note: Upon upgrading the openssh packages, You need to do all this again, of course.

That's it! You're done!

17.04.2010

New Ubuntu themes and button positions

Ubuntu 10.04 looks neat. That is, except for the position of the window control buttons (minimize, maximize, close). Probably they thought something like "Hey, if Apple does it this way, it must be good!" and placed the buttons on the left side of the window title bar.
This sucks if You don't have a Mac and aren't used to it.
Fortunately, there's a way to "simply" change the position. It involves (once again) GConf.
Either use gconftool or the gconf-editor to access the key:
Code:
/apps/metacity/general/button_layout
If You're using gconftool - the key is of type string.
You can set the key to order the buttons in almost any way you want. Just specify the order in which the items should appear in the window title bar:

menu - a button for the window menu (the menu You get when You right-click the title bar)
: (colon) - the window title (will be placed at the end if omitted)
minimize, maximize, close - the respective button

The default is "close,minimize,maximize:" and the default in earlier distributions was "menu:minimize,maximize,close".
In case You just want back the good old layout, here's the command line:
Code:
$ gconftool -t string -s /apps/metacity/general/button_layout "menu:minimize,maximize,close"
That's it! You're done!

No asterisks for passwords in gdm login window!

The GNOME Display Manager was extensively customisable - until it got rewritten. Now it's a pain the arse to change anything about the login mask. There are 2 things that I wanted to change and I finally managed to do so.
  1. Disable the user album. One disadvantage of this is that everyone can see which users exist on the computer - this might be a security concern. Another issue is that it's impossible to log in as root.
    As this setting is saved in the gconf-tree, You need to edit that. The graphical gconf-editor didn't work for me, but using the command line is faster anyway (if you know what to enter, of course):
    Code:
    $ sudo -u gdm gconftool -t bool -s /apps/gdm/simple-greeter/disable_user_list true
    If You're asked for gdm's password, try executing the command as root (still with sudo -u gdm, of course).
  2. The other issue is related to the password entry in the gdm login window. When entering the password, a black circle is displayed for every letter. This makes it possible for everyone looking to observe Your password length. To change it, You need to edit the .ui file of the simple-greeter application. Its location is:
    Code:
    /usr/share/gdm/gdm-greeter-login-window.ui
    Search for the line
    Code:
    <object class="GtkEntry" id="auth-prompt-entry">
    This seems to be some GTK data describing the user/password entry field in the login window. Following that line there's a list of <property> entries. At the end of the list, insert the following line:
    Code:
    <property name="invisible_char">&#x200B;</property>
    This sets the character which is displayed instead of the typed letters to the unicode letter 200B, which is the zero-width space character, effectively hiding anything You type into the password field. You can also set the character to anything else you like - at least any unicode letter. Using non-existant letters like 0000, however, will break Your gdm, as the gdm-greeter-login-window will fail and will not be displayed, disabling the ability to log in via gdm.
That's it! You're done!

Ubuntu's sudo policy

UPDATE: I don't recommend to follow the guide in this post any longer. It can lead to unwanted behaviour (regular users can't reboot or shut down the computer, only root can do so by using a console). A friend pointed out that as You are probably using Ubuntu as a desktop or laptop OS (There are way better distros to use as a server OS than Ubuntu!), the crucial data on the machine will probably be Your personal data (and not the system files). If someone cracks Your user account, You're screwed. If that person now gains root access by using Your user account, he doesn't gain anything.

Yay, f1rst post!
Ubuntu is quite a fine distribution, but I don't like their sudo policy. It's like Windows' administrator policy, giving a regular user full control of the system. Linux used to have a dedicated root user for changing the system's configuration. And I want it back that way.
If You think the same, there are basically 3 things You need to do to get the root user back in control:
  1. Give root a password.
    Code:
    $ sudo passwd root
  2. Change the sudoers file so sudo <command> asks for the root password instead of the user's one.
    Code:
    $ su -
    $ visudo
    Add the targetpw option to the Defaults line so it looks like this:
    Code:
    Defaults env_reset,targetpw
    A side-effect of using targetpw instead of rootpw is that sudo -u <username> <command> asks for username's password instead of the root password.
    You might also want to add timestamp_timeout=0, this option is described in the sudoers manpage. A tip: add insults for some extra fun!
    In order to enable every user to use the sudo command (not without entering the root password, of course), You also need to change the user privilege specification.
    Comment out the 2 lines beginning with %sudo and %admin and add the line:
    Code:
    ALL ALL=(ALL) ALL
    to the end of the file
  3. Change gnome's gksu. You don't really have to do this, because entering the root password in the password dialogues of gnome will still launch Synaptic or whatever program we want to use, but this is more a decorational thing. gksudo asks for the user's password, although we need to enter the root password. gksu asks for the root password (and also has the ability to save the password for a short time).
    Code:
    $ gksu-properties
    Change Authentication mode from sudo to su.
That's it! You're done!