[Xfce4-commits] [xfce/xfce4-power-manager] 01/01: Begin cleanup of notification code
noreply at xfce.org
noreply at xfce.org
Sun Oct 29 11:03:42 CET 2017
This is an automated email from the git hooks/post-receive script.
o c h o s i p u s h e d a c o m m i t t o b r a n c h m a s t e r
in repository xfce/xfce4-power-manager.
commit b1195c1b54baa9725a91966281ccb65adb08555c
Author: Simon Steinbeiss <simon.steinbeiss at elfenbeinturm.at>
Date: Sun Oct 29 11:03:24 2017 +0100
Begin cleanup of notification code
Also use symbolic icons where possible/appropriate.
---
src/xfpm-backlight.c | 92 ++++++++++++++-------------
src/xfpm-battery.c | 1 -
src/xfpm-kbd-backlight.c | 14 ++---
src/xfpm-notify.c | 157 ++++++++++++++++++++---------------------------
src/xfpm-notify.h | 24 ++++----
src/xfpm-power.c | 3 -
6 files changed, 128 insertions(+), 163 deletions(-)
diff --git a/src/xfpm-backlight.c b/src/xfpm-backlight.c
index 3ca25f5..6cc5640 100644
--- a/src/xfpm-backlight.c
+++ b/src/xfpm-backlight.c
@@ -72,15 +72,15 @@ struct XfpmBacklightPrivate
XfpmXfconf *conf;
XfpmButton *button;
XfpmNotify *notify;
-
+
NotifyNotification *n;
-
+
gboolean has_hw;
gboolean on_battery;
-
+
gint32 last_level;
gint32 max_level;
-
+
gint brightness_switch;
gint brightness_switch_save;
gboolean brightness_switch_initialized;
@@ -104,25 +104,25 @@ static void
xfpm_backlight_dim_brightness (XfpmBacklight *backlight)
{
gboolean ret;
-
+
if (xfpm_power_is_in_presentation_mode (backlight->priv->power) == FALSE )
{
gint32 dim_level;
-
+
g_object_get (G_OBJECT (backlight->priv->conf),
backlight->priv->on_battery ? BRIGHTNESS_LEVEL_ON_BATTERY : BRIGHTNESS_LEVEL_ON_AC, &dim_level,
NULL);
-
+
ret = xfpm_brightness_get_level (backlight->priv->brightness, &backlight->priv->last_level);
-
+
if ( !ret )
{
g_warning ("Unable to get current brightness level");
return;
}
-
+
dim_level = dim_level * backlight->priv->max_level / 100;
-
+
/**
* Only reduce if the current level is brighter than
* the configured dim_level
@@ -139,15 +139,15 @@ static gboolean
xfpm_backlight_destroy_popup (gpointer data)
{
XfpmBacklight *backlight;
-
+
backlight = XFPM_BACKLIGHT (data);
-
+
if ( backlight->priv->n )
{
g_object_unref (backlight->priv->n);
backlight->priv->n = NULL;
}
-
+
return FALSE;
}
@@ -159,22 +159,20 @@ xfpm_backlight_show_notification (XfpmBacklight *backlight, gfloat value)
/* create the notification on demand */
if ( backlight->priv->n == NULL )
{
- backlight->priv->n = xfpm_notify_new_notification (backlight->priv->notify,
- "",
- "",
- "display-brightness",
- 0,
- XFPM_NOTIFY_NORMAL);
+ /* generate a human-readable summary for the notification */
+ summary = g_strdup_printf (_("Brightness: %.0f percent"), value);
+ backlight->priv->n = xfpm_notify_new_notification (backlight->priv->notify,
+ _("Power Manager"),
+ summary,
+ XFPM_DISPLAY_BRIGHTNESS_ICON,
+ 0,
+ XFPM_NOTIFY_NORMAL);
+ g_free (summary);
}
- /* generate a human-readable summary for the notification */
- summary = g_strdup_printf (_("Brightness: %.0f percent"), value);
- notify_notification_update (backlight->priv->n, summary, NULL, NULL);
- g_free (summary);
-
/* add the brightness value to the notification */
- notify_notification_set_hint_int32 (backlight->priv->n, "value", value);
-
+ notify_notification_set_hint (backlight->priv->n, "value", value);
+
/* show the notification */
notify_notification_show (backlight->priv->n, NULL);
}
@@ -183,9 +181,9 @@ static void
xfpm_backlight_show (XfpmBacklight *backlight, gint level)
{
gfloat value;
-
+
XFPM_DEBUG ("Level %u", level);
-
+
value = (gfloat) 100 * level / backlight->priv->max_level;
xfpm_backlight_show_notification (backlight, value);
}
@@ -195,7 +193,7 @@ static void
xfpm_backlight_alarm_timeout_cb (EggIdletime *idle, guint id, XfpmBacklight *backlight)
{
backlight->priv->block = FALSE;
-
+
if ( id == TIMEOUT_BRIGHTNESS_ON_AC && !backlight->priv->on_battery)
xfpm_backlight_dim_brightness (backlight);
else if ( id == TIMEOUT_BRIGHTNESS_ON_BATTERY && backlight->priv->on_battery)
@@ -221,14 +219,14 @@ xfpm_backlight_button_pressed_cb (XfpmButton *button, XfpmButtonKey type, XfpmBa
{
gint32 level;
gboolean ret = TRUE;
-
+
gboolean handle_brightness_keys, show_popup;
-
+
g_object_get (G_OBJECT (backlight->priv->conf),
HANDLE_BRIGHTNESS_KEYS, &handle_brightness_keys,
SHOW_BRIGHTNESS_POPUP, &show_popup,
NULL);
-
+
if ( type != BUTTON_MON_BRIGHTNESS_UP && type != BUTTON_MON_BRIGHTNESS_DOWN )
return; /* sanity check, can this ever happen? */
@@ -250,13 +248,13 @@ static void
xfpm_backlight_brightness_on_ac_settings_changed (XfpmBacklight *backlight)
{
guint timeout_on_ac;
-
+
g_object_get (G_OBJECT (backlight->priv->conf),
BRIGHTNESS_ON_AC, &timeout_on_ac,
NULL);
-
+
XFPM_DEBUG ("Alarm on ac timeout changed %u", timeout_on_ac);
-
+
if ( timeout_on_ac == ALARM_DISABLED )
{
egg_idletime_alarm_remove (backlight->priv->idle, TIMEOUT_BRIGHTNESS_ON_AC );
@@ -271,13 +269,13 @@ static void
xfpm_backlight_brightness_on_battery_settings_changed (XfpmBacklight *backlight)
{
guint timeout_on_battery ;
-
+
g_object_get (G_OBJECT (backlight->priv->conf),
BRIGHTNESS_ON_BATTERY, &timeout_on_battery,
NULL);
-
+
XFPM_DEBUG ("Alarm on battery timeout changed %u", timeout_on_battery);
-
+
if ( timeout_on_battery == ALARM_DISABLED )
{
egg_idletime_alarm_remove (backlight->priv->idle, TIMEOUT_BRIGHTNESS_ON_BATTERY );
@@ -285,7 +283,7 @@ xfpm_backlight_brightness_on_battery_settings_changed (XfpmBacklight *backlight)
else
{
egg_idletime_alarm_set (backlight->priv->idle, TIMEOUT_BRIGHTNESS_ON_BATTERY, timeout_on_battery * 1000);
- }
+ }
}
@@ -336,10 +334,10 @@ static void
xfpm_backlight_init (XfpmBacklight *backlight)
{
backlight->priv = XFPM_BACKLIGHT_GET_PRIVATE (backlight);
-
+
backlight->priv->brightness = xfpm_brightness_new ();
backlight->priv->has_hw = xfpm_brightness_setup (backlight->priv->brightness);
-
+
backlight->priv->notify = NULL;
backlight->priv->idle = NULL;
backlight->priv->conf = NULL;
@@ -348,7 +346,7 @@ xfpm_backlight_init (XfpmBacklight *backlight)
backlight->priv->dimmed = FALSE;
backlight->priv->block = FALSE;
backlight->priv->brightness_switch_initialized = FALSE;
-
+
if ( !backlight->priv->has_hw )
{
g_object_unref (backlight->priv->brightness);
@@ -419,19 +417,19 @@ xfpm_backlight_init (XfpmBacklight *backlight)
g_signal_connect (backlight->priv->idle, "alarm-expired",
G_CALLBACK (xfpm_backlight_alarm_timeout_cb), backlight);
-
+
g_signal_connect (backlight->priv->idle, "reset",
G_CALLBACK(xfpm_backlight_reset_cb), backlight);
-
+
g_signal_connect (backlight->priv->button, "button-pressed",
G_CALLBACK (xfpm_backlight_button_pressed_cb), backlight);
-
+
g_signal_connect_swapped (backlight->priv->conf, "notify::" BRIGHTNESS_ON_AC,
G_CALLBACK (xfpm_backlight_brightness_on_ac_settings_changed), backlight);
-
+
g_signal_connect_swapped (backlight->priv->conf, "notify::" BRIGHTNESS_ON_BATTERY,
G_CALLBACK (xfpm_backlight_brightness_on_battery_settings_changed), backlight);
-
+
g_signal_connect (backlight->priv->power, "on-battery-changed",
G_CALLBACK (xfpm_backlight_on_battery_changed_cb), backlight);
g_object_get (G_OBJECT (backlight->priv->power),
diff --git a/src/xfpm-battery.c b/src/xfpm-battery.c
index 2a37fe4..4b40052 100644
--- a/src/xfpm-battery.c
+++ b/src/xfpm-battery.c
@@ -194,7 +194,6 @@ xfpm_battery_notify (XfpmBattery *battery)
message,
xfpm_battery_get_icon_name (battery),
8000,
- FALSE,
XFPM_NOTIFY_NORMAL);
g_free (message);
diff --git a/src/xfpm-kbd-backlight.c b/src/xfpm-kbd-backlight.c
index 8210c33..aeb65ab 100644
--- a/src/xfpm-kbd-backlight.c
+++ b/src/xfpm-kbd-backlight.c
@@ -111,21 +111,19 @@ xfpm_kbd_backlight_show_notification (XfpmKbdBacklight *self, gfloat value)
if ( self->priv->n == NULL )
{
+ /* generate a human-readable summary for the notification */
+ summary = g_strdup_printf (_("Keyboard Brightness: %.0f percent"), value);
self->priv->n = xfpm_notify_new_notification (self->priv->notify,
- "",
- "",
+ _("Power Manager"),
+ summary,
"keyboard-brightness",
0,
XFPM_NOTIFY_NORMAL);
+ g_free (summary);
}
- /* generate a human-readable summary for the notification */
- summary = g_strdup_printf (_("Keyboard Brightness: %.0f percent"), value);
- notify_notification_update (self->priv->n, summary, NULL, NULL);
- g_free (summary);
-
/* add the brightness value to the notification */
- notify_notification_set_hint_int32 (self->priv->n, "value", value);
+ notify_notification_set_hint (self->priv->n, "value", value);
/* show the notification */
notify_notification_show (self->priv->n, NULL);
diff --git a/src/xfpm-notify.c b/src/xfpm-notify.c
index e642610..4797628 100644
--- a/src/xfpm-notify.c
+++ b/src/xfpm-notify.c
@@ -48,10 +48,10 @@
static void xfpm_notify_finalize (GObject *object);
-static NotifyNotification * xfpm_notify_new_notification_internal (const gchar *title,
- const gchar *message,
- const gchar *icon_name,
- guint timeout,
+static NotifyNotification * xfpm_notify_new_notification_internal (const gchar *title,
+ const gchar *message,
+ const gchar *icon_name,
+ guint timeout,
XfpmNotifyUrgency urgency) G_GNUC_MALLOC;
#define XFPM_NOTIFY_GET_PRIVATE(o) \
@@ -60,13 +60,13 @@ static NotifyNotification * xfpm_notify_new_notification_internal (const gchar *
struct XfpmNotifyPrivate
{
XfpmDBusMonitor *monitor;
-
+
NotifyNotification *notification;
NotifyNotification *critical;
-
+
gulong critical_id;
gulong notify_id;
-
+
gboolean supports_actions;
gboolean supports_sync; /* For x-canonical-private-synchronous */
};
@@ -86,14 +86,14 @@ xfpm_notify_get_server_caps (XfpmNotify *notify)
GList *caps = NULL;
notify->priv->supports_actions = FALSE;
notify->priv->supports_sync = FALSE;
-
+
caps = notify_get_server_caps ();
-
- if (caps != NULL)
+
+ if (caps != NULL)
{
if (g_list_find_custom (caps, "x-canonical-private-synchronous", (GCompareFunc) g_strcmp0) != NULL)
notify->priv->supports_sync = TRUE;
-
+
if (g_list_find_custom (caps, "actions", (GCompareFunc) g_strcmp0) != NULL)
notify->priv->supports_actions = TRUE;
@@ -103,8 +103,8 @@ xfpm_notify_get_server_caps (XfpmNotify *notify)
}
static void
-xfpm_notify_check_server (XfpmDBusMonitor *monitor,
- gchar *service_name,
+xfpm_notify_check_server (XfpmDBusMonitor *monitor,
+ gchar *service_name,
gboolean connected,
gboolean on_session,
XfpmNotify *notify)
@@ -119,9 +119,9 @@ static void xfpm_notify_get_property (GObject *object,
GParamSpec *pspec)
{
XfpmNotify *notify;
-
+
notify = XFPM_NOTIFY (object);
-
+
switch (prop_id)
{
case PROP_ACTIONS:
@@ -165,18 +165,18 @@ static void
xfpm_notify_init (XfpmNotify *notify)
{
notify->priv = XFPM_NOTIFY_GET_PRIVATE (notify);
-
+
notify->priv->notification = NULL;
notify->priv->critical = NULL;
-
+
notify->priv->critical_id = 0;
notify->priv->notify_id = 0;
-
+
notify->priv->monitor = xfpm_dbus_monitor_new ();
xfpm_dbus_monitor_add_service (notify->priv->monitor, G_BUS_TYPE_SESSION, "org.freedesktop.Notifications");
g_signal_connect (notify->priv->monitor, "service-connection-changed",
G_CALLBACK (xfpm_notify_check_server), notify);
-
+
xfpm_notify_get_server_caps (notify);
}
@@ -186,24 +186,11 @@ xfpm_notify_finalize (GObject *object)
XfpmNotify *notify;
notify = XFPM_NOTIFY (object);
-
+
xfpm_notify_close_normal (notify);
xfpm_notify_close_critical (notify);
-
- G_OBJECT_CLASS (xfpm_notify_parent_class)->finalize(object);
-}
-static void
-xfpm_notify_set_notification_icon (NotifyNotification *n, const gchar *icon_name )
-{
- GdkPixbuf *pix = xfpm_icon_load (icon_name, 48);
-
- if ( pix )
- {
- notify_notification_set_image_from_pixbuf (n, pix);
- g_object_unref ( G_OBJECT(pix));
- }
-
+ G_OBJECT_CLASS (xfpm_notify_parent_class)->finalize(object);
}
static NotifyNotification *
@@ -212,35 +199,29 @@ xfpm_notify_new_notification_internal (const gchar *title, const gchar *message,
XfpmNotifyUrgency urgency)
{
NotifyNotification *n;
-
+
#ifdef NOTIFY_CHECK_VERSION
-#if NOTIFY_CHECK_VERSION (0, 7, 0)
- n = notify_notification_new (title, message, NULL);
+#if NOTIFY_CHECK_VERSION (0, 7, 0)
+ n = notify_notification_new (title, message, icon_name);
#else
- n = notify_notification_new (title, message, NULL, NULL);
+ n = notify_notification_new (title, message, icon_name, NULL);
#endif
#else
- n = notify_notification_new (title, message, NULL, NULL);
+ n = notify_notification_new (title, message, icon_name, NULL);
#endif
- notify_notification_set_hint (n, "transient", g_variant_new_boolean (TRUE));
-
- if ( icon_name )
- xfpm_notify_set_notification_icon (n, icon_name);
+ /* Only set transient hint on non-critical notifications, so that the critical
+ ones also end up in the notification server's log */
+ if (!notify->priv->critical)
+ notify_notification_set_hint (n, "transient", g_variant_new_boolean (FALSE));
+ notify_notification_set_hint (n, "image-path", g_variant_new_string (icon_name));
notify_notification_set_urgency (n, (NotifyUrgency)urgency);
-
- if ( timeout != 0)
- notify_notification_set_timeout (n, timeout);
-
- return n;
-}
-static void
-xfpm_notify_closed_cb (NotifyNotification *n, XfpmNotify *notify)
-{
- notify->priv->notification = NULL;
- g_object_unref (G_OBJECT (n));
+ if (timeout != 0)
+ notify_notification_set_timeout (n, timeout);
+
+ return n;
}
static void
@@ -265,12 +246,12 @@ xfpm_notify_close_notification (XfpmNotify *notify )
g_source_remove (notify->priv->notify_id);
notify->priv->notify_id = 0;
}
-
+
if ( notify->priv->notification )
{
if (!notify_notification_close (notify->priv->notification, NULL))
g_warning ("Failed to close notification\n");
-
+
g_object_unref (G_OBJECT(notify->priv->notification) );
notify->priv->notification = NULL;
}
@@ -280,7 +261,7 @@ XfpmNotify *
xfpm_notify_new (void)
{
static gpointer xfpm_notify_object = NULL;
-
+
if ( xfpm_notify_object != NULL )
{
g_object_ref (xfpm_notify_object);
@@ -295,19 +276,17 @@ xfpm_notify_new (void)
void xfpm_notify_show_notification (XfpmNotify *notify, const gchar *title,
const gchar *text, const gchar *icon_name,
- gint timeout, gboolean simple,
- XfpmNotifyUrgency urgency)
+ gint timeout, XfpmNotifyUrgency urgency)
{
NotifyNotification *n;
-
- if ( !simple )
- xfpm_notify_close_notification (notify);
-
- n = xfpm_notify_new_notification_internal (title,
- text, icon_name,
+
+ xfpm_notify_close_notification (notify);
+
+ n = xfpm_notify_new_notification_internal (title,
+ text, icon_name,
timeout, urgency);
- xfpm_notify_present_notification (notify, n, simple);
+ xfpm_notify_present_notification (notify, n);
}
NotifyNotification *xfpm_notify_new_notification (XfpmNotify *notify,
@@ -317,8 +296,8 @@ NotifyNotification *xfpm_notify_new_notification (XfpmNotify *notify,
guint timeout,
XfpmNotifyUrgency urgency)
{
- NotifyNotification *n = xfpm_notify_new_notification_internal (title,
- text, icon_name,
+ NotifyNotification *n = xfpm_notify_new_notification_internal (title,
+ text, icon_name,
timeout, urgency);
return n;
}
@@ -328,27 +307,23 @@ void xfpm_notify_add_action_to_notification (XfpmNotify *notify, NotifyNotificat
NotifyActionCallback callback, gpointer data)
{
g_return_if_fail (XFPM_IS_NOTIFY(notify));
-
+
notify_notification_add_action (n, id, action_label,
(NotifyActionCallback)callback,
data, NULL);
-
+
}
-void xfpm_notify_present_notification (XfpmNotify *notify, NotifyNotification *n, gboolean simple)
+void xfpm_notify_present_notification (XfpmNotify *notify, NotifyNotification *n)
{
g_return_if_fail (XFPM_IS_NOTIFY(notify));
-
- if ( !simple )
- xfpm_notify_close_notification (notify);
-
- if ( !simple )
- {
- g_signal_connect (G_OBJECT(n),"closed",
- G_CALLBACK(xfpm_notify_closed_cb), notify);
- notify->priv->notification = n;
- }
-
+
+ xfpm_notify_close_notification (notify);
+
+ g_signal_connect (G_OBJECT(n),"closed",
+ G_CALLBACK(xfpm_notify_closed_cb), notify);
+ notify->priv->notification = n;
+
notify->priv->notify_id = g_idle_add ((GSourceFunc) xfpm_notify_show, n);
}
@@ -357,31 +332,31 @@ void xfpm_notify_critical (XfpmNotify *notify, NotifyNotification *n)
g_return_if_fail (XFPM_IS_NOTIFY (notify));
xfpm_notify_close_critical (notify);
-
+
notify->priv->critical = n;
-
- g_signal_connect (G_OBJECT (n), "closed",
+
+ g_signal_connect (G_OBJECT (n), "closed",
G_CALLBACK (xfpm_notify_close_critical_cb), notify);
-
+
notify->priv->critical_id = g_idle_add ((GSourceFunc) xfpm_notify_show, n);
}
void xfpm_notify_close_critical (XfpmNotify *notify)
{
g_return_if_fail (XFPM_IS_NOTIFY (notify));
-
-
+
+
if (notify->priv->critical_id != 0)
{
g_source_remove (notify->priv->critical_id);
notify->priv->critical_id = 0;
}
-
+
if ( notify->priv->critical )
{
if (!notify_notification_close (notify->priv->critical, NULL))
g_warning ("Failed to close notification\n");
-
+
g_object_unref (G_OBJECT(notify->priv->critical) );
notify->priv->critical = NULL;
}
@@ -390,6 +365,6 @@ void xfpm_notify_close_critical (XfpmNotify *notify)
void xfpm_notify_close_normal (XfpmNotify *notify)
{
g_return_if_fail (XFPM_IS_NOTIFY (notify));
-
+
xfpm_notify_close_notification (notify);
}
diff --git a/src/xfpm-notify.h b/src/xfpm-notify.h
index 04d2520..0420a48 100644
--- a/src/xfpm-notify.h
+++ b/src/xfpm-notify.h
@@ -32,12 +32,12 @@ G_BEGIN_DECLS
#define XFPM_NOTIFY(o) (G_TYPE_CHECK_INSTANCE_CAST((o), XFPM_TYPE_NOTIFY, XfpmNotify))
#define XFPM_IS_NOTIFY(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), XFPM_TYPE_NOTIFY))
-typedef enum
+typedef enum
{
XFPM_NOTIFY_LOW = 0,
XFPM_NOTIFY_NORMAL,
XFPM_NOTIFY_CRITICAL
-
+
} XfpmNotifyUrgency;
typedef struct XfpmNotifyPrivate XfpmNotifyPrivate;
@@ -46,13 +46,13 @@ typedef struct
{
GObject parent;
XfpmNotifyPrivate *priv;
-
+
} XfpmNotify;
typedef struct
{
GObjectClass parent_class;
-
+
} XfpmNotifyClass;
GType xfpm_notify_get_type (void) G_GNUC_CONST;
@@ -63,7 +63,6 @@ void xfpm_notify_show_notification (XfpmNotify *notify,
const gchar *text,
const gchar *icon_name,
gint timeout,
- gboolean simple,
XfpmNotifyUrgency urgency);
NotifyNotification *xfpm_notify_new_notification (XfpmNotify *notify,
@@ -73,17 +72,16 @@ NotifyNotification *xfpm_notify_new_notification (XfpmNotify *notify
guint timeout,
XfpmNotifyUrgency urgency) G_GNUC_MALLOC;
-void xfpm_notify_add_action_to_notification (XfpmNotify *notify,
+void xfpm_notify_add_action_to_notification (XfpmNotify *notify,
NotifyNotification *n,
- const gchar *id,
+ const gchar *id,
const gchar *action_label,
- NotifyActionCallback callback,
+ NotifyActionCallback callback,
gpointer data);
-
-void xfpm_notify_present_notification (XfpmNotify *notify,
- NotifyNotification *n,
- gboolean simple);
-
+
+void xfpm_notify_present_notification (XfpmNotify *notify,
+ NotifyNotification *n);
+
void xfpm_notify_critical (XfpmNotify *notify,
NotifyNotification *n);
diff --git a/src/xfpm-power.c b/src/xfpm-power.c
index 172cff8..ec2bf3a 100644
--- a/src/xfpm-power.c
+++ b/src/xfpm-power.c
@@ -359,7 +359,6 @@ xfpm_power_report_error (XfpmPower *power, const gchar *error, const gchar *icon
error,
icon_name,
10000,
- FALSE,
XFPM_NOTIFY_CRITICAL);
}
@@ -848,7 +847,6 @@ xfpm_power_battery_charge_changed_cb (XfpmBattery *battery, XfpmPower *power)
_("System is running on low power"),
xfpm_battery_get_icon_name (battery),
10000,
- FALSE,
XFPM_NOTIFY_NORMAL);
}
@@ -871,7 +869,6 @@ xfpm_power_battery_charge_changed_cb (XfpmBattery *battery, XfpmPower *power)
msg,
xfpm_battery_get_icon_name (battery),
10000,
- FALSE,
XFPM_NOTIFY_NORMAL);
g_free (msg);
g_free (time_str);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list