2008年12月4日星期四

Synaptics及其他:xorg.conf一些新旧设置

Archlinux的xorg-server升级到1.5.3了,最大的变化是默认启用了hotplugging,简单说就是支持输入设备的热插拔了。各位可以去wiki看看,有很清楚的说明。

反映到xorg.conf就是所有的InputDevice都不需要了,扔这儿吧:

Section "InputDevice"
Identifier "Keyboard0"
Driver "keyboard"
Option "CoreKeyboard"
Option "XkbRules" "xorg"
Option "XkbModel" "pc105"
Option "XkbLayout" "us"
Option "XkbVariant" ""
EndSection

Section "InputDevice"
Identifier "Serial Mouse"
Driver "mouse"
Option "Protocol" "Microsoft"
Option "Device" "/dev/ttyS0"
Option "Emulate3Buttons" "true"
Option "Emulate3Timeout" "70"
Option "SendCoreEvents" "true"
EndSection
Section "InputDevice"
Identifier "PS/2 Mouse"
Driver "mouse"
Option "Protocol" "auto"
Option "ZAxisMapping" "4 5"
Option "Device" "/dev/psaux"
Option "Emulate3Buttons" "true"
Option "Emulate3Timeout" "70"
Option "SendCoreEvents" "true"
EndSection

Section "InputDevice"
Identifier "USB Mouse"
Driver "mouse"
Option "Device" "/dev/input/mice"
Option "SendCoreEvents" "true"
Option "Protocol" "IMPS/2"
Option "ZAxisMapping" "4 5"
Option "Buttons" "5"
EndSection
Section "InputDevice"
Driver "synaptics"
Identifier "Touchpad"
Option "Device" "/dev/input/mouse1"
Option "Protocol" "auto-dev"
Option "LeftEdge" "1700"
Option "RightEdge" "5300"
Option "TopEdge" "1700"
Option "BottomEdge" "4200"
Option "FingerLow" "25"
Option "FingerHigh" "30"
Option "MaxTapTime" "180"
Option "MaxTapMove" "220"
Option "VertScrollDelta" "100"
Option "MinSpeed" "0.06"
Option "MaxSpeed" "0.12"
Option "AccelFactor" "0.0010"
Option "SHMConfig" "on"
# Option "Repeater" "/dev/ps2mouse"
Option "CircularScrolling" "on"
Option "CircScrollTrigger" "0"
EndSection
当然,别忘了删除ServerLayout字段中的相关内容。

