From 02baab07033f9db4c1d44e0df8379587ecec2e74 Mon Sep 17 00:00:00 2001 From: Oliver Deja Date: Mon, 30 Mar 2026 17:37:10 +0000 Subject: [PATCH] x11: displays: Add hotplug event handling When handling the RRScreenChangeNotify event, auto resize if the preferred mode was selected and updated. Fixes: #142 --- xfsettingsd/displays-x11.c | 51 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/xfsettingsd/displays-x11.c b/xfsettingsd/displays-x11.c index f96ce6a5..696b17f2 100644 --- a/xfsettingsd/displays-x11.c +++ b/xfsettingsd/displays-x11.c @@ -616,6 +616,57 @@ screen_on_event (gpointer data) xfconf_channel_set_string (channel, ACTIVE_PROFILE, DEFAULT_SCHEME_NAME); } + /* hotplup event handling: see https://gitlab.xfce.org/xfce/xfce4-settings/-/issues/142 */ + if (old_outputs->len == helper->outputs->len + && helper->resources->timestamp < helper->resources->configTimestamp + && edids_changed) + { + gboolean changed = FALSE; + + for (guint n = 0; n < helper->outputs->len; ++n) + { + XfceRROutput *output = g_ptr_array_index (helper->outputs, n); + XfceRROutput *old_output = g_ptr_array_index (old_outputs, n); + XfceRRCrtc *crtc = xfce_displays_helper_x11_find_crtc_by_id (helper, output->info->crtc); + + if (output->id != old_output->id) + { + xfsettings_dbg (XFSD_DEBUG_DISPLAYS, "Output identifiers or order changed, aborting."); + break; + } + + if (crtc == NULL) + continue; + + /* if the new output has a new preferred mode and the crtc was configured in the previours preferred + mode, reconfigure to use the new preferred mode */ + if (old_output->preferred_mode != output->preferred_mode && old_output->preferred_mode == crtc->mode) + { + for (gint m = 0; m < helper->resources->nmode; ++m) + { + if (output->preferred_mode == helper->resources->modes[m].id) + { + crtc->mode = helper->resources->modes[m].id; + crtc->width = helper->resources->modes[m].width; + crtc->height = helper->resources->modes[m].height; + crtc->changed = TRUE; + xfce_displays_helper_x11_set_outputs (crtc, output); + + changed |= output->active; + break; + } + } + } + } + + if (changed) + { + xfce_displays_helper_x11_apply_all (helper); + g_ptr_array_unref (old_outputs); + return FALSE; + } + } + if (old_outputs->len > helper->outputs->len || edids_changed) { gboolean changed = FALSE; -- GitLab