[mutter] monitor-config: refactor make_default_config()
- From: Jonathon Jongsma <jjongsma src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter] monitor-config: refactor make_default_config()
- Date: Thu, 20 Nov 2014 18:34:50 +0000 (UTC)
commit a0d2d207e79e59be3691d7c4b853b496103bfd87
Author: Jonathon Jongsma <jjongsma redhat com>
Date: Mon Nov 17 15:13:15 2014 -0600
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.
src/backends/meta-monitor-config.c | 144 +++++++++++++++++++++---------------
1 files changed, 85 insertions(+), 59 deletions(-)
---
diff --git a/src/backends/meta-monitor-config.c b/src/backends/meta-monitor-config.c
index 1f0db70..90b2e6a 100644
--- a/src/backends/meta-monitor-config.c
+++ b/src/backends/meta-monitor-config.c
@@ -1096,40 +1096,63 @@ init_config_from_preferred_mode (MetaOutputConfig *config,
config->is_presentation = FALSE;
}
-static MetaConfiguration *
-make_default_config (MetaMonitorConfig *self,
- MetaOutput *outputs,
- unsigned n_outputs,
- int max_width,
- int max_height)
+static void
+make_linear_config (MetaMonitorConfig *self,
+ MetaOutput *outputs,
+ unsigned n_outputs,
+ int max_width,
+ int max_height,
+ MetaConfiguration *config)
{
- unsigned i, j;
- int x, y;
- MetaConfiguration *ret;
MetaOutput *primary;
+ unsigned i;
+ int x;
- ret = config_new ();
- make_config_key (ret, outputs, n_outputs, -1);
- ret->outputs = g_new0 (MetaOutputConfig, n_outputs);
+ g_return_if_fail (config != NULL);
- /* Special case the simple case: one output, primary at preferred mode,
- nothing else to do */
- if (n_outputs == 1)
+ primary = find_primary_output (outputs, n_outputs);
+
+ x = primary->preferred_mode->width;
+ for (i = 0; i < n_outputs; i++)
{
- init_config_from_preferred_mode (&ret->outputs[0], &outputs[0]);
- ret->outputs[0].is_primary = TRUE;
- return ret;
- }
+ gboolean is_primary = (&outputs[i] == primary);
- /* If we reach this point, this is either the first time mutter runs
- on this system ever, or we just hotplugged a new screen.
- In the latter case, search for a configuration that includes one
- less screen, then add the new one as a presentation screen
- in preferred mode.
+ init_config_from_preferred_mode (&config->outputs[i], &outputs[i]);
+ config->outputs[i].is_primary = is_primary;
- XXX: but presentation mode is not implemented in the control-center
- or in mutter core, so let's do extended for now.
+ if (is_primary)
+ {
+ config->outputs[i].rect.x = 0;
+ }
+ else
+ {
+ config->outputs[i].rect.x = x;
+ x += config->outputs[i].rect.width;
+ }
+
+ /* Disable outputs that would go beyond framebuffer limits */
+ if (config->outputs[i].rect.x + config->outputs[i].rect.width > max_width)
+ config->outputs[i].enabled = FALSE;
+ }
+}
+
+/* Search for a configuration that includes one 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 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;
y = 0;
for (i = 0; i < n_outputs; i++)
@@ -1147,65 +1170,68 @@ make_default_config (MetaMonitorConfig *self,
{
if (j < i)
{
- g_assert (output_key_equal (&ret->keys[j], &ref->keys[j]));
- ret->outputs[j] = ref->outputs[j];
+ g_assert (output_key_equal (&config->keys[j], &ref->keys[j]));
+ config->outputs[j] = ref->outputs[j];
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);
}
else if (j > i)
{
- g_assert (output_key_equal (&ret->keys[j], &ref->keys[j - 1]));
- ret->outputs[j] = ref->outputs[j - 1];
+ g_assert (output_key_equal (&config->keys[j], &ref->keys[j - 1]));
+ config->outputs[j] = ref->outputs[j - 1];
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);
}
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,
otherwise below it, otherwise disable it (or apply_configuration will fail) */
- if (x + ret->outputs[i].rect.width <= max_width)
- ret->outputs[i].rect.x = x;
- else if (y + ret->outputs[i].rect.height <= max_height)
- ret->outputs[i].rect.y = y;
+ if (x + config->outputs[i].rect.width <= max_width)
+ config->outputs[i].rect.x = x;
+ else if (y + config->outputs[i].rect.height <= max_height)
+ config->outputs[i].rect.y = y;
else
- ret->outputs[i].enabled = FALSE;
+ config->outputs[i].enabled = FALSE;
- return ret;
+ return TRUE;
}
}
- /* No previous configuration found, try with a really default one, which
- is one primary that goes first and the rest to the right of it, extended.
- */
- primary = find_primary_output (outputs, n_outputs);
+ return FALSE;
+}
- x = primary->preferred_mode->width;
- for (i = 0; i < n_outputs; i++)
- {
- gboolean is_primary = (&outputs[i] == primary);
+static MetaConfiguration *
+make_default_config (MetaMonitorConfig *self,
+ MetaOutput *outputs,
+ unsigned n_outputs,
+ int max_width,
+ int max_height)
+{
+ MetaConfiguration *ret = NULL;
- init_config_from_preferred_mode (&ret->outputs[i], &outputs[i]);
- ret->outputs[i].is_primary = is_primary;
+ ret = config_new ();
+ make_config_key (ret, outputs, n_outputs, -1);
+ ret->outputs = g_new0 (MetaOutputConfig, n_outputs);
- if (is_primary)
- {
- ret->outputs[i].rect.x = 0;
- }
- else
- {
- ret->outputs[i].rect.x = x;
- x += ret->outputs[i].rect.width;
- }
+ /* Special case the simple case: one output, primary at preferred mode,
+ nothing else to do */
+ if (n_outputs == 1)
+ {
- /* 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;
+ init_config_from_preferred_mode (&ret->outputs[0], &outputs[0]);
+ ret->outputs[0].is_primary = TRUE;
+ return ret;
}
+ if (extend_stored_config (self, outputs, n_outputs, max_width, max_height, ret))
+ return ret;
+
+ make_linear_config (self, outputs, n_outputs, max_width, max_height, ret);
+
return ret;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]