+static void
+simple_head_enable(struct ivi_compositor *ivi, struct weston_head *head)
+{
+ struct ivi_output *output;
+ struct weston_config_section *section;
+ char *output_name = NULL;
+ const char *name = weston_head_get_name(head);
+
+ section = find_controlling_output_config(ivi->config, name);
+ if (section) {
+ char *mode;
+
+ weston_config_section_get_string(section, "mode", &mode, NULL);
+ if (mode && strcmp(mode, "off") == 0) {
+ free(mode);
+ return;
+ }
+ free(mode);
+
+ weston_config_section_get_string(section, "name",
+ &output_name, NULL);
+ } else {
+ output_name = strdup(name);
+ }
+
+ if (!output_name)
+ return;
+
+ output = ivi_ensure_output(ivi, output_name, section, head);
+ if (!output) {
+ weston_log("Failed to create output %s\n", output_name);
+ return;
+ }
+
+ add_head_destroyed_listener(head);
+}
+
+
+static void
+simple_head_disable(struct weston_head *head)
+{
+ struct weston_output *output;
+ struct wl_listener *listener;
+
+ listener = weston_head_get_destroy_listener(head, handle_head_destroy);
+ wl_list_empty(&listener->link);
+
+ output = weston_head_get_output(head);
+ assert(output);
+ weston_output_destroy(output);
+}
+
+
+static void
+simple_heads_changed(struct wl_listener *listener, void *arg)
+{
+ struct weston_compositor *compositor = arg;
+ struct ivi_compositor *ivi = to_ivi_compositor(compositor);
+ struct weston_head *head = NULL;
+ bool connected;
+ bool enabled;
+ bool changed;
+ bool non_desktop;
+
+ while ((head = weston_compositor_iterate_heads(ivi->compositor, head))) {
+ connected = weston_head_is_connected(head);
+ enabled = weston_head_is_enabled(head);
+ changed = weston_head_is_device_changed(head);
+ non_desktop = weston_head_is_non_desktop(head);
+
+ if (connected && !enabled && !non_desktop) {
+ simple_head_enable(ivi, head);
+ } else if (!connected && enabled) {
+ simple_head_disable(head);
+ } else if (enabled && changed) {
+ weston_log("Detected a monitor change on head '%s', "
+ "not bothering to do anything about it.\n",
+ weston_head_get_name(head));
+ }
+ weston_head_reset_device_changed(head);
+ }
+}
+
+