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
This commit is contained in:
Rui Matos 2014-10-31 15:02:05 +01:00
parent a19eda5ae7
commit c98686da92

View File

@ -945,6 +945,19 @@ laptop_display_is_on (MetaConfiguration *config)
return FALSE; 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 * static MetaConfiguration *
make_laptop_lid_config (MetaConfiguration *reference) make_laptop_lid_config (MetaConfiguration *reference)
{ {
@ -954,7 +967,7 @@ make_laptop_lid_config (MetaConfiguration *reference)
int x_after, y_after; int x_after, y_after;
int x_offset, y_offset; int x_offset, y_offset;
g_assert (reference->n_outputs > 1); g_assert (multiple_outputs_are_enabled (reference));
new = g_slice_new0 (MetaConfiguration); new = g_slice_new0 (MetaConfiguration);
new->n_outputs = reference->n_outputs; new->n_outputs = reference->n_outputs;
@ -1025,7 +1038,7 @@ meta_monitor_config_apply_stored (MetaMonitorConfig *self,
if (stored) if (stored)
{ {
if (self->lid_is_closed && if (self->lid_is_closed &&
stored->n_outputs > 1 && multiple_outputs_are_enabled (stored) &&
laptop_display_is_on (stored)) laptop_display_is_on (stored))
{ {
if (apply_configuration (self, make_laptop_lid_config (stored), if (apply_configuration (self, make_laptop_lid_config (stored),
@ -1287,7 +1300,7 @@ meta_monitor_config_make_default (MetaMonitorConfig *self,
if (default_config != NULL) if (default_config != NULL)
{ {
if (self->lid_is_closed && if (self->lid_is_closed &&
default_config->n_outputs > 1 && multiple_outputs_are_enabled (default_config) &&
laptop_display_is_on (default_config)) laptop_display_is_on (default_config))
{ {
ok = apply_configuration (self, make_laptop_lid_config (default_config), ok = apply_configuration (self, make_laptop_lid_config (default_config),
@ -1378,7 +1391,7 @@ turn_off_laptop_display (MetaMonitorConfig *self,
{ {
MetaConfiguration *new; MetaConfiguration *new;
if (self->current->n_outputs == 1) if (!multiple_outputs_are_enabled (self->current))
return; return;
new = make_laptop_lid_config (self->current); new = make_laptop_lid_config (self->current);