Oct 14, 2010

配置Touchpad

为了彻底抛弃对于鼠标的依赖, 这几天先是改用了Awesome, 又手动打开了新版xorg(after 7.4)默认不开启的触摸板点击(tapping)功能.

好消息是: 用于触摸板的synclient和syndaemon不再需要开启SHMConfig选项了. 所以只要在.xinitrc中加入下面两行就能满足我的需求:

synclient TapButton1=1
syndaemon -i 2 -k -d &

第一行是启用点击, 第二行是用来防止敲击键盘时不小心碰到触摸板. 详细说明和方法请参考manual.

另外, 如果想通过xorg.conf来配置, 较简单的方法是使用子配置目录以及用Match匹配设备的InputClass段, 例如:

/etc/X11/xorg.conf.d/50-synaptics.conf

Section "InputClass"
	Identifier "Touchpad"
	MatchIsTouchpad "on"
	Driver "synaptics"
	Option "TapButton1" "1"
	Option "TapButton2" "2"
	Option "TapButton3" "3"
	Option "VertEdgeScroll" "true"
	Option "HorizEdgeScroll" "true"
EndSection

Oct 13, 2010

Awesome下设置notification

Awesome下的notification是靠它自己的Naughty模块实现, 所以在Awesome下用notify-send发出的notification并不和你在别的窗口管理器下样式一致.

如果你不喜欢默认样式, 可以override它的配置, Awesome的wiki(via)中给出了方法, 例如我的:

naughty.config.default_preset.font             = "sans 13.5"
naughty.config.default_preset.position         = "bottom_right"
naughty.config.default_preset.fg               = beautiful.fg_focus
naughty.config.default_preset.bg               = beautiful.bg_focus
naughty.config.default_preset.border_color     = beautiful.border_focus

需要注意的是, 如果你像我一样引用了诸如beautiful.fg_focus之类的变量, 记得把这几行配置放到beautiful.init之后.


Oct 13, 2010

开始用Awesome

前几天终于挪出点时间把Awesome好好配置了下, 用起来实在是舒服, 不用鼠标了, 操作快了, 手也不疼了, 我的小桌子上也可以同时放笔记本和书了. ^_^

除了它是平铺窗口管理器, Awesome最棒的地方是基于lua的配置语言, 更灵活更强大, 个人感觉和Fvwm一个量级, 但比Fvwm更容易理解和配置.

clean:

dirty:

PS: 配置已经上传, 还是在这里: http://adam8157.info/projects/


Sep 23, 2010

无视Recommends

话说apt的包依赖关系分了几个不同的权值, 严谨而清晰. 但我一直觉得其中的Recommends域比较混乱, 这个域应该定义的是”非必须或者不常用的功能性依赖”, 而大多数包维护者却都按照字面意思把”推荐”的包放到了这里.

所以我安装完基本Debian系统后的第一个操作就是对apt进行设置, 避免装上Recommends域的包, 像这样:

cat << EOF | sudo tee /etc/apt/apt.conf.d/90no-recommends
APT
{
	Install-Recommends 0;
};
EOF

可惜我很久之前就发现了一个问题, 一直没有解决, 例如: A depends C, B recommends C, 我将A卸载之后, 再执行autoremove操作, C却并不会被卸载掉, 因为apt将Recommends视作依赖了. 总之, 虽然我安装的时候不会去装Recommends域的包, 但是还是有可能会因为别的操作而装上这些对我来说不必要的包.

大概纠结了一年多这个问题, 今天终于找到了解决办法:

cat << EOF | sudo tee /etc/apt/apt.conf.d/90no-recommends
APT
{
	Install-Recommends 0;
	AutoRemove
	{
		RecommendsImportant 0;
	}
};
EOF

顺便抱怨下apt的文档, /usr/share/doc/apt/examples/configure-index.gz中所谓的全部选项根本不全, 我现在已经忘了我在哪个犄角旮旯搜索到这个的了…

PS: 1, autoremove不危险, 前提是你对apt的包管理体系很熟悉. 2, 我知道aptitude有Keep-Recommends的配置选项, 但是我个人不喜欢用aptitude.


Sep 8, 2010

静态库的链接顺序

今天工作中遇到了一个很诡异的问题:

