348 lines
11 KiB
Diff
348 lines
11 KiB
Diff
From 849e8e5f450d5ba1fae9d8ee65b60ac693679cfd Mon Sep 17 00:00:00 2001
|
|
From: =?UTF-8?q?Guido=20G=C3=BCnther?= <agx@sigxcpu.org>
|
|
Date: Tue, 8 Dec 2020 17:40:49 +0100
|
|
Subject: [PATCH 1/4] util: Add helper to munge app-id
|
|
MIME-Version: 1.0
|
|
Content-Type: text/plain; charset=UTF-8
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
Signed-off-by: Guido Günther <guido.gunther@puri.sm>
|
|
---
|
|
src/util.c | 33 +++++++++++++++++++++++++++++++++
|
|
src/util.h | 1 +
|
|
2 files changed, 34 insertions(+)
|
|
|
|
diff --git a/src/util.c b/src/util.c
|
|
index dd7ad50a..501179d9 100644
|
|
--- a/src/util.c
|
|
+++ b/src/util.c
|
|
@@ -58,3 +58,36 @@ phosh_clear_handler (gulong *handler, gpointer object)
|
|
*handler = 0;
|
|
}
|
|
}
|
|
+
|
|
+/**
|
|
+ * phosh_munge_app_id:
|
|
+ * @app_id: the app_id
|
|
+ *
|
|
+ * Munges an app_id according to the rules used by
|
|
+ * gnome-shell, feedbackd and phoc:
|
|
+ *
|
|
+ * Returns: The munged_app id
|
|
+ */
|
|
+char *
|
|
+phosh_munge_app_id (const char *app_id)
|
|
+{
|
|
+ char *id = g_strdup (app_id);
|
|
+ int i;
|
|
+
|
|
+ if (g_str_has_suffix (id, ".desktop")) {
|
|
+ char *c = g_strrstr (id, ".desktop");
|
|
+ if (c)
|
|
+ *c = '\0';
|
|
+ }
|
|
+
|
|
+ g_strcanon (id,
|
|
+ "0123456789"
|
|
+ "abcdefghijklmnopqrstuvwxyz"
|
|
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
+ "-",
|
|
+ '-');
|
|
+ for (i = 0; id[i] != '\0'; i++)
|
|
+ id[i] = g_ascii_tolower (id[i]);
|
|
+
|
|
+ return id;
|
|
+}
|
|
diff --git a/src/util.h b/src/util.h
|
|
index 55f79eec..266eeef6 100644
|
|
--- a/src/util.h
|
|
+++ b/src/util.h
|
|
@@ -12,3 +12,4 @@
|
|
void phosh_cp_widget_destroy (void *widget);
|
|
char *phosh_fix_app_id (const char *app_id);
|
|
void phosh_clear_handler (gulong *handler, gpointer object);
|
|
+gchar *phosh_munge_app_id (const gchar *app_id);
|
|
--
|
|
2.26.2
|
|
|
|
|
|
From aecd9cdd2ae1b25b5ee4ef8490fa36b64a6c975f Mon Sep 17 00:00:00 2001
|
|
From: =?UTF-8?q?Guido=20G=C3=BCnther?= <agx@sigxcpu.org>
|
|
Date: Tue, 8 Dec 2020 17:41:11 +0100
|
|
Subject: [PATCH 2/4] notification-manager: Add helper to determine if banners
|
|
should be shown
|
|
MIME-Version: 1.0
|
|
Content-Type: text/plain; charset=UTF-8
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
Signed-off-by: Guido Günther <guido.gunther@puri.sm>
|
|
---
|
|
src/notifications/notify-manager.c | 43 ++++++++++++++++++++++++++++++
|
|
src/notifications/notify-manager.h | 4 +++
|
|
2 files changed, 47 insertions(+)
|
|
|
|
diff --git a/src/notifications/notify-manager.c b/src/notifications/notify-manager.c
|
|
index 0911a3d6..4b380856 100644
|
|
--- a/src/notifications/notify-manager.c
|
|
+++ b/src/notifications/notify-manager.c
|
|
@@ -18,6 +18,7 @@
|
|
#include "notify-manager.h"
|
|
#include "shell.h"
|
|
#include "phosh-enums.h"
|
|
+#include "util.h"
|
|
|
|
#define NOTIFICATION_DEFAULT_TIMEOUT 5000 /* ms */
|
|
#define NOTIFICATIONS_SPEC_VERSION "1.2"
|
|
@@ -25,6 +26,10 @@
|
|
#define NOTIFICATIONS_SCHEMA_ID "org.gnome.desktop.notifications"
|
|
#define NOTIFICATIONS_KEY_SHOW_BANNERS "show-banners"
|
|
|
|
+#define NOTIFICATIONS_APP_SCHEMA_ID NOTIFICATIONS_SCHEMA_ID ".application"
|
|
+#define NOTIFICATIONS_APP_PREFIX "/org/gnome/desktop/notifications/application"
|
|
+#define NOTIFICATIONS_APP_KEY_SHOW_BANNERS "show-banners"
|
|
+
|
|
/**
|
|
* SECTION:notify-manager
|
|
* @short_description: Manages notifications
|
|
@@ -693,3 +698,41 @@ phosh_notify_manager_close_notification_by_id (PhoshNotifyManager *self,
|
|
phosh_notification_close (notification, reason);
|
|
return TRUE;
|
|
}
|
|
+
|
|
+/**
|
|
+ * phosh_notify_manager_get_show_notfication_banner:
|
|
+ * @self: the #PhoshNotifyManager
|
|
+ * @notification: the #PhoshNotification in question
|
|
+ *
|
|
+ * Checks whether a #PhoshNotificationBanner should be displayed
|
|
+ * for the given #PhoshNotification according to current policy.
|
|
+ *
|
|
+ * Returns: %TRUE if the banner should be shown, otherwise %FALSE
|
|
+ */
|
|
+gboolean
|
|
+phosh_notify_manager_get_show_notification_banner (PhoshNotifyManager *self,
|
|
+ PhoshNotification *notification)
|
|
+{
|
|
+ g_autoptr (GSettings) settings = NULL;
|
|
+ g_autofree char *path = NULL;
|
|
+ g_autofree char *munged_id = NULL;
|
|
+ GAppInfo *app_info;
|
|
+ gboolean show;
|
|
+
|
|
+ g_return_val_if_fail (PHOSH_IS_NOTIFY_MANAGER (self), FALSE);
|
|
+
|
|
+ if (!self->show_banners)
|
|
+ return FALSE;
|
|
+
|
|
+ app_info = phosh_notification_get_app_info (notification);
|
|
+ if (!app_info)
|
|
+ return TRUE;
|
|
+
|
|
+ munged_id = phosh_munge_app_id (g_app_info_get_id(app_info));
|
|
+ path = g_strconcat (NOTIFICATIONS_APP_PREFIX, "/", munged_id, "/", NULL);
|
|
+ settings = g_settings_new_with_path (NOTIFICATIONS_APP_SCHEMA_ID, path);
|
|
+ show = g_settings_get_boolean (settings, NOTIFICATIONS_APP_KEY_SHOW_BANNERS);
|
|
+
|
|
+ g_debug ("Show banners for %s: %d", munged_id, show);
|
|
+ return show;
|
|
+}
|
|
diff --git a/src/notifications/notify-manager.h b/src/notifications/notify-manager.h
|
|
index 0f75107f..9282b685 100644
|
|
--- a/src/notifications/notify-manager.h
|
|
+++ b/src/notifications/notify-manager.h
|
|
@@ -30,4 +30,8 @@ void phosh_notify_manager_add_notification (PhoshNotifyManager
|
|
gboolean phosh_notify_manager_close_notification_by_id (PhoshNotifyManager *self,
|
|
int id,
|
|
PhoshNotificationReason reason);
|
|
+gboolean
|
|
+ phosh_notify_manager_get_show_notification_banner (
|
|
+ PhoshNotifyManager *self,
|
|
+ PhoshNotification *notification);
|
|
G_END_DECLS
|
|
--
|
|
2.26.2
|
|
|
|
|
|
From 1d8c7b2892dd80600f0cdabf6a86849309b9ee1b Mon Sep 17 00:00:00 2001
|
|
From: =?UTF-8?q?Guido=20G=C3=BCnther?= <agx@sigxcpu.org>
|
|
Date: Tue, 8 Dec 2020 18:53:42 +0100
|
|
Subject: [PATCH 3/4] notification-manager: Keep a list of applications around
|
|
MIME-Version: 1.0
|
|
Content-Type: text/plain; charset=UTF-8
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
This allows users to configure their notification properties in
|
|
g-c-c.
|
|
|
|
Signed-off-by: Guido Günther <guido.gunther@puri.sm>
|
|
---
|
|
src/notifications/notify-manager.c | 68 +++++++++++++++++++++++++++++-
|
|
1 file changed, 66 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/src/notifications/notify-manager.c b/src/notifications/notify-manager.c
|
|
index 4b380856..14c0c6b5 100644
|
|
--- a/src/notifications/notify-manager.c
|
|
+++ b/src/notifications/notify-manager.c
|
|
@@ -25,10 +25,12 @@
|
|
|
|
#define NOTIFICATIONS_SCHEMA_ID "org.gnome.desktop.notifications"
|
|
#define NOTIFICATIONS_KEY_SHOW_BANNERS "show-banners"
|
|
+#define NOTIFICATIONS_KEY_APP_CHILDREN "application-children"
|
|
|
|
#define NOTIFICATIONS_APP_SCHEMA_ID NOTIFICATIONS_SCHEMA_ID ".application"
|
|
#define NOTIFICATIONS_APP_PREFIX "/org/gnome/desktop/notifications/application"
|
|
#define NOTIFICATIONS_APP_KEY_SHOW_BANNERS "show-banners"
|
|
+#define NOTIFICATIONS_APP_KEY_APP_ID "application-id"
|
|
|
|
/**
|
|
* SECTION:notify-manager
|
|
@@ -53,6 +55,7 @@ typedef struct _PhoshNotifyManager
|
|
guint next_id;
|
|
guint unknown_source;
|
|
gboolean show_banners;
|
|
+ GStrv app_children;
|
|
|
|
GSettings *settings;
|
|
|
|
@@ -277,6 +280,36 @@ parse_icon_string (const char *string)
|
|
}
|
|
|
|
|
|
+static void
|
|
+phosh_notify_manager_add_application (PhoshNotifyManager *self, GAppInfo *info)
|
|
+{
|
|
+ g_autofree char *munged_id = NULL;
|
|
+ g_autofree char *path = NULL;
|
|
+ g_autoptr (GSettings) settings = NULL;
|
|
+ g_autoptr(GPtrArray) new_apps = NULL;
|
|
+ const gchar *id;
|
|
+
|
|
+ id = g_app_info_get_id(info);
|
|
+ munged_id = phosh_munge_app_id (id);
|
|
+ if (g_strv_contains ((const gchar * const *)self->app_children, munged_id))
|
|
+ return;
|
|
+
|
|
+ g_debug ("Adding new application: %s/%s", id, munged_id);
|
|
+ new_apps = g_ptr_array_sized_new (g_strv_length (self->app_children) + 1);
|
|
+ for (int i = 0; i < g_strv_length (self->app_children); i++) {
|
|
+ g_ptr_array_add (new_apps, self->app_children[i]);
|
|
+ }
|
|
+ g_ptr_array_add (new_apps, munged_id);
|
|
+ g_ptr_array_add (new_apps, NULL);
|
|
+
|
|
+ path = g_strconcat (NOTIFICATIONS_APP_PREFIX, "/", munged_id, "/", NULL);
|
|
+ settings = g_settings_new_with_path (NOTIFICATIONS_APP_SCHEMA_ID, path);
|
|
+ g_settings_set_string (settings, NOTIFICATIONS_APP_KEY_APP_ID, id);
|
|
+ g_settings_set_strv (self->settings, NOTIFICATIONS_KEY_APP_CHILDREN,
|
|
+ (const gchar * const *)new_apps->pdata);
|
|
+}
|
|
+
|
|
+
|
|
static gboolean
|
|
handle_notify (PhoshNotifyDBusNotifications *skeleton,
|
|
GDBusMethodInvocation *invocation,
|
|
@@ -409,8 +442,10 @@ handle_notify (PhoshNotifyDBusNotifications *skeleton,
|
|
} else {
|
|
PhoshDBusNotification *dbus_notification;
|
|
|
|
- id = phosh_notify_manager_get_notification_id (self);
|
|
+ if (info)
|
|
+ phosh_notify_manager_add_application (self, info);
|
|
|
|
+ id = phosh_notify_manager_get_notification_id (self);
|
|
dbus_notification = phosh_dbus_notification_new (id,
|
|
app_name,
|
|
info,
|
|
@@ -460,6 +495,19 @@ on_notifications_setting_changed (PhoshNotifyManager *self,
|
|
}
|
|
|
|
|
|
+static void
|
|
+on_notification_apps_setting_changed (PhoshNotifyManager *self,
|
|
+ const char *key,
|
|
+ GSettings *settings)
|
|
+{
|
|
+ g_return_if_fail (PHOSH_IS_NOTIFY_MANAGER (self));
|
|
+ g_return_if_fail (G_IS_SETTINGS (settings));
|
|
+
|
|
+ g_strfreev (self->app_children);
|
|
+ self->app_children = g_settings_get_strv (settings, NOTIFICATIONS_KEY_APP_CHILDREN);
|
|
+}
|
|
+
|
|
+
|
|
static void
|
|
on_name_acquired (GDBusConnection *connection,
|
|
const char *name,
|
|
@@ -508,6 +556,18 @@ phosh_notify_manager_dispose (GObject *object)
|
|
}
|
|
|
|
|
|
+static void
|
|
+phosh_notify_manager_finalize (GObject *object)
|
|
+{
|
|
+ PhoshNotifyManager *self = PHOSH_NOTIFY_MANAGER (object);
|
|
+
|
|
+ g_strfreev (self->app_children);
|
|
+
|
|
+ G_OBJECT_CLASS (phosh_notify_manager_parent_class)->finalize (object);
|
|
+}
|
|
+
|
|
+
|
|
+
|
|
static void
|
|
phosh_notify_manager_constructed (GObject *object)
|
|
{
|
|
@@ -528,6 +588,10 @@ phosh_notify_manager_constructed (GObject *object)
|
|
g_signal_connect_swapped (self->settings, "changed::" NOTIFICATIONS_KEY_SHOW_BANNERS,
|
|
G_CALLBACK (on_notifications_setting_changed), self);
|
|
on_notifications_setting_changed (self, NULL, self->settings);
|
|
+
|
|
+ g_signal_connect_swapped (self->settings, "changed::" NOTIFICATIONS_KEY_APP_CHILDREN,
|
|
+ G_CALLBACK (on_notification_apps_setting_changed), self);
|
|
+ on_notification_apps_setting_changed (self, NULL, self->settings);
|
|
}
|
|
|
|
|
|
@@ -538,7 +602,7 @@ phosh_notify_manager_class_init (PhoshNotifyManagerClass *klass)
|
|
|
|
object_class->constructed = phosh_notify_manager_constructed;
|
|
object_class->dispose = phosh_notify_manager_dispose;
|
|
-
|
|
+ object_class->finalize = phosh_notify_manager_finalize;
|
|
|
|
/**
|
|
* PhoshNotifyManager::new-notification:
|
|
--
|
|
2.26.2
|
|
|
|
|
|
From e86ce9f9706c3824c1ae3f3cd42c68f6306eacf6 Mon Sep 17 00:00:00 2001
|
|
From: =?UTF-8?q?Guido=20G=C3=BCnther?= <agx@sigxcpu.org>
|
|
Date: Tue, 8 Dec 2020 18:54:22 +0100
|
|
Subject: [PATCH 4/4] shell: Only show banners for apps with show-banners
|
|
MIME-Version: 1.0
|
|
Content-Type: text/plain; charset=UTF-8
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
Signed-off-by: Guido Günther <guido.gunther@puri.sm>
|
|
---
|
|
src/shell.c | 2 +-
|
|
1 file changed, 1 insertion(+), 1 deletion(-)
|
|
|
|
diff --git a/src/shell.c b/src/shell.c
|
|
index 34833e6f..96152af9 100644
|
|
--- a/src/shell.c
|
|
+++ b/src/shell.c
|
|
@@ -417,7 +417,7 @@ on_new_notification (PhoshShell *self,
|
|
gtk_widget_destroy (priv->notification_banner);
|
|
}
|
|
|
|
- if (phosh_notify_manager_get_show_banners (manager) &&
|
|
+ if (phosh_notify_manager_get_show_notification_banner (manager, notification) &&
|
|
!phosh_lockscreen_manager_get_locked (priv->lockscreen_manager) &&
|
|
phosh_panel_get_state (PHOSH_PANEL (priv->panel)) == PHOSH_PANEL_STATE_FOLDED) {
|
|
g_set_weak_pointer (&priv->notification_banner,
|
|
--
|
|
2.26.2
|
|
|