diff options
author | Bardia Moshiri <bardia@furilabs.com> | 2025-03-08 17:08:24 -0500 |
---|---|---|
committer | Bardia Moshiri <bardia@furilabs.com> | 2025-03-08 17:16:42 -0500 |
commit | aefad6d79104a14ef06b303f92feda226ee9b9ba (patch) | |
tree | dfc47c99875f47615bacdf035e014ef2fb7166b6 /src | |
parent | 0e19a6c6cc9ae3078d8bb683b4fdc97cc01ddab4 (diff) | |
download | ayatana-indicator-power-aefad6d79104a14ef06b303f92feda226ee9b9ba.tar.gz ayatana-indicator-power-aefad6d79104a14ef06b303f92feda226ee9b9ba.tar.bz2 ayatana-indicator-power-aefad6d79104a14ef06b303f92feda226ee9b9ba.zip |
flashlight: allow to get simple flashlight enable and disable values from deviceinfo
the value for enable/disable for simple sysfs might not always be 0 or 1. one example is the FLX1 phone.
allow to override using deviceinfo and fallback to SIMPLE_ENABLE and SIMPLE_DISABLE if built without deviceinfo or no value is provided
Signed-off-by: Bardia Moshiri <bardia@furilabs.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/deviceinfo-flashlight.c | 12 | ||||
-rw-r--r-- | src/flashlight.c | 20 |
2 files changed, 32 insertions, 0 deletions
diff --git a/src/deviceinfo-flashlight.c b/src/deviceinfo-flashlight.c index 1bbf14d..91e9f02 100644 --- a/src/deviceinfo-flashlight.c +++ b/src/deviceinfo-flashlight.c @@ -30,3 +30,15 @@ char* flashlight_switch_path() struct DeviceInfo* di = deviceinfo_new(); return deviceinfo_get(di, "FlashlightSwitchPath", ""); } + +char* flashlight_simple_enable_value() +{ + struct DeviceInfo* di = deviceinfo_new(); + return deviceinfo_get(di, "FlashlightSimpleEnableValue", ""); +} + +char* flashlight_simple_disable_value() +{ + struct DeviceInfo* di = deviceinfo_new(); + return deviceinfo_get(di, "FlashlightSimpleDisableValue", ""); +} diff --git a/src/flashlight.c b/src/flashlight.c index 88e93fd..337c01c 100644 --- a/src/flashlight.c +++ b/src/flashlight.c @@ -34,6 +34,8 @@ #ifdef ENABLE_LIBDEVICEINFO extern char* flashlight_path(); extern char* flashlight_switch_path(); +extern char* flashlight_simple_enable_value(); +extern char* flashlight_simple_disable_value(); #endif const size_t qcom_sysfs_size = 7; @@ -141,7 +143,25 @@ toggle_flashlight_action_simple() fd = fopen(flash_sysfs_path, "w"); if (fd != NULL) { +# ifdef ENABLE_LIBDEVICEINFO + char* enable_value = flashlight_simple_enable_value(); + char* disable_value = flashlight_simple_disable_value(); + + const char* value_to_write; + if (activated) + value_to_write = (strcmp(disable_value, "") != 0) ? disable_value : SIMPLE_DISABLE; + else + value_to_write = (strcmp(enable_value, "") != 0) ? enable_value : SIMPLE_ENABLE; + + fprintf(fd, "%s", value_to_write); + + if (enable_value) + free(enable_value); + if (disable_value) + free(disable_value); +# else fprintf(fd, activated ? SIMPLE_DISABLE : SIMPLE_ENABLE); +# endif fclose(fd); return 1; } |