项目中, a.c和b.c编译出的obj先打包成静态库c.a, 再和另外一个d.a以及main.c编译出的obj链接成最后的bin文件. a.c中有private_init()和private_read()两个函数, 其中private_init()是个空函数, private_read()则在d.a中被调用.

出现的现象是这样: 如果我main.c中不调用那两个函数, 最后就会链接报错 undefined reference to ‘private_read’, 但如果我在main.c中调用其中一个, 即使只是调用空函数private_init(), 链接也会正常完成. 更诡异得是, Makefile中的链接参数是”-lc -ld”, 但如果改成”-ld -lc”, 现象就消失了.

想了半天没想明白, 最后翻了下_Linkers & Loaders_ by John R. Levine, 终于找到了答案:

Searching libraries

After a library is created, the linker has to be able to search it. Library search generally happens during the first linker pass, after all of the individual input files have been read. If the library or libraries have symbol directories, the linker reads in the directory, and checks each symbol in turn against the linker’s symbol table. If the symbol is used but undefined, the linker includes that symbol’s file from the library. It’s not enough to mark the file for later loading; the linker has to process the symbols in the segments in the library file just like those in an explicitly linked file. The segments go in the segment table, and the symbols, both defined and undefined are entered into the global symbol table. It’s quite common for one library routine to refer to symbols in another library routine, for example, a higher level I/O routine like printf might refer to a lower level putc or write routine.

Library symbol resolution is an interative process. After the linker has made a pass over the symbols in the directory, if it included any files from the library during that pass, it should make another pass to resolve any symbols required by the included files, until it makes a complete pass over the directory and finds nothing else to include. Not all linkers do this; many just make a single sequential pass over the directory and miss any backwards dependencies from a file to another file earlier in the library. Tools like tsort and lorder can minimize the difficulty due to single-pass linkers, but it’s not uncommon for programmers to explcitly list the same library several times on the linker command line to force multiple passes and resolve all the symbols.

Unix linkers and many Windows linkers take an intermixed list of object files and libraries on the command line or in a control file, and process each in order, so that the programmer can control the order in which objects are loaded and libraries are searched. Although in principle this offers a great deal of flexibility and the ability to interpose private versions of library routines by listing the private versions before the library versions, in practice the ordered search provides little extra utility. Programmers invariably list all of their object files, then any application-specific libraries, then system libraries for math functions, network facilities and the like, and finally the standard system libraries.

When programmers use multiple libraries, it’s often necessary to list libraries more than once when there are circular dependencies among libraries. That is, if a routine in library A depends on a routine in library B, but another routine in library B depends on a routine in library A, neither searching A followed by B or B followed by A will find all of the required routines. The problem becomes even worse when the dependencies involve three or more libraries. Telling the linker to search A B A or B A B, or sometimes even A B C D A B C D is inelegant but solves the problem. Since there are rarely any duplicated symbols among the libraries, if the linker simply searched them all as a group as IBM’s mainframe linkers and AIX linker do, programmers would be well served.

简单说就是: 传统的Unix编译环境下, 静态库的加载是顺序搜索一遍, 遇到没链接的函数就记下, 如果这个函数在后面的库或obj中出现了, 链接器就会把这个函数所在的obj链接过去, 不包含未链接函数的obj就会被忽略过去(静态库也只是obj的简单打包而已).

于是, “-lc”的时候, 因为那两个函数在main.c中都没有被调用, 链接器就把a.o略过去了, “-ld”的时候虽然有了a.o中函数的调用, 但链接器已经把它给略过去, 找不到了.

所以如果库A依赖库B, 链接的顺序就应该写为A B, 如果相互依赖就应该为A B A或者B A B的顺序.

PS: 我查了一下, 大多现代的编译链都不会有这个问题, 但是传统, 标准以及我手里的这个编译链却都是这样的, 为了通用, 以后还是注意点吧.


Sep 2, 2010

WordPress评论的自动填表

嗯, 我是一个”洁癖症”患者.

我喜欢评论, 我喜欢清理Cookie, 我不喜欢装很多插件. So, 总是麻麻烦烦地把名字, 邮箱和网址挨个敲进去.

可是, 我也很懒. 于是搜索到了这个东西(via neolee.com), 很不错, 很方便.

简单说, 就是把下面的代码保存为书签, 需要填的时候点一下就好.

javascript:(function(){document.getElementById('author').value='名字';document.getElementById('email').value='邮箱';document.getElementById('url').value='网址';})()

