Skip navigation.

Fat R笔记……与减肥无关

Fat awful terrible Rubbish-bin

Posts tagged with "linux"

使用gnome-sound播放声音

,

嗯……我就喜欢这种简单的东西……gnome-sound只有几个函数,可以用来实现简单的声音播放。它的具体文档:http://developer.gnome.org/doc/API/2.0/libgnome/libgnome-gnome-sound.html

目前这个模块只是esound功能的封装(正合我意呢……),以后可能会进行扩展。提供的函数有:
void        gnome_sound_init                (const char *hostname);
void        gnome_sound_shutdown            (void);
void        gnome_sound_play                (const char *filename);
int         gnome_sound_sample_load         (const char *sample_name,
                                             const char *filename);
int         gnome_sound_connection_get      (void);


本机启用了esd后,会监听一个tcp端口,客户端连接这个tcp端口并发送声音数据就可以实现声音播放了。gnome-sound简化了这些细节,应用程序只需要先调用gnome_sound_init()连接esd服务器,再调用gnome_sound_play()播放声音就可以了。例如:
  gnome_sound_init(NULL);
  gnome_sound_play ("/usr/share/sounds/login.wav");

这样就可以在后台播放声音文件/usr/share/sounds/login.wav了。不用担心混音的问题,也不用担心任何错误。如果播放失败它会返回程序继续执行。与init对应,gnome_sound_shutdown ()用于关闭声音(应该就是关闭程序与esd的连接),似乎不是必须要调用的,反正即使shutdown了退出程序后正在播放的音频好像也是不会停止的。

另外两个函数,gnome_sound_sample_load ()和gnome_sound_connection_get (),相对来说low-level一些。这两个变量主要是配合esd_sample_play()函数来播放声音的。
简单的例子:
  int sampleID,connection;
  gnome_sound_init(NULL);
  sampleID =  gnome_sound_sample_load (NULL, "/usr/share/sounds/login.wav");
  connection = gnome_sound_connection_get();
  esd_sample_play (connection, sampleID);

gnome_sound_sample_load的第一个参数是sample name,不太清楚用途,估计是跟esd有关,反正写NULL也能工作……

bak

,

$ cat /etc/apt/sources.list

deb http://ubuntu.cn99.com/ubuntu/ dapper main restricted universe multiverse
deb http://ubuntu.cn99.com/ubuntu/ dapper-updates main restricted universe multiverse
deb http://ubuntu.csie.ntu.edu.tw/ubuntu/ dapper-security main restricted universe multiverse
deb http://ubuntu.cn99.com/ubuntu/ dapper-backports main restricted universe multiverse
deb http://ubuntu.cn99.com/ubuntu-cn/ dapper main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ dapper main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ dapper main restricted universe multiverse
deb http://quozl.netrek.org/pptp/pptpconfig ./

$ sudo apt-get install pptpconfig


$ cat f
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"'

$ . f

在ubuntu下连上OpenVPN了……

, ,

之前pptp虽然能拨通,ifconfig也能看到ppp0的interface,可是就是没办法通过那个interface上网 ,于是只好改用OpenVPN。还好以前被折磨了那么痛苦,积累了宝贵的经验,这次很快就弄好了。

首先当然是apt-get install openvpn,目前是2.0.6,也够用了。然后在/etc/openvpn下面建一个配置文件,参考配置如下:
client
dev tun
proto udp #我的server使用的是udp协议
remote 192.168.1.199 1194 #当然,我实际使用的ip和port不是这个 ;)
resolv-retry infinite
nobind
persist-key
persist-tun
ca keys/ca.crt #key文件相对于config文件的路径。可以改用绝对路径
cert keys/mobile.crt
key keys/mobile.key
comp-lzo
verb 3
route 202.116.84.0 255.255.255.0 #通过VPN连接202.116.84.0/24

假设文件保存为mobile.conf。

在服务器上生成客户端证书mobile.crt和密钥mobile.key,scp到本机上。另外ca.crt也要scp到本机上。按照上面的设置,这些文件应该放在/etc/openvpn/keys下面。注意如果key位置不对,启动openvpn服务会提示failed。出于安全考虑,最好把mobile.key文件的权限改成400,否则openvpn会在log中给出一个warning。

