config: Refactor the check for the lid special-case out

This also fixes the case where current_is_for_laptop_lid wasn't properly
set in the default case.
This commit is contained in:
Jasper St. Pierre 2014-10-22 15:03:39 -07:00
parent 47e339b46e
commit f2546dfeea

View File

@ -887,8 +887,7 @@ apply_configuration (MetaMonitorConfig *self,
self->current = config;
self->current_is_stored = stored;
/* If true, we'll be overridden at the end of this call
inside turn_off_laptop_display()
*/
* inside turn_off_laptop_display / apply_configuration_with_lid */
self->current_is_for_laptop_lid = FALSE;
if (self->current == self->previous)
@ -990,6 +989,27 @@ make_laptop_lid_config (MetaConfiguration *reference)
return new;
}
static gboolean
apply_configuration_with_lid (MetaMonitorConfig *self,
MetaConfiguration *config,
MetaMonitorManager *manager)
{
if (self->lid_is_closed &&
config->n_outputs > 1 &&
laptop_display_is_on (config))
{
if (apply_configuration (self, make_laptop_lid_config (config), manager, FALSE))
{
self->current_is_for_laptop_lid = TRUE;
return TRUE;
}
else
return FALSE;
}
else
return apply_configuration (self, config, manager, TRUE);
}
gboolean
meta_monitor_config_apply_stored (MetaMonitorConfig *self,
MetaMonitorManager *manager)
@ -1002,23 +1022,7 @@ meta_monitor_config_apply_stored (MetaMonitorConfig *self,
stored = meta_monitor_config_get_stored (self, outputs, n_outputs);
if (stored)
{
if (self->lid_is_closed &&
stored->n_outputs > 1 &&
laptop_display_is_on (stored))
{
if (apply_configuration (self, make_laptop_lid_config (stored),
manager, FALSE))
{
self->current_is_for_laptop_lid = TRUE;
return TRUE;
}
else
return FALSE;
}
else
return apply_configuration (self, stored, manager, TRUE);
}
return apply_configuration_with_lid (self, stored, manager);
else
return FALSE;
}
@ -1264,18 +1268,7 @@ meta_monitor_config_make_default (MetaMonitorConfig *self,
default_config = make_default_config (self, outputs, n_outputs, max_width, max_height);
if (default_config != NULL)
{
if (self->lid_is_closed &&
default_config->n_outputs > 1 &&
laptop_display_is_on (default_config))
{
ok = apply_configuration (self, make_laptop_lid_config (default_config),
manager, FALSE);
config_free (default_config);
}
else
ok = apply_configuration (self, default_config, manager, FALSE);
}
ok = apply_configuration_with_lid (self, default_config, manager);
else
ok = FALSE;