From 18d92e36d1d08affd20ae905f6a9efdb139af170 Mon Sep 17 00:00:00 2001 From: Ratchanan Srirattanamet Date: Wed, 6 Dec 2023 23:52:09 +0700 Subject: Revert "Remove orphan osd-notify remnants" As discussed in [1], these hints are essential to make the indicator functions correctly on Lomiri. These hints should not make any difference on DE's that doesn't support them. [1] https://gitlab.com/ubports/development/core/content-hub/-/merge_requests/32#note_1552217874 This reverts commit ba37bd3998252a759434a8455e52f00699b50a09. --- src/notifier.c | 4 ++++ tests/test-notify.cc | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/notifier.c b/src/notifier.c index 07c5efa..cef8a3c 100644 --- a/src/notifier.c +++ b/src/notifier.c @@ -343,6 +343,10 @@ notification_show(IndicatorPowerNotifier * self) } } + notify_notification_set_hint(nn, "x-lomiri-snap-decisions", g_variant_new_string("true")); + notify_notification_set_hint(nn, "x-lomiri-non-shaped-icon", g_variant_new_string("true")); + notify_notification_set_hint(nn, "x-lomiri-private-affirmative-tint", g_variant_new_string("true")); + notify_notification_set_hint(nn, "x-lomiri-snap-decisions-timeout", g_variant_new_int32(INT32_MAX)); notify_notification_set_timeout(nn, NOTIFY_EXPIRES_NEVER); notify_notification_add_action(nn, "dismiss", _("OK"), on_dismiss_clicked, NULL, NULL); notify_notification_add_action(nn, "settings", _("Battery settings"), on_battery_settings_clicked, NULL, NULL); diff --git a/tests/test-notify.cc b/tests/test-notify.cc index 9fdb577..12a80fb 100644 --- a/tests/test-notify.cc +++ b/tests/test-notify.cc @@ -72,6 +72,8 @@ protected: static constexpr char const * METHOD_GET_INFO {"GetServerInformation"}; static constexpr char const * SIGNAL_CLOSED {"NotificationClosed"}; + static constexpr char const * HINT_TIMEOUT {"x-lomiri-snap-decisions-timeout"}; + protected: void SetUp() -- cgit v1.2.3 From f494eae6a5d5acd7b84437e5e251c6e3ff6f83a8 Mon Sep 17 00:00:00 2001 From: Ratchanan Srirattanamet Date: Thu, 7 Dec 2023 00:19:08 +0700 Subject: tests/test-notify: remove unused hint variable This variable becomes unused in "commit" 2cb851b018c5 [1], and doesn't seem to be used anywhere else in the code. Remove it. [1] 2cb851b018c5 ("add tests to confirm that the DBus object's PowerLevel property changes at the right times (and only at the right times) when the battery is draining"), which is part of this merge proposal on Launchpad: https://code.launchpad.net/~charlesk/indicator-power/lp-1296431-low-power-snap-decisions/+merge/233744 --- tests/test-notify.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test-notify.cc b/tests/test-notify.cc index 12a80fb..9fdb577 100644 --- a/tests/test-notify.cc +++ b/tests/test-notify.cc @@ -72,8 +72,6 @@ protected: static constexpr char const * METHOD_GET_INFO {"GetServerInformation"}; static constexpr char const * SIGNAL_CLOSED {"NotificationClosed"}; - static constexpr char const * HINT_TIMEOUT {"x-lomiri-snap-decisions-timeout"}; - protected: void SetUp() -- cgit v1.2.3 From 28b0b55e98b9e955209e5a26f28acc9b1b6e43ad Mon Sep 17 00:00:00 2001 From: Ratchanan Srirattanamet Date: Fri, 8 Dec 2023 16:55:29 +0700 Subject: Guard Lomiri-specific notification hints under conditionals --- src/notifier.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 9 deletions(-) diff --git a/src/notifier.c b/src/notifier.c index cef8a3c..73f62b4 100644 --- a/src/notifier.c +++ b/src/notifier.c @@ -88,6 +88,9 @@ typedef struct gboolean caps_queried; gboolean actions_supported; + #ifdef LOMIRI_FEATURES_ENABLED + gboolean lomiri_snap_decisions_supported; + #endif GCancellable * cancellable; #ifdef LOMIRI_FEATURES_ENABLED @@ -265,8 +268,8 @@ on_dismiss_clicked(NotifyNotification * nn G_GNUC_UNUSED, /* no-op; libnotify warns if we have a NULL action callback */ } -static gboolean -are_actions_supported(IndicatorPowerNotifier * self) +static void +ensure_caps_queried(IndicatorPowerNotifier * self) { priv_t * const p = get_priv(self); @@ -276,22 +279,54 @@ are_actions_supported(IndicatorPowerNotifier * self) GList * caps; GList * l; - /* see if actions are supported */ + #ifdef LOMIRI_FEATURES_ENABLED + gboolean lomiri_snap_decisions_supported = FALSE; + #endif + + /* see if actions and snap decisions are supported */ actions_supported = FALSE; caps = notify_get_server_caps(); - for (l=caps; l!=NULL && !actions_supported; l=l->next) + for (l=caps; l!=NULL; l=l->next) { if (!g_strcmp0(l->data, "actions")) actions_supported = TRUE; + #ifdef LOMIRI_FEATURES_ENABLED + else if (!g_strcmp0(l->data, "x-lomiri-snap-decisions")) + lomiri_snap_decisions_supported = TRUE; + #endif + } p->actions_supported = actions_supported; + #ifdef LOMIRI_FEATURES_ENABLED + p->lomiri_snap_decisions_supported = lomiri_snap_decisions_supported; + #endif p->caps_queried = TRUE; g_list_free_full(caps, g_free); } +} + +static gboolean +are_actions_supported(IndicatorPowerNotifier * self) +{ + priv_t * const p = get_priv(self); + + ensure_caps_queried(self); return p->actions_supported; } +#ifdef LOMIRI_FEATURES_ENABLED +static gboolean +are_lomiri_snap_decisions_supported(IndicatorPowerNotifier * self) +{ + priv_t * const p = get_priv(self); + + ensure_caps_queried(self); + + return p->lomiri_snap_decisions_supported; +} +#endif + static void notification_show(IndicatorPowerNotifier * self) { @@ -342,11 +377,14 @@ notification_show(IndicatorPowerNotifier * self) notify_notification_set_hint(nn, "sound-file", g_variant_new_string("file://" LOMIRI_SOUNDSDIR "/notifications/" LOW_BATTERY_SOUND)); } } - - notify_notification_set_hint(nn, "x-lomiri-snap-decisions", g_variant_new_string("true")); - notify_notification_set_hint(nn, "x-lomiri-non-shaped-icon", g_variant_new_string("true")); - notify_notification_set_hint(nn, "x-lomiri-private-affirmative-tint", g_variant_new_string("true")); - notify_notification_set_hint(nn, "x-lomiri-snap-decisions-timeout", g_variant_new_int32(INT32_MAX)); + #ifdef LOMIRI_FEATURES_ENABLED + if (are_lomiri_snap_decisions_supported(self)) { + notify_notification_set_hint(nn, "x-lomiri-snap-decisions", g_variant_new_string("true")); + notify_notification_set_hint(nn, "x-lomiri-non-shaped-icon", g_variant_new_string("true")); + notify_notification_set_hint(nn, "x-lomiri-private-affirmative-tint", g_variant_new_string("true")); + notify_notification_set_hint(nn, "x-lomiri-snap-decisions-timeout", g_variant_new_int32(INT32_MAX)); + } + #endif notify_notification_set_timeout(nn, NOTIFY_EXPIRES_NEVER); notify_notification_add_action(nn, "dismiss", _("OK"), on_dismiss_clicked, NULL, NULL); notify_notification_add_action(nn, "settings", _("Battery settings"), on_battery_settings_clicked, NULL, NULL); -- cgit v1.2.3 From c96d7eda53f5eb73cf4d3c850de2f444035ae8f3 Mon Sep 17 00:00:00 2001 From: Ratchanan Srirattanamet Date: Fri, 8 Dec 2023 17:02:05 +0700 Subject: Confirm that all supposedly boolean hints take strings --- src/notifier.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/notifier.c b/src/notifier.c index 73f62b4..5f0562e 100644 --- a/src/notifier.c +++ b/src/notifier.c @@ -379,6 +379,7 @@ notification_show(IndicatorPowerNotifier * self) } #ifdef LOMIRI_FEATURES_ENABLED if (are_lomiri_snap_decisions_supported(self)) { + /* Yes, all supposedly boolean values take strings... */ notify_notification_set_hint(nn, "x-lomiri-snap-decisions", g_variant_new_string("true")); notify_notification_set_hint(nn, "x-lomiri-non-shaped-icon", g_variant_new_string("true")); notify_notification_set_hint(nn, "x-lomiri-private-affirmative-tint", g_variant_new_string("true")); -- cgit v1.2.3