Set window urgency hint independent of notification setting

fixes #960
This commit is contained in:
fiaxh 2020-12-30 20:22:14 +01:00
parent c454bd904d
commit 99e98ac8d9
4 changed files with 21 additions and 26 deletions

View file

@ -10,10 +10,6 @@ public class NotificationEvents : StreamInteractionModule, Object {
public string id { get { return IDENTITY.id; } } public string id { get { return IDENTITY.id; } }
public signal void notify_content_item(ContentItem content_item, Conversation conversation); public signal void notify_content_item(ContentItem content_item, Conversation conversation);
public signal void notify_subscription_request(Conversation conversation);
public signal void notify_connection_error(Account account, ConnectionManager.ConnectionError error);
public signal void notify_muc_invite(Account account, Jid room_jid, Jid from_jid, string? password, string? reason);
public signal void notify_voice_request(Account account, Jid room_jid, Jid from_jid, string nick);
private StreamInteractor stream_interactor; private StreamInteractor stream_interactor;
private NotificationProvider? notifier; private NotificationProvider? notifier;
@ -77,7 +73,10 @@ public class NotificationEvents : StreamInteractionModule, Object {
if (!highlight) return; if (!highlight) return;
} }
notify_content_item(item, conversation);
if (notify != Conversation.NotifySetting.OFF) {
notifier.notify_message.begin(message, conversation, conversation_display_name, participant_display_name); notifier.notify_message.begin(message, conversation, conversation_display_name, participant_display_name);
}
break; break;
case FileItem.TYPE: case FileItem.TYPE:
FileTransfer file_transfer = ((FileItem) item).file_transfer; FileTransfer file_transfer = ((FileItem) item).file_transfer;
@ -87,7 +86,10 @@ public class NotificationEvents : StreamInteractionModule, Object {
if (notify == Conversation.NotifySetting.HIGHLIGHT) return; if (notify == Conversation.NotifySetting.HIGHLIGHT) return;
if (file_transfer.direction == FileTransfer.DIRECTION_SENT) return; if (file_transfer.direction == FileTransfer.DIRECTION_SENT) return;
notify_content_item(item, conversation);
if (notify != Conversation.NotifySetting.OFF) {
notifier.notify_file.begin(file_transfer, conversation, is_image, conversation_display_name, participant_display_name); notifier.notify_file.begin(file_transfer, conversation, is_image, conversation_display_name, participant_display_name);
}
break; break;
} }
} }

View file

@ -28,11 +28,22 @@ public class Dino.Ui.Application : Gtk.Application, Dino.Application {
create_actions(); create_actions();
startup.connect(() => { startup.connect(() => {
stream_interactor.get_module(NotificationEvents.IDENTITY).register_notification_provider(new GNotificationsNotifier(stream_interactor)); NotificationEvents notification_events = stream_interactor.get_module(NotificationEvents.IDENTITY);
notification_events.register_notification_provider(new GNotificationsNotifier(stream_interactor));
FreeDesktopNotifier? free_desktop_notifier = FreeDesktopNotifier.try_create(stream_interactor); FreeDesktopNotifier? free_desktop_notifier = FreeDesktopNotifier.try_create(stream_interactor);
if (free_desktop_notifier != null) { if (free_desktop_notifier != null) {
stream_interactor.get_module(NotificationEvents.IDENTITY).register_notification_provider(free_desktop_notifier); notification_events.register_notification_provider(free_desktop_notifier);
} }
notification_events.notify_content_item.connect((content_item, conversation) => {
// Set urgency hint also if (normal) notifications are disabled
// Don't set urgency hint in GNOME, produces "Window is active" notification
var desktop_env = Environment.get_variable("XDG_CURRENT_DESKTOP");
if (desktop_env == null || !desktop_env.down().contains("gnome")) {
if (this.active_window != null) {
this.active_window.urgency_hint = true;
}
}
});
}); });
activate.connect(() => { activate.connect(() => {

View file

@ -107,15 +107,6 @@ public class Dino.Ui.FreeDesktopNotifier : NotificationProvider, Object {
} catch (Error e) { } catch (Error e) {
warning("Failed showing content item notification: %s", e.message); warning("Failed showing content item notification: %s", e.message);
} }
// Don't set urgency hint in GNOME, produces "Window is active" notification
var desktop_env = Environment.get_variable("XDG_CURRENT_DESKTOP");
if (desktop_env == null || !desktop_env.down().contains("gnome")) {
var app = (GLib.Application.get_default() as Application);
if (app.active_window != null) {
app.active_window.urgency_hint = true;
}
}
} }
public async void notify_subscription_request(Conversation conversation) { public async void notify_subscription_request(Conversation conversation) {

View file

@ -63,15 +63,6 @@ namespace Dino.Ui {
if (active_conversation_ids != null) { if (active_conversation_ids != null) {
active_conversation_ids.add(conversation.id.to_string()); active_conversation_ids.add(conversation.id.to_string());
} }
// Don't set urgency hint in GNOME, produces "Window is active" notification
var desktop_env = Environment.get_variable("XDG_CURRENT_DESKTOP");
if (desktop_env == null || !desktop_env.down().contains("gnome")) {
var app = (GLib.Application.get_default() as Application);
if (app.active_window != null) {
app.active_window.urgency_hint = true;
}
}
} }
public async void notify_subscription_request(Conversation conversation) { public async void notify_subscription_request(Conversation conversation) {