aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2013-06-28 17:50:12 -0400
committerLars Uebernickel <lars.uebernickel@canonical.com>2013-06-28 17:50:12 -0400
commit4ec8c2f614424a4d6ceb716f55320f1d81fd70b8 (patch)
treea143b5c8d3348d61ab6ca27db32a643ac2a84a62
parent3470db7e3e7df1c4490f9faa3eb2df7df9a630eb (diff)
parente7e2b6357c8b4f1dade9c4e4be9b193d747626e2 (diff)
downloadlibayatana-indicator-4ec8c2f614424a4d6ceb716f55320f1d81fd70b8.tar.gz
libayatana-indicator-4ec8c2f614424a4d6ceb716f55320f1d81fd70b8.tar.bz2
libayatana-indicator-4ec8c2f614424a4d6ceb716f55320f1d81fd70b8.zip
Add support for indicators to tell the panel where they'd like to appear
Merged from lp:~larsu/libindicator/positionable
-rw-r--r--README13
-rw-r--r--configure.ac2
-rw-r--r--libindicator/indicator-ng.c35
-rw-r--r--libindicator/indicator-object.c18
-rw-r--r--libindicator/indicator-object.h5
5 files changed, 68 insertions, 5 deletions
diff --git a/README b/README
index 1ea62ef..b51e110 100644
--- a/README
+++ b/README
@@ -6,14 +6,21 @@ files in `/usr/share/unity/indicators`. These files have to have the same
name as the well-known D-Bus name that the corresponding service owns.
An indicator file is a normal key file (like desktop files). It must have
-an `[Indicator Service]` section, that contains the service's name
-(`Name`) and optionally the object path at which its action group is found
-(`ObjectPath`). For example:
+an `[Indicator Service]` section, that must contain the service's name (`Name`)
+and the object path at which its action group is found (`ObjectPath`). For
+example:
[Indicator Service]
Name=indicator-example
ObjectPath=/com/canonical/indicator/example
+It should also contain a hint to where the indicator should appear in the panel:
+
+ Position=70
+
+The smaller the position, the further to the right (or left when RTL is
+enabled) the indicator appears.
+
An indicator can only export one action group, but a menu for each profile
("desktop", "greeter", "phone") supports. There must be a section for each
of those profiles, containing the object path on which the menu is
diff --git a/configure.ac b/configure.ac
index 698d64b..7c81575 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,5 +1,5 @@
AC_INIT([libindicator],
- [12.10.1],
+ [12.10.2],
[http://bugs.launchpad.net/libindicator],
[libindicator],
[http://launchpad.net/libindicator])
diff --git a/libindicator/indicator-ng.c b/libindicator/indicator-ng.c
index b372e2e..d8ac840 100644
--- a/libindicator/indicator-ng.c
+++ b/libindicator/indicator-ng.c
@@ -33,6 +33,7 @@ struct _IndicatorNg
gchar *bus_name;
gchar *profile;
gchar *header_action;
+ gint position;
guint name_watch_id;
@@ -169,6 +170,14 @@ indicator_ng_get_entries (IndicatorObject *io)
return g_list_append (NULL, &self->entry);
}
+static gint
+indicator_ng_get_position (IndicatorObject *io)
+{
+ IndicatorNg *self = INDICATOR_NG (io);
+
+ return self->position;
+}
+
static void
indicator_ng_set_accessible_desc (IndicatorNg *self,
const gchar *accessible_desc)
@@ -458,6 +467,27 @@ indicator_ng_service_vanished (GDBusConnection *connection,
}
}
+/* Get an integer from a keyfile. Returns @default_value if the key
+ * doesn't exist exists or is not an integer */
+static gint
+g_key_file_maybe_get_integer (GKeyFile *keyfile,
+ const gchar *group,
+ const gchar *key,
+ gint default_value)
+{
+ GError *error = NULL;
+ gint i;
+
+ i = g_key_file_get_integer (keyfile, group, key, &error);
+ if (error)
+ {
+ g_error_free (error);
+ return default_value;
+ }
+
+ return i;
+}
+
static gboolean
indicator_ng_load_from_keyfile (IndicatorNg *self,
GKeyFile *keyfile,
@@ -475,6 +505,8 @@ indicator_ng_load_from_keyfile (IndicatorNg *self,
if (self->object_path == NULL)
return FALSE;
+ self->position = g_key_file_maybe_get_integer (keyfile, "Indicator Service", "Position", -1);
+
/*
* Don't throw an error when the profile doesn't exist. Non-existant
* profiles are silently ignored by not showing an indicator at all.
@@ -537,6 +569,7 @@ indicator_ng_class_init (IndicatorNgClass *class)
object_class->finalize = indicator_ng_finalize;
io_class->get_entries = indicator_ng_get_entries;
+ io_class->get_position = indicator_ng_get_position;
properties[PROP_SERVICE_FILE] = g_param_spec_string ("service-file",
"Service file",
@@ -575,6 +608,8 @@ indicator_ng_init (IndicatorNg *self)
self->accessible_desc = g_strdup ("");
self->entry.accessible_desc = self->accessible_desc;
+ self->position = -1;
+
indicator_object_set_visible (INDICATOR_OBJECT (self), FALSE);
}
diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c
index 30a6543..40f114e 100644
--- a/libindicator/indicator-object.c
+++ b/libindicator/indicator-object.c
@@ -115,6 +115,7 @@ static GList * get_entries_default (IndicatorObject*);
static GList * get_all_entries (IndicatorObject*);
static void indicator_object_entry_being_removed (IndicatorObject*, IndicatorObjectEntry*);
static void indicator_object_entry_was_added (IndicatorObject*, IndicatorObjectEntry*);
+static gint indicator_object_real_get_position (IndicatorObject*);
static IndicatorObjectEntryPrivate * entry_get_private (IndicatorObject*, IndicatorObjectEntry*);
G_DEFINE_TYPE (IndicatorObject, indicator_object, G_TYPE_OBJECT);
@@ -141,6 +142,7 @@ indicator_object_class_init (IndicatorObjectClass *klass)
klass->get_location = NULL;
klass->entry_being_removed = NULL;
klass->entry_was_added = NULL;
+ klass->get_position = indicator_object_real_get_position;
klass->entry_activate = NULL;
klass->entry_activate_window = NULL;
@@ -778,6 +780,14 @@ indicator_object_entry_was_added (IndicatorObject * io, IndicatorObjectEntry * e
}
}
+static gint
+indicator_object_real_get_position (IndicatorObject *io)
+{
+ g_return_val_if_fail (INDICATOR_IS_OBJECT (io), -1);
+
+ return -1;
+}
+
/**
indicator_object_set_environment:
@io: #IndicatorObject to set on
@@ -942,3 +952,11 @@ indicator_object_entry_is_visible (IndicatorObject * io, IndicatorObjectEntry *
return entry_get_private (io, entry)->visibility == ENTRY_VISIBLE;
}
+
+gint
+indicator_object_get_position (IndicatorObject *io)
+{
+ g_return_val_if_fail (INDICATOR_IS_OBJECT (io), FALSE);
+
+ return INDICATOR_OBJECT_GET_CLASS (io)->get_position (io);
+}
diff --git a/libindicator/indicator-object.h b/libindicator/indicator-object.h
index 3c1a203..5c8de4b 100644
--- a/libindicator/indicator-object.h
+++ b/libindicator/indicator-object.h
@@ -111,6 +111,7 @@ typedef struct _IndicatorObjectEntry IndicatorObjectEntry;
@show_now_changed: Slot for #IndicatorObject::show-now-changed
@accessible_desc_update: Slot for #IndicatorObject::accessible-desc-update
@secondary_activate: Slot for #IndicatorObject::secondary-activate
+ @get_position: returns the desired position on the panel (0 is right-most), or -1
*/
struct _IndicatorObjectClass {
GObjectClass parent_class;
@@ -143,12 +144,13 @@ struct _IndicatorObjectClass {
void (*accessible_desc_update) (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_data);
void (*secondary_activate) (IndicatorObject * io, IndicatorObjectEntry * entry, guint timestamp, gpointer user_data);
+ gint (*get_position) (IndicatorObject *io);
+
/* Reserved */
void (*reserved1) (void);
void (*reserved2) (void);
void (*reserved3) (void);
void (*reserved4) (void);
- void (*reserved5) (void);
};
/**
@@ -203,6 +205,7 @@ gboolean indicator_object_entry_is_visible (IndicatorObject * io, IndicatorObjec
void indicator_object_entry_activate (IndicatorObject * io, IndicatorObjectEntry * entry, guint timestamp);
void indicator_object_entry_activate_window (IndicatorObject * io, IndicatorObjectEntry * entry, guint windowid, guint timestamp);
void indicator_object_entry_close (IndicatorObject * io, IndicatorObjectEntry * entry, guint timestamp);
+gint indicator_object_get_position (IndicatorObject *io);
void indicator_object_set_environment (IndicatorObject * io, GStrv env);
GStrv indicator_object_get_environment (IndicatorObject * io);