PS: 记得把相应的内容改成你自己的, and, enjoy it.


Aug 15, 2010

设置Qt主题

非KDE环境下的Qt4程序默认主题, 实在是丑.

我有两个比较常用的Qt程序: SMPlayer和VirtualBox, 自从它俩升级至Qt4后我就一直在忍受那个丑陋的默认主题, 而今天, 终于忍不住动手调整了下.

方法嘛, Debian用户安装qt4-qtconfig, 运行qtconfig就是了, 一目了然. 当然, 对于我来说, 装这么个东西外加那么多依赖是不可以接受的, 目的只是为了搞清楚配置文件的位置和写法, 呵呵.

废话少说, 配置文件位于~/.config/Trolltech.conf

[Qt]
style=Cleanlooks
font="Sans Serif,9,-1,5,50,0,0,0,0,0"

最主要的主题和字体配置语句如上, Cleanlooks是默认带的, 个人觉得挺好. 另外, 指定主题为”GTK+”则会使用QGtkStyle特性让Qt使用当前的Gtk主题, 可惜我这里会报错”QGtkStyle was unable to detect the current GTK+ theme.”


好了, 可以把qt4-qtconfig卸载了.


Aug 8, 2010

好用的bc

最近搞的东西需要算很多偏移量之类的东西, 又多又烦. 还好, 在被Windows自带的计算器逼疯之前, 我改用了bc.

bc实际上是一种无限精度的计算语言, 可以赋值, 可以循环, 可以判断, 可以打印, 可以编写脚本. 不过我没有玩得那么花, 只是用来计算一些简单的式子而已, 例如:

echo '300+(525*5)-900+25^2' | bc
echo 'scale=3;100/(125-68)' | bc
echo 'obase=16;ibase=10;2*1024*1024+512*1024' | bc

都很简单, 只解释两点:
1, scale代表小数位数, 涉及到除法的时候最好加上, 否则会对齐输入数字中最长的小数位数.
2, obase代表输出进位制, ibase代表输入进位制, 默认都是十进制. 建议把obase写在前面, 否则二进制输入十进制输出”obase=10;ibase=2;”就得写成”ibase=2;obase=1010;”了, 呵呵.


Jul 23, 2010

不规矩的Firefox

Firefox, Swiftfox, Iceweasel都太可气了!

相信各位用wm的朋友都会给特定的应用程序制定规则, 例如放到特定的桌面, 不要边框等等, 很简单, 也很有用.

但是我很久之前就发现这些规则对Firefox及其衍生版都不起作用, 它们不会跟着你的特定规则自动出现在某个桌面, 而是坚持出现在当前桌面. 这个问题在我这一直都是悬案, 直到今天在Arch的Wiki中看到这段: Xprop_for_Firefox.

大概意思就是说: 不管实际是什么, Firefox及其衍生版都只认”Firefox*“这个WM_CLASS字符串. 真这么流氓? 用下面的openbox配置试了一下, 果然老老实实的…

<application class="Firefox*">
  <desktop>1</desktop>
</application>

PS: Wiki中说不知道具体原因, 但我猜是因为启动起来以后WM_CLASS这个值变了, 一直都在启动Xulrunner, 最后时刻给套上了个Firefox, Swiftfox或者Iceweasel的外壳. 改天验证下.


Jul 12, 2010

感人的文字

今天等车的时候看了几页罗永浩的<我的奋斗>, 好吧, 我被感动了.

我这辈子做过的绝大多数看起来不错的选择, 都不是完全被一个纯粹而又崇高的动机所驱使的: 当我勤奋读书的时候, 除了喜欢读书, 我也知道这会换来一些现实的好处;  当我择善固执和坚持原则的时候, 除了清楚这是我希望坚持的, 我也知道这会给我带来好的名声和影响力; 当我努力把事情做得漂亮又敞亮的时候, 除了确实想把它做好, 我也知道这会让很多人喜欢上我; 当我对朋友够意思, 对女朋友关心体贴的时候, 除了我愿意这样, 我也知道这会让他们受到感动…很惭愧, 我从来都不是那种浑然天成, 清澈纯净而又全无自知的真人.

再一次, 我觉得年龄不应该成为行事如此糟糕的借口, 在我的同龄小朋友里, 我也见过很多人是不像我那时候那么不堪的.