From e2125c765d05976108e5107e562532fff6fa6408 Mon Sep 17 00:00:00 2001 From: Victor Kareh Date: Thu, 9 Oct 2025 08:56:41 -0400 Subject: 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 --- src/daemon/daemon.c | 14 ++++++++++++-- 1 file 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) -- cgit v1.2.1