From f58200760a812e50bbec90a6b55d0812ec9e2048 Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Mon, 7 Nov 2022 23:06:19 +0100 Subject: Add colour temperature changing functionality --- data/org.ayatana.indicator.display.gschema.xml | 6 ++ src/rotation-lock.cpp | 107 ++++++++++++++++++++++++- 2 files changed, 112 insertions(+), 1 deletion(-) diff --git a/data/org.ayatana.indicator.display.gschema.xml b/data/org.ayatana.indicator.display.gschema.xml index 9afa253..f9a04c8 100644 --- a/data/org.ayatana.indicator.display.gschema.xml +++ b/data/org.ayatana.indicator.display.gschema.xml @@ -20,5 +20,11 @@ Orientation lock Locks orientation to a specific value. + + + 6500 + Color temperature + Sets the color temperature of your screen. The lower the value, the higher the intensity of the redness effect applied to the display. + diff --git a/src/rotation-lock.cpp b/src/rotation-lock.cpp index 0da971f..2bb03b3 100644 --- a/src/rotation-lock.cpp +++ b/src/rotation-lock.cpp @@ -20,7 +20,7 @@ */ #include - +#include #include extern "C" @@ -94,10 +94,14 @@ public: std::shared_ptr desktop_menu (create_desktop_menu(), menu_model_deleter); m_desktop = std::make_shared("desktop", desktop_menu); update_desktop_header(); + + g_unix_signal_add (SIGINT, onSigInt, m_settings); + onColorTemp (m_settings, "color-temp", NULL); } ~Impl() { + onColorTemp (m_settings, "color-temp", GUINT_TO_POINTER (6500)); g_signal_handlers_disconnect_by_data(m_settings, this); g_clear_object(&m_action_group); g_clear_object(&m_settings); @@ -118,6 +122,13 @@ public: private: + static gboolean onSigInt (gpointer pData) + { + onColorTemp (G_SETTINGS (pData), "color-temp", GUINT_TO_POINTER (6500)); + + return G_SOURCE_REMOVE; + } + /*** **** Actions ***/ @@ -137,6 +148,27 @@ private: return g_value_dup_variant(value); } + static gboolean settingsToActionStateDouble (GValue *pValue, GVariant *pVariant, gpointer pData) + { + gdouble fVariant = (gdouble) g_variant_get_uint16 (pVariant); + GVariant *pVariantDouble = g_variant_new_double (fVariant); + g_value_set_variant (pValue, pVariantDouble); + + return TRUE; + } + + static GVariant* actionStateToSettingsInt (const GValue *pValue, const GVariantType *pVariantType, gpointer pData) + { + GVariant *pVariantDouble = g_value_get_variant (pValue); + guint16 nValue = (guint16) g_variant_get_double (pVariantDouble); + GVariant *pVariantInt = g_variant_new_uint16 (nValue); + GValue cValue = G_VALUE_INIT; + g_value_init (&cValue, G_TYPE_VARIANT); + g_value_set_variant (&cValue, pVariantInt); + + return g_value_dup_variant (&cValue); + } + GSimpleActionGroup* create_action_group() { GSimpleActionGroup* group; @@ -161,6 +193,20 @@ private: g_signal_connect_swapped(m_settings, "changed::rotation-lock", G_CALLBACK(on_rotation_lock_setting_changed), this); + pVariantType = g_variant_type_new ("d"); + action = g_simple_action_new_stateful ("color-temp", pVariantType, g_variant_new_double (0)); + g_variant_type_free (pVariantType); + g_settings_bind_with_mapping (m_settings, "color-temp", action, "state", G_SETTINGS_BIND_DEFAULT, settingsToActionStateDouble, actionStateToSettingsInt, 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", G_CALLBACK (onColorTemp), NULL); + + pVariantType = g_variant_type_new ("s"); + action = g_simple_action_new_stateful ("profile", pVariantType, g_variant_new_string("1")); + g_variant_type_free (pVariantType); + g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(action)); + g_object_unref(G_OBJECT(action)); + action = g_simple_action_new ("settings", NULL); g_action_map_add_action (G_ACTION_MAP (group), G_ACTION (action)); g_object_unref (G_OBJECT (action)); @@ -196,6 +242,33 @@ private: return G_MENU_MODEL(menu); } + static void onColorTemp (GSettings *pSettings, const gchar *sKey, gpointer pData) + { + guint16 nTemp = 0; + + if (pData) + { + nTemp = GPOINTER_TO_UINT (pData); + } + else + { + GVariant *pTemp = g_settings_get_value (pSettings, sKey); + nTemp = g_variant_get_uint16 (pTemp); + } + + GError *pError = NULL; + gchar *sCommand = g_strdup_printf ("xsct %u", nTemp); + 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); + } + + g_free (sCommand); + } + static void onSettings (GSimpleAction *pAction, GVariant *pVariant, gpointer pData) { if (ayatana_common_utils_is_mate ()) @@ -229,6 +302,38 @@ private: if (ayatana_common_utils_is_lomiri() == FALSE) { + section = g_menu_new (); + GIcon *pIconMin = g_themed_icon_new_with_default_fallbacks ("ayatana-indicator-display-colortemp-on"); + GIcon *pIconMax = g_themed_icon_new_with_default_fallbacks ("ayatana-indicator-display-colortemp-off"); + GVariant *pIconMinSerialised = g_icon_serialize (pIconMin); + GVariant *pIconMaxSerialised = g_icon_serialize (pIconMax); + menu_item = g_menu_item_new (_("Color temperature"), "indicator.color-temp"); + g_menu_item_set_attribute (menu_item, "x-ayatana-type", "s", "org.ayatana.indicator.slider"); + g_menu_item_set_attribute (menu_item, "x-ayatana-type", "s", "org.ayatana.indicator.slider"); + g_menu_item_set_attribute_value (menu_item, "min-icon", pIconMinSerialised); + g_menu_item_set_attribute_value (menu_item, "max-icon", pIconMaxSerialised); + g_menu_item_set_attribute (menu_item, "min-value", "d", 3500.0); + g_menu_item_set_attribute (menu_item, "max-value", "d", 6500.0); + g_menu_item_set_attribute (menu_item, "step", "d", 100.0); + g_menu_append_item (section, menu_item); + + GMenu *pMenuProfiles = g_menu_new (); + GMenuItem *pItemProfile1 = g_menu_item_new (_("Manual"), "indicator.profile::1"); + GMenuItem *pItemProfiles = g_menu_item_new_submenu (_("Color temperature profiles"), G_MENU_MODEL (pMenuProfiles)); + g_menu_append_item (pMenuProfiles, pItemProfile1); + g_object_unref (pItemProfile1); + 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 (pIconMin); + g_object_unref (pIconMax); + g_variant_unref (pIconMinSerialised); + g_variant_unref (pIconMaxSerialised); + g_object_unref (section); + g_object_unref (menu_item); + section = g_menu_new (); menu_item = g_menu_item_new (_("Display settingsā€¦"), "indicator.settings"); g_menu_append_item (section, menu_item); -- cgit v1.2.3 From 67565343c59f1d43d7735a3b0621e9102c172288 Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Mon, 7 Nov 2022 23:08:23 +0100 Subject: Provide icons for the colour temperature slider --- data/CMakeLists.txt | 6 + .../ayatana-indicator-display-colortemp-off.svg | 1879 ++++++++++++++++++++ .../ayatana-indicator-display-colortemp-on.svg | 1687 ++++++++++++++++++ 3 files changed, 3572 insertions(+) create mode 100644 data/icons/ayatana-indicator-display-colortemp-off.svg create mode 100644 data/icons/ayatana-indicator-display-colortemp-on.svg diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt index b7a68dc..1159064 100644 --- a/data/CMakeLists.txt +++ b/data/CMakeLists.txt @@ -56,3 +56,9 @@ set (AYATANA_INDICATOR_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${AYATANA_INDICATOR_NAM install (FILES "${AYATANA_INDICATOR_FILE}" DESTINATION "${AYATANA_INDICATOR_DIR}") + + +# ayatana-indicator-display-colortemp-off.svg +# ayatana-indicator-display-colortemp-on.svg + +install (DIRECTORY "icons/" DESTINATION "${CMAKE_INSTALL_FULL_DATADIR}/icons/hicolor/scalable/status" FILES_MATCHING PATTERN "*.svg") diff --git a/data/icons/ayatana-indicator-display-colortemp-off.svg b/data/icons/ayatana-indicator-display-colortemp-off.svg new file mode 100644 index 0000000..0a376b3 --- /dev/null +++ b/data/icons/ayatana-indicator-display-colortemp-off.svg @@ -0,0 +1,1879 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/icons/ayatana-indicator-display-colortemp-on.svg b/data/icons/ayatana-indicator-display-colortemp-on.svg new file mode 100644 index 0000000..277d6d3 --- /dev/null +++ b/data/icons/ayatana-indicator-display-colortemp-on.svg @@ -0,0 +1,1687 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3 From f3d919bd0c3327043d6db0a5ae6f4716cd5959fc Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Mon, 7 Nov 2022 23:10:34 +0100 Subject: debian/control: Add xsct as a dependency --- debian/control | 1 + 1 file changed, 1 insertion(+) diff --git a/debian/control b/debian/control index 6662291..22740ac 100644 --- a/debian/control +++ b/debian/control @@ -38,6 +38,7 @@ Depends: ${shlibs:Depends}, ${misc:Depends}, ayatana-indicator-common, libglib2.0-bin, + xsct, Description: Ayatana Indicator for Display configuration This Ayatana Indicator is designed to be placed on the right side of a panel and give the user easy control for changing their display settings. -- cgit v1.2.3 From 353d95c678bfa97088a75f48291744c56e8a1efd Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Mon, 7 Nov 2022 23:46:04 +0100 Subject: .build.yml: Build xsct from source --- .build.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.build.yml b/.build.yml index 46aead6..70aaf78 100644 --- a/.build.yml +++ b/.build.yml @@ -49,6 +49,9 @@ requires: - lcov - gcovr - systemd +# For xsct + - libx11-dev + - libxrandr-dev ubuntu: - clang @@ -77,6 +80,9 @@ requires: - gcovr - systemd - gsettings-ubuntu-schemas +# For xsct + - libx11-dev + - libxrandr-dev ubuntu:focal: - clang @@ -105,6 +111,9 @@ requires: - gcovr - systemd - gsettings-ubuntu-schemas +# For xsct + - libx11-dev + - libxrandr-dev variables: - 'CHECKERS=" @@ -139,6 +148,16 @@ before_scripts: - make install - cd - - rm -Rf libayatana-common-build/ + - + - cd ${START_DIR} + - if [ ! -d xsct-build ]; then + - git clone --depth 1 https://github.com/faf0/sct.git xsct-build + - fi + - cd xsct-build + - make + - make install + - cd - + - rm -Rf xsct-build/ build_scripts: - if [ ${DISTRO_NAME} == "debian" ];then -- cgit v1.2.3