触摸板synaptics驱动需要安装xf86-input-synaptics,老的不知在哪一次升级的时候被卸掉了,害我折腾了一会儿,也怪我没重新看一下wiki。以下是我的新配置文件:
<?xml version="1.0" encoding="ISO-8859-1"?>
<deviceinfo version="0.2">
<device>
<match key="info.capabilities" contains="input.touchpad">
<match key="info.product" contains="SynPS/2 Synaptics TouchPad">
<merge key="input.x11_driver" type="string">synaptics</merge>
<!-- Arbitrary options can be passed to the driver using
the input.x11_options property since xorg-server-1.5. -->
<!-- EXAMPLE:
<merge key="input.x11_options.LeftEdge" type="string">120</merge>
-->
<merge key="input.x11_options.Protocol" type="string">auto-dev</merge>
<merge key="input.x11_options.LeftEdge" type="string">1700</merge>
<merge key="input.x11_options.RightEdge" type="string">5300</merge>
<merge key="input.x11_options.TopEdge" type="string">1700</merge>
<merge key="input.x11_options.BottomEdge" type="string">4200</merge>
<merge key="input.x11_options.FingerLow" type="string">25</merge>
<merge key="input.x11_options.FingerHigh" type="string">30</merge>
<merge key="input.x11_options.MaxTapTime" type="string">180</merge>
<merge key="input.x11_options.MaxTapMove" type="string">220</merge>
<merge key="input.x11_options.VertScrollDelta" type="string">100</merge>
<merge key="input.x11_options.MinSpeed" type="string">0.06</merge>
<merge key="input.x11_options.MaxSpeed" type="string">0.12</merge>
<merge key="input.x11_options.AccelFactor" type="string">0.0010</merge>
<merge key="input.x11_options.SHMConfig" type="string">true</merge>
<merge key="input.x11_options.CircularScrolling" type="string">on</merge>
<merge key="input.x11_options.CircScrollTrigger" type="string">0</merge>
<merge key="input.x11_options.TapButton1" type="string">1</merge>
<merge key="input.x11_options.TapButton2" type="string">2</merge>
<merge key="input.x11_options.TapButton3" type="string">3</merge>
</match>
<match key="info.product" contains="AlpsPS/2 ALPS">
<merge key="input.x11_driver" type="string">synaptics</merge>
</match>
<match key="info.product" contains="appletouch">
<merge key="input.x11_driver" type="string">synaptics</merge>
</match>
<match key="info.product" contains="bcm5974">
<merge key="input.x11_driver" type="string">synaptics</merge>
</match>
</match>
</device>
</deviceinfo>
默认配置是/usr/share/hal/fdi/policy/10osvendor/11-x11-synaptics.fdi,复制到/etc/hal/fdi/policy/,再把老的配置项添加进去。型号(如SynPS/2 Synaptics TouchPad)可以用以下命令查到(参见wiki):
hal-device|grep -B 15 input.x11.driver
如我的机器上显示是这样的:
--
input.x11_options.MaxTapMove = '220' (string)
input.x11_options.VertScrollDelta = '100' (string)
input.x11_options.MinSpeed = '0.06' (string)
linux.sysfs_path = '/sys/class/input/input8/event8' (string)
linux.device_file = '/dev/input/event8' (string)
input.x11_options.MaxSpeed = '0.12' (string)
info.parent = '/org/freedesktop/Hal/devices/platform_i8042_i8042_AUX2_port' (
string)
input.x11_options.AccelFactor = '0.0010' (string)
input.x11_options.SHMConfig = 'true' (string)
input.x11_options.CircularScrolling = 'on' (string)
input.x11_options.CircScrollTrigger = '0' (string)
input.device = '/dev/input/event8' (string)
input.x11_options.TapButton1 = '1' (string)
input.product = 'SynPS/2 Synaptics TouchPad' (string)
input.x11_options.TapButton2 = '2' (string)
input.x11_driver = 'synaptics' (string)


论坛上也有一些配置(15楼)可以参考。

另外,再附送一个小脚本,可以快速开关Synaptics,我把它绑定到了Fn+1:
#!/bin/bash

Status=$(synclient -l | grep TouchpadOff | tr -d [:blank:])

eval $Status

if [ "$TouchpadOff" = "0" ]
then
synclient TouchpadOff=1
elif [ "$TouchpadOff" = "1" ]
then
synclient TouchpadOff=0
fi
另外,好象已经可以不用xorg.conf了,但我的还不行,不知是否没装开源ati驱动的缘故(只有fglrx)。

KDE快捷键与keyboard layout的问题

近日arch的xorg-server升级到1.5.3,默认使用hotplugging。问题是方向键等许多按键失灵了,论坛上说需要在KDE系统设置->地区和语言->键盘布局中使用键盘布局"Evdev-managed keyboard",一试之下,果然好多了。只是系统的一些快捷键依旧无法使用,比如无须确认注销。

系统设置->键盘和鼠标->键盘快捷键重新设置一下,又可使用了。想起这个问题以前配置xmodmap时就碰到过。简单测试一下后,可以确认,键盘布局(映射)必须在KDE启动之前应用,否则就会出现这种情况。虽然有一些其他的考虑,如键盘布局切换后,按键都变了,原来的快捷键可能不是你需要的。但我依然认为这是个Bug(我已经去官网确认了),我们需要全局快捷键机制(比如用于快速切换键盘布局,有人就遇到了麻烦),每个键盘布局也应该可以有自己的快捷键,而不是象现在这样直接罢工。

解决很简单,在上述系统设置中禁用键盘布局,而把它放到.xinitrc中,下面是我的配置:

# SCIM
export LC_ALL=zh_CN.utf8
export XMODIFIERS=@im=SCIM
export GTK_IM_MODULE="scim"
export QT_IM_MODULE="scim"
scim -d

