Thursday, August 23, 2007

Custom Font Config

<?xml version="1.0"?><!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>

<!--
default settings for all fonts.
-->
<match target="font" >
<edit mode="assign" name="rgba" >
<const>rgb</const>
</edit>
</match>
<match target="font" >
<edit mode="assign" name="hinting" >
<bool>true</bool>
</edit>
</match>
<match target="font" >
<edit mode="assign" name="hintstyle" >
<const>hintmedium</const>
</edit>
</match>
<match target="font" >
<edit mode="assign" name="antialias" >
<bool>true</bool>
</edit>
</match>


<!-- disable anti-alias for 8-17 size fonts -->
<match target="font" >

<test compare="contains" name="lang" qual="any">
<string>zh-cn</string>
<string>zh-sg</string>
<string>zh-tw</string>
<string>ja</string>
<string>ko</string>
</test>

<test compare="more_eq" name="pixelsize" qual="any" >
<double>8</double>
</test>
<test compare="less_eq" name="pixelsize" qual="any" >
<double>17</double>
</test>
<edit mode="assign" name="antialias" >
<bool>false</bool>
</edit>
</match>

<!-- the space between English fonts is too wide,solve this problem -->
<match target="font">

<test name="lang" compare="contains" qual="any">
<string>zh-tw</string>
<string>zh-sg</string>
<string>zh-cn</string>
<string>ja</string>
<string>ko</string>
</test>
<edit name="spacing">
<const>proportional</const>
</edit>
<edit name="globaladvance">
<bool>false</bool>
</edit>
</match>

<!--
define the smallest size of Chinese fonts
-->
<match target="font" >
<test name="family" qual="any" >
<string>SimSun</string>
<string>NSimSun</string>
<string>SimHei</string>
<string>AR PL ShanHeiSun Uni</string>
<string>AR PL ZenKai Uni</string>
<string>AR PL New Sung</string>
</test>
<test compare="more_eq" name="pixelsize" >
<int>8</int>
</test>
<test compare="less_eq" name="pixelsize" >
<int>12</int>
</test>
<edit compare="eq" name="pixelsize" >
<int>12</int>
</edit>
</match>
<!--
sort the family of "serif ,sans,monospace",make it fit to Chinese people
-->
<alias>
<family>serif</family>
<prefer>
<family>Times New Roman</family>
<family>Liberation Serif</family>
<family>Nimbus Roman No9 L</family>
<family>Luxi Serif</family>
<family>Times</family>
<family>Bitstream Vera Serif</family>
<family>DejaVu Serif</family>
<family>Simsun</family>
<family>MingLiu</family>
<family>WenQuanYi Bitmap Song</family>
<family>AR PL ShanHeiSun Uni</family>
<family>AR PL ZenKai Uni</family>
<family>AR PL New Sung</family>
</prefer>
</alias>
<alias>
<family>sans-serif</family>
<prefer>
<family>Arial</family>
<family>Verdana</family>
<family>Tahoma</family>
<family>Helvetica</family>
<family>Liberation Sans</family>
<family>Bitstream Vera Sans</family>
<family>DejaVu Sans</family>
<family>SimSun</family>
<family>WenQuanYi Bitmap Song</family>
<family>AR PL ShanHeiSun Uni</family>
<family>AR PL ZenKai Uni</family>
</prefer>
</alias>
<alias>
<family>monospace</family>
<prefer>
<family>Courier New</family>
<family>Liberation Mono</family>
<family>Luxi Mono</family>
<family>Andale Mono</family>
<family>Bitstream Vera Sans Mono</family>
<family>Nimbus Mono L</family>
<family>NSimSun</family>
<family>PMingLiu</family>
<family>WenQuanYi Bitmap Song</family>
<family>AR PL ShanHeiSun Uni</family>
<family>AR PL ZenKai Uni</family>
</prefer>
</alias>
<alias>
<family>Courier New</family>
<prefer>
<family>Courier New</family>
<family>Liberation Mono</family>
<family>Bitstream Vera Sans Mono</family>
<family>Nimbus Mono L</family>
<family>Courier</family>
<family>Luxi Mono</family>
<family>Andale Mono</family>
<family>NSimSun</family>
<family>PMingLiu</family>
<family>WenQuanYi Bitmap Song</family>
<family>AR PL ShanHeiSun Uni</family>
<family>AR PL ZenKai Uni</family>
</prefer>
</alias>
</fontconfig>

Sunday, August 5, 2007

Enabling DRI for Intel 945G/GMA950

Update for Slackware 12.1
In Slackware 12.1, don't have to do all the changes in xorg.conf, except setting the driver to the right one (mine is "intel").

However, I observed some slowness in firefox in 12.1. After setting the following option for the intel driver, the problem goes away. Seems it is caused by the new acceleration method EXA, which is the default.

Option "AccelMethod" "XAA"

