xfce panel plugin和gnome applets的写法和参考文档

 

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值