# 键盘设置
xmodmap ~/.Xmodmap

# 关闭触摸板
synclient TouchpadOff=1

# 键盘绑定
xbindkeys &

setxkbmap -keycodes evdev -model evdev

exec startkde

2008年11月19日星期三

欲练神舟,必先自宫

我的神舟笔记本买了2年多了,一直没什么大问题,只是对Linux的支持不太友好,以下几个问题一直没解决:

  • 关机时不能切断电源,尝试过各种命令和内核参数(acpi=off noapic)。在休眠时也有这个现象。
  • 在启用acpi的情况下,Fn组合键调节屏幕亮度、关闭显示器等无效。
所有这些问题,其实只要一个内核参数就可以解决,只是你要先自宫,把你的双核变单核。

在你的grub配置文件menu.lst中kernel字段添加:
kernel /vmlinuz26 root=/dev/sda2 ro nosmp
nosmp也可以换成maxcpus=0,经尝试maxcpus=1虽然cpuinfo显示cpu cores为1,但似乎cpu编号为cpu1而非cpu0,老问题依然存在。

对于日常的普通应用,应该影响不大,除非你用的是gentoo,经常要编译东西。

我曾经尝试过acpi解决(有修订)而未果,最近似乎找到了原因,结合上述关闭acpi的实践,应该可以确认是dsdt的一个error引起,但目前没有解决办法。详情还请看那篇文章中错误信息第3条。

所以,自宫似乎是目前最好的解决办法。

2008年11月17日星期一

Archlinux上编译自己的QT

Arch更新频繁,为了保持稳定和可控,决定自己编译该死的QT。

首先chroot到移动硬盘上的测试系统

sudo chroot /mnt/ /bin/su - foo
qt的源码包比较大(99M),建议单独用下载工具下载,下载PKGBUILD,修改以符合自己需要,我这里去掉了几个快捷方式(desktop文件)以及安装(make install)后的处理,同时编译demos、examples和docs:
# $Id$
# Maintainer: Pierre Schmitz

pkgname=qt
pkgver=4.4.3
pkgrel=2
_qtcopyver=880178
pkgdesc="The QT gui toolkit."
arch=('i686' 'x86_64')
url="http://www.trolltech.com/products/qt"
license=('GPL3')
options=('!libtool' '!docs')
depends=('libpng' 'libxi' 'mesa' 'fontconfig' 'libxrandr' 'glib2' 'libtiff' 'libmng' 'sqlite3' 'dbus' 'libxcursor' 'libxinerama')
optdepends=('postgresql-libs' 'libmysqlclient' 'unixodbc')
makedepends=('inputproto' 'postgresql-libs' 'mysql' 'unixodbc' 'cups' 'libxfixes')
provides=("qt4=${pkgver}")
replaces=('qt4')
conflicts=('qt4')
_pkgfqn=qt-x11-opensource-src-$pkgver
# svn export -r -${_qtcopyver} svn://anonsvn.kde.org/home/kde/trunk/qt-copy/patches/ qt-copy-patches-${_qtcopyver}
source=("ftp://ftp.trolltech.com/qt/source/${_pkgfqn}.tar.bz2"
"ftp://ftp.archlinux.org/other/qt/qt-copy-patches-${_qtcopyver}.tar.bz2")
md5sums=('00e00c6324d342a7b0d8653112b4f08c'
'd3a40d783528a86174b62ecfc136b031')

