ubuntu下漂亮的冒泡提示 (2011-11-07 20:49)

来源:互联网 发布:十年期国债 知乎 编辑:程序博客网 时间:2024/05/16 05:01
 

 
UBUNTU 下漂亮的冒泡提示,可定制图标。挺好玩的,很久以前弄的一个小程序。
得先安装依赖库libnotify
 
/*   *  Copyright (C) 2011 crazyleen <357228736@qq.com>, All Rights Reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * HOWTO: * $(CC) $(Flags) -c mynotify.c -o mynotify.o `pkg-config --cflags --libs gtk+-2.0` -l notify */#include <libnotify/notify.h>#include "mynotify.h"int notification_show(char *title, char *body, char *icon){GError *error = NULL;NotifyNotification *notify_p;if (title == NULL)return -1;//you should init notify using app's nameif(notify_is_initted() == FALSE)if(notify_init("argv[0]") == FALSE){return -1;}    notify_p = notify_notification_new(title, body, icon, NULL);    //miliseconds, NOTIFY_EXPIRES_DEFAULT NOTIFY_EXPIRES_NEVERnotify_notification_set_timeout(notify_p, 1000);   //NOTIFY_URGENCY_LOW,NOTIFY_URGENCY_NORMAL, NOTIFY_URGENCY_CRITICAL,    notify_notification_set_urgency (notify_p,NOTIFY_URGENCY_NORMAL);//notify_notification_update(title, body, icon, NULL);//notify_notification_close(notify_p, &error);    if (notify_notification_show(notify_p, &error) == FALSE)return -1;//notify_uninit();return 0;}

/* mynotify.h * this function is to display a notification on the screan, * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * Copyright (C) 2011 crazyleen <357228736@qq.com>, All Rights Reserved. */#ifndef MYNOTIFY_H#define MYNOTIFY_H/* body & icoon are both optional * Returns : error: -1, success return 0 */int notification_show(char *title, char *body, char *icon);#endi

/* file.c * Copyright (C) 2011 crazyleen <357228736@qq.com>, All Rights Reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. */#include <stdio.h>#include <string.h>#include <unistd.h>#include "mynotify.h"int main(char argc, char *argv[]){notification_show("cheery", "here is body...", "/usr/share/pixmaps/apple-green.png");sleep(5);notification_show("cheery", NULL, NULL);printf("UNIX\n");return 0;}

原创粉丝点击