xorg的i810(或者新的intel)驱动支持945G/GMA950. 实际上,i810驱动支持所有这些intel chipset:
i810, i810-DC100, i810e, i815, 830M, 845G, 852GM, 855GM, 865G, 915G, 915GM, 945G, 945GM
虽然man page里只提到915G和915GM。可以man i810看具体情况.

关键就是打开DRI. 我参照了以下文章。
http://dri.freedesktop.org/wiki/DriTroubleshooting

这篇文章很有帮助,告诉你如何一步一步确定DRI的问题的原因。建议有需要的看一看。

1. 我确定了我的内核(Slackware 12.0缺省huge smp内核)有Intel i810及以后芯片组的AGPGART和DRM的支持。

2. 我发现要在X里打开DRI.

编辑 xorg.conf
...
Section "Module"
...
# This loads the DRI module 载入DRI模块
Load "dri"

# This loads the GLX module 载入GLX模块
Load "glx"
...
EndSection
...
# 建一个用i810驱动的设备
Section "Device"
Identifier "i810"
Driver "i810"
# Alternative to Load "dri" 这个Option与Load "dri"等效
# Option "DRI" "true"
EndSection
...
# 使用i810设备
Section "Screen"
Identifier "Screen 1"
Device "i810"
Monitor "Samsung 710N"
...

# 让普通用户也可以使用DRI. 如果没有这个,只有root可以用。
Section "DRI"
Mode 0666
EndSection

之前:
x@slackx:~$ glxinfo
name of display: :0.0
display: :0 screen: 0
direct rendering: No
server glx vendor string: SGI

x@slackx:~$ glxgears
4246 frames in 5.1 seconds = 840.647 FPS
4200 frames in 5.0 seconds = 835.972 FPS
4605 frames in 5.1 seconds = 901.136 FPS
4920 frames in 5.1 seconds = 961.904 FPS
5160 frames in 5.0 seconds = 1027.514 FPS
5160 frames in 5.0 seconds = 1027.391 FPS
5160 frames in 5.0 seconds = 1028.289 FPS
5160 frames in 5.0 seconds = 1028.484 FPS
5160 frames in 5.0 seconds = 1027.678 FPS
5173 frames in 5.0 seconds = 1027.146 FPS
...

重起X之后:
x@slackx:~$ glxinfo
name of display: :0.0
display: :0 screen: 0
direct rendering: Yes
server glx vendor string: SGI

x@slackx:~$ glxgears
7591 frames in 5.0 seconds = 1518.076 FPS
7774 frames in 5.0 seconds = 1554.788 FPS
17984 frames in 5.0 seconds = 3596.714 FPS
17536 frames in 5.0 seconds = 3507.012 FPS
17372 frames in 5.0 seconds = 3474.314 FPS
18021 frames in 5.0 seconds = 3604.041 FPS

Saturday, August 4, 2007

转载:让 xterm 与其它程序间复制粘贴更灵活

在 TERM 中选中文字“甲”,需鼠标中键贴入其它程序(如 firefox ),而此时在 firefox 里选中文字“乙”并不 Ctrl-c ,再用鼠标中键贴出,发现贴出“乙”,而“甲”不见了。

需要效果:在 TERM 中选中即可 Ctrl-v 贴入 firefox 一类的程序中,无需鼠标中键。而在 firefox 一类的程序中 Ctrl-c 复制后,鼠标不论再选中什么,在 TERM 中 Shift-Insert 出的依然是 Ctrl-c 的内容

在 Xwindow 里有一个选中缓冲(PRIMARY)和一个剪贴板(CLIPBOARD)
几乎除了 TERM 程序以外,没有还在用选中缓冲的程序
造成 TERM 中选中的,需要鼠标中键才能贴到其它程序里。在贴之前,在其它程序中还不能选中任何东西,一旦选中,选中缓冲就被刷新

a) xterm 功能强大,本身就带剪贴板功能,如下配置即可
在 $HOME/.Xresources 里如下写,可让 xterm 的复制进入剪贴板,不再过选中缓中

*VT100*translations: #override \n\
Shift Insert:insert-selection(CLIPBOARD, CUT_BUFFER1) \n\
~Shift~Ctrl: insert-selection(CLIPBOARD, CUT_BUFFER1) \n\
~Shift: select-end(CLIPBOARD, CUT_BUFFER1)

前两句是说当 Shift-Insert 与鼠标中键(Btn2UP)效果是贴出剪贴板内容
第三句是说当 鼠标左键(BtnUP)效果是复制给剪贴板

这样一来,在 firefox 中任意选中的文字(不 Ctrl-c ),不管是 Shift-Insert 还是鼠标中键都复制不出来了

*VT100*translations: #override \n\
Shift Insert:insert-selection(CLIPBOARD, CUT_BUFFER1) \n\
~Shift~Ctrl: insert-selection(PRIMARY, CUT_BUFFER0) \n\
~Shift: select-end(CLIPBOARD, CUT_BUFFER1) \n\
~Shift: select-end(PRIMARY, CUT_BUFFER0)