build() {
# 按源码的INSTALL文件,其实不需要为编译设置变量
unset QMAKESPEC
export QT4DIR=$srcdir/$_pkgfqn
export PATH=${QT4DIR}/bin:${PATH}
export LD_LIBRARY_PATH=${QT4DIR}/lib:${LD_LIBRARY_PATH}

cd $srcdir/$_pkgfqn
for i in $srcdir/qt-copy-patches-${_qtcopyver}/*; do
echo "applying $i"
patch -p0 -i $i || return 1
done

# remove unwanted mkspecs
cd mkspecs/
find . -maxdepth 1 -regextype posix-egrep -type d ! -regex "./linux.*|./common|./features|./qws" -exec rm -rf "{}" \;
cd qws
find . -maxdepth 1 -regextype posix-egrep -type d ! -regex "./linux.*" -exec rm -rf "{}" \;
cd ../../

sed -i 's|-cp -P -f|-cp -L -f|' qmake/Makefile.unix
sed -i "s|-O2|$CXXFLAGS|" mkspecs/common/g++.conf
# fix postgres build
sed -e '/pg_config --libs/d' -i configure
# do not compile demos, examples and docs

# prefix很重要,qt严重依赖,且以后不能更改
./configure -confirm-license \
-prefix /home/foo/qt4.4.3 \
-no-exceptions \
-plugin-sql-{psql,mysql,sqlite,odbc} \
-system-sqlite \
-dbus-linked \
-webkit \
-no-separate-debug-info \
-assistant-webkit \
-system-libpng \
-system-libjpeg \
-system-zlib \
-openssl-linked \
-cups \
-reduce-relocations \
-xinerama \
-xcursor \
-xfixes \
-optimized-qmake || return 1

make || return 1
make INSTALL_ROOT=$pkgdir install || return 1
}
开始编译:
makepkg -s -r
人品不好,一开始就报错
/dev/null: Permission Denied
knoppix的wiki上有详细的说明,简单说就是,mount的时候需要dev参数:
mount -o remount,dev /dev/hda1
接下来,就一切顺利了,2个多小时后,顺利生成qt-4.4.3-2-i686.pkg.tar.gz,你可以使用pacman -U安装,不过我是解压后移动到相应目录。

2008年11月16日星期日

Qt的安装路径问题

真他妈BS啊,许多关键的路径居然都是绝对路径且hard coded,将安装目录换个地方就出错,唯一的值得安慰的是商业版也这样

Hi,

I had that problem with Commercial Edition as well. I asked Trolltech for
support, they told me, I'd have to recompile all but examples, tutorials
and demos :-(

sorry to say that,
regards,
Malte
qtcn上也有人问起,结论也是NO WAY!

这些家伙脑瓜进水了么,知道编译一次要多少时间吗?

2008年11月15日星期六

emacsclient(w)和gnuclient(w)

Emacs有一个Server-Client模式,如果你是码字狂人,同时编辑好几个文件,这就很有用了,比如你在网上发帖子,就可以在Firefox中将文本发送到Emacs中进行编辑,是的,我知道你离不开Emacs,人不能没有信仰啊。


Windows上,我原本使用的是gnuclient(w),XEmacs自带的。我在Live Drive上有个备份,安装很简单,exe文件放bin目录,el文件放到site-lisp目录就可以了。在配置文件中添加如下代码:
(load "gnuserv")
(gnuserv-start)
启动的时候,用gnuclientw.exe -s代替runemacs.exe启动。

事实上,Emacs自22.1以后也自带了类似工具:emacsclient(w),虽然有点小问题,不过个人还是倾向于使用原配,纯粹个人喜好,就象我使用Windows画图多过photoshop。既然是自带的,就没有安装问题了,配置也很简单,只要1句配置就可以使用了:
(server-start)
只有把Emacs集成到Windows右键菜单,这一切才算完整。你需要的只是一个注册表文件,下面是gnuclient(w)的:
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell]
@="*"

[HKEY_CLASSES_ROOT\*\shell\emacs]
@="用Emacs打开..."

[HKEY_CLASSES_ROOT\*\shell\emacs\command]
@="D:\\Programs\\ntemacs23\\bin\\gnuclientw.exe -s \"%1\""

[HKEY_LOCAL_MACHINE\SOFTWARE\GNU\Emacs]
"HOME"="D:\\foo\\Home"
emacsclient(w)的如下:
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell]
@="*"

[HKEY_CLASSES_ROOT\*\shell\emacs]
@="用Emacs打开..."

[HKEY_CLASSES_ROOT\*\shell\emacs\command]
@="D:\\ntemacs\\bin\\emacsclientw.exe -a \"D:\\ntemacs\\bin\\runemacs.exe\" \"%1\""

[HKEY_LOCAL_MACHINE\SOFTWARE\GNU\Emacs]
"HOME"="D:\\foo\\Home\\"
上面提到过emacsclient(w)有点小问题,就是这里设置的HOME目录似乎对emacsclient(w)不起作用,必须设置HOME变量才可以,还有就是如果Emacs事先未打开,会弹出一个对话框报告connet: No error,确定后就可以正常打开了,不过这个文件不是通过emacsclient(w)打开的,而是runemacs,所以关闭该buffer用的也不是C-x #,这点gnuclient(w)做得完美,反正只要用gnuclient(w)替代runemacs启动就可以了,它的buffer关闭也跟普通buffer一样,而不是C-x #

不过我觉得这是个小问题,不是么?而且可能跟我用的Emacs 23比较老有关,ntemacs很久没更新了,emacs.cn又挂了:( ,因为我看到了这个讨论,不过也并不完全一样,我是在废话么......

2008年11月9日星期日

老爷机是每个高手的恶梦

帮同事的电脑重装了一下系统,差点毁了我“电脑高手”的一世英名,谨以此文记之。

一台老爷机,联想天禧6220,赛扬II 800M CPU,128内存,20G硬盘。

差点毁在硬盘上,还兼有灵异事件发生。一开始就发现硬盘有问题,因为启动时会进行分区自检,而且是检查到一半就不动了,有时想跳过自检都不行,明明按任意键取消自检还有5-6秒,可不知是键盘失去了相应还是什么原因,还是开始自检了,然后死机,于是反复重启若干遍,终于侥幸进入了系统,但桌面出来后,等待系统相应鼠标事件还是曼德拉,无奈重装系统。使用雨林木风的ghost光盘系统,每次都在5%的地方出错,然后重启。无法进入PE系统,应该是内存不够。用PQmagic 8.5 分区,依然如故。用DM 9.57分区,终于顺利通过了那该死的5%,以为OK了,出去抽了根烟回来,发现又自动重启了,没ghost完。只能尝试安装版,手头没XP的,用了一张2000 sp4的,虽然很慢,还是顺利装上了。进入系统,磁盘管理,分区,然后就是直接不能格式化,除非把这些问题分区隐藏或删除,否则系统就会不时卡住。事件日志里记录了两件事:硬盘的fireware太老可能会影响性能,硬盘有block错误。用系统自带的chkdsk在最后一步检查空闲空间时过了50%就很慢,最后90%多终于象是死了,我要下班了,关机。

看到一款软件HD Tune,试用之下非常棒,当然我知道我火星了,用它查硬盘坏扇区(快速检查)速度飞快,摸清了10G以后的地方已是满目苍痍,不堪复用,再度祭出DM 9.57,修改了硬盘的容量参数,彻底跟那后10G说拜拜。再度尝试ghost,还是失败,现在是连ghost都进不去了,一切似乎更糟了。再次重装被破坏的2000,还好这招依然有效,进入磁盘管理分区,一切顺利。装上maxdos 7.0,将镜像文件拷贝的D盘,使用maxdos引导,手动ghost,等待,5分钟后,本电脑高手的名节终于保住了。

装的是XP SP3,除了在设备管理器里根本看不到网卡,一切完美。长江后浪小谢查察之下说那是内置猫,没有XP下的驱动,下了几个都装不上。不管它了,反正事主根本不要求上网。查看内存使用,开机后什么都不做,稳定下来后在70M左右,令人称奇。发现原配显示器应该是15寸的,把分辨鋝调到800x600后,一般的文件夹操作简直可以用比较流畅来形容了。

后记:后来发现雨林木风光盘ghost失败还是一桩疑案,进入winpe桌面,将gho文件拷到硬盘,在PE中进行ghost,则一切正常,此案疑点在于若是光盘错误,gho镜像文件如何拷得出?若是机器问题,则试过新老多款机器,问题都一样。

Flash的10全9美

Flash Player 10 For Linux推出已经有一段时间了,有人在欢呼“Linux在Flash播放器领域终于成为了主流的操作系统了”,昨日试用之下,优点还没发现,倒是一上优酷就会崩溃,这可是我现在的主力视频站点。其他如56去了一趟火星之后,已经处女膜修复了,tudou速度慢,视频大小也似乎有限制,经常集分上下,youtube也是这个问题。

于是毫不犹豫换回了flash 9.0.124,不过找这个版本可是花费了一段时间,有同样需要的朋友可以看这里,虽然官网上已经找不到链接了,看来文件还在。

Update:再一次Arch升级后,一播放flash video,Firefox就僵死,初以为Firefox或flash player版本问题,遂皆升级到最新版,问题依旧,又一日,在次系统升级后,问题解决。所以现在我也已用上了flash 10.0.15

2008年10月11日星期六

wine成功魔兽争霸

我用的是1.20d绿色免CD版,注意2个问题:

  1. 将Movies文件夹改名或者干脆移除。这里面都是开场动画,Divx格式的,目前wine还不支持(据说Cedega有支持)。如果你运行后发现有声音无画面(黑屏),就是这个原因了。
  2. 如果游戏非常卡,请使用opengl。魔兽争霸默认使用DirectX,这个对wine来说,有点勉为其难了。
    WINEDEBUG=-all wine "C:\\Program Files\\Warcraft III\\Warcraft III.exe" -opengl
    使用该参数还有一个好处,如果你使用的是ATI闭源驱动,KDE4下开启特效也不会屏闪了。
顺便找了几个图标作快捷方式。

2008年9月23日星期二

挂载archlinux的img文件

1. 先查看第一个空闲loop设备
sudo losetup -f
/dev/loop0
2. 使用上一步得到的设备名,第一次创建loop设备
sudo losetup /dev/loop0 archlinux-2008.06-core-i686.img
3. 查看信息
sudo fdisk -lu /dev/loop0

Disk /dev/loop0: 322 MB, 322469376 bytes
53 heads, 12 sectors/track, 990 cylinders, total 629823 sectors
Units = sectors of 1 * 512 = 512 bytes
Disk identifier: 0x00000000

      Device Boot      Start         End      Blocks   Id  System
/dev/loop0p1   *          63      629822      314880   83  Linux
Partition 1 has different physical/logical beginnings (non-Linux?):
     phys=(0, 1, 1) logical=(0, 5, 4)
Partition 1 has different physical/logical endings:
     phys=(39, 52, 12) logical=(990, 15, 3)
我们可以看到,该镜像只有一个分区(loop0p1),从第63扇区开始(Start列),每扇区512字节(Units = sectors of 1 * 512 = 512 bytes),我们算出offset,下面mout命令会用到:
63*512=32256
4. mout
sudo losetup -o 32256 /dev/loop1 archlinux-2008.06-core-i686.img
sudo mount -o loop /dev/loop1 /mnt/
ls /mnt/
addons  archlive.sqfs  boot  lost+found
事实上,fdisk可以直接查看img文件(虽然功能不全,下面会说到),mount可以自动创建loop设备,所以上面步骤可以简化为:

I. 查看信息
sudo fdisk -lu archlinux-2008.06-core-i686.img
You must set cylinders.
You can do this from the extra functions menu.

Disk archlinux-2008.06-core-i686.img: 0 MB, 0 bytes
53 heads, 12 sectors/track, 0 cylinders, total 0 sectors
Units = sectors of 1 * 512 = 512 bytes
Disk identifier: 0x00000000

                          Device Boot      Start         End      Blocks   Id  System
archlinux-2008.06-core-i686.img1   *          63      629822      314880   83  Linux
Partition 1 has different physical/logical beginnings (non-Linux?):
     phys=(0, 1, 1) logical=(0, 5, 4)
Partition 1 has different physical/logical endings:
     phys=(39, 52, 12) logical=(990, 15, 3)
第一行抱怨不能得到cylinders,原因是普通文件上没有实现ioctl操作,我们可以看到0 cylinders,但这对我们不重要,关键是我们依然可以得到第一个分区(archlinux-2008.06-core-i686.img1)的偏移值

II. 直接mount
sudo mount -o loop,offset=32256 archlinux-2008.06-core-i686.img /mnt/
ls /mnt/
addons  archlive.sqfs  boot  lost+found