A Simple Tutorial for XFCE Panel Plugin Programming

Forewarning: This write up assumes you are at least a user of */Linux or *BSD, and have some familiarity with developing anything.

As a FOSS OS user, there are times when my environment is lacking. As a FOSS OS user, there are times when my problems can be immediately addressed! I wanted a file manager that integrated with my desktop environment, such that I could manage files quickly in a tree view-style file manager that would always be visible on my left. Little did I know programming a plugin for XFCE was not straight forward due to the lack of documentation and instruction. The information that was available was convoluted and I had to resort to looking at the source of other plugins instead, as well as Makefiles to understand how to build them. This write up aims to fill this niche and make programming XFCE panel plugins a breeze! We'll begin with what you'll need, setting up the simple build process, implementation of the plugin, and installation.

Required Programs and Libraries
The following command is for Debian sid, which should work on Ubuntu as well.

apt-get install build-essentials libxfce4ui-common libxfce4ui-2-0

Depending if you already have GTK and friends installed, this will either be a big download, or around 25MB.

Setting up ./make.sh
For really tiny projects like this, I avoid using Makefiles. They are just an unnecessary complexity. So instead we'll call our compiler with a simple script that we'll call make.sh.

So first create a directory for your project. Call it whatever you wish. I named mine after a moon, enceladus.

Next, create the make.sh file. Run chmod 755 ./make.sh so that you can execute it later. Open up make.sh and add this to it:

You may have to change the libxfce4panel-1.0 to libxfce4panel-2.0. Save the file and quit.

Now when you want to compile your program, you just run ./make.sh! Easy-peasy.

The Fun Part
Time to get coding! Every plugin you write will begin with these lines:

constructor is the entry point to our code. You can rename it anything you want, but remember to use the register macro (XFCE_PANEL_PLUGIN_REGISTER_INTERNAL) so XFCE knows where to start executing code.

Now you just start programming like you would with any GTK application, with some tiny differences. The code below explains what you need to do next:

And that's it! Very simple and straight forward. If you compiled this, you would just get a blank XFCE plugin. The XFCE panel library offers more but most of the time people just want to create a simple plugin. You can check out my finished product, which uses exactly what I've described here.

Installation
Now this may vary from system to system. I had to have root permissions to install my custom plugins, because plugins are located at /usr/lib/xfce4/panel-plugins. After you've copied your plugin there you have to create a mypluginname.desktop file.

And install it in /usr/share/xfce4/panel-plugins.

Here is a quick visual result of my plugin. I'd say it's quite nice. (It's on the very left)



If there are any questions or better ways to do a certain aspect of this tutorial, feel free to leave a comment! I love comments (but not spam).

References:
1: https://wiki.xfce.org/dev/howto/panel_plugins

Comments

  1. Hi thank you for yr tutorial, I am trying to develop a XFCE panel plugin as well, but how do you debug the code? Thanks.

    ReplyDelete
    Replies
    1. I normally put printf()s in it. You could probably use gdb, but I'm unsure.

      Delete
  2. You write:
    "As a FOSS OS user, there are times when my environment is lacking. As a FOSS OS user, there are times when my problems can be immediately addressed! "

    I couldn't state it better. You successfully boiled it down to this essential statement. This is why I get upset with Windows almost each day (I am forced to use it a work). I am not saying that Linux-OS's dont have issues. But one can ADDRESS them easily :)

    Thanks for sharing your thoughts and code!!

    S4nshi

    ReplyDelete

Post a Comment

Popular Posts