Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 26 additions & 22 deletions src/controlCenter/controlCenter.vala
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,6 @@ namespace SwayNotificationCenter {
set_anchor ();
}

this.map.connect (() => {
set_anchor ();

unowned Gdk.Surface surface = get_surface ();
if (!(surface is Gdk.Surface)) {
warn_if_reached ();
return;
}

ulong id = 0;
id = surface.enter_monitor.connect ((monitor) => {
surface.disconnect (id);
debug ("ControlCenter mapped on monitor: %s",
Functions.monitor_to_string (monitor));
app.show_blank_windows (monitor);
});
});
this.unmap.connect (() => {
debug ("ControlCenter un-mapped");
app.hide_blank_windows ();
});

/*
* Handling of bank window presses (pressing outside of Control Center)
*/
Expand Down Expand Up @@ -134,6 +112,32 @@ namespace SwayNotificationCenter {
});
}

protected override void map () {
base.map ();
debug ("ControlCenter mapped, waiting for enter-monitor signal");
set_anchor ();

unowned Gdk.Surface surface = get_surface ();
if (!(surface is Gdk.Surface)) {
warn_if_reached ();
return;
}

ulong id = 0;
id = surface.enter_monitor.connect ((monitor) => {
surface.disconnect (id);
debug ("ControlCenter mapped on monitor: %s",
Functions.monitor_to_string (monitor));
app.show_blank_windows (monitor);
});
}

protected override void unmap () {
base.unmap ();
debug ("ControlCenter un-mapped");
app.hide_blank_windows ();
}

private void key_released_event_cb (uint keyval, uint keycode, Gdk.ModifierType state) {
if (this.get_focus () is Gtk.Entry) {
switch (Gdk.keyval_name (keyval)) {
Expand Down
99 changes: 56 additions & 43 deletions src/notificationWindow/notificationWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace SwayNotificationCenter {
Gee.HashMap<uint32, unowned Notification> notification_ids
= new Gee.HashMap<uint32, unowned Notification> ();

private static string ?monitor_name = null;
private string ?monitor_name = null;

private const int MAX_HEIGHT = 600;

Expand All @@ -29,48 +29,54 @@ namespace SwayNotificationCenter {
}
this.set_anchor ();

this.map.connect (() => {
set_anchor ();

unowned Gdk.Surface surface = get_surface ();
if (!(surface is Gdk.Surface)) {
warn_if_reached ();
return;
}
ulong id = 0;
id = surface.enter_monitor.connect ((monitor) => {
surface.disconnect (id);
debug ("NotificationWindow mapped on monitor: %s",
Functions.monitor_to_string (monitor));
});
});
this.unmap.connect (() => {
debug ("NotificationWindow un-mapped");

// Destroy the wl_surface to get a new "enter-monitor" signal and
// fixes issues where keyboard shortcuts stop working after clearing
// all notifications.
((Gtk.Widget) this).unrealize ();
});

// TODO: Make option
list.use_card_animation = true;

// set_resizable (false);
default_width = ConfigModel.instance.notification_window_width;

// Change output on config reload
app.config_reload.connect ((old, config) => {
string monitor_name = config.notification_window_preferred_output;
if (old == null
|| old.notification_window_preferred_output != monitor_name
|| NotificationWindow.monitor_name != monitor_name) {
NotificationWindow.monitor_name = null;
|| this.monitor_name != monitor_name) {
this.monitor_name = null;
set_anchor ();
}
});
}

protected override void map () {
base.map ();
debug ("NotificationWindow mapped, waiting for enter-monitor signal");
set_anchor ();

unowned Gdk.Surface surface = get_surface ();
if (!(surface is Gdk.Surface)) {
warn_if_reached ();
return;
}
ulong id = 0;
id = surface.enter_monitor.connect ((monitor) => {
surface.disconnect (id);
debug ("NotificationWindow mapped on monitor: %s",
Functions.monitor_to_string (monitor));
});
}

protected override void unmap () {
base.unmap ();
debug ("NotificationWindow un-mapped");

// Make sure that all notifications are dismissed
noti_daemon.remove_all_floating_notifications (false, null);

// Destroy the wl_surface to get a new "enter-monitor" signal and
// fixes issues where keyboard shortcuts stop working after clearing
// all notifications.
((Gtk.Widget) this).unrealize ();
}

protected override void size_allocate (int w, int h, int baseline) {
base.size_allocate (w, h, baseline);

Expand Down Expand Up @@ -132,8 +138,8 @@ namespace SwayNotificationCenter {

// Set the preferred monitor
string ?monitor_name = ConfigModel.instance.notification_window_preferred_output;
if (NotificationWindow.monitor_name != null) {
monitor_name = NotificationWindow.monitor_name;
if (this.monitor_name != null) {
monitor_name = this.monitor_name;
}
set_monitor (Functions.try_get_monitor (monitor_name));
}
Expand Down Expand Up @@ -233,6 +239,14 @@ namespace SwayNotificationCenter {
return notification;
}

private inline void hide_if_empty () {
if (list.is_empty ()) {
set_visible (false);
} else {
set_input_region ();
}
}

/**
* Hides all notifications. Only invokes the NotificationClosed signal when transient.
* The optional callback is used to remove select notifications where each
Expand All @@ -256,8 +270,11 @@ namespace SwayNotificationCenter {
set_visible (false);
}

private void remove_notification_internal (Notification notification, bool transition) {
return_if_fail (notification != null);
private bool remove_notification_internal (Notification notification, bool transition) {
if (notification == null) {
critical ("Trying to remove NULL Notification");
return false;
}

NotifyParams param = notification.param;
notification_ids.unset (param.applied_id);
Expand All @@ -276,13 +293,8 @@ namespace SwayNotificationCenter {
}
// Remove notification and its destruction timeout
notification.remove_noti_timeout ();
list.remove.begin (notification, transition, (obj, res) => {
if (list.is_empty ()) {
set_visible (false);
return;
}
set_input_region ();
});
list.remove.begin (notification, transition, (obj, res) => hide_if_empty ());
return true;
}

public void add_notification (NotifyParams param) {
Expand All @@ -303,7 +315,7 @@ namespace SwayNotificationCenter {
}
}

set_visible (true);
present ();

list.append.begin (noti);
notification_ids.set (param.applied_id, noti);
Expand All @@ -312,8 +324,9 @@ namespace SwayNotificationCenter {
/** Removes the notification widget with ID. Doesn't dismiss */
public void remove_notification (uint32 id) {
unowned Notification ?notification = find_notification (id);
if (notification != null) {
remove_notification_internal (notification, true);
if (notification == null
|| !remove_notification_internal (notification, true)) {
hide_if_empty ();
}
}

Expand Down Expand Up @@ -362,7 +375,7 @@ namespace SwayNotificationCenter {
public void set_monitor (Gdk.Monitor ?monitor) {
debug ("Setting monitor for Floating Notifications: %s",
Functions.monitor_to_string (monitor) ?? "Monitor Picked by Compositor");
NotificationWindow.monitor_name = monitor == null ? null : monitor.connector;
this.monitor_name = monitor == null ? null : monitor.connector;
GtkLayerShell.set_monitor (this, monitor);

set_input_region ();
Expand Down