From 3b1271d9be8a5603f3d52cc5b5f31958623f391c Mon Sep 17 00:00:00 2001 From: Rui Matos Date: Fri, 31 Oct 2014 15:02:05 +0100 Subject: [PATCH] monitor-config: Prevent a crash applying config for a closed lid When a laptop's lid is closed we try to build and apply a temporary configuration that disables the laptop's display if we have other outputs. This isn't enough though, we must also check if at least one of these other outputs is enabled otherwise we'll try to resize the screen to 0x0 which (rightfully) hits an assertion. https://bugzilla.gnome.org/show_bug.cgi?id=739450 --- src/backends/meta-monitor-config.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/backends/meta-monitor-config.c b/src/backends/meta-monitor-config.c index a421761f2..98ae22056 100644 --- a/src/backends/meta-monitor-config.c +++ b/src/backends/meta-monitor-config.c @@ -914,6 +914,19 @@ laptop_display_is_on (MetaConfiguration *config) return FALSE; } +static gboolean +multiple_outputs_are_enabled (MetaConfiguration *config) +{ + unsigned int i, enabled; + + enabled = 0; + for (i = 0; i < config->n_outputs; i++) + if (config->outputs[i].enabled) + enabled++; + + return enabled > 1; +} + static MetaConfiguration * make_laptop_lid_config (MetaConfiguration *reference) { @@ -923,7 +936,7 @@ make_laptop_lid_config (MetaConfiguration *reference) int x_after, y_after; int x_offset, y_offset; - g_assert (reference->n_outputs > 1); + g_assert (multiple_outputs_are_enabled (reference)); new = config_new (); new->n_outputs = reference->n_outputs; @@ -986,7 +999,7 @@ apply_configuration_with_lid (MetaMonitorConfig *self, MetaMonitorManager *manager) { if (self->lid_is_closed && - config->n_outputs > 1 && + multiple_outputs_are_enabled (config) && laptop_display_is_on (config)) { MetaConfiguration *laptop_lid_config = make_laptop_lid_config (config); @@ -1353,7 +1366,7 @@ turn_off_laptop_display (MetaMonitorConfig *self, { MetaConfiguration *new; - if (self->current->n_outputs == 1) + if (!multiple_outputs_are_enabled (self->current)) return; new = make_laptop_lid_config (self->current);