diff options
author | Jonas Ã…dahl <jadahl@gmail.com> | 2021-12-06 11:55:28 +0100 |
---|---|---|
committer | Carlos Garnacho <carlosg@gnome.org> | 2022-09-01 17:45:20 +0200 |
commit | c1ee6ea004f61bacdc81536218544def93ea5ffd (patch) | |
tree | 4542f885afcdcbde5e9e3f3e9659df6087b6cf30 /plugins | |
parent | ceb301a4f693174d676850f1d11e545884048d3e (diff) | |
download | gnome-settings-daemon-c1ee6ea004f61bacdc81536218544def93ea5ffd.tar.gz |
color: Stop managing color profiles
This is now done by mutter too. We still apply them however.
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/color/gsd-color-manager.c | 14 | ||||
-rw-r--r-- | plugins/color/gsd-color-profiles.c | 246 | ||||
-rw-r--r-- | plugins/color/gsd-color-profiles.h | 40 | ||||
-rw-r--r-- | plugins/color/gsd-color-state.c | 298 | ||||
-rw-r--r-- | plugins/color/meson.build | 1 |
5 files changed, 1 insertions, 598 deletions
diff --git a/plugins/color/gsd-color-manager.c b/plugins/color/gsd-color-manager.c index 4d6d2832..a9d8f74e 100644 --- a/plugins/color/gsd-color-manager.c +++ b/plugins/color/gsd-color-manager.c @@ -28,7 +28,6 @@ #include "gnome-settings-profile.h" #include "gsd-color-calibrate.h" #include "gsd-color-manager.h" -#include "gsd-color-profiles.h" #include "gsd-color-state.h" #include "gsd-night-light.h" @@ -65,7 +64,6 @@ struct _GsdColorManager GCancellable *bus_cancellable; GsdColorCalibrate *calibrate; - GsdColorProfiles *profiles; GsdColorState *state; GsdNightLight *nlight; @@ -97,21 +95,14 @@ gboolean gsd_color_manager_start (GsdColorManager *manager, GError **error) { - gboolean ret; - g_debug ("Starting color manager"); gnome_settings_profile_start (NULL); /* start the device probing */ gsd_color_state_start (manager->state); - /* start the profiles collection */ - ret = gsd_color_profiles_start (manager->profiles, error); - if (!ret) - goto out; -out: gnome_settings_profile_end (NULL); - return ret; + return TRUE; } void @@ -119,7 +110,6 @@ gsd_color_manager_stop (GsdColorManager *manager) { g_debug ("Stopping color manager"); gsd_color_state_stop (manager->state); - gsd_color_profiles_stop (manager->profiles); } static void @@ -220,7 +210,6 @@ gsd_color_manager_init (GsdColorManager *manager) { /* setup calibration features */ manager->calibrate = gsd_color_calibrate_new (); - manager->profiles = gsd_color_profiles_new (); manager->state = gsd_color_state_new (); /* night light features */ @@ -266,7 +255,6 @@ gsd_color_manager_finalize (GObject *object) g_source_remove (manager->nlight_forced_timeout_id); g_clear_object (&manager->calibrate); - g_clear_object (&manager->profiles); g_clear_object (&manager->state); g_clear_object (&manager->nlight); diff --git a/plugins/color/gsd-color-profiles.c b/plugins/color/gsd-color-profiles.c deleted file mode 100644 index c73abd71..00000000 --- a/plugins/color/gsd-color-profiles.c +++ /dev/null @@ -1,246 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu> - * Copyright (C) 2011-2013 Richard Hughes <richard@hughsie.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -#include "config.h" - -#include <glib/gi18n.h> -#include <colord.h> - -#include "gsd-color-profiles.h" - -struct _GsdColorProfiles -{ - GObject parent; - - GCancellable *cancellable; - CdClient *client; - CdIccStore *icc_store; -}; - -static void gsd_color_profiles_class_init (GsdColorProfilesClass *klass); -static void gsd_color_profiles_init (GsdColorProfiles *color_profiles); -static void gsd_color_profiles_finalize (GObject *object); - -G_DEFINE_TYPE (GsdColorProfiles, gsd_color_profiles, G_TYPE_OBJECT) - -static void -gsd_color_profiles_class_init (GsdColorProfilesClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->finalize = gsd_color_profiles_finalize; -} - -static void -gcm_session_client_connect_cb (GObject *source_object, - GAsyncResult *res, - gpointer user_data) -{ - gboolean ret; - GError *error = NULL; - CdClient *client = CD_CLIENT (source_object); - GsdColorProfiles *profiles; - - /* connected */ - ret = cd_client_connect_finish (client, res, &error); - if (!ret) { - if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - g_warning ("failed to connect to colord: %s", error->message); - g_error_free (error); - return; - } - - /* is there an available colord instance? */ - profiles = GSD_COLOR_PROFILES (user_data); - ret = cd_client_get_has_server (profiles->client); - if (!ret) { - g_warning ("There is no colord server available"); - return; - } - - /* add profiles */ - ret = cd_icc_store_search_kind (profiles->icc_store, - CD_ICC_STORE_SEARCH_KIND_USER, - CD_ICC_STORE_SEARCH_FLAGS_CREATE_LOCATION, - profiles->cancellable, - &error); - if (!ret) { - g_warning ("failed to add user icc: %s", error->message); - g_error_free (error); - } -} - -gboolean -gsd_color_profiles_start (GsdColorProfiles *profiles, - GError **error) -{ - /* use a fresh cancellable for each start->stop operation */ - g_cancellable_cancel (profiles->cancellable); - g_clear_object (&profiles->cancellable); - profiles->cancellable = g_cancellable_new (); - - cd_client_connect (profiles->client, - profiles->cancellable, - gcm_session_client_connect_cb, - profiles); - - return TRUE; -} - -void -gsd_color_profiles_stop (GsdColorProfiles *profiles) -{ - g_cancellable_cancel (profiles->cancellable); -} - -static void -gcm_session_create_profile_cb (GObject *object, - GAsyncResult *res, - gpointer user_data) -{ - CdProfile *profile; - GError *error = NULL; - CdClient *client = CD_CLIENT (object); - - profile = cd_client_create_profile_finish (client, res, &error); - if (profile == NULL) { - if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) && - !g_error_matches (error, CD_CLIENT_ERROR, CD_CLIENT_ERROR_ALREADY_EXISTS)) - g_warning ("%s", error->message); - g_error_free (error); - return; - } - g_object_unref (profile); -} - -static void -gcm_session_icc_store_added_cb (CdIccStore *icc_store, - CdIcc *icc, - GsdColorProfiles *profiles) -{ - cd_client_create_profile_for_icc (profiles->client, - icc, - CD_OBJECT_SCOPE_TEMP, - profiles->cancellable, - gcm_session_create_profile_cb, - profiles); -} - -static void -gcm_session_delete_profile_cb (GObject *object, - GAsyncResult *res, - gpointer user_data) -{ - gboolean ret; - GError *error = NULL; - CdClient *client = CD_CLIENT (object); - - ret = cd_client_delete_profile_finish (client, res, &error); - if (!ret) { - if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - g_warning ("%s", error->message); - g_error_free (error); - } -} - -static void -gcm_session_find_profile_by_filename_cb (GObject *object, - GAsyncResult *res, - gpointer user_data) -{ - GError *error = NULL; - CdProfile *profile; - CdClient *client = CD_CLIENT (object); - GsdColorProfiles *profiles = GSD_COLOR_PROFILES (user_data); - - profile = cd_client_find_profile_by_filename_finish (client, res, &error); - if (profile == NULL) { - if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - g_warning ("%s", error->message); - g_error_free (error); - goto out; - } - - /* remove it from colord */ - cd_client_delete_profile (profiles->client, - profile, - profiles->cancellable, - gcm_session_delete_profile_cb, - profiles); -out: - if (profile != NULL) - g_object_unref (profile); -} - -static void -gcm_session_icc_store_removed_cb (CdIccStore *icc_store, - CdIcc *icc, - GsdColorProfiles *profiles) -{ - /* find the ID for the filename */ - g_debug ("filename %s removed", cd_icc_get_filename (icc)); - cd_client_find_profile_by_filename (profiles->client, - cd_icc_get_filename (icc), - profiles->cancellable, - gcm_session_find_profile_by_filename_cb, - profiles); -} - -static void -gsd_color_profiles_init (GsdColorProfiles *profiles) -{ - /* have access to all user profiles */ - profiles->client = cd_client_new (); - profiles->icc_store = cd_icc_store_new (); - cd_icc_store_set_load_flags (profiles->icc_store, - CD_ICC_LOAD_FLAGS_FALLBACK_MD5); - g_signal_connect (profiles->icc_store, "added", - G_CALLBACK (gcm_session_icc_store_added_cb), - profiles); - g_signal_connect (profiles->icc_store, "removed", - G_CALLBACK (gcm_session_icc_store_removed_cb), - profiles); -} - -static void -gsd_color_profiles_finalize (GObject *object) -{ - GsdColorProfiles *profiles; - - g_return_if_fail (object != NULL); - g_return_if_fail (GSD_IS_COLOR_PROFILES (object)); - - profiles = GSD_COLOR_PROFILES (object); - - g_cancellable_cancel (profiles->cancellable); - g_clear_object (&profiles->cancellable); - g_clear_object (&profiles->icc_store); - g_clear_object (&profiles->client); - - G_OBJECT_CLASS (gsd_color_profiles_parent_class)->finalize (object); -} - -GsdColorProfiles * -gsd_color_profiles_new (void) -{ - GsdColorProfiles *profiles; - profiles = g_object_new (GSD_TYPE_COLOR_PROFILES, NULL); - return GSD_COLOR_PROFILES (profiles); -} diff --git a/plugins/color/gsd-color-profiles.h b/plugins/color/gsd-color-profiles.h deleted file mode 100644 index 24aed348..00000000 --- a/plugins/color/gsd-color-profiles.h +++ /dev/null @@ -1,40 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu> - * Copyright (C) 2011-2013 Richard Hughes <richard@hughsie.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - * - */ - -#ifndef __GSD_COLOR_PROFILES_H -#define __GSD_COLOR_PROFILES_H - -#include <glib-object.h> - -G_BEGIN_DECLS - -#define GSD_TYPE_COLOR_PROFILES (gsd_color_profiles_get_type ()) -G_DECLARE_FINAL_TYPE (GsdColorProfiles, gsd_color_profiles, GSD, COLOR_PROFILES, GObject) - -GQuark gsd_color_profiles_error_quark (void); - -GsdColorProfiles * gsd_color_profiles_new (void); -gboolean gsd_color_profiles_start (GsdColorProfiles *profiles, - GError **error); -void gsd_color_profiles_stop (GsdColorProfiles *profiles); - -G_END_DECLS - -#endif /* __GSD_COLOR_PROFILES_H */ diff --git a/plugins/color/gsd-color-state.c b/plugins/color/gsd-color-state.c index 16716e46..1b153d09 100644 --- a/plugins/color/gsd-color-state.c +++ b/plugins/color/gsd-color-state.c @@ -57,7 +57,6 @@ struct _GsdColorState GsdSessionManager *session; CdClient *client; GnomeRRScreen *state_screen; - GHashTable *edid_cache; GdkWindow *gdk_window; gboolean session_is_active; GHashTable *device_assign_hash; @@ -89,46 +88,6 @@ gsd_color_state_error_quark (void) return quark; } -static GcmEdid * -gcm_session_get_output_edid (GsdColorState *state, GnomeRROutput *output, GError **error) -{ - const guint8 *data; - gsize size; - GcmEdid *edid = NULL; - gboolean ret; - - /* can we find it in the cache */ - edid = g_hash_table_lookup (state->edid_cache, - gnome_rr_output_get_name (output)); - if (edid != NULL) { - g_object_ref (edid); - return edid; - } - - /* parse edid */ - data = gnome_rr_output_get_edid_data (output, &size); - if (data == NULL || size == 0) { - g_set_error_literal (error, - GNOME_RR_ERROR, - GNOME_RR_ERROR_UNKNOWN, - "unable to get EDID for output"); - return NULL; - } - edid = gcm_edid_new (); - ret = gcm_edid_parse (edid, data, size, error); - if (!ret) { - g_object_unref (edid); - return NULL; - } - - /* add to cache */ - g_hash_table_insert (state->edid_cache, - g_strdup (gnome_rr_output_get_name (output)), - g_object_ref (edid)); - - return edid; -} - static CdIcc * gcm_get_srgb_icc (GError **error) { @@ -263,177 +222,6 @@ gcm_session_async_helper_free (GcmSessionAsyncHelper *helper) g_free (helper); } -static gboolean -gcm_utils_mkdir_for_filename (GFile *file, GError **error) -{ - gboolean ret = FALSE; - GFile *parent_dir = NULL; - - /* get parent directory */ - parent_dir = g_file_get_parent (file); - if (parent_dir == NULL) { - g_set_error_literal (error, - GSD_COLOR_MANAGER_ERROR, - GSD_COLOR_MANAGER_ERROR_FAILED, - "could not get parent dir"); - goto out; - } - - /* ensure desination does not already exist */ - ret = g_file_query_exists (parent_dir, NULL); - if (ret) - goto out; - ret = g_file_make_directory_with_parents (parent_dir, NULL, error); - if (!ret) - goto out; -out: - if (parent_dir != NULL) - g_object_unref (parent_dir); - return ret; -} - -static gboolean -gcm_get_system_icc_profile (GsdColorState *state, - GFile *file) -{ - const char efi_path[] = "/sys/firmware/efi/efivars/INTERNAL_PANEL_COLOR_INFO-01e1ada1-79f2-46b3-8d3e-71fc0996ca6b"; - /* efi variables have a 4-byte header */ - const int efi_var_header_length = 4; - g_autoptr(GFile) efi_file = g_file_new_for_path (efi_path); - gboolean ret; - g_autofree char *data = NULL; - gsize length; - g_autoptr(GError) error = NULL; - - ret = g_file_query_exists (efi_file, NULL); - if (!ret) - return FALSE; - - ret = g_file_load_contents (efi_file, - NULL /* cancellable */, - &data, - &length, - NULL /* etag_out */, - &error); - - if (!ret) { - g_warning ("failed to read EFI system color profile: %s", - error->message); - return FALSE; - } - - if (length <= efi_var_header_length) { - g_warning ("EFI system color profile was too short"); - return FALSE; - } - - ret = g_file_replace_contents (file, - data + efi_var_header_length, - length - efi_var_header_length, - NULL /* etag */, - FALSE /* make_backup */, - G_FILE_CREATE_NONE, - NULL /* new_etag */, - NULL /* cancellable */, - &error); - if (!ret) { - g_warning ("failed to write system color profile: %s", - error->message); - return FALSE; - } - - return TRUE; -} - -static gboolean -gcm_apply_create_icc_profile_for_edid (GsdColorState *state, - CdDevice *device, - GcmEdid *edid, - GFile *file, - GError **error) -{ - CdIcc *icc = NULL; - const gchar *data; - gboolean ret = FALSE; - - /* ensure the per-user directory exists */ - ret = gcm_utils_mkdir_for_filename (file, error); - if (!ret) - goto out; - - /* create our generated profile */ - icc = cd_icc_new (); - ret = cd_icc_create_from_edid (icc, - gcm_edid_get_gamma (edid), - gcm_edid_get_red (edid), - gcm_edid_get_green (edid), - gcm_edid_get_blue (edid), - gcm_edid_get_white (edid), - error); - if (!ret) - goto out; - - /* set copyright */ - cd_icc_set_copyright (icc, NULL, - /* deliberately not translated */ - "This profile is free of known copyright restrictions."); - - /* set model and title */ - data = gcm_edid_get_monitor_name (edid); - if (data == NULL) - data = cd_client_get_system_model (state->client); - if (data == NULL) - data = "Unknown monitor"; - cd_icc_set_model (icc, NULL, data); - cd_icc_set_description (icc, NULL, data); - - /* get manufacturer */ - data = gcm_edid_get_vendor_name (edid); - if (data == NULL) - data = cd_client_get_system_vendor (state->client); - if (data == NULL) - data = "Unknown vendor"; - cd_icc_set_manufacturer (icc, NULL, data); - - /* set the framework creator metadata */ - cd_icc_add_metadata (icc, - CD_PROFILE_METADATA_CMF_PRODUCT, - PACKAGE_NAME); - cd_icc_add_metadata (icc, - CD_PROFILE_METADATA_CMF_BINARY, - PACKAGE_NAME); - cd_icc_add_metadata (icc, - CD_PROFILE_METADATA_CMF_VERSION, - PACKAGE_VERSION); - cd_icc_add_metadata (icc, - CD_PROFILE_METADATA_MAPPING_DEVICE_ID, - cd_device_get_id (device)); - - /* set 'ICC meta Tag for Monitor Profiles' data */ - cd_icc_add_metadata (icc, CD_PROFILE_METADATA_EDID_MD5, gcm_edid_get_checksum (edid)); - data = gcm_edid_get_monitor_name (edid); - if (data != NULL) - cd_icc_add_metadata (icc, CD_PROFILE_METADATA_EDID_MODEL, data); - data = gcm_edid_get_serial_number (edid); - if (data != NULL) - cd_icc_add_metadata (icc, CD_PROFILE_METADATA_EDID_SERIAL, data); - data = gcm_edid_get_pnp_id (edid); - if (data != NULL) - cd_icc_add_metadata (icc, CD_PROFILE_METADATA_EDID_MNFT, data); - data = gcm_edid_get_vendor_name (edid); - if (data != NULL) - cd_icc_add_metadata (icc, CD_PROFILE_METADATA_EDID_VENDOR, data); - - /* save */ - ret = cd_icc_save_file (icc, file, CD_ICC_SAVE_FLAGS_NONE, NULL, error); - if (!ret) - goto out; -out: - if (icc != NULL) - g_object_unref (icc); - return ret; -} - static uint64_t gcm_double_to_ctmval (double value) { @@ -944,32 +732,6 @@ out: gcm_session_async_helper_free (helper); } -/* - * Check to see if the on-disk profile has the MAPPING_device_id - * metadata, and if not, we should delete the profile and re-create it - * so that it gets mapped by the daemon. - */ -static gboolean -gcm_session_check_profile_device_md (GFile *file) -{ - const gchar *key_we_need = CD_PROFILE_METADATA_MAPPING_DEVICE_ID; - CdIcc *icc; - gboolean ret; - - icc = cd_icc_new (); - ret = cd_icc_load_file (icc, file, CD_ICC_LOAD_FLAGS_METADATA, NULL, NULL); - if (!ret) - goto out; - ret = cd_icc_get_metadata_item (icc, key_we_need) != NULL; - if (!ret) { - g_debug ("auto-edid profile is old, and contains no %s data", - key_we_need); - } -out: - g_object_unref (icc); - return ret; -} - static void gcm_session_device_assign_connect_cb (GObject *object, GAsyncResult *res, @@ -978,12 +740,8 @@ gcm_session_device_assign_connect_cb (GObject *object, CdDeviceKind kind; CdProfile *profile = NULL; gboolean ret; - gchar *autogen_filename = NULL; - gchar *autogen_path = NULL; - GcmEdid *edid = NULL; GnomeRROutput *output = NULL; GError *error = NULL; - GFile *file = NULL; GcmSessionAsyncHelper *helper; CdDevice *device = CD_DEVICE (object); GsdColorState *state = GSD_COLOR_STATE (user_data); @@ -1021,49 +779,6 @@ gcm_session_device_assign_connect_cb (GObject *object, goto out; } - /* create profile from device edid if it exists */ - edid = gcm_session_get_output_edid (state, output, &error); - if (edid == NULL) { - g_warning ("unable to get EDID for %s: %s", - cd_device_get_id (device), - error->message); - g_clear_error (&error); - - } else { - autogen_filename = g_strdup_printf ("edid-%s.icc", - gcm_edid_get_checksum (edid)); - autogen_path = g_build_filename (g_get_user_data_dir (), - "icc", autogen_filename, NULL); - - /* check if auto-profile has up-to-date metadata */ - file = g_file_new_for_path (autogen_path); - if (gcm_session_check_profile_device_md (file)) { - g_debug ("auto-profile edid %s exists with md", autogen_path); - } else { - g_debug ("auto-profile edid does not exist, creating as %s", - autogen_path); - - /* check if the system has a built-in profile */ - ret = gnome_rr_output_is_builtin_display (output) && - gcm_get_system_icc_profile (state, file); - - /* try creating one from the EDID */ - if (!ret) { - ret = gcm_apply_create_icc_profile_for_edid (state, - device, - edid, - file, - &error); - } - - if (!ret) { - g_warning ("failed to create profile from EDID data: %s", - error->message); - g_clear_error (&error); - } - } - } - /* get the default profile for the device */ profile = cd_device_get_default_profile (device); if (profile == NULL) { @@ -1103,12 +818,6 @@ gcm_session_device_assign_connect_cb (GObject *object, gcm_session_device_assign_profile_connect_cb, helper); out: - g_free (autogen_filename); - g_free (autogen_path); - if (file != NULL) - g_object_unref (file); - if (edid != NULL) - g_object_unref (edid); if (profile != NULL) g_object_unref (profile); } @@ -1414,12 +1123,6 @@ gsd_color_state_init (GsdColorState *state) state->gdk_window = gdk_screen_get_root_window (gdk_screen_get_default ()); #endif - /* parsing the EDID is expensive */ - state->edid_cache = g_hash_table_new_full (g_str_hash, - g_str_equal, - g_free, - g_object_unref); - /* we don't want to assign devices multiple times at startup */ state->device_assign_hash = g_hash_table_new_full (g_str_hash, g_str_equal, @@ -1446,7 +1149,6 @@ gsd_color_state_finalize (GObject *object) g_clear_object (&state->cancellable); g_clear_object (&state->client); g_clear_object (&state->session); - g_clear_pointer (&state->edid_cache, g_hash_table_destroy); g_clear_pointer (&state->device_assign_hash, g_hash_table_destroy); g_clear_object (&state->state_screen); diff --git a/plugins/color/meson.build b/plugins/color/meson.build index 2ae1740a..effe1f64 100644 --- a/plugins/color/meson.build +++ b/plugins/color/meson.build @@ -3,7 +3,6 @@ sources = files( 'gnome-datetime-source.c', 'gsd-color-calibrate.c', 'gsd-color-manager.c', - 'gsd-color-profiles.c', 'gsd-color-state.c', 'gsd-night-light.c', 'gsd-night-light-common.c', |