diff options
author | Victor Kareh <[email protected]> | 2025-10-09 08:56:41 -0400 |
---|---|---|
committer | Victor Kareh <[email protected]> | 2025-10-10 14:01:58 +0000 |
commit | e2125c765d05976108e5107e562532fff6fa6408 (patch) | |
tree | a19ad03d0e925eab99850ae08eecb59c48ef2d6b | |
parent | 2dd24f923f4d4f2bbc77314445a6b1b6701b3569 (diff) | |
download | mate-notification-daemon-e2125c765d05976108e5107e562532fff6fa6408.tar.bz2 mate-notification-daemon-e2125c765d05976108e5107e562532fff6fa6408.tar.xz |
daemon: Fix crash when monitor is disconnected
Add checks for monitor_id to prevent crash during monitor change events.
Instead it falls back to last available monitor and allows notification
processing to continue without a monitor.
Fixes: #200
-rw-r--r-- | src/daemon/daemon.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c index 4d303d7..ef8682c 100644 --- a/src/daemon/daemon.c +++ b/src/daemon/daemon.c @@ -1756,14 +1756,24 @@ static gboolean notify_daemon_notify_handler(NotifyDaemonNotifications *object, g_settings_get_int(daemon->gsettings, GSETTINGS_KEY_MONITOR_NUMBER)); } - if (_gtk_get_monitor_num (monitor_id) >= daemon->screen->n_stacks) + /* If the monitor was disconnected or invalid, fall back to the last available monitor */ + if (monitor_id == NULL && daemon->screen->n_stacks > 0) + { + monitor_id = gdk_display_get_monitor (gdk_display_get_default(), (int) daemon->screen->n_stacks - 1); + } + + if (monitor_id != NULL && _gtk_get_monitor_num (monitor_id) >= daemon->screen->n_stacks) { /* screw it - dump it on the last one we'll get a monitors-changed signal soon enough*/ monitor_id = gdk_display_get_monitor (gdk_display_get_default(), (int) daemon->screen->n_stacks - 1); } - notify_stack_add_window (daemon->screen->stacks[_gtk_get_monitor_num (monitor_id)], nw, new_notification); + /* If we still don't have a valid monitor, something is seriously wrong */ + if (monitor_id != NULL && daemon->screen->n_stacks > 0) + { + notify_stack_add_window (daemon->screen->stacks[_gtk_get_monitor_num (monitor_id)], nw, new_notification); + } } if (id == 0) |