看看是否存在/dev/net/tun设备文件,如果没有就建立一个:
$ sudo mknod /dev/net/tun c 10 200

然后载入tun模块:
$ sudo modprobe tun

接着启动openvpn:
$ sudo /etc/init.d/openvpn start
Starting virtual private network daemon: mobile(OK).

可以看到openvpn自动调用mobile.conf作为配置文件启动了。如果一切正常,片刻之后就能用ifconfig看到tun0界面了。

当然,也可以以非daemon方式启动:
$sudo openvpn /etc/openvpn/mobile.conf

这种方式可以直接在屏幕上看到log,方便查错。

dubuntu下fcitx不能在opera和qterm中输入中文的问题

,

以前在ubuntu下面是没问题的,昨天装好了dubuntu后却发现用不了。开始怀疑是qt和fcitx版本的问题,但装了旧版本的fcitx却发现根本不能用。后来终于发现,是QT_IM_MODULE的设置的问题。把QT_IM_MODULE=fcitx改成QT_IM_MODULE=XIM就ok了。

我用ubuntu时是按照wiki.ubuntu.org.cn上提供的方法来设置的:
$sudo apt-get install fcitx
$sudo sh -c " echo 'export XMODIFIERS=@im=fcitx ; export GTK_IM_MODULE="fcitx" ; export QT_IM_MODULE="fcitx" ; fcitx ' > /etc/X11/Xsession.d/95xinput "
$sudo chmod +755 /etc/X11/Xsession.d/95xinput

(最后chmod似乎不需要)
然而这样设置在QTerm和opera下都用不了fcitx,要改成QT_IM_MODULE=XIM才行。

另外,网上也找到一篇文章,用的设置是这样的:
export XMODIFIERS="@im=fcitx"
export XIM=fcitx
export XIM_PROGRAM=fcitx
export GTK_IM_MODULE="XIM"
export QT_IM_MODULE="XIM"
fcitx

不太清楚GTK那行要不要改,XIM那两行似乎也不是必要的……

还有文章提到:

在QT/KDE 程序的输入框中, 可以单击鼠标右键,选择 "Imput Method"->"xim" , 接下来就可以使用 Ctrl+Space 呼出Fcitx输入法了!

还有一个一劳永X的方法:
代码:
主要原理就是设置 QT_IM_MODULE=xim 环境变量. 方法:
sudo vi /etc/X11/Xsession.d/95xinput
交里面的 QT_IM_MODULE=fcitx 改为 QT_IM_MODULE=xim

祝你愉快, 最后 /etc/X11/Xsession.d/95xinput 文件看起来像这样( 使用 fcitx 输入法时):
代码:
export XMODIFIERS=@im=fcitx
export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=xim
fcitx


嗯,要是我早点看到这篇就好了……

edgy的kernel(vmlinuz-2.6.17-10-generic)有bug...

我的蓝牙适配器用不了,虽然hciconfig可以看到设备,但地址是全0,而且hcitool scan会timedout。在LiveCD里面试也是这样。把dapper的内核(2.6.15-27-686)以及/lib/modules的内核可加载模块复制过来,然后修改/boot/grub/menu.lst,用这个kernel启动hciconfig就可以正常识别到设备。不过目前还不知道用dapper的内核会不会有副作用,所以干脆重新装了个dapper来用……(嗯,似乎dapper也是有bug,重启之后要重新插拔才能认得出来)

Using opera under ubuntu Edgy~

,

Everything seems ok except for the chinese IM
My settings are easy to port to Linux version from Windows version. With a fresh installed opera, there is no menu/, mouse/, skin/, keyboard/ directories under my ~/.opera directory. However, I just uploaded them via scp and restart opera, and opera can detect them automatically(Note: the default file name of the filter is ~./opera/urlfilter.ini). So glad that no change is needed to make to the config file. But at first, I found that I can't change my keyboard settings. I deleted the "space ctrl" entry but it just refused to work. After a few minutes, I figured out that the owner of the files is root becase I used root account to scp them, so the change I made was unable to apply to the .ini file. I think opera should at least give out a prompt windows if it can't write a file, instead of acting as nothing is happened.:smile: