Wednesday, September 02, 2009

Disable touchpad when USB Mouse connected on Ubuntu (Jaunty)

Do you have problem with Synaptics touchpad Palm detection? Do you accidentally touch the touchpad while typing? On Windows Vista, there is an option to disable touchpad when USB Mouse connected, but how to do that on Ubuntu? Here's how I 'properly' did it on my Ubuntu 9.04 (Jaunty).
  • Create a Dbus signal handler script using Python. Here's the script
#!/usr/bin/python

global DeviceName, AddAction, RemoveAction, bus, hal_manager

#DeviceName = 'usb_device_15ca_c3_noserial_if0_logicaldev_input'
DevicePattern = r'usb_device.*_input'
DeviceCap = 'input.mouse'
AddAction = '/usr/bin/gconftool --set --type=bool /desktop/gnome/peripherals/mouse/touchpad_enabled false'
RemoveAction = '/usr/bin/gconftool --set --type=bool /desktop/gnome/peripherals/mouse/touchpad_enabled true'

import dbus # needed to do anything
import dbus.decorators # needed to receive messages
import dbus.glib # needed to receive messages
import gobject # needed to loop & monitor
import os # needed to
import re, time

DeviceRe = re.compile(DevicePattern, re.IGNORECASE | re.DOTALL)

#@dbus.decorators.explicitly_pass_message
def add_device(*args, **keywords):
Path = args[0].split('/')
device_obj = bus.get_object('org.freedesktop.Hal', args[0])
device = dbus.Interface(device_obj, dbus_interface = "org.freedesktop.Hal.Device")

cap = device.QueryCapability(DeviceCap)

if cap and DeviceRe.match(Path[-1]) :
os.system(AddAction)

#@dbus.decorators.explicitly_pass_message
def remove_device(*args, **keywords):
Path = args[0].split('/')
try :
device_obj = bus.get_object('org.freedesktop.Hal', args[0])
device = dbus.Interface(device_obj, dbus_interface = "org.freedesktop.Hal.Device")
cap = device.QueryCapability(DeviceCap)
except :
# assume true, since device might be already removed
cap = True

if cap and DeviceRe.match(Path[-1]) : # Device found
os.system(RemoveAction)

bus = dbus.SystemBus() # connect to system bus
hal_manager_obj = bus.get_object('org.freedesktop.Hal', '/org/freedesktop/Hal/Manager')
hal_manager = dbus.Interface(hal_manager_obj, 'org.freedesktop.Hal.Manager')

# Add listeners for all devices being added or removed
bus.add_signal_receiver(add_device, 'DeviceAdded', 'org.freedesktop.Hal.Manager',
'org.freedesktop.Hal', '/org/freedesktop/Hal/Manager')
bus.add_signal_receiver(remove_device, 'DeviceRemoved', 'org.freedesktop.Hal.Manager',
'org.freedesktop.Hal', '/org/freedesktop/Hal/Manager')

# Run remove action once to enable touchpad
os.system(RemoveAction)
time.sleep(1)

# Find mouse first
udis = hal_manager.FindDeviceByCapability('input.mouse')
for udi in udis :
Path = udi.split('/')
if DeviceRe.match(Path[-1]) : # Check if this is our prefer mouse
os.system(AddAction)
break # no need to keep looking

# monitor
loop = gobject.MainLoop()
loop.run()
  • If you wonder how I got the HAL path of USB mouse, try connecting your mouse and do "lshal", look for "Mouse" and see how your path looks like. Change the path properly if the default one is not match.
  • Add the script to run when log-in by going to System->Start up Applications
  • Log-out and re-Log-in again. That's it.
Another way to do this is to handle it in UDEV. However, I found that GNOME will always try to enable it back that way. Besides, UDEV is run by root, but touchpad setting is per-user. Disabling Touchpad permanently (in Mouse setting) and use synclient to control touchpad is another way to go.

Saturday, August 01, 2009

View a movie on PS3 with decent Subtitle

Most of the method I found when I search for "AVCHD Subtitle .sub" which point me to either mkv2vob or tsMuxer. Most of them refer to text base subtitle (.srt) file which is good for English base subtitle. But for me I'm Thai. If possible, I would love to have the method that works for picture-base Thai subtitle. Don't ask why I am not converting this file to text base subtitle, there is no free good Thai OCR available to do that (yet).

And at last I found it. With the following toolchain you can create an AVCHD content to be played on PS3 with subtitle on/off capability, using picture-base subtitle taken from Bluray disc!
  • BDSup2Sub - Use this tool to convert .sub and .idx distributed in the Internet back to PGS .sup file (BD subtitle). Don't forget to change the resolution. I think it should be possible too to take this from a BD movie directly (but I rarely found anyone distribute subtitle file in .sup format, since .sub works well computer-base player like VLC or Media Player Classic).
  • tsMuxer - As with normal AVCHD creation, use tsMuxer to mux MKV video and audio stream, then select add and add .sup subtitle file created above. If you have a compatible MKV (H264+(AC3 or DTS)), the conversion takes only about 5-10 minutes. I would recommend writing directly to your external hard drive where you will use to plug to PS3, since speed here depend mostly on hard drive speed.
  • AVCHDMe - After the the creation of AVCHD, use AVCHDMe to make sure that the created AVCHD is playable on PS3. Mostly this only concern 8.3 file name, so I guess just renaming the file manually may work.
With this, I can view HD content with decent translation on screen. The only problem I face is that the movie has been pushed back up to top of screen, leaving a blank black panel on the bottom (instead of black panel on both top and bottom). Other than that, everything seems fine.

Tuesday, March 17, 2009

MBPurple 0.2.1 for PortableApps

New Microblog-Purple for Pidgin 2.5 PortableApps, where you can store your Pidgin on thumbdrive and bring it wherever you go, is released! Download it here

Thanks to rottnkorpse for very quick help!

Sunday, March 15, 2009

Adium port for MBPurple released!

Thanks for @jsippel for your hard work. Now the first release of Adium port for #mbpurple is here (base on 0.2.1). Enjoy!

Friday, March 13, 2009

Using PS3 to view MKV with Thai Subtitle

No, the subject is misleading. Actually I found no viable solution for viewing MKV on PS3 properly. Many will thought that I found a way to do this on Linux, but no.

The problem is sound driver. It seems that with latest mplayer-ps combination with spu-medialib, HD MKV can be viewed without any problem. (not to mention that latest mplayer now has improve x264 support + multi-thread decode on ffmpeg!). However, sound driver for any PS3-base Linux support only 2 channels!

The method I am using right now is very simple. I use mkv2vob to translate the MKV file into AVCHD-compatible format on my 80GB USB HDD. mkv2vob also handle size-limit on FAT32 by separating file into small pieces. The only problem lies in subtitle. I want the thai subtitle to be displayed on PS3!

The solution is to use SSA sub, with Thai font specified in SSA, and then use mkv2vob with "load subtitle file" enabled!. I tested this with Eagle Eye and it worked well! Thai subtitle displayed correctly on my TV screen!

The only problem is that movie screen is not in the middle of my TV. I saw on some forum said that this was because the size of original MKV file is not exact 720p or 1080p. Anyway it is a very minor point, at the least we have lots of space for subtitle.

Friday, January 23, 2009

PackageManagerCheatsheet - Naked Ape Wiki

PackageManagerCheatsheet - Naked Ape Wiki

This page include Debian, Red Hat, Sun package management cheatsheet.