diff options
author | Florian Leeber <florian@ubports.com> | 2020-07-15 18:14:26 +0200 |
---|---|---|
committer | Mike Gabriel <mike.gabriel@das-netzwerkteam.de> | 2020-08-06 16:00:24 +0200 |
commit | 4aaddc4dedd026b55cb8d7f02409b481915ea472 (patch) | |
tree | 67f16103a7cf4c9ad81e06ef46f6130e85f1bf84 /src | |
parent | 215c6ddc8712a798ae6df8a54900d81a76c5ca56 (diff) | |
download | ayatana-indicator-power-4aaddc4dedd026b55cb8d7f02409b481915ea472.tar.gz ayatana-indicator-power-4aaddc4dedd026b55cb8d7f02409b481915ea472.tar.bz2 ayatana-indicator-power-4aaddc4dedd026b55cb8d7f02409b481915ea472.zip |
Try to detect if flash needs to be enabled (latched) separately
Diffstat (limited to 'src')
-rw-r--r-- | src/flashlight.c | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/src/flashlight.c b/src/flashlight.c index a5d7f97..55a108a 100644 --- a/src/flashlight.c +++ b/src/flashlight.c @@ -34,6 +34,8 @@ const char* const qcom_sysfs[] = {"/sys/class/leds/torch-light/brightness", "/sys/class/leds/torch-light0/brightness", "/sys/class/leds/torch-light1/brightness"}; +const char* qcom_torch_enable = "/sys/class/leds/led:switch/brightness"; + char* flash_sysfs_path = NULL; gboolean activated = 0; @@ -61,7 +63,9 @@ toggle_flashlight_action(GAction *action, gpointer data G_GNUC_UNUSED) { GVariant *state; - FILE* fd; + FILE *fd1 = NULL, *fd2 = NULL; + + int needs_enable; if (!set_sysfs_path()) return; @@ -69,14 +73,25 @@ toggle_flashlight_action(GAction *action, state = g_action_get_state(action); activated = g_variant_get_boolean(state); g_variant_unref(state); - fd = fopen(flash_sysfs_path, "w"); - if (fd != NULL){ - if (activated) - fprintf(fd, QCOM_DISABLE); + fd1 = fopen(flash_sysfs_path, "w"); + if (fd1 != NULL) { + needs_enable = access(qcom_torch_enable, F_OK ) != -1; + if (needs_enable) + fd2 = fopen(qcom_torch_enable, "w"); + if (activated) + if (needs_enable && fd2 != NULL) + fprintf(fd2, "0"); else - fprintf(fd, QCOM_ENABLE); - fclose(fd); - g_action_change_state(action, g_variant_new_boolean(!activated)); + fprintf(fd1, QCOM_DISABLE); + else { + fprintf(fd1, QCOM_ENABLE); + if (needs_enable && fd2 != NULL) + fprintf(fd2, "1"); + } + fclose(fd1); + if (fd2 !=NULL) + fclose(fd2); + g_action_change_state(action, g_variant_new_boolean(!activated)); } } |