This site has been retired. For up to date information, see handbook.gnome.org or gitlab.gnome.org.


[Home] [TitleIndex] [WordIndex

1. A Library for Single-Instance Applications

This page covers a library for single-instance Gnome applications. It is a Google Summer of Code 2006 project and hopefully will be finished on August 21, 2006.

/!\ Attention: guniqueapp is not maintained anymore: please, see GtkApplication and GApplication.

1.1. The problem

1.2. Summer of Code project

This project is expected to improve the above mentioned situation. Details:

Email: Vytautas.Liuolia at gmail dot com

Project: Making a library for single-instance apps

Project website and source code: http://guniqueapp.akl.lt

Benefits to the Gnome community: A unified library to manage single-instance applications

Deliverables:

Project schedule: The project is due to be finished on August 21, 2006.

Project mentors: Elijah Newren and Matthias Clasen

1.3. Current methods in various applications

Application

Communication method with other instances

Notes

gedit

bacon

Is aware of desktops/workspaces

totem

bacon

gnome-system-monitor

bacon

epiphany

dbus

dbus string: org.gnome.Epiphany

evince

dbus

dbus string: org.gnome.evince.ApplicationService

rhythmbox

bonobo/dbus, optional at compile time

org.gnome.Rhythmbox

liferea

lock file

creates a lock file /.liferea/lock, no communication -- needs fixing

openoffice.org

socket in /tmp (OSL_PIPE*), similar to bacon

problems with startup notification

nautilus

LibUnique

gnome-panel

bonobo

firefox

X methods (see https://bugzilla.mozilla.org/show_bug.cgi?id=223492 for nasty details)

latest versions seem to work fine; Elijah doesn't believe me though

xmms

socket in /tmp

old gtk1 app, probably not targeted in this project

evolution

bonobo

issues with ending startup notification (fixed here)

gnome-terminal

dbus

dbus string: org.gnome.Terminal.Factory

yelp

bonobo (HEAD uses dbus - BrentSmith)

sound-juicer

bacon

1.4. User expectations on application startup (visual/desktop issues)

1.4.1. Focus stealing

User expects a newly created window to be activated (focused and raised) by their window manager (Metacity) if, and only if:

If windows do not get activated on launch, the window manager should use some mechanism to notify the user that they appeared (and which may need to account for workspaces and viewports). The canonical and current example is to flash them in the taskbar unless they are fully visible.

There are nasty corner cases, like a transient of the focus window that shouldn't get focus, windows that don't appear in the taskbar, windows that don't accept focus, and so on. They're all way out of the scope of this project and are the window manager maintainer's headache (input-only windows, in particular, are totally busted with Metacity right now). More about ICCCM input handling can be found at http://tronche.com/gui/x/icccm/sec-4.html#s-4.1.7

1.4.2. Startup notification

The technical details of X protocol for startup notification can be found on http://webcvs.freedesktop.org/startup-notification/startup-notification/doc/startup-notification.txt?view=markup

1.4.3. Workspaces

Users expect newly launched applications to appear in the workspace in which they were launched.

  1. Applications that can do multiple windows for multiple documents, should create a new window in the workspace, if it is not there. GEdit is an example of managing this right, with the exception that no hint has been given to Metacity about what happened so that Metacity doesn't know to activate it.
  2. Applications that cannot provide a second window, or are a one-window applications in nature (like Desktop preferences, for example), should be moved to the workspace where the launch occurred. This is closely related to gnomebug:328080.

1.4.4. Application examples that work incorrectly

Please note, that while some of the specified expectations are trivial, others may be disputed and only reflect my personal opinion. Feel free to post your attitude in the comments section below.

1.5. Implementation details & API

1.5.1. Object Hierarchy

GObject -> GUniqueApp -> GuniqueAppBacon, GUniqueAppDBus

1.5.2. Constructing App object

GUniqueApp* g_unique_app_get (gchar* name); /* Constructs a GUniqueApp object (DBus if present, Bacon otherwise */

GUniqueApp* g_unique_app_get_with_startup_id (gchar *name, gchar* startup_id); /* Same, but with the given startup-id; useful mostly for older GTK versions */

GUniqueAppBacon* g_unique_app_bacon_new (gchar* name);

GUniqueAppBacon* g_unique_app_bacon_new_with_startup_id (gchar* name, gchar* startup_id);

GUniqueAppDBus* g_unique_app_dbus_new (gchar* name);

GUniqueAppDBus* g_unique_app_dbus_new_with_startup_id (gchar* name, gchar* startup_id);

1.5.3. GUniqueApp

gboolean g_unique_app_is_running (GUniqueApp *app); /* Is another instance running? */

void g_unique_app_send_message (GUniqueApp *app, GUniqueAppCommand command, const gchar* data); /* Sends a message to another instance. Please see the convenience functions below, which represent the predefined commands */

void g_unique_app_activate (GUniqueApp *app); /* Activate the running instance */

void g_unique_app_new_document (GUniqueApp *app); /* Create a new document or window */

void g_unique_app_open_uri (GUniqueApp *app, const gchar *uri); /* Open a given file or URI */

void g_unique_app_custom_message (GUniqueApp *app, const gchar *data); /* Send a custom message */

1.5.4. Data types

typedef enum {

} GUniqueAppCommand;

1.5.5. GUniqueApp properties

Property

Type

Attributes

"name"

string

Read / Write / Construct Only

"startup-id"

string

Read / Write / Construct Only

"workspace"

guint

Read / Write / Construct Only

1.5.6. GUniqueApp signals

"message" void user_function (GUniqueApp *app, GUniqueAppCommand command, gchar* data, gchar* startup_id, guint workspace, gpointer user_data);

1.6. Porting applications to use the new library

I have started porting some applications to the new library, see https://bugzilla.gnome.org/show_bug.cgi?id=351092.

However, some of the applications will be left to port for maintainers, if they are willing to. I have prepared a small howto: GuniqueappUsageGuide.

1.7. Comments

Note that there's a recent discussion on the Usability list about this -- all the preference tools should be single instance too -- JoachimNoreiko

"If windows do not steal focus, they should flash in the taskbar and/or use other window manager methods to notify user about the new windows available to deal with." -- this goes against the spec being worked on at Metacity/WindowTypes.

[1] Yeah, I'm ignoring the globally-active input model of the ICCCM. I think it would be a bad idea for apps to try to use it in most all cases, and it turns out that most apps today don't use it.

Note -- do you guys know about this: http://www.o-hand.com/~iain/single-instance-with-dbus/making-single-instance-programs-with-dbus.html

Comments on the proposed API (MatthiasClasen)

Comments on the proposed API (ElijahNewren)

Comments on exiting (RossBurton)

Comments on exiting (DannyMilo)

Comments on DBus (SteveFrécinaux)

Comments on Closs Platform Issues (BrentSmith)

"Almost single" instance (muntyan).

Comments on "Almost single" instance (Danny Milo)

Single instance in SELinux (tedx).


2024-10-23 11:28