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 13b6bd20ca
commit 3b1271d9be

View File

@ -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);