Gentoo Linux on T43 (17) VGA输出

接口 VGA 的输出可以利用xrandr 命令控制,这个软件包应该已经跟随xorg-x11安装好了。 通过xrandr 命令的输出,知道T43支持以下视频接口: VGA DVI LVDS S-video VGA接口在笔记本右侧,可外接显示器、投影仪等VGA 设备。 DVI接口在产品的spec中并没有声称支持,机身也找不到借口,但可以被检测到,猜测笔记本内可能存在相关的硬件。 LVDS就是内置的液晶屏接口。 S-video在USB接口旁边,我从未测试过。 xrandr...

接口

VGA 的输出可以利用xrandr 命令控制,这个软件包应该已经跟随xorg-x11安装好了。

通过xrandr 命令的输出,知道T43支持以下视频接口:

  • VGA
  • DVI
  • LVDS
  • S-video

VGA接口在笔记本右侧,可外接显示器、投影仪等VGA 设备。

DVI接口在产品的spec中并没有声称支持,机身也找不到借口,但可以被检测到,猜测笔记本内可能存在相关的硬件。

LVDS就是内置的液晶屏接口。

S-video在USB接口旁边,我从未测试过。

xrandr

不带参数的xrandr 命令会列出系统支持的视频接口名称和设备连接情况。

$ xrandr
Screen 0: minimum 320 x 200, current 1400 x 1050, maximum 1400 x 1200
VGA-0 disconnected (normal left inverted right x axis y axis)
DVI-0 disconnected (normal left inverted right x axis y axis)
LVDS connected 1400x1050+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
1400x1050      50.0*+
1280x1024      59.9  
1024x768       60.0     59.9  
800x600        60.3     59.9  
640x480        59.9  
S-video disconnected (normal left inverted right x axis y axis)

用以下命令将视频输出发送到某个接口设备。

 $ xrandr --output VGA-0 --auto

用以下命令关闭某个接口设备的视频输出。

 $ xrandr --output VGA-0 --off

Fn+keys

下面的脚本用于Fn+F7 控制VGA 输出的转换,脚本会自动搜索connected 到VGA输出的设备(包含内置液晶屏LVDS;S-video可能会支持,但未做测试),并顺序将显示输出到每一个设备,同时关闭所有其它设备的输出,这其中还包含一个将所有设备打开的步骤,整个过程循环。

