control-center: make notifications widget optional

parent 8ac5050f
...@@ -22,7 +22,9 @@ namespace XimperShellNotificationCenter { ...@@ -22,7 +22,9 @@ namespace XimperShellNotificationCenter {
Object (css_name: "blankwindow"); Object (css_name: "blankwindow");
widgets = new List<unowned Widgets.BaseWidget> (); widgets = new List<unowned Widgets.BaseWidget> ();
widgets.append (notifications_widget); if (notifications_widget != null) {
widgets.append (notifications_widget);
}
if (app.use_layer_shell) { if (app.use_layer_shell) {
if (!GtkLayerShell.is_supported ()) { if (!GtkLayerShell.is_supported ()) {
...@@ -164,7 +166,12 @@ namespace XimperShellNotificationCenter { ...@@ -164,7 +166,12 @@ namespace XimperShellNotificationCenter {
} }
break; break;
default: default:
return notifications_widget.key_press_event_cb (keyval, keycode, state); if (notifications_widget != null) {
return notifications_widget
.key_press_event_cb (
keyval, keycode, state);
}
return false;
} }
// Override the builtin list navigation // Override the builtin list navigation
return true; return true;
...@@ -189,12 +196,6 @@ namespace XimperShellNotificationCenter { ...@@ -189,12 +196,6 @@ namespace XimperShellNotificationCenter {
w = DEFAULT_WIDGETS; w = DEFAULT_WIDGETS;
} }
// Add the notifications widget if not found in the list
if (!("notifications" in w)) {
warning ("Notification widget not included in \"widgets\" config. " +
"Using default bottom position");
w += "notifications";
}
bool has_notifications = false; bool has_notifications = false;
foreach (string key in w) { foreach (string key in w) {
// Add the widget if it is valid // Add the widget if it is valid
...@@ -203,16 +204,18 @@ namespace XimperShellNotificationCenter { ...@@ -203,16 +204,18 @@ namespace XimperShellNotificationCenter {
key, out is_notifications); key, out is_notifications);
if (is_notifications) { if (is_notifications) {
if (notifications_widget == null) {
continue;
}
if (has_notifications) { if (has_notifications) {
warning ("Cannot have multiple \"notifications\" widgets! Skipping\"%s\"", warning ("Cannot have multiple " +
key); "\"notifications\" widgets! " +
"Skipping \"%s\"", key);
continue; continue;
} }
has_notifications = true; has_notifications = true;
notifications_widget.reload_config (); notifications_widget.reload_config ();
// Append the notifications widget to the box in the order of the provided list
box.append (notifications_widget); box.append (notifications_widget);
continue; continue;
} }
...@@ -334,18 +337,24 @@ namespace XimperShellNotificationCenter { ...@@ -334,18 +337,24 @@ namespace XimperShellNotificationCenter {
default: default:
case PositionY.TOP: case PositionY.TOP:
align_y = Gtk.Align.START; align_y = Gtk.Align.START;
// Set cc widget position if (notifications_widget != null) {
notifications_widget.set_list_is_reversed (false); notifications_widget
.set_list_is_reversed (false);
}
break; break;
case PositionY.CENTER: case PositionY.CENTER:
align_y = Gtk.Align.CENTER; align_y = Gtk.Align.CENTER;
// Set cc widget position if (notifications_widget != null) {
notifications_widget.set_list_is_reversed (false); notifications_widget
.set_list_is_reversed (false);
}
break; break;
case PositionY.BOTTOM: case PositionY.BOTTOM:
align_y = Gtk.Align.END; align_y = Gtk.Align.END;
// Set cc widget position if (notifications_widget != null) {
notifications_widget.set_list_is_reversed (true); notifications_widget
.set_list_is_reversed (true);
}
break; break;
} }
// Fit the ControlCenter to the monitor height // Fit the ControlCenter to the monitor height
......
...@@ -12,6 +12,10 @@ namespace XimperShellNotificationCenter.Widgets { ...@@ -12,6 +12,10 @@ namespace XimperShellNotificationCenter.Widgets {
}); });
} }
public override bool is_available () {
return notifications_widget != null;
}
private void update_icon () { private void update_icon () {
icon.set_from_icon_name (active icon.set_from_icon_name (active
? "notifications-disabled-symbolic" ? "notifications-disabled-symbolic"
......
...@@ -37,12 +37,19 @@ namespace XimperShellNotificationCenter.Widgets { ...@@ -37,12 +37,19 @@ namespace XimperShellNotificationCenter.Widgets {
} }
title_widget.set_text (title); title_widget.set_text (title);
clear_all_button.set_visible (has_clear_all_button);
clear_all_button.set_sensitive (!notifications_widget.is_empty ());
ximper_shell_notification_center_daemon.subscribe_v2.connect ((count) => { clear_all_button.set_visible (
clear_all_button.set_sensitive (count > 0); has_clear_all_button
}); && notifications_widget != null);
if (notifications_widget != null) {
clear_all_button.set_sensitive (
!notifications_widget.is_empty ());
ximper_shell_notification_center_daemon
.subscribe_v2.connect ((count) => {
clear_all_button.set_sensitive (count > 0);
});
}
} }
[GtkCallback] [GtkCallback]
......
...@@ -110,26 +110,37 @@ namespace XimperShellNotificationCenter { ...@@ -110,26 +110,37 @@ namespace XimperShellNotificationCenter {
noti_daemon = new NotiDaemon (); noti_daemon = new NotiDaemon ();
ximper_shell_notification_center_daemon = new XimperShellNotificationCenterDaemon (); ximper_shell_notification_center_daemon = new XimperShellNotificationCenterDaemon ();
// Notification Daemon
Bus.own_name_on_connection (conn, // Register notification daemon only if notifications widget is enabled
"org.freedesktop.Notifications", bool has_notifications = false;
bus_name_flags, foreach (string w in ConfigModel.instance.widgets.data) {
() => { if (w.has_prefix ("notifications")) {
try { has_notifications = true;
conn.register_object ("/org/freedesktop/Notifications", noti_daemon); break;
init.callback ();
} catch (Error e) {
error ("Could not register notification service: \"%s\"", e.message);
} }
}, }
() => {
stderr.printf ( if (has_notifications) {
"Could not acquire notification name. " + Bus.own_name_on_connection (conn,
"Please close any other notification daemon " + "org.freedesktop.Notifications",
"like mako or dunst\n"); bus_name_flags,
Process.exit (1); () => {
}); try {
yield; conn.register_object ("/org/freedesktop/Notifications", noti_daemon);
init.callback ();
} catch (Error e) {
error ("Could not register notification service: \"%s\"", e.message);
}
},
() => {
stderr.printf (
"Could not acquire notification name. " +
"Please close any other notification daemon " +
"like mako or dunst\n");
Process.exit (1);
});
yield;
}
// Ximper Shell Notification Center Daemon // Ximper Shell Notification Center Daemon
// Name is already owned by GApplication via register() // Name is already owned by GApplication via register()
...@@ -143,23 +154,26 @@ namespace XimperShellNotificationCenter { ...@@ -143,23 +154,26 @@ namespace XimperShellNotificationCenter {
xdg_activation = new XdgActivationHelper (); xdg_activation = new XdgActivationHelper ();
floating_notifications = new NotificationWindow (); if (has_notifications) {
notifications_widget = new Widgets.Notifications (); notifications_widget = new Widgets.Notifications ();
control_center = new ControlCenter (); floating_notifications = new NotificationWindow ();
add_window (floating_notifications);
add_window (floating_notifications);
add_window (control_center); noti_daemon.on_dnd_toggle.connect ((dnd) => {
if (dnd && floating_notifications.visible) {
noti_daemon.on_dnd_toggle.connect ((dnd) => { noti_daemon
// Hide all non-critical notifications on toggle .remove_all_floating_notifications (
if (dnd && floating_notifications.visible) { true, (noti) => {
noti_daemon.remove_all_floating_notifications (true, (noti) => { return noti.param.urgency
return noti.param.urgency != UrgencyLevels.CRITICAL; != UrgencyLevels.CRITICAL;
}); });
} }
ximper_shell_notification_center_daemon
.emit_subscribe ();
});
}
ximper_shell_notification_center_daemon.emit_subscribe (); control_center = new ControlCenter ();
});
// Update on start // Update on start
ximper_shell_notification_center_daemon.emit_subscribe (); ximper_shell_notification_center_daemon.emit_subscribe ();
......
...@@ -23,6 +23,7 @@ namespace XimperShellNotificationCenter { ...@@ -23,6 +23,7 @@ namespace XimperShellNotificationCenter {
internal uint n_notifications { internal uint n_notifications {
get { get {
if (notifications_widget == null) return 0;
return notifications_widget.n_notifications; return notifications_widget.n_notifications;
} }
} }
...@@ -85,6 +86,7 @@ namespace XimperShellNotificationCenter { ...@@ -85,6 +86,7 @@ namespace XimperShellNotificationCenter {
/** Hides all floating notifications (closes transient) */ /** Hides all floating notifications (closes transient) */
internal inline void remove_all_floating_notifications (bool transition, internal inline void remove_all_floating_notifications (bool transition,
notification_filter_func ?func) { notification_filter_func ?func) {
if (floating_notifications == null) return;
debug ("Hiding all floating notifications"); debug ("Hiding all floating notifications");
floating_notifications.remove_all_notifications (transition, (notification) => { floating_notifications.remove_all_notifications (transition, (notification) => {
if (func == null || func (notification)) { if (func == null || func (notification)) {
...@@ -104,6 +106,7 @@ namespace XimperShellNotificationCenter { ...@@ -104,6 +106,7 @@ namespace XimperShellNotificationCenter {
/** Hides/closes latest floating notification */ /** Hides/closes latest floating notification */
internal void hide_latest_floating_notification (bool close) { internal void hide_latest_floating_notification (bool close) {
if (floating_notifications == null) return;
NotifyParams ?param = floating_notifications.get_latest_notification (); NotifyParams ?param = floating_notifications.get_latest_notification ();
if (param == null) { if (param == null) {
return; return;
...@@ -119,6 +122,7 @@ namespace XimperShellNotificationCenter { ...@@ -119,6 +122,7 @@ namespace XimperShellNotificationCenter {
/** Activates the `action_index` action of the latest notification */ /** Activates the `action_index` action of the latest notification */
internal void invoke_latest_floating_action (uint32 action_index) { internal void invoke_latest_floating_action (uint32 action_index) {
if (floating_notifications == null) return;
floating_notifications.latest_notification_action (action_index); floating_notifications.latest_notification_action (action_index);
} }
......
...@@ -237,7 +237,9 @@ namespace XimperShellNotificationCenter { ...@@ -237,7 +237,9 @@ namespace XimperShellNotificationCenter {
return false; return false;
} }
floating_notifications.set_monitor (monitor); if (floating_notifications != null) {
floating_notifications.set_monitor (monitor);
}
return true; return true;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment