diff --git a/src/backends/meta-monitor-manager-private.h b/src/backends/meta-monitor-manager-private.h index c30e8d7b0..1b80299d1 100644 --- a/src/backends/meta-monitor-manager-private.h +++ b/src/backends/meta-monitor-manager-private.h @@ -414,6 +414,10 @@ gint meta_monitor_manager_get_monitor_at_point (MetaMonitorManager gfloat x, gfloat y); +void meta_monitor_manager_clear_output (MetaOutput *output); +void meta_monitor_manager_clear_mode (MetaMonitorMode *mode); +void meta_monitor_manager_clear_crtc (MetaCRTC *crtc); + /* Returns true if transform causes width and height to be inverted This is true for the odd transforms in the enum */ static inline gboolean diff --git a/src/backends/meta-monitor-manager.c b/src/backends/meta-monitor-manager.c index a15673e64..38ccc7261 100644 --- a/src/backends/meta-monitor-manager.c +++ b/src/backends/meta-monitor-manager.c @@ -346,6 +346,23 @@ meta_monitor_manager_constructed (GObject *object) manager->in_init = FALSE; } +void +meta_monitor_manager_clear_output (MetaOutput *output) +{ + g_free (output->name); + g_free (output->vendor); + g_free (output->product); + g_free (output->serial); + g_free (output->modes); + g_free (output->possible_crtcs); + g_free (output->possible_clones); + + if (output->driver_notify) + output->driver_notify (output); + + memset (output, 0, sizeof (*output)); +} + static void meta_monitor_manager_free_output_array (MetaOutput *old_outputs, int n_old_outputs) @@ -353,22 +370,22 @@ meta_monitor_manager_free_output_array (MetaOutput *old_outputs, int i; for (i = 0; i < n_old_outputs; i++) - { - g_free (old_outputs[i].name); - g_free (old_outputs[i].vendor); - g_free (old_outputs[i].product); - g_free (old_outputs[i].serial); - g_free (old_outputs[i].modes); - g_free (old_outputs[i].possible_crtcs); - g_free (old_outputs[i].possible_clones); - - if (old_outputs[i].driver_notify) - old_outputs[i].driver_notify (&old_outputs[i]); - } + meta_monitor_manager_clear_output (&old_outputs[i]); g_free (old_outputs); } +void +meta_monitor_manager_clear_mode (MetaMonitorMode *mode) +{ + g_free (mode->name); + + if (mode->driver_notify) + mode->driver_notify (mode); + + memset (mode, 0, sizeof (*mode)); +} + static void meta_monitor_manager_free_mode_array (MetaMonitorMode *old_modes, int n_old_modes) @@ -376,16 +393,20 @@ meta_monitor_manager_free_mode_array (MetaMonitorMode *old_modes, int i; for (i = 0; i < n_old_modes; i++) - { - g_free (old_modes[i].name); - - if (old_modes[i].driver_notify) - old_modes[i].driver_notify (&old_modes[i]); - } + meta_monitor_manager_clear_mode (&old_modes[i]); g_free (old_modes); } +void +meta_monitor_manager_clear_crtc (MetaCRTC *crtc) +{ + if (crtc->driver_notify) + crtc->driver_notify (crtc); + + memset (crtc, 0, sizeof (*crtc)); +} + static void meta_monitor_manager_free_crtc_array (MetaCRTC *old_crtcs, int n_old_crtcs) @@ -393,10 +414,7 @@ meta_monitor_manager_free_crtc_array (MetaCRTC *old_crtcs, int i; for (i = 0; i < n_old_crtcs; i++) - { - if (old_crtcs[i].driver_notify) - old_crtcs[i].driver_notify (&old_crtcs[i]); - } + meta_monitor_manager_clear_crtc (&old_crtcs[i]); g_free (old_crtcs); }