00001007)
# Fn + F7 (Switch VGA/DVI/LVDS/S-video)
default=LVDS
# 1: connected and online
# 0: connected but not online
# N: disconnected
# i.e. "VGA-0 0 DVI-0 N LVDS 1 S-video N"
#screen=$(/usr/bin/xrandr |awk '/connected| \+|\*\+/ { \
#            if (match($2, /^connected$/) > 0) {printf $1 FS; next} \
#            else if (match($2, /^disconnected$/) > 0) {print $1, "N"; next} \
#            else if (match($0,/\ \+/) > 0) {print "0"} \
#            else if (match($0,/\*\+/) > 0) {print "1"} }')
screen=$(/usr/bin/xrandr |awk '/connected| \+|\*\+/ { if (match($2, /^connected$/) > 0) {printf $1 FS; next} else if (match($2, /^disconnected$/) > 0) {print $1, "N"; next} else if (match($0,/\ \+/) > 0) {print "0"} else if (match($0,/\*\+/) > 0) {print "1"} }')
#screen="VGA-0 0 DVI-0 N LVDS 1 S-video N"
arr_output=($(echo $screen |xargs -n2 |awk '{print $2 == "N"?"":$1}')) # connected screens
arr_status=($(echo $screen |xargs -n2 |awk '{print $2 == "N"?"":$2}')) # 1: online; 0: offline
logger -t "$0" "Supported Output: $(echo $screen |xargs -n2 |cut -d' ' -f1 |xargs)"
logger -t "$0" "Connected Output: $(echo $screen |xargs -n2 |awk '{ if ($2 == 1) print $1"*"; else if ($2 == 0) print $1 }' |xargs)"
[[ $(echo ${arr_status[@]} |xargs -n1 |awk /1/ |wc -l) -eq ${#arr_status[@]} ]] && all_online=1
[[ $(echo ${arr_status[@]} |xargs -n1 |awk /0/ |wc -l) -eq ${#arr_status[@]} ]] && all_offline=1
if [[ $all_offline -eq 1 ]] ; then
xrandr --output $default --auto
return
fi
[[ ${#arr_output[@]} -ne ${#arr_status[@]} ]] && return 1
[[ ${#arr_output[@]} -le 1 ]] && return
i=0
while [[ $i -le ${#arr_output[@]} ]]
do
next=$((i + 1))
[[ $next -ge ${#arr_output[@]} ]] && next=0
if [[ ${arr_status[$i]} -eq 1 ]] ; then
if [[ ${arr_status[$i]} -eq 0 && $all_online -ne 1 ]] ; then
logger -t "$0" "Switching all outputs on: ${arr_output[@]}"
for output in ${arr_output[@]}
do
xrandr --output $output --auto
done
break
fi
logger -t "$0" "Switching ${arr_output[$next]} off"
xrandr --output ${arr_output[$next]} --auto
logger -t "$0" "Switching ${arr_output[$i]} on"
xrandr --output ${arr_output[$i]} --off
break
fi
i=$((i + 1))
done
;;
 

上面这段脚本用于acpi的事件处理,这部分内容请查看Fn + Keys

下载

以上脚本包含在/etc/acpi/default.sh ,请根据自己的情况提取使用。

参考资料

 

Gentoo Linux on T43 (16) 蓝牙传输文件

通过蓝牙,可方便的实现与其它设备交换文件,接驳蓝牙耳机,组建局域网,甚至利用蓝牙连接移动设备进行拨号。我的需求不多,仅实现了与其它蓝牙设备双向传输文件,下面是我用到的应用程序、方法以及资源。 配置内核 内核的配置参考了Thinkwiki。 应用程序 我用到了以下软件包: net-wireless/bluez-libs-3.36  (库文件) net-wireless/bluez-utils-3.36 (基础配置工具,蓝牙系统服务) dev-libs/openobex-1.3 (库文件) app-mobilephone/obex-data-server-0.3.2 (bluez-gnome依赖它) gnome-extra/gnome-vfs-obexftp-0.4 (bluez-gnome依赖它) ...

通过蓝牙,可方便的实现与其它设备交换文件,接驳蓝牙耳机,组建局域网,甚至利用蓝牙连接移动设备进行拨号。我的需求不多,仅实现了与其它蓝牙设备双向传输文件,下面是我用到的应用程序、方法以及资源。

配置内核

内核的配置参考了Thinkwiki。

应用程序

我用到了以下软件包:

  • net-wireless/bluez-libs-3.36  (库文件)
  • net-wireless/bluez-utils-3.36 (基础配置工具,蓝牙系统服务)
  • dev-libs/openobex-1.3 (库文件)
  • app-mobilephone/obex-data-server-0.3.2 (bluez-gnome依赖它)
  • gnome-extra/gnome-vfs-obexftp-0.4 (bluez-gnome依赖它) 
  • net-wireless/bluez-gnome-0.28 (Bluetooth applet, 文件传输gui)
  • net-wireless/gnome-bluetooth-0.11.0 (文件接收Daemon: gnome-obex-server)
  • app-mobilephone/obexftp-0.22 (命令行文件传输工具) 

Bluetooth applet 可以在蓝牙设备打开时自动运行,可以浏览附近的蓝牙设备,提供文件发送与接收的操作,并进行基础的蓝牙属性配置。

但Bluetooth applet的文件接收功能在我的电脑上遇到问题,无法收到其它设备的发送文件请求。为此需要安装 gnome-bluetooth,这事另外一个文件接收服务器(仅接收)。

obexftp 是一个命令行ftp工具,可选安装。

将以上软件包merge到系统,然会添加蓝牙的系统服务

# rc-update add bluetooth default 

gnome-obex-server 不会跟随蓝牙设备的开启自动运行,可以将其加入Gnome的启动session,令其跟随系统启动运行。

再进行接下来的配置。

配置文件

编辑修改/etc/bluetooth/hcid.conf ,对照修改黄底色的部分,密码88888改成自己的。

 options {
# Automatically initialize new devices
autoinit yes;
# Security Manager mode
#   none - Security manager disabled
#   auto - Use local PIN for incoming connections
#   user - Always ask user for a PIN
#
security auto;
# Pairing mode
#   none  - Pairing disabled
#   multi - Allow pairing with already paired devices
#   once  - Pair once and deny successive attempts
pairing multi;
	# Default PIN code for incoming connections
passkey "88888";
}
# Default settings for HCI devices
device {
# Local device name
#   %d - device id
#   %h - host name
name "BlueZ (%d)";
# Local device class
class 0x000100;
# Default packet type
#pkt_type DH1,DM1,HV1;
# Inquiry and Page scan
iscan enable; pscan enable;
# Default link mode
#   none   - no specific policy 
#   accept - always accept incoming connections
#   master - become master on incoming connections,
#            deny role switch on outgoing connections
lm accept;
# Default link policy
#   none    - no specific policy
#   rswitch - allow role switch
#   hold    - allow hold mode
#   sniff   - allow sniff mode
#   park    - allow park mode
lp rswitch,hold,sniff,park;
}

测试

配置完成之后,启动蓝牙系统服务。

# /etc/init.d/bluetooth start 

此时应该可以看到Bluetooth applet出现在托盘,右键选择发送文件,选择浏览到的目标设备,应该可以测试成功。

然后测试接收文件,从系统工具中运行Bluetooth File Sharing (即bluetooth-obex-server),托盘会出现另外一个图标。此时从其它蓝牙设备选择向这部电脑发送文件,应该可以收到确认请求。

Toggle 蓝牙开关

为了方便的开启/关闭蓝牙,我将以下脚本添加到acpi的事件处理当中,可以利用Thinkpad 的Fn+F5 toggle 蓝牙的开关。

/etc/acpi/default.sh

00001005)
# Fn + F5 (Bluetooth on/off)
# 2006-03-07 <pille@struction.de>
#
# acpi called script to toogle bluetooth
#
# get current bluetooth state
cat /proc/acpi/ibm/bluetooth |grep "^status:.*enabled" > /dev/null
if [ $? == 0 ] ; then
logger -t "$0" "bluetooth is on. switching it off."
logger -t "$0" "disabling bluetooth."
echo disable >/proc/acpi/ibm/bluetooth
else
logger -t "$0" "bluetooth is off. switching it on."
logger -t "$0" "enabling bluetooth."
echo enable >/proc/acpi/ibm/bluetooth
fi
;;

有关acp事件处理,请参考Fn + Keys获得详细信息。

有关命令行工具

以下几个是比较常用的命令行工具。

hcitool

hcitool 可用于蓝牙设备扫描,连接,认证等操作。

$ hcitool scan

如果输出扫描到的蓝牙设备名是乱码,可能是蓝牙设备与电脑环境编码不一致,可尝试将UTF-8 编码转换到GBK:

$ hcitool scan |iconv -f utf-8 -t gbk 

hciconfig

类似于ifconfig,可用于配置蓝牙设备,一般设备名为hci0。

# hciconfig hci0 

下载

以上脚本包含在/etc/acpi/default.sh ,请根据自己的情况提取使用。  

参考资料

 

Gentoo Linux on T43 (15) Fn + Keys

对于Linux 对Thinkpad Fn 组合键的支持的了解一直比较模糊,有很多内核中的支持以及软件包,不太清楚具体的分工以及关系,今天查阅了一些资料,试图清理一下自己的思路,也把自己的配置共享一下。 下面给一些包及内核Module加一些注释: 内核Thinkpad ACPI 在2.6.20 中叫做IBM ACPI,这里是它的项目主页。如果编译为module,名字为thinkpad_acpi,它的功能是把Fn 组合按键的事件export 到/proc/acpi(在kernel-2.6.24 中应该选择此项:[*] Deprecated /proc/acpi/event...

对于Linux 对Thinkpad Fn 组合键的支持的了解一直比较模糊,有很多内核中的支持以及软件包,不太清楚具体的分工以及关系,今天查阅了一些资料,试图清理一下自己的思路,也把自己的配置共享一下。

下面给一些包及内核Module加一些注释:

内核Thinkpad ACPI

在2.6.20 中叫做IBM ACPI,这里是它的项目主页。如果编译为module,名字为thinkpad_acpi,它的功能是把Fn 组合按键的事件export 到/proc/acpi(在kernel-2.6.24 中应该选择此项:[*] Deprecated /proc/acpi/event support ),但其并不负责处理事件,需要其它userspace 程序来处理。

app-laptop/tp_smapi

来自Tpctl 项目 ,将thinkpad 硬件的信息export 到sysfs,供其它程序使用,目前主要实现了电池管理和HDAPS的功能。Fn keys应该不需要这个软件包,但我一直使用patched kernel + tp_smapi 来驱动HDAPS。

包含moduels:

hdaps
thinkpad_ec
tp_smapi

app-laptop/thinkpad

也来自Tpctl 项目 ,但目前已经被上面的tp_smapi 所取代,除非使用很古老的笔记本(before 2001),应该不需要这个软件包。

sys-power/acpid

acpid需要配合thinkpad-acpi使用,它默认读取/proc/acpi/event 中的条目,并将其传递给事件处理脚本,作出相应动作,比如关闭屏幕、待机等。 这些条目由/etc/acpi/events/default 捕获,并传递给/etc/acpi/default.sh 处理,但默认的/etc/acpi/default.sh 功能十分有限,必须自己修改。

配置Fn+Keys

这里已经有人写好了一些常用脚本,我根据他的内容整理了一份default.sh,目前可以处理Fn+F3(关屏), Fn+F4(Suspend to ram), Fn+F5(开关蓝牙), Fn+F6(开关wifi),Fn+F7(Toggle VGA-out),Fn+F12(Suspend to disk) 。这个脚本会用到radeontool,如果系统没有这么命令,merge它(也可以使用xset,但需要自己更改default.sh)。

# emerge -av1 radeontool

另外,我注释了脚本中的xosd 命令,如果你有GUI 程序需要显示Fn控制程序的状态,那么可以去掉注释(需要merge xosd)

调试

共享一下调试Fn 组合键的方法,thinkpad_acpi 会将按键事件写入/proc/acpi/event,但acpid 运行时我们无法读取这个文件,先停掉服务:

# /etc/init.d/acpid stop

然后cat这个文件(确保module thinkpad_acpi 已经装载,或者内建在内核)

# cat /proc/acpi/event

接着按Fn 组合键,console 中会打印出事件条目,括号中是我的注释。default.sh 将解析这些条目,并调用不同的命令进行处理。

ibm/hotkey HKEY 00000080 00001001 (Fn+F1)
ibm/hotkey HKEY 00000080 00001002 (Fn+..)
ibm/hotkey HKEY 00000080 00001003
ibm/hotkey HKEY 00000080 00001004
ibm/hotkey HKEY 00000080 00001005
ibm/hotkey HKEY 00000080 00001006
ibm/hotkey HKEY 00000080 00001007
ibm/hotkey HKEY 00000080 00001008
ibm/hotkey HKEY 00000080 00001009
ibm/hotkey HKEY 00000080 0000100a
ibm/hotkey HKEY 00000080 0000100b
ibm/hotkey HKEY 00000080 0000100c (Fn+F12)
ibm/hotkey HKEY 00000080 00001018 (Access IBM)
ibm/hotkey HKEY 00000080 00001014 (Fn+Space)

在我这里,调整屏幕亮度、屏幕灯、音量几个按键thinkpad_acpi 似乎是捕获不到的,event 没有输出,但功能正常,是不是xmodmap 处理了?

另外,内核中还有一个ACPI Button 支持,如果编译为module,在rmmod thinkpad_acpi之后,并且已经装在button,诸如Fn+F4 的事件会被其捕获,同样写入/proc/acpi/event:

button/sleep SLPB 00000080 00000001
button/sleep SLPB 00000080 00000002

下载

使用default.sh 覆盖acpid 默认的文件/etc/acpi/default.sh 即可,/etc/acpi/events/default 不用更改。

更新了default.sh,加入了toggleVGA-out 的脚本。(2008-11-06)

更新 2008-04-09 

今天偶然发现hal (0.5.10)中已经包含全系列thinkpad 型号hotkey的policy 配置文件,包括最新的T/X 6系列,这个文件位于:/usr/share/hal/fdi/information/10freedesktop/30-keymap-module-thinkpad-acpi.fdi,对于T4  系列,有如下定义:

<match key="/org/freedesktop/Hal/devices/computer:system.hardware.version" contains="T4">
<append key="input.keymap.data" type="strlist">0x02:screenlock</append> <!-- Fn+F3 lock -->
<append key="input.keymap.data" type="strlist">0x03:sleep</append> <!-- Fn+F4 suspend -->
<append key="input.keymap.data" type="strlist">0x04:radio</append> <!-- Fn+F5 switch radio -->
<append key="input.keymap.data" type="strlist">0x06:switchvideomode</append> <!-- Fn+F7 switch video output device -->
<append key="input.keymap.data" type="strlist">0x0b:suspend</append> <!-- Fn+F12 hibernate -->
<append key="input.keymap.data" type="strlist">0x0f:brightnessup</append> <!-- Fn+Home -->
<append key="input.keymap.data" type="strlist">0x10:brightnessdown</append> <!-- Fn+End -->
<append key="input.keymap.data" type="strlist">0x13:zoom</append> <!-- Fn+Space -->
<append key="input.keymap.data" type="strlist">0x17:vendor</append> <!-- ThinkPad/ThinkVantage button -->
<append key="info.capabilities" type="strlist">input.keymap</append>
</match> 

我猜想如果使用这个配置文件,应该可以免去上面手工配置Fn keys的步骤,或者不再使用/proc/acpi/event 这个interface,代之使用经由hal 提供的事件绑定?

尝试将其copy 至/etc/hal/fdi/policy 或者/usr/share/hal/fdi/policy/10osvendor,然后重启/etc/init.d/hald 服务,同时关闭了可能与其冲突的acpid 服务,但并没有预期的作用。查看lshal,似乎也都符合配置文件:

$ lshal |grep input.product 
  input.product = 'ThinkPad Extra Buttons'  (string)
...
$ lshal |grep system.hardware.vendor
  system.hardware.vendor = 'IBM'  (string)
$ lshal |grep system.hardware.version
  system.hardware.version = 'ThinkPad T43'  (string)

继续关注这个问题。

下面添加了一篇Gentoo 配置的参考文章。

延展阅读

Gentoo Linux on T43 总结:环境与配置文件

这篇笔记将集中给出一些系统中的环境设置与配置文件,有些配置文件在前面可能有所提及,有些并未涉及到,算作对前面内容的总结和补充。 环境  $ emerge --info  Portage 2.1.3.18 (default-linux/x86/2007.0, gcc-4.2.2, glibc-2.6.1-r0, 2.6.23-gentoo i686) ================================================================= System uname:...

这篇笔记将集中给出一些系统中的环境设置与配置文件,有些配置文件在前面可能有所提及,有些并未涉及到,算作对前面内容的总结和补充。

环境 

$ emerge --info 
Portage 2.1.3.18 (default-linux/x86/2007.0, gcc-4.2.2, glibc-2.6.1-r0, 2.6.23-gentoo i686)
=================================================================
System uname: 2.6.23-gentoo i686 Intel(R) Pentium(R) M processor 2.00GHz
Timestamp of tree: Mon, 05 Nov 2007 13:20:01 +0000
app-shells/bash:     3.2_p17-r1
dev-java/java-config: 1.3.7, 2.1.2-r1
dev-lang/python:     2.5.1-r3
sys-apps/baselayout: 1.12.10-r5
sys-apps/sandbox:    1.2.18.1-r2
sys-devel/autoconf:  2.13, 2.61-r1
sys-devel/automake:  1.9.6-r2, 1.10
sys-devel/binutils:  2.18-r1
sys-devel/gcc-config: 1.4.0-r1
sys-devel/libtool:   1.5.24
virtual/os-headers:  2.6.23
ACCEPT_KEYWORDS="x86 ~x86"
CBUILD="i686-pc-linux-gnu"
CFLAGS="-Os -march=pentium-m -pipe"
CHOST="i686-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/kde/3.5/env /usr/kde/3.5/share/config /usr/kde/3.5/shutdown /usr/share/X11/xkb /usr/share/config"
CONFIG_PROTECT_MASK="/etc/env.d /etc/env.d/java/ /etc/gconf /etc/revdep-rebuild /etc/splash /etc/terminfo /etc/udev/rules.d"
CXXFLAGS="-Os -march=pentium-m -pipe"
DISTDIR="/usr/portage/distfiles"
FEATURES="distlocks metadata-transfer sandbox sfperms strict unmerge-orphans userfetch"
GENTOO_MIRRORS="http://ftp.ncnu.edu.tw/Linux/Gentoo/     http://distro.ibiblio.org/pub/linux/distributions/gentoo/     http://ftp.ucsb.edu/pub/mirrors/linux/gentoo/"
LANG="en_US"
LINGUAS="en zh zh_CN"
MAKEOPTS="-j3"
PKGDIR="/usr/portage/packages"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --delete-after --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --filter=H_**/files/digest-*"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY="/usr/local/portage"
SYNC="rsync://rsync.asia.gentoo.org/gentoo-portage"
USE="X a52 aac aalib acl acpi alsa apache2 asf avahi avi berkdb bitmap-fonts bluetooth bzip2 cdparanoia cdr cjk cli console cracklib crypt cups dbus divx4linux dri dv dvd dvdr dvdread emacs encode esd exif ffmpeg firefox flac foomatic fortran gdbm gif glitz gnome gphoto2 gpm gstreamer gtk hal hdaps iconv immqt-bc irda isdnlog java jpeg lame live mad madwifi midi mjpeg mmx mp3 mp4 mpeg msn mudflap mysql ncurses nls nptl nptlonly nsplugin ogg opengl openmp oss pam pcre pda pdf perl png ppds pppd python qq quicktime rar readline real reflection ruby session sound spell spl sse sse2 ssl svg symlink tcpd tiff truetype truetype-fonts type1 type1-fonts unicode usb userlocales vcd vidix vorbis wav win32codecs wmv x86 xcb xine xinerama xml xorg xv xvid zip zlib" ALSA_CARDS="intel8x0" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mulaw multi null plug rate route share shm softvol" ELIBC="glibc" INPUT_DEVICES="keyboard evdev mouse synaptics" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LINGUAS="en zh zh_CN" USERLAND="GNU" VIDEO_CARDS="radeon vesa"
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LC_ALL, LDFLAGS, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS 
$ set 
ANT_HOME=/usr/share/ant-core
BASH=/bin/bash
BASH_ARGC=()
BASH_ARGV=()
BASH_LINENO=()
BASH_SOURCE=()
BASH_VERSINFO=([0]="3" [1]="2" [2]="17" [3]="1" [4]="release" [5]="i686-pc-linux-gnu")
BASH_VERSION='3.2.17(1)-release'
CLASSPATH=/home/db2amor/sqllib/java/db2java.zip:/home/db2amor/sqllib/java/db2jcc.jar:/home/db2amor/sqllib/java/sqlj.zip:/home/db2amor/sqllib/function:/home/db2amor/sqllib/java/db2jcc_license_cisuz.jar:/home/db2amor/sqllib/java/db2jcc_license_cu.jar:.
COLORTERM=gnome-terminal
COLUMNS=152
CONFIG_PROTECT='/usr/share/X11/xkb /usr/kde/3.5/share/config /usr/kde/3.5/env /usr/kde/3.5/shutdown /usr/share/config'
CONFIG_PROTECT_MASK='/etc/env.d/java/ /etc/udev/rules.d /etc/gconf /etc/terminfo /etc/revdep-rebuild /etc/splash'
CVS_RSH=ssh
DB2INSTANCE=db2amor
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-S9K8WiCEnf,guid=d7447ddfa94cec100759df0047da3397
DIRSTACK=()
DISPLAY=:0.0
EDITOR=/usr/bin/emacs
EUID=1000
FLTK_DOCDIR=/usr/share/doc/fltk-1.1.7-r2/html
GCC_SPECS=
GDK_USE_XFT=1
GENERATION=2
GNOME_DESKTOP_SESSION_ID=Default
GNOME_KEYRING_SOCKET=/tmp/keyring-HarWwA/socket
GROUPS=()
GTK_IM_MODULE=scim
GTK_RC_FILES=/etc/gtk/gtkrc:/home/alex/.gtkrc-1.2-gnome2
G_BROKEN_FILENAMES=1
HISTFILE=/home/alex/.bash_history
HISTFILESIZE=500
HISTSIZE=500
HOME=/home/alex
HOSTTYPE=i686
HUSHLOGIN=FALSE
IFS=$' \t\n'
INFOPATH=/usr/share/info:/usr/share/binutils-data/i686-pc-linux-gnu/2.18/info:/usr/share/gcc-data/i686-pc-linux-gnu/4.2.2/info:/usr/share/info/emacs-22
JAVAC=/home/alex/.gentoo/java-config-2/current-user-vm/bin/javac
JAVA_HOME=/home/alex/.gentoo/java-config-2/current-user-vm
JDK_HOME=/home/alex/.gentoo/java-config-2/current-user-vm
KDEDIRS=/usr:/usr/local:/usr/kde/3.5
LANG=en_US
LC_CTYPE=zh_CN
LD_LIBRARY_PATH=/opt/ibm-jdk-bin-1.4.2.9/bin:/opt/ibm-jdk-bin-1.4.2.9/jre/bin:/home/db2amor/sqllib/lib
LESS='-R -M --shift 5'
LESSOPEN='|lesspipe.sh %s'
LIBPATH=/home/db2amor/sqllib/lib
LINES=51
LOGNAME=alex
LS_COLORS='no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:su=37;41:sg=30;43:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.pdf=00;32:*.ps=00;32:*.txt=00;32:*.patch=00;32:*.diff=00;32:*.log=00;32:*.tex=00;32:*.doc=00;32:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:'
MACHTYPE=i686-pc-linux-gnu
MAIL=/var/mail/alex
MAILCHECK=60
MANPATH=/home/alex/.gentoo/java-config-2/current-user-vm/man:/usr/local/share/man:/usr/share/man:/usr/share/binutils-data/i686-pc-linux-gnu/2.18/man:/usr/share/gcc-data/i686-pc-linux-gnu/4.2.2/man:/etc/java-config/system-vm/man/:/usr/kde/3.5/share/man:/usr/qt/3/doc/man
OPENGL_PROFILE=xorg-x11
OPTERR=1
OPTIND=1
OSTYPE=linux-gnu
PAGER=/usr/bin/less
PATH=/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.2.2:/opt/mts-client:/opt/mts:/opt/ibm-jdk-bin-1.4.2.9/bin:/opt/ibm-jdk-bin-1.4.2.9/jre/bin:/usr/kde/3.5/bin:/usr/qt/3/bin:/usr/games/bin:/home/alex/bin:/home/alex/foo:/home/alex/foo/order:/home/db2amor/sqllib/bin:/home/db2amor/sqllib/adm:/home/db2amor/sqllib/misc:/home/alex/bin:/home/alex/foo:/home/alex/foo/order
PIPESTATUS=([0]="2")
PKG_CONFIG_PATH=/usr/qt/3/lib/pkgconfig
PPID=7553
PRELINK_PATH_MASK=/usr/lib/gstreamer-0.10:/usr/lib/klibc
PYTHONPATH=/usr/lib/portage/pym
QMAKESPEC=linux-g++
QTDIR=/usr/qt/3
QT_IM_MODULE=scim
SHELL=/bin/bash
SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
SHLVL=3
SSH_AGENT_PID=7403
SSH_AUTH_SOCK=/tmp/ssh-VHqDnq7373/agent.7373
TERM=xterm
USER=alex
VMHANDLE=ibm-jdk-bin-1.4
VWSPATH=/home/db2amor/sqllib
VWS_LOGGING=/home/db2amor/sqllib/logging
VWS_TEMPLATES=/home/db2amor/sqllib/templates
WINDOWID=20980933
WINDOWPATH=7
XAUTHORITY=/home/alex/.Xauthority
XDG_DATA_DIRS=/usr/share:/usr/kde/3.5/share:/usr/local/share
XDG_SESSION_COOKIE=
XMODIFIERS=@im=SCIM

配置文件

后记

这篇笔记不会是这个系列的最后一篇,因为有些部分自己还没有整理清楚,待合适的时候,将继续更新。

延展阅读

Gentoo Linux on T43 (10) Fingerprint Reader 指纹认证

Thinkpad Integrated Fingerprint Reader 可以使用指纹认证代替用户登录过程中的密码认证,减少用户手工输入密码的机会,在Windows 下使用CSS 软件,配合内置加密芯片,更可以实现指纹认证的文件加解密。 在Gentoo Linux 下整个配置过程比较容易,How to enable the fingerprint reader...

Thinkpad Integrated Fingerprint Reader 可以使用指纹认证代替用户登录过程中的密码认证,减少用户手工输入密码的机会,在Windows 下使用CSS 软件,配合内置加密芯片,更可以实现指纹认证的文件加解密。

在Gentoo Linux 下整个配置过程比较容易,How to enable the fingerprint reader with ThinkFinger - ThinkWiki 提供了非常清晰的描述,请参考文中的Gentoo 部分以及后续步骤。下面仅列出几点Gentoo 用户需要注意的地方。

  • 文件/etc/pam.d/common-auth 在Gentoo Linux 下无法找到,应该使用 /etc/pam.d/system-auth,以下是我修改后的内容。

/etc/pam.d/system-auth

#%PAM-1.0
auth       required     pam_env.so
# Added by alex
auth       sufficient   pam_thinkfinger.so
auth       sufficient   pam_unix.so try_first_pass likeauth nullok
auth       required     pam_deny.so
account    required     pam_unix.so
# This can be used only if you enabled the cracklib USE flag
password   required     pam_cracklib.so difok=2 minlen=8 dcredit=2 ocredit=2 try_first_pass retry=3
# This can be used only if you enabled the cracklib USE flag
password   sufficient   pam_unix.so try_first_pass use_authtok nullok md5 shadow
# This can be used only if you enabled the !cracklib USE flag
# password   sufficient pam_unix.so try_first_pass nullok md5 shadow
password   required     pam_deny.so
session    required     pam_limits.so
session    required     pam_unix.so
  • 将uinput 加入/etc/modules.autoload.d/kernel-2.6
# Modules for fingerprint
uinput
  • 将文中的环境变量$USERNAME 替换为$USER 再使用,例如:
# gpasswd -a $USERNAME fingerprint 
  • 若使指纹认证在xscreensaver/gnome-screensaver 中工作,必须按照上文4 xscreensaver/gnome-screensaver 一节进行额外配置。我在以下环境测试成功。
    • gnome-screensaver-2.20.0
    • pam-0.99.9.0

      但需要指出的是,文件/etc/pam.d/gnome-screensaver 并不需要修改,因为其已经通过include 关键字包含文件system-auth。
  • 关于gksu/gksudo 的workaround ,我未进行测试。

延展阅读

Gentoo Linux on T43 (9) HDAPS 硬盘动态保护系统

本文参考How to protect the harddisk through APS ,以下内容可直接应用于Gentoo Linux。 Thinkpad HDAPS 依靠笔记本内部的2D 加速度传感器检测笔记本位移, 将数据写入sysfs,系统中有一个demon (守护进程)负责监视这个sysfs...

本文参考How to protect the harddisk through APS ,以下内容可直接应用于Gentoo Linux。

Thinkpad HDAPS 依靠笔记本内部的2D 加速度传感器检测笔记本位移, 将数据写入sysfs,系统中有一个demon (守护进程)负责监视这个sysfs interface,必要时执行硬盘磁头parking 动作。此外,有一个applet,可以在任务托盘实时反映当前的保护状态,这个不是必须的。

在Linux 上完整的HDAPS 包括以下几个部分:

  • hdaps 驱动程序,从硬件传感器读取数据(内核内置此驱动,但不要使用,推荐使用tp_smapi 提供的驱动)。
  • 内核 patch,负责向sysfs 写入数据,需要重新编译内核。
  • hdapsd,demon 程序
  • applet,有多种选择:gnome-hdaps-applet, khdapsmonitor 等,可以不安装,并不影响HDAPS 作用。

下面就以上4个部分分别讨论。

内核Patch 

这一步需要提前来做。

根据自己的内核版本,找到相应的patch 下载另外一个下载地址),我的内核版本是2.6.23:

$ eselect kernel list
Available kernel symlink targets:
  [1]   linux-2.6.20-gentoo-r8
  [2]   linux-2.6.23-gentoo *
  [3]   linux-2.6.23-gentoo-r1

网络上没有找到版本完全符合的patch,但在2.6.23-kamikaze4 中找到了thinkpad-2.6.23-1.patch ,它里面包含了我们需要的protection patch,我将其提取出来,做成 hdaps-protect-2.6.23.patch ,可以单独使用。

用以下命令应用patch,并重新编译内核安装modules 。

# cd /usr/src/linux
# patch -p1 <  ~/hdaps-protect-2.6.23.patch 
# make && make modules_install

重新启动系统之后,会在sysfs 生成文件 /sys/block/xxx/queue/protect,表明patch 成功。

hdaps 驱动程序 

首先要禁止内核中的驱动程序,确保以下内核选项没有被设置,否则,将在不同的路径生成两个同名的module hdaps,load 过程会出错。

$ zcat /proc/config.gz |grep -i hdaps
# CONFIG_SENSORS_HDAPS is not set 

接下来在/etc/make.conf 的USE flag 中加入hdaps 支持,将会被tp_smapi 用到。

/etc/make.conf

USE="hdaps"

tp_smapi 已经被加入Gentoo package list,可以直接emerge,我目前使用0.31 版本。

# emerge -av app-laptop/tp_smapi

载入hdaps 与tp_smapi

# modprobe tp_smapi hdaps 

并将其加入到/etc/modules.autoload.d/kernel-2.6

# Modules for Thinkpad HDAPS
tp_smapi
hdaps

hdapsd

安装demon,直接emerge 即可,我的版本是20060409-r1 。

# emerge -av  app-laptop/hdapsd

编辑hdapsd 配置文件,在DISK 中指定需要保护的硬盘设备名称,作为可选,也可以调整保护动作阈值THRESHOLD ,值越小,保护动作越早,但也会更频繁。

/etc/conf.d/hdapsd

# The name of the disk device that hdapsd should monitor.
# Usually this is 'hda' or 'sda' the primary master.
DISK="sda"
# hdapsd sensitivity 
# The lower the threshold is the earlier 
# the heads are parked when the laptop is shaked
THRESHOLD="15"
# Set any extra options here, like -a for Adaptive mode
OPTIONS="-a"

启动hdaspd 服务

# /etc/init.d/hdapsd start

将hdapsd 设置为跟随系统自动启动 

# rc-update add hdapsd boot 

applet

如果希望监视硬盘保护状态,则需要安装applet 。我使用gnome 环境,因此选择了gnome-hdaps-applet ,但其还未被加入Gentoo 官方package list,需要下载回来自己编译安装。以下是步骤。

下载:

$ cd
$ wget http://www.zen24593.zen.co.uk/hdaps/gnome-hdaps-applet-20060120.tar.gz
$ mkdir gnome-hdaps-applet
$ tar -zxvf gnome-hdaps-applet-20060120.tar.gz -C gnome-hdaps-applet
$ cd gnome-hdaps-applet

编译:

$ gcc $(pkg-config --cflags --libs libpanelapplet-2.0) -o gnome-hdaps-applet gnome-hdaps-applet.c

安装:

# cp gnome-hdaps-applet /usr/bin
# mkdir /usr/share/pixmaps/gnome-hdaps-applet/
# cp *.png /usr/share/pixmaps/gnome-hdaps-applet/
# cp GNOME_HDAPS_StatusApplet.server /usr/lib/bonobo/servers

重启Xwindow,在applet 列表中可以找到新的项目,加入到panel 即可。

Tips

  • 我在hdapsd 中设置的设备名为sda,但我的第二块硬盘sdb(在硬盘托架内)并没有受到保护,我尝试更改配置文件为sdb,保护动作正常,但无法对2个设备同时进行保护,hdaps project 邮件列表有一条关于此的讨论,希望未来会支持多个设备
  • 如果没有安装applet,在那里查看硬盘的保护状态呢?可以用以下命令查看历史状态,也可以使用ctrl + alt + F12 查看实时状态。
$ dmesg |tail
...
scsi_protect_queue(): head parked..
... 
  • 我曾经在kernel-2.6.20-r8 下设置hdaps,但始终无法成功patch 内核,没有sysfs 数据写入,因此,hdapsd服务也无法启动成功。若有相似问题的用户可以尝试升级内核。

下载

延展阅读

(未完)

Gentoo Linux on T43 (8) X300 显卡的驱动以及3D 加速

T43 包括两种显卡方案,一种是915GM 主板集成Intel 显卡 ,另一种是ATI X300 独立显卡 ,我的显卡是X300 ,这里所有的讨论都是与X300 相关。 ATI X300 有2种驱动方案,一种是开源驱动radeon,通过开源R300 项目已经可以支持X300 显卡的3D...

T43 包括两种显卡方案,一种是915GM 主板集成Intel 显卡 ,另一种是ATI X300 独立显卡 ,我的显卡是X300 ,这里所有的讨论都是与X300 相关。

ATI X300 有2种驱动方案,一种是开源驱动radeon,通过开源R300 项目已经可以支持X300 显卡的3D 加速;另一种是ATI 官方的闭源驱动fglrx 。

下面针对这2种方案,分别给出我的配置,涉及到:内核配置、make.conf 、安装软件包、X11 配置、装载module以及OpenGL 设置。

内核配置

请参照 Gentoo Linux on T43 (5) 配置内核(kernel) 显卡一节。

make.conf

在开时编译一些软件包之前,需要在/etc/make.conf  中设置变量:USE 与VIDEO_CARDS 。

开源驱动与官方驱动都需要设定如下USE flag,将其添加到原有USE flag 列表

USE="dri opengl" 

VIDEO_CARDS 中的设定值会被软件包x11-server、x11-drm 等软件包使用,对于开源驱动设定:

VIDEO_CARDS="radeon vesa"

对于官方驱动设定: 

VIDEO_CARDS="fglrx vesa" 

加入vesa 用来对启动过程中的字符界面提供支持。

安装软件包

如果使用开源驱动,emerge:

# emerge -av xorg-x11 xf86-video-ati 

下面的软件包会作为依赖被自动安装

x11-base/xorg-server
x11-drivers/xf86-video-vesa
media-libs/mesa

前面内核配置,如果没有选择内核中的drm,那么此处应该把drm 也安装上:

# emerge -av x11-base/x11-drm 

如果使用官方驱动,emerge:

# emerge -av ati-drivers 

X11 配置

X11 的配置文件位于/etc/X11/xorg.conf ,这里不介绍如何生成一个默认的xorg.conf 文件(相关内容请参考Gentoo 手册),仅给出我的配置,将其合并入你的配置文件即可,以下是针对T43 1400x1050 高分屏以及X300显卡,并开启3D 加速的配置。

开源驱动
Section "Module"
    Load	"dbe"
    SubSection	"extmod"
        Option	"omit xfree86-dga"
    EndSubSection
    Load 	"glx"
    Load 	"dri"
    ...
EndSection
Section "Extensions"
    Option  "Composite" "1"
EndSection
Section "ServerFlags"
    Option      "AIGLX"         "on"
EndSection
Section "Monitor"
    Identifier	"Thinkpad LCD Monitor"
    Option	"dpms"
    DisplaySize	      370	277
EndSection
Section "Device"
    Identifier	"ATI Graphics Mobile X300"
    Driver	"radeon"
    BusID	"PCI:1:0:0"
EndSection
Section "Screen"
    Identifier "High Screen"
    Device     "ATI Graphics Mobile X300"
    Monitor    "Thinkpad LCD Monitor"
    DefaultDepth     24
    SubSection "Display"
        Viewport   0 0
        Depth      24
        Modes      "1400x1050" "1280x1024" "1024x768" "800x600"
    EndSubSection
EndSection
Section "ServerLayout"
    Identifier	"Main Layout"
    Screen	"High Screen"
    ...
EndSection
Section "dri"
    Mode         0666
EndSection 
官方驱动 

将上面的配置进行如下修改即可

...
Section "Extensions"
    Option  "Composite" "0"
EndSection
Section "ServerFlags"
    Option      "AIGLX"         "off"
EndSection
...
Section "Device"
    Identifier	"ATI Graphics Mobile X300"
    Driver	"fglrx"
    BusID	"PCI:1:0:0"
EndSection
...

装载module 

在/etc/modules.autoload.d/kernel-2.6 文件中加入在启动时需要装载的module 名称。

开源驱动 
# Modules for video card & 3D
drm
radeon
官方驱动 
# Modules for video card & 3D
drm
fglrx

可以使用以下命令确认module 是否装载成功,以及查看引用关系(以开源驱动为例)

$ lsmod |grep radeon
radeon                121376  2 
drm                    63380  3 radeon

OpenGL 配置

为系统选择OpenGL 程序。

开源驱动 
# eselect opengl set xorg-x11
官方驱动 
# eselect opengl set ati

延展阅读

(未完)

Gentoo Linux on T43 (7) 中文字体

Linux 下字体的配置可以很简单,也可以很复杂,这取决于个人需求的复杂程度,以及对相关知识的了解和技术掌控程度,其差别会导致悬殊的时间成本。在我本人开始这项工作之前,对相关内容了解很少,因此不得不花费时间来了解一些基础性内容。 在这个过程中,一本在线书籍Free/Open Source Software Localization 为我提供了有益的帮助,其整个第七章都是有关字体的内容,介绍了基本的字体概念,字体的分类,以及Linux 如何处理字体 等。 对于中文字体的详细配置,参考了quanliking 的2 篇文章: Linux 字体微调 -...

Linux 下字体的配置可以很简单,也可以很复杂,这取决于个人需求的复杂程度,以及对相关知识的了解和技术掌控程度,其差别会导致悬殊的时间成本。在我本人开始这项工作之前,对相关内容了解很少,因此不得不花费时间来了解一些基础性内容。

在这个过程中,一本在线书籍Free/Open Source Software Localization 为我提供了有益的帮助,其整个第七章都是有关字体的内容,介绍了基本的字体概念字体的分类,以及Linux 如何处理字体 等。

对于中文字体的详细配置,参考了quanliking 的2 篇文章: Linux 字体微调 - windows 效果版Linux 字体微调- Vista 效果版 以及kemean 的字体配置local.conf详解[带Win效果和AA效果]

下面先描述一下字体的安装方法,然后给出我的字体配置,更多的内容可以参考以上的链接。

安装字体

Gentoo Linux有2种主要的字体系统并存:Core X11 font systemxft font system,分别有不同的安装方法。

Core X11 font system

对于Core X11,系统与应用程序的字体一般放在/usr/share/fonts 下面的子目录内,建议把用户自己安装的字体放在/usr/local/share/fonts 下的子目录,并且需要将这些路径加入到Xwindow的配置文件 /etc/X11/xorg.conf。举例:

将新的truetype 类型字体放在/usr/local/share/fonts/TTF 目录,然后执行以下命令(注意顺序):

# mkfontscale  /usr/local/share/fonts/TTF
# mkfontdir /usr/local/share/fonts/TTF

接着编辑/etc/X11/xorg.conf 来让使用Core X11 font system 的X 应用程序知道有新的字体可以利用,添加以下行到文件的Files 与Module Section(其实这个目录默认已经存在,无须添加)。

Section "Files"
    FontPath   "/usr/local/share/fonts/TTF"
    ...
EndSection
重启Xwindow 即可,新的字体将会被识别。 
xft font system

有些X 应用程序使用xft font system ,Gentoo Linux 默认设置了以下环境变量,使gtk+ 2.0 应用程序的字体使用xft,而不是Core X11 font system。

$ cat /etc/env.d/50gtk2
GDK_USE_XFT=1

xft font system 会自动搜索标准的字体路径并发现新字体,无须多余的步骤。如果希望新字体可以立即使用,那么执行命令fc-chache -fv 来即可刷新字体缓存。

对字体的配置可以存放在2个文件当中,其一是系统级别的/etc/fonts/local.conf (没有此文件可以自己建立),其二是用户Home目录下的.fonts.conf,仅影响当前用户。

字体配置

目前Linux 下的中文字体配置主要分为以下几种。

Windows 或Mac 效果 

使用Windows 平台的宋体(SimSun)、新宋体(NSimSun)与黑体(SimHei) ,或者最新vista 系统中的微软雅黑字体(Microsoft YaHei)。另外还有Mac 平台采用的华文黑体(STHeiti),其效果与SimHei 类似,但小字体的效果更出色。这几种字体包含的字符集非常齐全,覆盖了汉字简繁以及日韩字体,因此对繁体以及日韩字体显示效果要求不很高的用户,就没必要再去配置细明体(PMingLiU) 等其它字体。

使用这些字体的方法很简单,将其从Windows 目录复制到Linux 下简单配置即可,但严格来讲,这里面有版权问题,因此,在大多数Linux 发布之中,我们找不到以上字体。

使用免费的开源字体 

在这方面做得比较出色的是文泉驿 字体,目前通过网络协作的方式,已经开发出了点阵宋体、黑体以及等宽三大类字体,并不断升级改善中。

可以直接在Gentoo 中安装其中的点阵宋体和正黑字体:

# emerge -av  media-fonts/wqy-bitmapfont media-fonts/wqy-zenhei
配置文件 

为了对比,我尝试了以上的各种字体配置方案,经过调整后,在T43 高分屏1400x1050分辨率下,效果都不错,其差别仅在个人喜好罢了。因此,我将配置文件整理,如果你安装了以上几种字体,那么简单修改几行,重启Xwindow ,即可更换一种字体。

下面是我的.fonts.conf (整理自quanliking 与kemean 的文章),放在我的HOME 目录,会被/etc/fonts/fonts.conf 自动读取,其优先级低于/etc/fonts/local.conf

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<!-- ~/.font.conf file for user customizations -->
<fontconfig>
<!--
    Breaf:
    Search keyword "editable" for configuation.
    Section:
    1. Fonts family configuration
    2. Fonts substitution
    3. Global configuration
    4. English fonts configuration
    5. CJK fonts configuration
    Installed fonts list:
    STHeiti
    微软雅黑,Microsoft YaHei
    黑体,SimHei
    宋体-18030,SimSun-18030
    宋体,SimSun
    新宋体-18030,SimSun-18030,NSimSun-18030
    新宋体,NSimSun
    WenQuanYi Bitmap Song
    文泉驿正黑,文泉罅正黑,WenQuanYi Zen Hei
    Arial
    Arial Black
    Verdana
    Comic Sans MS
    Georgia
    Times New Roman
    Courier New
    Andale Mono
    Fixed
    Impact
    Trebuchet MS
    Webdings
-->
<!--
*******************************************************************************
    1. Fonts family configuration [Begin]
*******************************************************************************
-->
    <alias>
        <family>serif</family>
        <prefer>
            <!-- @@@ editable -->
            <family>SimSun</family>
        </prefer>
    </alias>
    <alias>
        <family>sans-serif</family>
        <prefer>
            <!-- @@@ editable -->
            <family>Microsoft YaHei</family>
        </prefer>
    </alias>
    <alias>
        <family>monospace</family>
        <prefer>
            <!-- @@@ editable -->
            <family>NSimSun</family>
        </prefer>
    </alias>
<!--
*******************************************************************************
    1. Fonts family configuration [End]
*******************************************************************************
-->
<!--
*******************************************************************************
    2. Fonts substitution [Begin]
*******************************************************************************
-->
<!--
    fonts alias substitution
-->
    <match target="pattern">
        <test name="family">
            <string>宋体</string>
        </test>
        <edit name="family" mode="assign">
            <string>SimSun</string>
        </edit>
    </match>
    <match target="pattern">
        <test name="family">
            <string>新宋体</string>
        </test>
        <edit name="family" mode="assign">
            <string>NSimSun</string>
        </edit>
    </match>
    <match target="pattern">
        <test name="family">
            <string>宋体-18030</string>
        </test>
        <edit name="family" mode="assign">
            <string>SimSun-18030</string>
        </edit>
    </match>
    <match target="pattern">
        <test name="family">
            <string>新宋体-18030</string>
        </test>
        <edit name="family" mode="assign">
            <string>NSimSun-18030</string>
        </edit>
    </match>
    <match target="pattern">
        <test name="family">
            <string>黑体</string>
        </test>
        <edit name="family" mode="assign">
            <string>SimHei</string>
        </edit>
    </match>
    <match target="pattern">
        <test name="family">
            <string>微软雅黑</string>
        </test>
        <edit name="family" mode="assign">
            <string>Microsoft YaHei</string>
        </edit>
    </match>
    <match target="pattern">
        <test name="family">
            <string>文泉驿正黑</string>
        </test>
        <edit name="family" mode="assign">
            <string>WenQuanYi Zen Hei</string>
        </edit>
    </match>
<!--
    not installed fonts substitution
-->
    <match target="pattern">
        <test name="family">
            <string>Times</string>
        </test>
        <edit name="family" mode="assign">
            <string>Times New Roman</string>
        </edit>
    </match>
    <match target="pattern">
        <test name="family">
            <string>Helvetica</string>
        </test>
        <edit name="family" mode="assign">
            <string>Verdana</string>
        </edit>
    </match>
    <match target="pattern">
        <test name="family">
            <string>Courier</string>
        </test>
        <edit name="family" mode="assign">
            <string>Courier New</string>
        </edit>
    </match>
    <match target="pattern" >
        <test name="family" >
            <string>PMingLiU</string>
            <string>MingLiU</string>
            <string>FangSong_GB2312</string>
            <string>KaiTi_GB2312</string>
            <string>AR PL KaitiM GB</string>
            <string>AR PL KaitiM Bit5</string>
            <string>AR PL SungtiL GB</string>
            <string>AR PL Mingti2L Bit5</string>
            <string>AR PL ShanHeiSun Uni</string>
            <string>AR PL ZenKai Uni</string>
            <string>Bitstream Vera Serif</string>
            <string>Bitstream Vera Sans</string>
            <string>Bitstream Vera Sans Mono</string>
            <string>DejaVu Sans</string>
            <string>DejaVu Sans Mono</string>
            <string>DejaVu Serif</string>
            <string>MS 明朝</string>
            <string>MS ゴシック</string>
            <string>Kochi Mincho</string>
            <string>Kochi Gothic</string>
            <string>Baekmuk Batang</string>
            <string>Baekmuk Dotum</string>
            <string>Baekmuk Gulim</string>
            <string>Baekmuk Headline</string>
        </test>
        <edit name="family" mode="assign" >
            <string>san-serif</string>
        </edit>
    </match>
<!--
    english portion substitution
-->
    <match target="pattern" >
        <test name="family" >
            <string>serif</string>
        </test>
        <edit name="family" mode="prepend" binding="strong" >
            <!-- @@@ editable -->
            <string>Georgia</string>
        </edit>
    </match>
    <match target="pattern" >
        <test name="family" >
            <string>sans-serif</string>
        </test>
        <edit name="family" mode="prepend" binding="strong" >
            <!-- @@@ editable -->
            <string>Verdana</string>
        </edit>
    </match>
    <match target="pattern" >
        <test name="family" >
            <string>monospace</string>
        </test>
        <edit name="family" mode="prepend" binding="strong" >
            <!-- @@@ editable -->
            <string>Courier New</string>
        </edit>
    </match>
<!--
*******************************************************************************
    2. Fonts substitution [End]
*******************************************************************************
-->
<!--
*******************************************************************************
    3. Global configuration [Begin]
*******************************************************************************
-->
<!--
    target dots per inch, change dpi to 96
-->
    <match target="pattern" >
        <edit name="dpi" mode="assign" >
            <double>96</double>
        </edit>
    </match>
<!--
    enable sub-pixel rendering.
    if you are using CRT, set rgb -> none
-->
    <match target="font">
        <edit name="rgba" mode="assign">
            <const>none</const>
        </edit>
    </match>
<!--
    default Fonts setting
    here autohint = ture / hinting = false is for free fonts in your system
    we will use autohint = false / hinting = true for MS core fonts
-->
    <match target="font" >
        <edit name="antialias" mode="assign" >
            <bool>true</bool>
        </edit>
        <edit name="autohint" mode="assign" >
            <bool>true</bool>
        </edit>
        <edit name="hinting" mode="assign" >
            <bool>false</bool>
        </edit>
        <edit name="hintstyle" mode="assign" >
            <const>hintfull</const>
        </edit>
    </match>
<!--
    font size settings:
    set the apposite font size,so it is easy to be read
-->
    <match target="pattern" >
        <test name="pixelsize" compare="more_eq" >
            <double>8</double>
        </test>
        <test name="pixelsize" compare="less_eq" >
            <double>12</double>
        </test>
        <edit name="pixelsize" mode="assign" >
            <double>12</double>
        </edit>
    </match>
<!--
    synthetic emboldening for fonts that do not have bold face available
-->
    <match target="font">
        <!-- check to see if the font is just regular -->
        <test name="weight" compare="less_eq">
            <int>100</int>
        </test>
        <!-- check to see if the pattern requests bold -->
        <test target="pattern" name="weight" compare="more_eq">
            <int>180</int>
        </test>
        <!-- set the embolden flag -->
        <edit name="embolden" mode="assign">
            <bool>true</bool>
        </edit>
    </match>
<!--
*******************************************************************************
    3. Global configuration [End]
*******************************************************************************
-->
<!--
*******************************************************************************
    4. English fonts configuration [Begin]
*******************************************************************************
-->
<!--
    default : smoothed and hinted
-->
    <match target="font" >
        <test name="foundry" qual="any" >
            <string>monotype</string>
            <string>microsoft</string>
        </test>
        <edit name="antialias" mode="assign" >
            <bool>true</bool>
        </edit>
        <edit name="autohint" mode="assign" >
            <bool>false</bool>
        </edit>
        <edit name="hinting" mode="assign" >
            <bool>true</bool>
        </edit>
        <edit name="hintstyle" mode="assign" >
            <const>hintfull</const>
        </edit>
    </match>
<!--
    for point size less equal than 6 : only smoothed
-->
    <match target="font" >
        <test name="foundry" qual="any" >
            <string>monotype</string>
            <string>microsoft</string>
        </test>
        <test name="size" compare="less_eq" >
            <double>6</double>
        </test>
        <edit name="antialias" mode="assign" >
            <bool>true</bool>
        </edit>
        <edit name="autohint" mode="assign" >
            <bool>false</bool>
        </edit>
        <edit name="hinting" mode="assign" >
            <bool>false</bool>
        </edit>
    </match>
<!--
    Arial Regular
-->
    <match target="font" >
        <test name="family" >
            <string>Arial</string>
        </test>
        <test name="weight" compare="eq">
            <const>regular</const>
        </test>
        <test name="slant" compare="eq" >
            <const>roman</const>
        </test>
        <test name="size" compare="more_eq" >
            <double>7</double>
        </test>
        <test name="size" compare="less_eq" >
            <double>13</double>
        </test>
        <edit name="antialias" mode="assign" >
            <bool>false</bool>
        </edit>
        <edit name="autohint" mode="assign" >
            <bool>false</bool>
        </edit>
        <edit name="hinting" mode="assign" >
            <bool>true</bool>
        </edit>
        <edit name="hintstyle" mode="assign" >
            <const>hintfull</const>
        </edit>
    </match>
<!--
    Times New Roman Bold Italic
-->
    <match target="font" >
        <test name="family" >
            <string>Times New Roman</string>
        </test>
        <test name="weight" compare="eq">
            <const>bold</const>
        </test>
        <test name="slant" compare="eq" >
            <const>italic</const>
        </test>
        <test name="size" compare="more_eq" >
            <double>7</double>
        </test>
        <test name="size" compare="less_eq" >
            <double>13</double>
        </test>
        <edit name="antialias" mode="assign" >
            <bool>false</bool>
        </edit>
        <edit name="autohint" mode="assign" >
            <bool>false</bool>
        </edit>
        <edit name="hinting" mode="assign" >
            <bool>true</bool>
        </edit>
        <edit name="hintstyle" mode="assign" >
            <const>hintfull</const>
        </edit>
    </match>
<!--
    Courier New:
    both enable autohint and hinting looks very well.
-->
   <match target="font" >
      <test name="family" >
         <string>Courier New</string>
      </test>
      <edit name="antialias" mode="assign" >
         <bool>true</bool>
      </edit>
      <edit name="autohint" mode="assign" >
         <bool>true</bool>
      </edit>
      <edit name="hinting" mode="assign" >
         <bool>true</bool>
      </edit>
      <edit name="hintstyle" mode="assign" >
         <const>hintfull</const>
      </edit>
   </match>
<!--
    Courier New font size
-->
   <match target="font" >
      <test name="family" >
         <string>Courier New</string>
      </test>
      <test name="pixelsize" compare="less_eq" >
         <double>14.7</double>
      </test>
      <edit name="pixelsize" mode="assign" >
         <double>14.7</double>
      </edit>
   </match>
<!--
*******************************************************************************
    4. English fonts configuration [End]
*******************************************************************************
-->
<!--
*******************************************************************************
    5. CJK fonts configuration [Begin]
*******************************************************************************
-->
<!--
    the dual-width Asian fonts (spacing=dual) are not rendered correctly,
    apparently FreeType forces all widths to match. Trying to disable the
    width forcing code by setting globaladvance=false alone doesnot  help.
    as a brute force workaround, also set spacing=proportional, i.e. handle
    them as proportional fonts:
-->
    <match target="font" >
        <test target="pattern" name="lang" compare="contains" >
            <string>zh</string>
            <string>ja</string>
            <string>ko</string>
        </test>
        <test name="spacing" compare="eq">
            <const>dual</const>
        </test>
        <edit name="spacing" mode="assign" >
            <const>proportional</const>
        </edit>
        <edit name="globaladvance" mode="assign" >
            <bool>false</bool>
        </edit>
    </match>
<!--
    adjusting
-->
    <match target="font" >
        <test qual="any" name="family" compare="eq" >
            <!-- installed fonts -->
            <!--
            <string>STHeiti</string>
            -->
            <string>Microsoft YaHei</string>
            <string>SimHei</string>
            <string>SimSun</string>
            <string>NSimSun</string>
            <string>SimSun-18030</string>
            <string>NSimSun-18030</string>
            <string>WenQuanYi Bitmap Song</string>
            <string>WenQuanYi Zen Hei</string>
        </test>
        <edit name="rgba" mode="assign">
            <const>none</const>
        </edit>
        <edit name="antialias" mode="assign" >
            <bool>true</bool>
        </edit>
        <edit name="autohint" mode="assign" >
            <bool>false</bool>
        </edit>
        <edit name="hinting" mode="assign" >
            <bool>true</bool>
        </edit>
        <edit name="hintstyle" mode="assign" >
            <const>hintfull</const>
        </edit>
        <edit name="embeddedbitmap" mode="assign" >
            <bool>true</bool>
        </edit>
    </match>
<!--
    enable embedded bitmap fonts
    non-bitmap:
       STHeiti: sthei.ttf 13563000 bytes
       Microsoft YaHei: msyh.ttf 15043584 bytes
       SimHei: simhei.ttf 10044356 bytes
    with bitmap:
       SimSun/NSimSun: simsun.ttf 10500792 bytes
       SimSun-18030/NSimSun-18030: simsun-18030.ttf 12642204
       WenQuanYi Zen Hei: wqy-zenhei.ttf 12844372 bytes
    checked by Linux tool: fontforge
-->
    <match target="font" >
        <test qual="any" name="family" compare="eq" >
            <string>SimSun</string>
            <string>NSimSun</string>
            <string>SimSun-18030</string>
            <string>NSimSun-18030</string>
        </test>
        <test name="pixelsize" compare="eq" >
            <double>12</double>
            <double>13</double>
            <double>14</double>
            <double>15</double>
            <double>16</double>
            <double>18</double>
        </test>
        <edit name="antialias" mode="assign" >
            <bool>false</bool>
        </edit>
    </match>
    <match target="font" >
        <test qual="any" name="family" compare="eq" >
            <string>WenQuanYi Bitmap Song</string>
        </test>
        <test name="pixelsize" compare="more_eq" >
            <double>9</double>
        </test>
        <test name="pixelsize" compare="less_eq" >
            <double>12</double>
        </test>
        <edit name="antialias" mode="assign" >
            <bool>false</bool>
        </edit>
    </match>
    <match target="font" >
        <test qual="any" name="family" compare="eq" >
            <string>WenQuanYi Zen Hei</string>
        </test>
        <test name="pixelsize" compare="eq" >
            <double>12</double>
            <double>13</double>
            <double>15</double>
            <double>16</double>
        </test>
        <edit name="antialias" mode="assign" >
            <bool>false</bool>
        </edit>
    </match>
<!--
*******************************************************************************
    5. CJK fonts configuration [End]
*******************************************************************************
-->
</fontconfig>

上面的字体配置使用3种虚拟字体:

  • 衬线字体:Serif
  • 非衬线字体:Sans-serif/Sans serif/Sans
  • 等宽字体:Monospace/Mono

虚拟字体已经被定义在/etc/fonts/conf.d/ 下面的配置文件中,并拥有了一个字体列表,以上字体配置中的字体会被加在顶部,具有更高的优先级。并且,/etc/fonts/fonts.conf 中也为虚拟字体添加了可能采用的别名,比如mono。有关衬线字体与非衬线字体,请参看:细说字体 Sans Serif 与 Serif

在上面,我定义了:对于衬线字体,中文使用宋体,英文使用Georgia;非衬线的字体,中文使用微软雅黑,英文使用Verdana;等宽字体,中文使用新宋体,英文使用Courier New,共6种字体。其中,除了中文字体需要自己额外安装以外,其它英文字体默认已经存在于/usr/share/fonts/corefonts 目录,它们属于media-fonts/corefonts ,如果你找不到这些字体,可以emerge 这个包。

如果想换不同的口味,只需要把上述6处字体名称替换为系统中已经安装的字体即可,为了方便配置,我在每一处增加了<!-- @@@ editable --> 这样的注释。

另外,有人觉得/etc/fonts/conf.d 下面的配置文件没什么用处,还可能干扰自己的配置,可以删除了事。我仔细看过,不提倡删除,如果删除的话,以下2个文件一定要保留,否则fontconfig 就不会读取~/.fonts.conf 与/etc/fonts/local.conf ,它们是这2个配置文件的装载入口。

  • 50-user.conf
  • 51-local.conf

下面是雅黑的效果截图:

screenshot-msyh.jpg

字体有关的命令 

下面介绍几个字体有关的命令,在配置过程中可能会用来进行配置的确认、除错等。

fc-list

列出系统中所有可用的字体名称(包含中英文别名),以及支持的style。

命令后面可加字体名称,但必须是全称,不支持通配符,否则无法匹配。如果是中文字体,要求环境为UTF-8,否则匹配不成功,输出也是乱码。字体名称如果包含空格,使用引号引起。

虚拟字体不会被列出。

fc-match  

列出字体文件名称、英文名称,不支持中文字体名匹配。同样不支持通配符,但支持虚拟字体,可以列出虚拟字体中优先级最高的字体。可以使用-v 参数输出字体详细信息。 

对于配置文件中进行过字体替换的字体,fc-match 会输出替换后的字体名称

$ fc-match courier
cour.ttf: "Courier New" "Normal"
fc-cat

从cache 文件中读取字体信息,很少用到。

以上三个命令来自media-libs/fontconfig,属于xft 的命令。

xlsfonts

xlsfonts 也用于列出字体,但格式不同,此外,它也可以列出一些未被xft 系统识别并cache 的字体。同时这个命令也支持通配符。

$ xlsfonts -fn "*sim*"
-misc-simhei-medium-r-normal--0-0-0-0-p-0-iso10646-1
-misc-simsun 18030-medium-r-normal--0-0-0-0-m-0-iso10646-1
-misc-simsun 18030-medium-r-normal--0-0-0-0-m-0-iso8859-1
-misc-simsun 18030-medium-r-normal--0-0-0-0-m-0-koi8-r
-misc-simsun-medium-r-normal--0-0-0-0-p-0-iso10646-1
-misc-simsun-medium-r-normal--0-0-0-0-p-0-iso8859-1
-misc-simsun-medium-r-normal--0-0-0-0-p-0-koi8-r

如果系统中找不到这个命令,需要emerge x11-apps/xlsfonts

fontforge

这是一个GUI 程序,可用于编辑字体文件,同时也可以获得大量的字体信息,比如一个TrueType 字体是否内嵌了点阵字体,size是多少。对于MS的宋体,fontforge 只能识别出部分size 的点阵字体:12、14、16,13、15、18 则识别不出来,开时我认为是字体文件的版本问题,后来看了quanliking 的回帖才知道是fontforge 的问题。

如果系统中找不到这个命令,需要emerge  media-gfx/fontforge

Tips

如果字体没有变化,仅仅修改了字体配置文件,如果使用fc-match 这样的命令,不需要重启Xwindow。对于其它应用程序,比如gedit,仅仅重新运行这个程序即可应用新的配置,但有些应用程序则需要重启动Xwindow 才可以应用新的配置,比如gnome-terminal 。了解这些可以在测试字体配置的时候节省一些时间。

下载

  • fontconfig 配置文件:.fonts.conf(如果直接使用这个文件,请重命名为 .fonts.conf,下载的文件名中没有点)
  • 因为版权问题,不提供一些字体的下载,在Windows 系统以及本文链接的文章中可以找到。

延展阅读

(未完)

Gentoo Linux on T43 (6) 中文环境

如果是初次安装Gentoo 系统与配置中文环境,在读接下来内容之前,建议首先阅读Gentoo Linux Localization Guide。 Locale locale 名称是一个具有命名约定、带有格式的字符串,其实质是其背后对应的字符集(codeset)。这里有一篇文章 关于locale的设定 Simple HOWTO 可以帮助理解locale ,虽然我并不完全同意文中的所有 观点。 使用不带任何参数的locale命令可以查看当前系统中与locale...

如果是初次安装Gentoo 系统与配置中文环境,在读接下来内容之前,建议首先阅读Gentoo Linux Localization Guide

Locale

locale 名称是一个具有命名约定、带有格式的字符串,其实质是其背后对应的字符集(codeset)。这里有一篇文章 关于locale的设定 Simple HOWTO 可以帮助理解locale ,虽然我并不完全同意文中的所有 观点。

使用不带任何参数的locale命令可以查看当前系统中与locale 有关的变量,以及它们所采用的locale 名称。

$ locale
LANG=en_US
LC_CTYPE=zh_CN
LC_NUMERIC="en_US"
LC_TIME="en_US"
LC_COLLATE="en_US"
LC_MONETARY="en_US"
LC_MESSAGES="en_US"
LC_PAPER="en_US"
LC_NAME="en_US"
LC_ADDRESS="en_US"
LC_TELEPHONE="en_US"
LC_MEASUREMENT="en_US"
LC_IDENTIFICATION="en_US"
LC_ALL=  

在Gentoo 手册 6. 安装Gentoo基本系统 最后一节,作为可选,简单的介绍了如何生成locale。Gentoo 提供了/etc/locale.gen 文件,用于指定为glibc 生成哪些locale,籍此来控制生成的locale 数量,减小系统体积。查看当前系统中已经生成并可用的locale 有哪些,使用以下命令:

$ locale -a
C
en_US
en_US.utf8
POSIX
zh_CN
zh_CN.gb2312
zh_CN.gbk
zh_CN.utf8

所有生成的locale 会被放在 /usr/lib/locale/ 下面的子目录,并且与locale 名称同名(除字符集部分的大小写)。(由于历史原因,C 与POSIX 是2个很特殊的locale)

$ ls -1 /usr/lib/locale/
en_US
en_US.utf8
zh_CN
zh_CN.gb2312
zh_CN.gbk
zh_CN.utf8

locale.gen 文件内容具有如下格式,空格之前是locale 名称,locale 名称中可以不包含字符集的部分,空格之后是所对应的字符集。

en_US ISO-8859-1
en_US.UTF-8 UTF-8 

作为中文用户,为了系统可以正确的识别、显示并处理中文字符,必须生成与中文字符集有关的的额外locale。字符集可以采用以下之一:

  • GB18030
  • GBK
  • GB2312
  • UTF-8

其中除UTF-8  是Unicode 解决方案以外,其它三个是父子集关系,其中GBK18030 最为完整,但仍然建议按以下格式,添加GBK 与GB2312 字符集相关的locale 到locale.gen 文件:

en_US ISO-8859-1
en_US.UTF-8 UTF-8
zh_CN GB18030
zh_CN.GBK GBK
zh_CN.GB2312 GB2312
zh_CN.UTF-8 UTF-8 

为什么不单独使用最完整的GB18030 字符集?理由是为了向下与一些较早的应用程序保持兼容,这个方法来自于 最精简有效的 glibc locales 设定

如果见到有些文章介绍使用/etc/locale.build 文件和不同的格式做类似的事情,不要奇怪,请用以下命令查看你的glibc 版本,如果大于等于glibc-2.3.6-r4 ,那么请用本文的文件名与格式,否则升级glibc 或者按他说的做。

$ emerge -s %^glibc$
*  sys-libs/glibc
Latest version available: 2.6.1
Latest version installed: 2.6.1

设置locale 有关的环境变量

对于中文用户,一般可以分为2种

  1. 一般性中