monitor-config: refactor make_default_config()
Move logic for creating different types of configurations into separate functions. This keeps things a bit cleaner and allows us to add alternate configuration types more easily.
This commit is contained in:
parent
6e25c37da1
commit
a0d2d207e7
@ -1096,40 +1096,63 @@ init_config_from_preferred_mode (MetaOutputConfig *config,
|
|||||||
config->is_presentation = FALSE;
|
config->is_presentation = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static MetaConfiguration *
|
static void
|
||||||
make_default_config (MetaMonitorConfig *self,
|
make_linear_config (MetaMonitorConfig *self,
|
||||||
MetaOutput *outputs,
|
MetaOutput *outputs,
|
||||||
unsigned n_outputs,
|
unsigned n_outputs,
|
||||||
int max_width,
|
int max_width,
|
||||||
int max_height)
|
int max_height,
|
||||||
|
MetaConfiguration *config)
|
||||||
{
|
{
|
||||||
unsigned i, j;
|
|
||||||
int x, y;
|
|
||||||
MetaConfiguration *ret;
|
|
||||||
MetaOutput *primary;
|
MetaOutput *primary;
|
||||||
|
unsigned i;
|
||||||
|
int x;
|
||||||
|
|
||||||
ret = config_new ();
|
g_return_if_fail (config != NULL);
|
||||||
make_config_key (ret, outputs, n_outputs, -1);
|
|
||||||
ret->outputs = g_new0 (MetaOutputConfig, n_outputs);
|
|
||||||
|
|
||||||
/* Special case the simple case: one output, primary at preferred mode,
|
primary = find_primary_output (outputs, n_outputs);
|
||||||
nothing else to do */
|
|
||||||
if (n_outputs == 1)
|
x = primary->preferred_mode->width;
|
||||||
|
for (i = 0; i < n_outputs; i++)
|
||||||
{
|
{
|
||||||
init_config_from_preferred_mode (&ret->outputs[0], &outputs[0]);
|
gboolean is_primary = (&outputs[i] == primary);
|
||||||
ret->outputs[0].is_primary = TRUE;
|
|
||||||
return ret;
|
init_config_from_preferred_mode (&config->outputs[i], &outputs[i]);
|
||||||
|
config->outputs[i].is_primary = is_primary;
|
||||||
|
|
||||||
|
if (is_primary)
|
||||||
|
{
|
||||||
|
config->outputs[i].rect.x = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
config->outputs[i].rect.x = x;
|
||||||
|
x += config->outputs[i].rect.width;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we reach this point, this is either the first time mutter runs
|
/* Disable outputs that would go beyond framebuffer limits */
|
||||||
on this system ever, or we just hotplugged a new screen.
|
if (config->outputs[i].rect.x + config->outputs[i].rect.width > max_width)
|
||||||
In the latter case, search for a configuration that includes one
|
config->outputs[i].enabled = FALSE;
|
||||||
less screen, then add the new one as a presentation screen
|
}
|
||||||
in preferred mode.
|
}
|
||||||
|
|
||||||
XXX: but presentation mode is not implemented in the control-center
|
/* Search for a configuration that includes one less screen, then add the new
|
||||||
or in mutter core, so let's do extended for now.
|
* one as a presentation screen in preferred mode.
|
||||||
|
*
|
||||||
|
* XXX: but presentation mode is not implemented in the control-center or in
|
||||||
|
* mutter core, so let's do extended for now.
|
||||||
*/
|
*/
|
||||||
|
static gboolean
|
||||||
|
extend_stored_config (MetaMonitorConfig *self,
|
||||||
|
MetaOutput *outputs,
|
||||||
|
unsigned n_outputs,
|
||||||
|
int max_width,
|
||||||
|
int max_height,
|
||||||
|
MetaConfiguration *config)
|
||||||
|
{
|
||||||
|
int x, y;
|
||||||
|
unsigned i, j;
|
||||||
|
|
||||||
x = 0;
|
x = 0;
|
||||||
y = 0;
|
y = 0;
|
||||||
for (i = 0; i < n_outputs; i++)
|
for (i = 0; i < n_outputs; i++)
|
||||||
@ -1147,64 +1170,67 @@ make_default_config (MetaMonitorConfig *self,
|
|||||||
{
|
{
|
||||||
if (j < i)
|
if (j < i)
|
||||||
{
|
{
|
||||||
g_assert (output_key_equal (&ret->keys[j], &ref->keys[j]));
|
g_assert (output_key_equal (&config->keys[j], &ref->keys[j]));
|
||||||
ret->outputs[j] = ref->outputs[j];
|
config->outputs[j] = ref->outputs[j];
|
||||||
x = MAX (x, ref->outputs[j].rect.x + ref->outputs[j].rect.width);
|
x = MAX (x, ref->outputs[j].rect.x + ref->outputs[j].rect.width);
|
||||||
y = MAX (y, ref->outputs[j].rect.y + ref->outputs[j].rect.height);
|
y = MAX (y, ref->outputs[j].rect.y + ref->outputs[j].rect.height);
|
||||||
}
|
}
|
||||||
else if (j > i)
|
else if (j > i)
|
||||||
{
|
{
|
||||||
g_assert (output_key_equal (&ret->keys[j], &ref->keys[j - 1]));
|
g_assert (output_key_equal (&config->keys[j], &ref->keys[j - 1]));
|
||||||
ret->outputs[j] = ref->outputs[j - 1];
|
config->outputs[j] = ref->outputs[j - 1];
|
||||||
x = MAX (x, ref->outputs[j - 1].rect.x + ref->outputs[j - 1].rect.width);
|
x = MAX (x, ref->outputs[j - 1].rect.x + ref->outputs[j - 1].rect.width);
|
||||||
y = MAX (y, ref->outputs[j - 1].rect.y + ref->outputs[j - 1].rect.height);
|
y = MAX (y, ref->outputs[j - 1].rect.y + ref->outputs[j - 1].rect.height);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
init_config_from_preferred_mode (&ret->outputs[j], &outputs[0]);
|
init_config_from_preferred_mode (&config->outputs[j], &outputs[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Place the new output at the right end of the screen, if it fits,
|
/* Place the new output at the right end of the screen, if it fits,
|
||||||
otherwise below it, otherwise disable it (or apply_configuration will fail) */
|
otherwise below it, otherwise disable it (or apply_configuration will fail) */
|
||||||
if (x + ret->outputs[i].rect.width <= max_width)
|
if (x + config->outputs[i].rect.width <= max_width)
|
||||||
ret->outputs[i].rect.x = x;
|
config->outputs[i].rect.x = x;
|
||||||
else if (y + ret->outputs[i].rect.height <= max_height)
|
else if (y + config->outputs[i].rect.height <= max_height)
|
||||||
ret->outputs[i].rect.y = y;
|
config->outputs[i].rect.y = y;
|
||||||
else
|
else
|
||||||
ret->outputs[i].enabled = FALSE;
|
config->outputs[i].enabled = FALSE;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static MetaConfiguration *
|
||||||
|
make_default_config (MetaMonitorConfig *self,
|
||||||
|
MetaOutput *outputs,
|
||||||
|
unsigned n_outputs,
|
||||||
|
int max_width,
|
||||||
|
int max_height)
|
||||||
|
{
|
||||||
|
MetaConfiguration *ret = NULL;
|
||||||
|
|
||||||
|
ret = config_new ();
|
||||||
|
make_config_key (ret, outputs, n_outputs, -1);
|
||||||
|
ret->outputs = g_new0 (MetaOutputConfig, n_outputs);
|
||||||
|
|
||||||
|
/* Special case the simple case: one output, primary at preferred mode,
|
||||||
|
nothing else to do */
|
||||||
|
if (n_outputs == 1)
|
||||||
|
{
|
||||||
|
|
||||||
|
init_config_from_preferred_mode (&ret->outputs[0], &outputs[0]);
|
||||||
|
ret->outputs[0].is_primary = TRUE;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* No previous configuration found, try with a really default one, which
|
if (extend_stored_config (self, outputs, n_outputs, max_width, max_height, ret))
|
||||||
is one primary that goes first and the rest to the right of it, extended.
|
return ret;
|
||||||
*/
|
|
||||||
primary = find_primary_output (outputs, n_outputs);
|
|
||||||
|
|
||||||
x = primary->preferred_mode->width;
|
make_linear_config (self, outputs, n_outputs, max_width, max_height, ret);
|
||||||
for (i = 0; i < n_outputs; i++)
|
|
||||||
{
|
|
||||||
gboolean is_primary = (&outputs[i] == primary);
|
|
||||||
|
|
||||||
init_config_from_preferred_mode (&ret->outputs[i], &outputs[i]);
|
|
||||||
ret->outputs[i].is_primary = is_primary;
|
|
||||||
|
|
||||||
if (is_primary)
|
|
||||||
{
|
|
||||||
ret->outputs[i].rect.x = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ret->outputs[i].rect.x = x;
|
|
||||||
x += ret->outputs[i].rect.width;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Disable outputs that would go beyond framebuffer limits */
|
|
||||||
if (ret->outputs[i].rect.x + ret->outputs[i].rect.width > max_width)
|
|
||||||
ret->outputs[i].enabled = FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user