您的位置:首页 > 其它

实现gnome桌面的全局热键

2011-12-12 17:07 656 查看
gtk+-2.0 没有提供全局热键的功能,而需要使用GConf和 metacity才能得到该功能。

不过有个叫 Mikkel Kamstrup Erlandsen <mikkel.kamstrup@gmail.com> 的人写了一个

libgtkhotkey ,可以提供该功能,而且是跨平台的。

在Fedora系统上,安装libgtkhotkey

$ su

# yum install libgtkhotkey-devel

基本用法

#include <gtkhotkey.h>

链接参数: `pkg-config --cflags --libs gtkhotkey-1.0`

使用方法(编程)

1、注册hotkey

// used to register the hotkey

static void register_hotkey() {

GtkHotkeyInfo *hotkey_info = gtk_hotkey_info_new("gtkxrandr", "projecter", "<Super>F3", NULL);

if ( hotkey_info == NULL ) {

printf("error 1\n");

}

if ( FALSE == gtk_hotkey_info_bind(hotkey_info, NULL) ) {

printf("[error] can not bind hotkey\n");

}

else {

g_signal_connect(hotkey_info, "activated", G_CALLBACK(hotkey_handler), NULL );

}

}

2、在gtk中捕捉 actived 信号

// called when the user pressed the combination key.

static void hotkey_handler(GtkHotkeyInfo* hotkey, guint event_time, gpointer user_data) {

// add your code here

}

3.在初始化的时候调用 register_hotkey

int main ( int argc, char* argv[]) {

//...

register_hotkey();

//...

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: