color-device: Create devices without a ready color manager

Every monitor should eventually have a corresponding color device. To
make sure this can work, we must handle situations where the color
manager didn't connect to colord yet, and thus isn't ready.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3904>
This commit is contained in:
Sebastian Wick 2024-07-18 14:16:11 +02:00
parent 25e5c59202
commit a50e0a76b6
2 changed files with 50 additions and 10 deletions

View File

@ -55,6 +55,7 @@ struct _MetaColorDevice
GObject parent;
MetaColorManager *color_manager;
gulong manager_ready_handler_id;
char *cd_device_id;
MetaMonitor *monitor;
@ -273,13 +274,16 @@ meta_color_device_dispose (GObject *object)
g_clear_object (&color_device->cancellable);
g_clear_signal_handler (&color_device->device_profile_ready_handler_id,
color_device->device_profile);
g_clear_signal_handler (&color_device->manager_ready_handler_id,
color_manager);
g_clear_object (&color_device->assigned_profile);
g_clear_object (&color_device->device_profile);
cd_device = color_device->cd_device;
cd_device_id = color_device->cd_device_id;
if (!cd_device && cd_device_id)
if (!cd_device && cd_device_id && meta_color_manager_is_ready (color_manager))
{
g_autoptr (GError) error = NULL;
@ -565,19 +569,14 @@ generate_color_device_props (MetaMonitor *monitor)
return device_props;
}
MetaColorDevice *
meta_color_device_new (MetaColorManager *color_manager,
MetaMonitor *monitor)
static void
create_cd_device (MetaColorDevice *color_device)
{
MetaColorDevice *color_device;
MetaColorManager *color_manager = color_device->color_manager;
MetaMonitor *monitor = color_device->monitor;
g_autoptr (GHashTable) device_props = NULL;
device_props = generate_color_device_props (monitor);
color_device = g_object_new (META_TYPE_COLOR_DEVICE, NULL);
color_device->cd_device_id = generate_cd_device_id (monitor);
color_device->monitor = g_object_ref (monitor);
color_device->cancellable = g_cancellable_new ();
color_device->color_manager = color_manager;
cd_client_create_device (meta_color_manager_get_cd_client (color_manager),
color_device->cd_device_id,
@ -586,6 +585,38 @@ meta_color_device_new (MetaColorManager *color_manager,
color_device->cancellable,
on_cd_device_created,
color_device);
}
static void
on_manager_ready (MetaColorManager *color_manager,
MetaColorDevice *color_device)
{
create_cd_device (color_device);
}
MetaColorDevice *
meta_color_device_new (MetaColorManager *color_manager,
MetaMonitor *monitor)
{
MetaColorDevice *color_device;
color_device = g_object_new (META_TYPE_COLOR_DEVICE, NULL);
color_device->cd_device_id = generate_cd_device_id (monitor);
color_device->monitor = g_object_ref (monitor);
color_device->cancellable = g_cancellable_new ();
color_device->color_manager = color_manager;
if (meta_color_manager_is_ready (color_manager))
{
create_cd_device (color_device);
}
else
{
color_device->manager_ready_handler_id =
g_signal_connect (color_manager, "ready",
G_CALLBACK (on_manager_ready),
color_device);
}
return color_device;
}

View File

@ -60,6 +60,7 @@
enum
{
DEVICE_UPDATED,
READY,
N_SIGNALS
};
@ -288,6 +289,7 @@ cd_client_connect_cb (GObject *source_object,
color_manager);
priv->is_ready = TRUE;
g_signal_emit (color_manager, signals[READY], 0);
}
static void
@ -506,6 +508,13 @@ meta_color_manager_class_init (MetaColorManagerClass *klass)
NULL, NULL, NULL,
G_TYPE_NONE, 1,
META_TYPE_COLOR_DEVICE);
signals[READY] =
g_signal_new ("ready",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, 0,
NULL, NULL, NULL,
G_TYPE_NONE, 0);
}
static void