diff --git a/xfsettingsd/displays.c b/xfsettingsd/displays.c index 3497804..80faebf 100644 --- a/xfsettingsd/displays.c +++ b/xfsettingsd/displays.c @@ -368,8 +368,8 @@ xfce_displays_helper_reload (XfceDisplaysHelper *helper) xfsettings_dbg (XFSD_DEBUG_DISPLAYS, "Refreshing RandR cache."); /* Free the caches */ - g_ptr_array_unref (helper->outputs); - g_ptr_array_unref (helper->crtcs); + g_ptr_array_free (helper->outputs, TRUE); + g_ptr_array_free (helper->crtcs, TRUE); gdk_error_trap_push (); @@ -407,7 +407,7 @@ xfce_displays_helper_screen_on_event (GdkXEvent *xevent, gpointer data) { XfceDisplaysHelper *helper = XFCE_DISPLAYS_HELPER (data); - GPtrArray *old_outputs; + GPtrArray *new_outputs; XfceRRCrtc *crtc; XfceRROutput *output, *o; XEvent *e = xevent; @@ -424,22 +424,21 @@ xfce_displays_helper_screen_on_event (GdkXEvent *xevent, { xfsettings_dbg (XFSD_DEBUG_DISPLAYS, "RRScreenChangeNotify event received."); - old_outputs = g_ptr_array_ref (helper->outputs); - xfce_displays_helper_reload (helper); + new_outputs = xfce_displays_helper_list_outputs (helper); xfsettings_dbg (XFSD_DEBUG_DISPLAYS, "Noutput: before = %d, after = %d.", - old_outputs->len, helper->outputs->len); + helper->outputs->len, new_outputs->len); - if (old_outputs->len > helper->outputs->len) + if (helper->outputs->len > new_outputs->len) { /* Diff the new and old output list to find removed outputs */ - for (n = 0; n < old_outputs->len; ++n) + for (n = 0; n < helper->outputs->len; ++n) { found = FALSE; - output = g_ptr_array_index (old_outputs, n); - for (m = 0; m < helper->outputs->len && !found; ++m) + output = g_ptr_array_index (helper->outputs, n); + for (m = 0; m < new_outputs->len && !found; ++m) { - o = g_ptr_array_index (helper->outputs, m); + o = g_ptr_array_index (new_outputs, m); found = o->id == output->id; } if (!found) @@ -462,9 +461,9 @@ xfce_displays_helper_screen_on_event (GdkXEvent *xevent, /* Basically, this means the external output was disconnected, so reenable the internal one if needed. */ - for (n = 0; n < helper->outputs->len; ++n) + for (n = 0; n < new_outputs->len; ++n) { - output = g_ptr_array_index (helper->outputs, n); + output = g_ptr_array_index (new_outputs, n); if (output->active) ++nactive; } @@ -480,13 +479,13 @@ xfce_displays_helper_screen_on_event (GdkXEvent *xevent, else { /* Diff the new and old output list to find new outputs */ - for (n = 0; n < helper->outputs->len; ++n) + for (n = 0; n < new_outputs->len; ++n) { found = FALSE; - output = g_ptr_array_index (helper->outputs, n); - for (m = 0; m < old_outputs->len && !found; ++m) + output = g_ptr_array_index (new_outputs, n); + for (m = 0; m < helper->outputs->len && !found; ++m) { - o = g_ptr_array_index (old_outputs, m); + o = g_ptr_array_index (helper->outputs, m); found = o->id == output->id; } if (!found) @@ -501,7 +500,9 @@ xfce_displays_helper_screen_on_event (GdkXEvent *xevent, xfce_spawn_command_line_on_screen (NULL, "xfce4-display-settings -m", FALSE, FALSE, NULL); } - g_ptr_array_unref (old_outputs); + g_ptr_array_unref (new_outputs); + + xfce_displays_helper_reload (helper); } /* Pass the event on to GTK+ */