ProductsDesktop Server For Scientific Computing For IBM POWER For IBM System z For SAP Business Applications Red Hat Network Satellite ManagementExtended Update Support High Availability High Performance Network Load Balancer Resilient Storage Scalable File System Smart Management Extended Lifecycle SupportWeb Server Developer Studio Portfolio Edition JBoss Operations Network FuseSource Integration Products Web Framework Kit Application Platform Data Grid Portal Platform SOA Platform Business Rules Management System (BRMS) Data Services Platform Messaging JBoss Community or JBoss enterprise
SolutionsApplication development Business process management Enterprise application integration Interoperability Operational efficiency Security VirtualizationMigrate to Red Hat Enterprise Linux Systems management Upgrading to Red Hat Enterprise Linux JBoss Enterprise Middleware IBM AIX to Red Hat Enterprise Linux HP-UX to Red Hat Enterprise Linux Solaris to Red Hat Enterprise Linux UNIX to Red Hat Enterprise Linux Start a conversation with Red Hat Migration services
TrainingPopular and new courses JBoss Middleware Administration curriculum Core System Administration curriculum JBoss Middleware Development curriculum Advanced System Administration curriculum Linux Development curriculum Cloud Computing and Virtualization curriculum
ConsultingStandard Operating Environment (SOE) Strategic Migration Planning Service-oriented architecture (SOA) Enterprise Data Solutions Business Process Management
Issue #12 October 2005
- Adding encryption support to HAL: A user's experience with Fedora development
- Python programming on Linux
- Integrating your applications into the desktop, Part 1
- The state of Java on Linux
- Maintaining an autotools-enabled package
- Performance tuning with GCC, Part 2: Analyzing performance problems
- Using OProfile to analyze an RPM package build
- Remix culture comes to film at the Internet Archive
- Video: Red Hat and TSANet coordinate customer support
- Summit 2006: Not just country
- Video: Red Hat and BEA have no time for downtime
- Video: Red Hat Learning Services get real-world results
From the Inside
In each Issue
- Editor's blog
- Red Hat speaks
- Ask Shadowman
- Tips & tricks
- Fedora status report
- Magazine archive
Integrating your applications into the desktop,
by Rosanna Yuen
- Introducing freedesktop.org
- Desktop files
- Startup notification
- Installing icons
- Adding MIME types
- Next time
- Further reading
- About the author
Creating a perfect application is a wonderful feeling. Whether large or small, you want the desktop to recognize your application and interact appropriately with it. With multiple desktops available, it is best for your application to be able to integrate itself into as many as possible. Although no official rules have been adopted, there is a set of specifications available at freedesktop.org.
Although not a formal standards body, freedesktop.org maintains a set of informal but commonly agreed upon guidelines. When followed, these guidelines allow applications to be integrated onto compliant desktops.
The biggest step in integrating your application into the desktop is to create a desktop file. This desktop file contains a listing of the configurations for your application. The desktop takes the information in this file and uses it to:
- Put the application in the .
- List the application in the Run Application... dialog.
- Create appropriate launchers in the Menu or on the desktop.
- Associate the name and description of the application.
- Use the appropriate icon.
- Recognize the MIME types it supports.
To allow the desktop to find your desktop file, create your
file with the name
using the name of your application. Place this file in the
Each working desktop file needs to follow the same format. A minimal example of a desktop file is shown in Example 1, “Sample desktop file”. The file is split into sections, each starting with the section descriptor in square brackets. In this example, only one section is shown, as that is the essential section to integrating your application to the desktop. Within each section, the part of each line before the equal sign is the key while the second half is the value. An explanation of each line is shown in Table 1, “Line-by-line explanation”.
Other than the first line identifying the desktop file, the
order of the lines is not important. In Example 1, “Sample desktop file”, the line
Type=Applicationcould be the second row, the fifth row, or the last row, and the result would be the same. However, the keys are case sensitive.
Type=Applicationis not the same as
[Desktop Entry] Type=Application Encoding=UTF-8 Name=Sample Application Name Comment=A sample application Exec=application Icon=application.png Terminal=false
||The first line of every desktop file and the section header to identify the block of key value pairs associated with the desktop. Necessary for the desktop to recognize the file correctly.|
||Tells the desktop that this desktop file pertains to
an application. Other valid values for this key are
||Describes the encoding of the entries in this desktop file.|
||Name of your application for the main menu and any launchers.|
||Describes the application. Used as a tooltip.|
||The command that starts this application from a shell. It can have arguments.|
||The icon name associated with this application.|
||Describes whether the application should run in a terminal.|
Starting your application
If your application can take command line arguments, you can signify them by using the fields as shown in Table 2, “Exec variables”.
||A single filename.|
||A single URL.|
||A single directory. Used in conjunction with
||Multiple directories. Used in conjunction with
||A single filename without a path.|
||multiple filenames without paths.|
||A URI or local filename of the location of the desktop file.|
||The name of the Device entry.|
To create localized names and comments, additional lines for each locale need to be added. For example, to add a Swedish version of the comment, add the following line:
There is no limit to the number of translations in the file.
Since maintaining a long list of translations in a file is
cumbersome, a better way to create these translations is to use
intltoolpackage. See the man pages for
intltool-mergefor more information.
Although the fields shown in the “Desktop files” section provide enough information for the desktop to recognize your application, there are other fields that may be useful for your particular case. One of these fields is startup notification.
When startup notification is set, the panel and cursor notify the user that the application has started. When the application appears onscreen, the panel and cursor return to normal.
To let the launcher know your application supports startup notification, add the following line to your desktop file:
This command in the desktop file enables the desktop to use whatever startup notification is built into either your application or your toolkit. Most modern toolkits work transparently with the startup notification system. If you are not using a modern toolkit, the Startup Notification Spec has the details that you need to implement it yourself.
- Regardless of toolkit, there is one type of application where you would have to manually handle feedback. Applications with remoting capabilities (where you tell an existing process to open a new window instead of starting a new process) cannot use the built-in mechanism. The value of the DESKTOP_LAUNCH_ID environment has to be passed by your application and has to notify the launching system of your new window. If you are using GTK+, the documentation for gdk_notify_startup_complete() has a bit more information.
In Example 1, “Sample desktop file”, we have specified the
icon for this file as
For this to work, we need to put that icon file in the
The desktop looks for icons in the selected theme directory of
/usr/share/icons/. If you have only one
icon, place it in
is the directory the desktop looks in if there is no icon for your
application in the selected theme. If you have themed icons, put
them in the appropriate directories.
Icons placed in the
/usr/share/icons/hicolor/directory should consist of neutral colors so as to not clash with any other theme.
Adding MIME types
If your application can open specific MIME types, you need to let
the desktop know in the desktop file. For example, if your
application can accept
png files, add the
following line into your desktop file:
Additional MIME types can be added by separating the different types with semicolons.
The system already knows of a large number of MIME types.
However, if you are creating one of your own, you need to register
your MIME type into the MIME database. In the
/usr/share/mime/packages/ directory, create
XML file with the format as shown in Example 2, “Sample file for registering a new MIME type”.
<?xml version="1.0" encoding="UTF-8"?> <mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info"> <mime-type type="application/x-example"> <comment>Example file type </comment> <magic priority="50"> <match value="search-string" type="string" offset="10:140"/> </magic> <glob pattern="*.newextension"/> </mime-type> </mime-info>
In this example, replace the sample MIME type with the name of your MIME type. The magic section searches files for the search string for identification. The glob line uses the suffix of filenames for identification.
magiccommand forces the computer to open the files to search for the string, the
globcommand is preferable.
Once your new MIME type is adequately described in the file, run the following in a shell:
- For more information on choosing a good MIME extension and to register your MIME type, go to the IANA website.
Although this article can get you started with your desktop files, there are many other specifications at freedesktop.org that are useful in integrating applications to the desktop. Next month, we will discuss specifications for XDND, system tray, Xsettings, and intltool.
- Freedesktop.org — A repository for desktop guidelines.
- Desktop Entry Specification — Specifications for creating a desktop file.
- Startup Notification Protocol — Describes how to implement startup notification in your application.
- Icon Theme Specification — Describes how to create icons and where they go.