xfce panel plugin和gnome applets在表现形式上基本是同一个概念,都是在桌面任务栏上显示运行的小程序。
分别通过xfce panel和gnome applets提供的接口来制作插件。
我们先来看看xfce panel plugin:
系统调用配置文件
/usr/local/share/xfce4/panel-plugins/sample.desktop 或者
/usr/share/xfce4/panel-plugins/myplugin.desktop 读取执行类。
外部插件.desktop内容:
[Xfce Panel]
Type=X-XFCE-PanelPlugin
Encoding=UTF-8
Name=Sample Plugin
Comment=Sample plugin for the Xfce panel
Icon=xfce4-sample-plugin
X-XFCE-Exec=/usr/local/libexec/xfce4/panel-plugins/xfce4-sample-plugin
#X-XFCE-Unique=true
内部插件.desktop内容:
X-XFCE-Module=<plugin_name>
X-XFCE-Module-Path=<prefix>/lib/xfce4/panel-plugins
在新版的xfce里出现了外部和内部插件的概念,两者实现的接口不同,内部是GModule,外部是GtkPlug 和 GtkSocket,至于具体有什么区别在下也没去仔细研究。
具体plugin实现类:
#include <libxfce4panel/xfce-panel-plugin.h>
XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL(construct);// 注册外部插件,内部插件GtkPlug 和 GtkSocket
XFCE_PANEL_PLUGIN_REGISTER_INTERNAL(construct);// 注册内部插件,内部插件用GModule 接口
具体的代码这里就不详细说了,这部分可以在最下方我提供的参考网站上找到。本文只是其中一个子集,基本上,其实忽略本文直接看参考资料就可以了。@_@!
接下来看看gnome applets:
系统调用配置文件
/usr/lib/bonobo/servers/ ExampleApplet_Factory.server
ExampleApplet_Factory.server内容:
<oaf_info>
<oaf_server iid="OAFIID:ExampleApplet_Factory" type="exe"
location="/usr/lib/gnome-panel/myexample">
<oaf_attribute name="repo_ids" type="stringv">
<item value="IDL:Bonobo/GenericFactory:1.0"/>
<item value="IDL:Bonobo/Unknown:1.0"/>
</oaf_attribute>
<oaf_attribute name="name" type="string" value="Example Applet Factory"/>
<oaf_attribute name="description" type="string" value="Factory to create the example applet"/>
</oaf_server>
<oaf_server iid="OAFIID:ExampleApplet" type="factory"
location="OAFIID:ExampleApplet_Factory">
<oaf_attribute name="repo_ids" type="stringv">
<item value="IDL:GNOME/Vertigo/PanelAppletShell:1.0"/>
<item value="IDL:Bonobo/Control:1.0"/>
<item value="IDL:Bonobo/Unknown:1.0"/>
</oaf_attribute>
<oaf_attribute name="name" type="string" value="Example Applet"/>
<oaf_attribute name="description" type="string" value="An example applet"/>
<oaf_attribute name="panel:category" type="string" value="Amusements"/>
<oaf_attribute name="panel:icon" type="string" value="myicon.png"/>
</oaf_server>
</oaf_info>
具体实现类 myexample.c:
#include <string.h>
#include <panel-applet.h>
#include <gtk/gtklabel.h>
static gboolean
myexample_applet_fill (PanelApplet *applet,
const gchar *iid,
gpointer data)
{
GtkWidget *label;
if (strcmp (iid, "OAFIID:ExampleApplet") != 0)
return FALSE;
label = gtk_label_new ("Hello World");
gtk_container_add (GTK_CONTAINER (applet), label);
gtk_widget_show_all (GTK_WIDGET (applet));
return TRUE;
}
PANEL_APPLET_BONOBO_FACTORY ("OAFIID:ExampleApplet_Factory",
PANEL_TYPE_APPLET,
"The Hello World Applet",
"0",
myexample_applet_fill,
NULL);
Compile this code with the following:
bash$ gcc $(pkg-config --cflags --libs libpanelapplet-2.0) -o myexample myexample.c
右键添加到面板就可以看到效果了。
参考和引用:
xfce panel plugin:
http://wiki.xfce.org/dev/howto/panel_plugins
gnome applets:
http://projects.gnome.org/ORBit2/appletstutorial.html