control-center: make notifications widget optional

parent 8ac5050f
......@@ -22,7 +22,9 @@ namespace XimperShellNotificationCenter {
Object (css_name: "blankwindow");
widgets = new List<unowned Widgets.BaseWidget> ();
if (notifications_widget != null) {
widgets.append (notifications_widget);
}
if (app.use_layer_shell) {
if (!GtkLayerShell.is_supported ()) {
......@@ -164,7 +166,12 @@ namespace XimperShellNotificationCenter {
}
break;
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
return true;
......@@ -189,12 +196,6 @@ namespace XimperShellNotificationCenter {
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;
foreach (string key in w) {
// Add the widget if it is valid
......@@ -203,16 +204,18 @@ namespace XimperShellNotificationCenter {
key, out is_notifications);
if (is_notifications) {
if (notifications_widget == null) {
continue;
}
if (has_notifications) {
warning ("Cannot have multiple \"notifications\" widgets! Skipping\"%s\"",
key);
warning ("Cannot have multiple " +
"\"notifications\" widgets! " +
"Skipping \"%s\"", key);
continue;
}
has_notifications = true;
notifications_widget.reload_config ();
// Append the notifications widget to the box in the order of the provided list
box.append (notifications_widget);
continue;
}
......@@ -334,18 +337,24 @@ namespace XimperShellNotificationCenter {
default:
case PositionY.TOP:
align_y = Gtk.Align.START;
// Set cc widget position
notifications_widget.set_list_is_reversed (false);
if (notifications_widget != null) {
notifications_widget
.set_list_is_reversed (false);
}
break;
case PositionY.CENTER:
align_y = Gtk.Align.CENTER;
// Set cc widget position
notifications_widget.set_list_is_reversed (false);
if (notifications_widget != null) {
notifications_widget
.set_list_is_reversed (false);
}
break;
case PositionY.BOTTOM:
align_y = Gtk.Align.END;
// Set cc widget position
notifications_widget.set_list_is_reversed (true);
if (notifications_widget != null) {
notifications_widget
.set_list_is_reversed (true);
}
break;
}
// Fit the ControlCenter to the monitor height
......
......@@ -12,6 +12,10 @@ namespace XimperShellNotificationCenter.Widgets {
});
}
public override bool is_available () {
return notifications_widget != null;
}
private void update_icon () {
icon.set_from_icon_name (active
? "notifications-disabled-symbolic"
......
......@@ -37,13 +37,20 @@ namespace XimperShellNotificationCenter.Widgets {
}
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 (
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]
private void on_clear_all_clicked () {
......
......@@ -110,7 +110,17 @@ namespace XimperShellNotificationCenter {
noti_daemon = new NotiDaemon ();
ximper_shell_notification_center_daemon = new XimperShellNotificationCenterDaemon ();
// Notification Daemon
// Register notification daemon only if notifications widget is enabled
bool has_notifications = false;
foreach (string w in ConfigModel.instance.widgets.data) {
if (w.has_prefix ("notifications")) {
has_notifications = true;
break;
}
}
if (has_notifications) {
Bus.own_name_on_connection (conn,
"org.freedesktop.Notifications",
bus_name_flags,
......@@ -130,6 +140,7 @@ namespace XimperShellNotificationCenter {
Process.exit (1);
});
yield;
}
// Ximper Shell Notification Center Daemon
// Name is already owned by GApplication via register()
......@@ -143,23 +154,26 @@ namespace XimperShellNotificationCenter {
xdg_activation = new XdgActivationHelper ();
floating_notifications = new NotificationWindow ();
if (has_notifications) {
notifications_widget = new Widgets.Notifications ();
control_center = new ControlCenter ();
floating_notifications = new NotificationWindow ();
add_window (floating_notifications);
add_window (control_center);
noti_daemon.on_dnd_toggle.connect ((dnd) => {
// Hide all non-critical notifications on toggle
if (dnd && floating_notifications.visible) {
noti_daemon.remove_all_floating_notifications (true, (noti) => {
return noti.param.urgency != UrgencyLevels.CRITICAL;
noti_daemon
.remove_all_floating_notifications (
true, (noti) => {
return noti.param.urgency
!= UrgencyLevels.CRITICAL;
});
}
ximper_shell_notification_center_daemon.emit_subscribe ();
ximper_shell_notification_center_daemon
.emit_subscribe ();
});
}
control_center = new ControlCenter ();
// Update on start
ximper_shell_notification_center_daemon.emit_subscribe ();
......
......@@ -23,6 +23,7 @@ namespace XimperShellNotificationCenter {
internal uint n_notifications {
get {
if (notifications_widget == null) return 0;
return notifications_widget.n_notifications;
}
}
......@@ -85,6 +86,7 @@ namespace XimperShellNotificationCenter {
/** Hides all floating notifications (closes transient) */
internal inline void remove_all_floating_notifications (bool transition,
notification_filter_func ?func) {
if (floating_notifications == null) return;
debug ("Hiding all floating notifications");
floating_notifications.remove_all_notifications (transition, (notification) => {
if (func == null || func (notification)) {
......@@ -104,6 +106,7 @@ namespace XimperShellNotificationCenter {
/** Hides/closes latest floating notification */
internal void hide_latest_floating_notification (bool close) {
if (floating_notifications == null) return;
NotifyParams ?param = floating_notifications.get_latest_notification ();
if (param == null) {
return;
......@@ -119,6 +122,7 @@ namespace XimperShellNotificationCenter {
/** Activates the `action_index` action of the latest notification */
internal void invoke_latest_floating_action (uint32 action_index) {
if (floating_notifications == null) return;
floating_notifications.latest_notification_action (action_index);
}
......
......@@ -237,7 +237,9 @@ namespace XimperShellNotificationCenter {
return false;
}
if (floating_notifications != null) {
floating_notifications.set_monitor (monitor);
}
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