From 5346a0cb1721a7f8e729fb35eb62fc33a32c51c8 Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Wed, 5 Jul 2023 03:09:35 +0200 Subject: src/rotation-lock.cpp: Simplify code and keep updater callback running --- src/rotation-lock.cpp | 85 +++++++++++++++++++-------------------------------- 1 file changed, 32 insertions(+), 53 deletions(-) diff --git a/src/rotation-lock.cpp b/src/rotation-lock.cpp index 9523358..55919d2 100644 --- a/src/rotation-lock.cpp +++ b/src/rotation-lock.cpp @@ -130,14 +130,7 @@ public: gclue_simple_new ("ayatana-indicator-display", GCLUE_ACCURACY_LEVEL_CITY, NULL, onGeoClueLoaded, this); } - GVariant *pProfile = g_settings_get_value (this->m_settings, "color-temp-profile"); - guint nProfile = g_variant_get_uint16 (pProfile); - - if (nProfile != 0) - { - this->nCallback = g_timeout_add_seconds (60, updateColorTemp, this); - } - + this->nCallback = g_timeout_add_seconds (60, updateColorTemp, this); updateColorTemp (this); } #endif @@ -145,6 +138,11 @@ public: ~Impl() { + if (nCallback) + { + g_source_remove (nCallback); + } + g_signal_handlers_disconnect_by_data(m_settings, this); g_clear_object(&m_action_group); g_clear_object(&m_settings); @@ -169,16 +167,14 @@ private: static gboolean updateColorTemp (gpointer pData) { RotationLockIndicator::Impl *pImpl = (RotationLockIndicator::Impl*) pData; - guint nTemperature = 6500; - GVariant *pProfile = g_settings_get_value (pImpl->m_settings, "color-temp-profile"); - guint nProfile = g_variant_get_uint16 (pProfile); - GVariant *pBrightness = g_settings_get_value (pImpl->m_settings, "brightness"); - gdouble fBrightness = g_variant_get_double (pBrightness); + guint nProfile = 0; + g_settings_get (pImpl->m_settings, "color-temp-profile", "q", &nProfile); + gdouble fBrightness = g_settings_get_double (pImpl->m_settings, "brightness"); + guint nTemperature = 0; if (nProfile == 0) { - GVariant *pTemperature = g_settings_get_value (pImpl->m_settings, "color-temp"); - nTemperature = g_variant_get_uint16 (pTemperature); + g_settings_get (pImpl->m_settings, "color-temp", "q", &nTemperature); g_debug("%i", nTemperature); } @@ -203,21 +199,26 @@ private: g_debug("%f, %f, %i", fShifting, fElevation, nTemperature); } - GAction *pAction = g_action_map_lookup_action (G_ACTION_MAP (pImpl->m_action_group), "color-temp"); - GVariant *pTemperature = g_variant_new_double (nTemperature); - g_action_change_state (pAction, pTemperature); + if (pImpl->fLastBrightness != fBrightness || pImpl->nLasColorTemp != nTemperature) + { + GAction *pAction = g_action_map_lookup_action (G_ACTION_MAP (pImpl->m_action_group), "color-temp"); + GVariant *pTemperature = g_variant_new_double (nTemperature); + g_action_change_state (pAction, pTemperature); - GError *pError = NULL; - gchar *sCommand = g_strdup_printf ("xsct %u %f", nTemperature, fBrightness); - gboolean bSuccess = g_spawn_command_line_sync (sCommand, NULL, NULL, NULL, &pError); + GError *pError = NULL; + gchar *sCommand = g_strdup_printf ("xsct %u %f", nTemperature, fBrightness); + gboolean bSuccess = g_spawn_command_line_sync (sCommand, NULL, NULL, NULL, &pError); - if (!bSuccess) - { - g_error ("The call to '%s' failed: %s", sCommand, pError->message); - g_error_free (pError); - } + if (!bSuccess) + { + g_error ("The call to '%s' failed: %s", sCommand, pError->message); + g_error_free (pError); + } - g_free (sCommand); + pImpl->fLastBrightness = fBrightness; + pImpl->nLasColorTemp = nTemperature; + g_free (sCommand); + } return G_SOURCE_CONTINUE; } @@ -250,30 +251,6 @@ private: updateColorTemp (pData); } - static void onBrightnessSettings (GSettings *pSettings, const gchar *sKey, gpointer pData) - { - updateColorTemp (pData); - } - - static void onColorTempProfile (GSettings *pSettings, const gchar *sKey, gpointer pData) - { - RotationLockIndicator::Impl *pImpl = (RotationLockIndicator::Impl*) pData; - GVariant *pProfile = g_settings_get_value (pImpl->m_settings, "color-temp-profile"); - guint nProfile = g_variant_get_uint16 (pProfile); - - if (nProfile == 0 && pImpl->nCallback != 0) - { - g_source_remove (pImpl->nCallback); - pImpl->nCallback = 0; - } - else if (nProfile != 0 && pImpl->nCallback == 0) - { - pImpl->nCallback = g_timeout_add_seconds (60, updateColorTemp, pImpl); - } - - updateColorTemp (pImpl); - } - static gboolean settingsIntToActionStateString (GValue *pValue, GVariant *pVariant, gpointer pData) { guint16 nVariant = g_variant_get_uint16 (pVariant); @@ -380,7 +357,7 @@ private: g_settings_bind_with_mapping (this->m_settings, "color-temp-profile", action, "state", G_SETTINGS_BIND_DEFAULT, settingsIntToActionStateString, actionStateStringToSettingsInt, NULL, NULL); g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(action)); g_object_unref(G_OBJECT(action)); - g_signal_connect (m_settings, "changed::color-temp-profile", G_CALLBACK (onColorTempProfile), this); + g_signal_connect_swapped (m_settings, "changed::color-temp-profile", G_CALLBACK (updateColorTemp), this); pVariantType = g_variant_type_new("d"); action = g_simple_action_new_stateful ("brightness", pVariantType, g_variant_new_double (0)); @@ -388,7 +365,7 @@ private: g_settings_bind_with_mapping (m_settings, "brightness", action, "state", G_SETTINGS_BIND_DEFAULT, settings_to_action_state, action_state_to_settings, NULL, NULL); g_action_map_add_action (G_ACTION_MAP (group), G_ACTION (action)); g_object_unref (G_OBJECT (action)); - g_signal_connect (m_settings, "changed::brightness", G_CALLBACK (onBrightnessSettings), this); + g_signal_connect_swapped (m_settings, "changed::brightness", G_CALLBACK (updateColorTemp), this); } #endif @@ -568,6 +545,8 @@ private: gdouble fLongitude = -0.0076589; gboolean bAutoSliderUpdate = FALSE; guint nCallback = 0; + gdouble fLastBrightness = 0.0; + guint nLasColorTemp = 0; #endif }; -- cgit v1.2.3 From d2e5eb6e98986cd2391ece1ae0cf9f1a7139b63c Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Wed, 5 Jul 2023 03:11:03 +0200 Subject: src/rotation-lock.cpp: Use singular profile in menu label --- src/rotation-lock.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rotation-lock.cpp b/src/rotation-lock.cpp index 55919d2..164f79c 100644 --- a/src/rotation-lock.cpp +++ b/src/rotation-lock.cpp @@ -472,7 +472,7 @@ private: g_menu_append_item (section, menu_item); GMenu *pMenuProfiles = g_menu_new (); - GMenuItem *pItemProfiles = g_menu_item_new_submenu (_("Color temperature profiles"), G_MENU_MODEL (pMenuProfiles)); + GMenuItem *pItemProfiles = g_menu_item_new_submenu (_("Color temperature profile"), G_MENU_MODEL (pMenuProfiles)); guint nProfile = 0; while (m_lTempProfiles[nProfile].sName != NULL) -- cgit v1.2.3 From 08134f79149c9378fb5e5ddde016b4f600ce33aa Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Thu, 6 Jul 2023 02:48:53 +0200 Subject: data/org.ayatana.indicator.display.gschema.xml: Add theme manipulation keys --- data/org.ayatana.indicator.display.gschema.xml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/data/org.ayatana.indicator.display.gschema.xml b/data/org.ayatana.indicator.display.gschema.xml index 3a0c89b..ededac4 100644 --- a/data/org.ayatana.indicator.display.gschema.xml +++ b/data/org.ayatana.indicator.display.gschema.xml @@ -37,5 +37,25 @@ Screen brightness Stores the current brightness value of your screen. + + 'current' + The name of the light theme + This is the theme the indicator will set when "Light" is selected. + + + 'current' + The name of the dark theme + This is the theme the indicator will set when "Dark" is selected. + + + + + + + + 'light' + Theme profile + The current theme temperature profile being used by the indicator. + -- cgit v1.2.3 From 24556f25958420e44f4bbdf299fd47adcdcb8594 Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Thu, 6 Jul 2023 02:51:57 +0200 Subject: src/rotation-lock.cpp: Add theme profiles --- src/rotation-lock.cpp | 198 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 182 insertions(+), 16 deletions(-) diff --git a/src/rotation-lock.cpp b/src/rotation-lock.cpp index 164f79c..9ca7218 100644 --- a/src/rotation-lock.cpp +++ b/src/rotation-lock.cpp @@ -60,6 +60,8 @@ public: Impl() { GSettingsSchemaSource *pSource = g_settings_schema_source_get_default(); + const gchar *sTest = g_getenv ("TEST_NAME"); + this->bTest = (sTest != NULL && g_str_equal (sTest, "rotation-lock-test")); if (pSource != NULL) { @@ -92,6 +94,56 @@ public: g_error("No schema could be found"); } + const gchar *sSchema = NULL; + + if (this->bTest) + { + sSchema = "org.ayatana.indicator.display"; + } + else + { + if (ayatana_common_utils_is_mate ()) + { + sSchema = "org.mate.interface"; + } + else + { + sSchema = "org.gnome.desktop.interface"; + } + } + + pSchema = g_settings_schema_source_lookup (pSource, sSchema, FALSE); + + if (pSchema != NULL) + { + g_settings_schema_unref (pSchema); + pThemeSettings = g_settings_new (sSchema); + } + else + { + g_error("No %s schema could be found", sSchema); + } + + if (this->bTest) + { + sSchema = "org.ayatana.indicator.display"; + } + else + { + sSchema = "org.gnome.desktop.interface"; + } + + pSchema = g_settings_schema_source_lookup (pSource, sSchema, FALSE); + + if (pSchema != NULL) + { + g_settings_schema_unref (pSchema); + pColorSchemeSettings = g_settings_new (sSchema); + } + else + { + g_error("No %s schema could be found", sSchema); + } } } @@ -123,15 +175,12 @@ public: #ifdef COLOR_TEMP_ENABLED if (ayatana_common_utils_is_lomiri() == FALSE) { - const gchar *sTest = g_getenv ("TEST_NAME"); - - if (sTest == NULL || !g_str_equal (sTest, "rotation-lock-test")) + if (!this->bTest) { gclue_simple_new ("ayatana-indicator-display", GCLUE_ACCURACY_LEVEL_CITY, NULL, onGeoClueLoaded, this); + this->nCallback = g_timeout_add_seconds (60, updateColor, this); + updateColor (this); } - - this->nCallback = g_timeout_add_seconds (60, updateColorTemp, this); - updateColorTemp (this); } #endif } @@ -146,6 +195,21 @@ public: g_signal_handlers_disconnect_by_data(m_settings, this); g_clear_object(&m_action_group); g_clear_object(&m_settings); + + if (sLastTheme) + { + g_free (sLastTheme); + } + + if (pThemeSettings) + { + g_clear_object (&pThemeSettings); + } + + if (pColorSchemeSettings) + { + g_clear_object (&pColorSchemeSettings); + } } GSimpleActionGroup* action_group() const @@ -164,24 +228,26 @@ public: private: #ifdef COLOR_TEMP_ENABLED - static gboolean updateColorTemp (gpointer pData) + static gboolean updateColor (gpointer pData) { RotationLockIndicator::Impl *pImpl = (RotationLockIndicator::Impl*) pData; guint nProfile = 0; g_settings_get (pImpl->m_settings, "color-temp-profile", "q", &nProfile); gdouble fBrightness = g_settings_get_double (pImpl->m_settings, "brightness"); + gchar *sThemeProfile = g_settings_get_string (pImpl->m_settings, "theme-profile"); + gboolean bThemeAdaptive = g_str_equal (sThemeProfile, "adaptive"); guint nTemperature = 0; + const gchar *sColorScheme = NULL; + gchar *sTheme = NULL; + gint64 nNow = g_get_real_time (); + gdouble fElevation = solar_elevation((gdouble) nNow / 1000000.0, pImpl->fLatitude, pImpl->fLongitude); if (nProfile == 0) { g_settings_get (pImpl->m_settings, "color-temp", "q", &nTemperature); - - g_debug("%i", nTemperature); } else { - gint64 nNow = g_get_real_time (); - gdouble fElevation = solar_elevation((gdouble) nNow / 1000000.0, pImpl->fLatitude, pImpl->fLongitude); gdouble fShifting = 0.0; if (fElevation < SOLAR_CIVIL_TWILIGHT_ELEV) @@ -195,12 +261,43 @@ private: nTemperature = m_lTempProfiles[nProfile].nTempHigh - (m_lTempProfiles[nProfile].nTempHigh - m_lTempProfiles[nProfile].nTempLow) * fShifting; pImpl->bAutoSliderUpdate = TRUE; + } + + if (!bThemeAdaptive) + { + gchar *sThemeKey = g_strdup_printf ("%s-theme", sThemeProfile); + sTheme = g_settings_get_string (pImpl->m_settings, sThemeKey); + g_free (sThemeKey); - g_debug("%f, %f, %i", fShifting, fElevation, nTemperature); + gboolean bLightTheme = g_str_equal (sThemeProfile, "light"); + + if (bLightTheme) + { + sColorScheme = "prefer-light"; + } + else + { + sColorScheme = "prefer-dark"; + } + } + else + { + if (fElevation < SOLAR_CIVIL_TWILIGHT_ELEV) + { + sColorScheme = "prefer-dark"; + sTheme = g_settings_get_string (pImpl->m_settings, "dark-theme"); + } + else + { + sColorScheme = "prefer-light"; + sTheme = g_settings_get_string (pImpl->m_settings, "light-theme"); + } } if (pImpl->fLastBrightness != fBrightness || pImpl->nLasColorTemp != nTemperature) { + g_debug ("Calling xsct with %u %f", nTemperature, fBrightness); + GAction *pAction = g_action_map_lookup_action (G_ACTION_MAP (pImpl->m_action_group), "color-temp"); GVariant *pTemperature = g_variant_new_double (nTemperature); g_action_change_state (pAction, pTemperature); @@ -220,6 +317,42 @@ private: g_free (sCommand); } + gboolean bSameColorScheme = g_str_equal (sColorScheme, pImpl->sLastColorScheme); + + if (!bSameColorScheme) + { + g_debug ("Changing color scheme to %s", sColorScheme); + + g_settings_set_string (pImpl->pColorSchemeSettings, "color-scheme", sColorScheme); + pImpl->sLastColorScheme = sColorScheme; + } + + gboolean bSameTheme = FALSE; + + if (pImpl->sLastTheme) + { + bSameTheme = g_str_equal (pImpl->sLastTheme, sTheme); + } + + gboolean bCurrentTheme = g_str_equal ("current", sTheme); + + if (!bSameTheme && !bCurrentTheme) + { + g_debug ("Changing theme to %s", sTheme); + + g_settings_set_string (pImpl->pThemeSettings, "gtk-theme", sTheme); + + if (pImpl->sLastTheme) + { + g_free (pImpl->sLastTheme); + } + + pImpl->sLastTheme = g_strdup (sTheme); + } + + g_free (sTheme); + g_free (sThemeProfile); + return G_SOURCE_CONTINUE; } @@ -240,7 +373,7 @@ private: pImpl->fLongitude = gclue_location_get_longitude (pLocation); } - updateColorTemp (pImpl); + updateColor (pImpl); } static void onColorTempSettings (GSettings *pSettings, const gchar *sKey, gpointer pData) @@ -248,7 +381,7 @@ private: GVariant *pProfile = g_variant_new_uint16 (0); g_settings_set_value (pSettings, "color-temp-profile", pProfile); - updateColorTemp (pData); + updateColor (pData); } static gboolean settingsIntToActionStateString (GValue *pValue, GVariant *pVariant, gpointer pData) @@ -357,7 +490,7 @@ private: g_settings_bind_with_mapping (this->m_settings, "color-temp-profile", action, "state", G_SETTINGS_BIND_DEFAULT, settingsIntToActionStateString, actionStateStringToSettingsInt, NULL, NULL); g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(action)); g_object_unref(G_OBJECT(action)); - g_signal_connect_swapped (m_settings, "changed::color-temp-profile", G_CALLBACK (updateColorTemp), this); + g_signal_connect_swapped (m_settings, "changed::color-temp-profile", G_CALLBACK (updateColor), this); pVariantType = g_variant_type_new("d"); action = g_simple_action_new_stateful ("brightness", pVariantType, g_variant_new_double (0)); @@ -365,7 +498,17 @@ private: g_settings_bind_with_mapping (m_settings, "brightness", action, "state", G_SETTINGS_BIND_DEFAULT, settings_to_action_state, action_state_to_settings, NULL, NULL); g_action_map_add_action (G_ACTION_MAP (group), G_ACTION (action)); g_object_unref (G_OBJECT (action)); - g_signal_connect_swapped (m_settings, "changed::brightness", G_CALLBACK (updateColorTemp), this); + g_signal_connect_swapped (m_settings, "changed::brightness", G_CALLBACK (updateColor), this); + + pVariantType = g_variant_type_new ("s"); + action = g_simple_action_new_stateful ("theme", pVariantType, g_variant_new_string ("light")); + g_variant_type_free (pVariantType); + g_settings_bind_with_mapping (this->m_settings, "theme-profile", action, "state", G_SETTINGS_BIND_DEFAULT, settings_to_action_state, action_state_to_settings, NULL, NULL); + g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(action)); + g_object_unref(G_OBJECT(action)); + g_signal_connect_swapped (m_settings, "changed::theme-profile", G_CALLBACK (updateColor), this); + g_signal_connect_swapped (m_settings, "changed::light-theme", G_CALLBACK (updateColor), this); + g_signal_connect_swapped (m_settings, "changed::dark-theme", G_CALLBACK (updateColor), this); } #endif @@ -497,6 +640,24 @@ private: g_variant_unref (pIconMaxSerialised); g_object_unref (section); g_object_unref (menu_item); + + section = g_menu_new (); + pMenuProfiles = g_menu_new (); + pItemProfiles = g_menu_item_new_submenu (_("Theme profile"), G_MENU_MODEL (pMenuProfiles)); + GMenuItem *pItemProfile = g_menu_item_new (_("Light"), "indicator.theme::light"); + g_menu_append_item (pMenuProfiles, pItemProfile); + g_object_unref (pItemProfile); + pItemProfile = g_menu_item_new (_("Dark"), "indicator.theme::dark"); + g_menu_append_item (pMenuProfiles, pItemProfile); + g_object_unref (pItemProfile); + pItemProfile = g_menu_item_new (_("Adaptive"), "indicator.theme::adaptive"); + g_menu_append_item (pMenuProfiles, pItemProfile); + g_object_unref (pItemProfile); + g_menu_append_item (section, pItemProfiles); + g_object_unref (pItemProfiles); + g_object_unref (pMenuProfiles); + g_menu_append_section (menu, NULL, G_MENU_MODEL (section)); + g_object_unref (section); #endif section = g_menu_new (); menu_item = g_menu_item_new (_("Display settingsā€¦"), "indicator.settings"); @@ -547,6 +708,11 @@ private: guint nCallback = 0; gdouble fLastBrightness = 0.0; guint nLasColorTemp = 0; + gchar *sLastTheme = NULL; + const gchar *sLastColorScheme = "default"; + GSettings *pThemeSettings = NULL; + GSettings *pColorSchemeSettings = NULL; + gboolean bTest; #endif }; -- cgit v1.2.3 From 5945143a01deece150425567a8a49a7c8f694001 Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Thu, 6 Jul 2023 09:38:02 +0200 Subject: src/exporter.cpp: Drop unused variable --- src/exporter.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/exporter.cpp b/src/exporter.cpp index 5609ca8..c75eb5b 100644 --- a/src/exporter.cpp +++ b/src/exporter.cpp @@ -1,6 +1,6 @@ /* * Copyright 2014 Canonical Ltd. - * Copyright 2022 Robert Tari + * Copyright 2022-2023 Robert Tari * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published @@ -188,7 +188,6 @@ private: static_cast(gthis)->emit_name_lost(name); } - const std::string m_bus_name; core::Signal m_name_lost; std::shared_ptr m_indicator; std::set m_exported_menu_ids; -- cgit v1.2.3 From 7827339842b045e98727531f8eb760b33596a2d3 Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Thu, 6 Jul 2023 03:02:50 +0200 Subject: CMakeLists.txt: Minor CMake warning fixes --- CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 25c5ff4..f856403 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ -project(ayatana-indicator-display LANGUAGES C CXX) cmake_minimum_required(VERSION 3.13) +project(ayatana-indicator-display VERSION 22.9.4 LANGUAGES C CXX) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) SET(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "..." FORCE) @@ -10,7 +10,6 @@ endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) ## include(GNUInstallDirs) -set(PROJECT_VERSION "22.9.4") set(PACKAGE ${CMAKE_PROJECT_NAME}) set(SERVICE_LIB ${PACKAGE}) set(SERVICE_EXEC "${PACKAGE}-service") -- cgit v1.2.3 From 37b166378e439bd5e7467e512f846cc180c9a518 Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Thu, 6 Jul 2023 03:38:32 +0200 Subject: .build.yml: Add missing dependency --- .build.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.build.yml b/.build.yml index 50f29e1..f65c396 100644 --- a/.build.yml +++ b/.build.yml @@ -15,8 +15,9 @@ requires: - glib2 - systemd - geoclue -# - libayatana-common -# - xsct + - gnome-desktop +# - libayatana-common (AUR) +# - xsct (AUR) debian: # Useful URL: https://salsa.debian.org/debian-ayatana-team/ayatana-indicator-display @@ -47,6 +48,7 @@ requires: - gcovr - systemd - libgeoclue-2-dev + - gsettings-desktop-schemas # For xsct - libx11-dev - libxrandr-dev @@ -79,6 +81,7 @@ requires: - systemd - gsettings-ubuntu-schemas - libgeoclue-2-dev + - gsettings-desktop-schemas # For xsct - libx11-dev - libxrandr-dev @@ -111,6 +114,7 @@ requires: - systemd - gsettings-ubuntu-schemas - libgeoclue-2-dev + - gsettings-desktop-schemas # For xsct - libx11-dev - libxrandr-dev -- cgit v1.2.3