这样就让在 firefox 里随意选中的文字,鼠标中键可贴在 TERM 中,而 Ctrl-c 的内容由 Shift-Insert 贴出
当然配置是灵活的,随自己喜欢了。

b) rxvt, aterm, mrxvt, rxvt-unicode 系列,需要一点小修改
这一系列都是基于 rxvt 的,代码相近,下面以 rxvt-unicode 为例:
(无需会编程,不过是替换游戏,把选中缓冲替换为剪贴板)

原理:把选中缓冲(XA_PRIMARY)换成剪贴板(xa[XA_CLIPBOARD])即可
vi rxvt-unicode-8.1/src/screen.C
2895 行:
if (selnum == Sel_Primary)
sel = xa[XA_CLIPBOARD];
else if (selnum == Sel_Secondary)
sel = XA_SECONDARY;
else
sel = XA_PRIMARY;

3066行:
XSetSelectionOwner (dpy, xa[XA_CLIPBOARD], vt, tm);
if (XGetSelectionOwner (dpy, xa[XA_CLIPBOARD]) == vt)

From: http://bbs.linuxsir.org/showthread.php?t=290883

Setting up Chinese in Slackware 12

Update: With Slackware 12.1, Chinese display works out-of-the-box with 文泉驿 (WenQuanYi) 正黑 font. IME packages like scim, skim and a lot more are included in 12.1, Chinese (and other language) input can be enabled easily by following instructions in CHANGES_AND_HINTS.TXT in the distribution.

Objective
- Allow displaying of Chinese characters in UTF-8 encoding while still having the normal English user interface.
- Allow inputing of Chinese characters using SCIM.

Environment
Slackware 12.0 full installation, default 2.6.21.5 huge smp kernel.
文泉驿 (WenQuanYi) Bitmap Song font 0.8.1
scim 1.4.7, scim-pinyin-0.5.91, skim-1.4.5

Display
Get 文泉驿 (WenQuanYi) Bitmap Song font from http://wqy.sourceforge.net/. I use the PCF format of current version 0.8.1. Follow the instructions included in the downloaded file (run mkfontdir, vc-cache, etc). I copied all the pcf files into /usr/share/fonts/ folder, so that no change to /etc/X11/xorg.conf and /etc/fonts/fonts.conf is required. You can also copy the file 85-wqy-bitmapsong.conf into /etc/fonts/conf.avail/ and created a link in /etc/fonts/conf.d/, as suggested by the installation instructions but with slight variation in directory names. However, this config file will force WenQuanYi to be the chosen for all kinds of font requests, and make your English contents ugly. So if you want beautiful English fonts, don't use this one, and do your own font config instead.

As I still want to use English as my primary desktop language, I leave the LC_* environment variables untouched, and only changed LC_CTYPE=zh_CN.UTF-8 in my ~/.profile. (Note: I tried en_US.utf8 but it does not work, as all KDE applications will show squares for Chinese characters. This means fontconfig does not pick WenQuanYi font. I guess the reason is because WenQuanYi Bitmap Song font's lang attribute does not have "en" in the list so it does not get matched. )

After that restart X.

Input
Download and compile scim, scim-pinyin, and skim, using root.
scim 1.4.7
./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var
make -j3
make instal DESTDIR=/your/dest
makepkg scim-1.4.7-i686-1xc.tgz
installpkg
scim-1.4.7-i686-1xc.tgz

scim-pinyin 0.5.91
./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var
make -j3
make instal DESTDIR=/your/dest
makepkg scim-pinyin-0.5.91-i686-1xc.tgz
installpkg scim-pinyin-0.5.91-i686-1xc.tgz

skim 1.4.5
scons configure prefix=/usr
scons -j3
mkdir -p /usr/lib/pkgconfig
cp skim.pc /usr/lib/pkgconfig/
scons install DESTDIR=/your/dest
makepkg skim-1.4.5-i686-1xc.tgz
installpkg
skim-1.4.5-i686-1xc.tgz

I also added the following lines to .profile:
export XMODIFIERS=@im=SCIM
export XIM=SCIM
export XIM_PROGRAM=SCIM

After that restart X.

Friday, August 3, 2007

Sample .bashrc

# Set the following to make all x terminals have proper PS1 and PS2
# \033[0;30m - Black
# \033[0;31m - Red
# \033[0;32m - Green
# \033[0;33m - Orange
# \033[0;34m - Blue
# \033[0;35m - Cyan
# \033[0;36m - Light Blue
# \033[0;37m - Grey
# \033[0;39m - White
export PS1='\u@\h:\w\$'
export PS2='> '

# Below sets the titlebar of the terminal windows
export PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'

# Display fortune for each new terminal session, and enable colors in ls output
for profile_script in '/etc/profile.d/bsd-games-login-fortune.sh' '/etc/profile.d/coreutils-dircolors.sh' ; do
if [ -x $profile_script ]; then
. $profile_script
fi
done
unset profile_script