235 lines
7.9 KiB
Diff
235 lines
7.9 KiB
Diff
diff -Npur phosh.orig/src/flashlightinfo.c phosh/src/flashlightinfo.c
|
|
--- phosh.orig/src/flashlightinfo.c 1970-01-01 01:00:00.000000000 +0100
|
|
+++ phosh/src/flashlightinfo.c 2020-10-18 18:07:27.590688070 +0200
|
|
@@ -0,0 +1,86 @@
|
|
+/*
|
|
+ * Author: clover <m.alexanderrobinson@yahoo.com>
|
|
+ */
|
|
+
|
|
+#define G_LOG_DOMAIN "phosh-flashlightinfo"
|
|
+
|
|
+#include "config.h"
|
|
+
|
|
+#include "flashlightinfo.h"
|
|
+#include "shell.h"
|
|
+#include <fcntl.h>
|
|
+
|
|
+#define FLASH_SYSFS_PATH "/sys/devices/platform/led-controller/leds/white:flash/brightness"
|
|
+
|
|
+/**
|
|
+ * SECTION:flashlightinfo
|
|
+ * @short_description: A widget to display the flashlight status
|
|
+ * @Title: PhoshFlashlightInfo
|
|
+ *
|
|
+ * Flashlight Info widget
|
|
+ */
|
|
+
|
|
+ typedef struct _PhoshFlashlightInfo {
|
|
+ PhoshStatusIcon parent;
|
|
+} PhoshFlashlightInfo;
|
|
+
|
|
+int flashlight_status;
|
|
+G_DEFINE_TYPE (PhoshFlashlightInfo, phosh_flashlight_info, PHOSH_TYPE_STATUS_ICON)
|
|
+
|
|
+static void
|
|
+toggle_flashlight(int status)
|
|
+{
|
|
+ int fd = open(FLASH_SYSFS_PATH, O_WRONLY);
|
|
+ if (fd < 0)
|
|
+ {
|
|
+ // Unable to open file
|
|
+ return;
|
|
+ }
|
|
+ write(fd, status ? "1" : "0", 1);
|
|
+}
|
|
+
|
|
+void
|
|
+set_flashlight_status(int new_status)
|
|
+{
|
|
+ toggle_flashlight(new_status);
|
|
+ flashlight_status = new_status;
|
|
+}
|
|
+
|
|
+int
|
|
+get_flashlight_status(void)
|
|
+{
|
|
+ return flashlight_status;
|
|
+}
|
|
+
|
|
+
|
|
+static void
|
|
+phosh_flashlight_info_finalize (GObject *object)
|
|
+{
|
|
+ PhoshFlashlightInfo *self = PHOSH_FLASHLIGHT_INFO(object);
|
|
+
|
|
+ // possibly can remove
|
|
+ g_signal_handlers_disconnect_by_data (phosh_shell_get_default (), self);
|
|
+
|
|
+ G_OBJECT_CLASS (phosh_flashlight_info_parent_class)->finalize (object);
|
|
+}
|
|
+
|
|
+static void
|
|
+phosh_flashlight_info_class_init (PhoshFlashlightInfoClass *klass)
|
|
+{
|
|
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
+ object_class->finalize = phosh_flashlight_info_finalize;
|
|
+}
|
|
+
|
|
+static void
|
|
+phosh_flashlight_info_init (PhoshFlashlightInfo *self)
|
|
+{
|
|
+ phosh_status_icon_set_icon_name (PHOSH_STATUS_ICON (self), "torch-disabled-symbolic");
|
|
+ phosh_status_icon_set_info (PHOSH_STATUS_ICON (self), "Off");
|
|
+ set_flashlight_status(0);
|
|
+}
|
|
+
|
|
+GtkWidget *
|
|
+phosh_flashlight_info_new (void)
|
|
+{
|
|
+ return g_object_new (PHOSH_TYPE_FLASHLIGHT_INFO, NULL);
|
|
+}
|
|
\ No newline at end of file
|
|
diff -Npur phosh.orig/src/flashlightinfo.h phosh/src/flashlightinfo.h
|
|
--- phosh.orig/src/flashlightinfo.h 1970-01-01 01:00:00.000000000 +0100
|
|
+++ phosh/src/flashlightinfo.h 2020-10-18 18:07:12.934021548 +0200
|
|
@@ -0,0 +1,20 @@
|
|
+/*
|
|
+ *
|
|
+ * SPDX-License-Identifier: GPL-3.0+
|
|
+ */
|
|
+#pragma once
|
|
+
|
|
+#include <gtk/gtk.h>
|
|
+#include "status-icon.h"
|
|
+
|
|
+G_BEGIN_DECLS
|
|
+
|
|
+#define PHOSH_TYPE_FLASHLIGHT_INFO (phosh_flashlight_info_get_type())
|
|
+
|
|
+G_DECLARE_FINAL_TYPE (PhoshFlashlightInfo, phosh_flashlight_info, PHOSH, FLASHLIGHT_INFO, PhoshStatusIcon)
|
|
+
|
|
+GtkWidget * phosh_flashlight_info_new (void);
|
|
+void set_flashlight_status (int);
|
|
+int get_flashlight_status (void);
|
|
+
|
|
+G_END_DECLS
|
|
\ No newline at end of file
|
|
diff -Npur phosh.orig/src/meson.build phosh/src/meson.build
|
|
--- phosh.orig/src/meson.build 2020-10-18 18:06:42.687355000 +0200
|
|
+++ phosh/src/meson.build 2020-10-18 18:07:18.194021496 +0200
|
|
@@ -126,6 +126,8 @@ libphosh_sources = [
|
|
'proximity.c',
|
|
'sensor-proxy-manager.c',
|
|
'sensor-proxy-manager.h',
|
|
+ 'flashlightinfo.c',
|
|
+ 'flashlightinfo.h',
|
|
'rotateinfo.c',
|
|
'rotateinfo.h',
|
|
'screen-saver-manager.c',
|
|
diff -Npur phosh.orig/src/settings.c phosh/src/settings.c
|
|
--- phosh.orig/src/settings.c 2020-10-18 18:06:42.690688000 +0200
|
|
+++ phosh/src/settings.c 2020-10-18 18:07:23.400688118 +0200
|
|
@@ -23,10 +23,12 @@
|
|
#include "rotateinfo.h"
|
|
#include "feedbackinfo.h"
|
|
#include "feedback-manager.h"
|
|
+#include "flashlightinfo.h"
|
|
#include "notifications/notify-manager.h"
|
|
#include "notifications/notification-frame.h"
|
|
#include "media-player.h"
|
|
#include "keyboard-events.h"
|
|
+#include <stdbool.h>
|
|
|
|
#include <pulse/pulseaudio.h>
|
|
#include "gvc-mixer-control.h"
|
|
@@ -72,6 +74,9 @@ typedef struct _PhoshSettings
|
|
GtkWidget *list_notifications;
|
|
GtkWidget *sw_notifications;
|
|
LfbEvent *notify_event;
|
|
+
|
|
+ /* Flashlight */
|
|
+ GtkWidget *flashlightinfo;
|
|
} PhoshSettings;
|
|
|
|
|
|
@@ -123,6 +128,26 @@ feedback_setting_clicked_cb (PhoshSettin
|
|
}
|
|
|
|
static void
|
|
+flashlight_setting_clicked_cb (PhoshSettings *self)
|
|
+{
|
|
+ bool currently_on = get_flashlight_status() == 1;
|
|
+ bool currently_off = get_flashlight_status() == 0;
|
|
+
|
|
+ if (currently_on)
|
|
+ {
|
|
+ phosh_status_icon_set_icon_name(PHOSH_STATUS_ICON (self->flashlightinfo), "torch-disabled-symbolic");
|
|
+ phosh_status_icon_set_info (PHOSH_STATUS_ICON (self->flashlightinfo), "Off");
|
|
+ set_flashlight_status(0);
|
|
+ }
|
|
+ if (currently_off)
|
|
+ {
|
|
+ phosh_status_icon_set_icon_name(PHOSH_STATUS_ICON (self->flashlightinfo), "torch-enabled-symbolic");
|
|
+ phosh_status_icon_set_info (PHOSH_STATUS_ICON (self->flashlightinfo), "On");
|
|
+ set_flashlight_status(1);
|
|
+ }
|
|
+}
|
|
+
|
|
+static void
|
|
wifi_setting_clicked_cb (PhoshSettings *self)
|
|
{
|
|
phosh_quick_setting_open_settings_panel ("wifi");
|
|
@@ -499,7 +524,6 @@ phosh_settings_finalize (GObject *object
|
|
}
|
|
|
|
|
|
-
|
|
static void
|
|
phosh_settings_class_init (PhoshSettingsClass *klass)
|
|
{
|
|
@@ -520,6 +544,7 @@ phosh_settings_class_init (PhoshSettings
|
|
g_type_ensure (PHOSH_TYPE_BT_INFO);
|
|
g_type_ensure (PHOSH_TYPE_DOCKED_INFO);
|
|
g_type_ensure (PHOSH_TYPE_FEEDBACK_INFO);
|
|
+ g_type_ensure (PHOSH_TYPE_FLASHLIGHT_INFO);
|
|
g_type_ensure (PHOSH_TYPE_MEDIA_PLAYER);
|
|
g_type_ensure (PHOSH_TYPE_QUICK_SETTING);
|
|
g_type_ensure (PHOSH_TYPE_ROTATE_INFO);
|
|
@@ -530,6 +555,7 @@ phosh_settings_class_init (PhoshSettings
|
|
gtk_widget_class_bind_template_child (widget_class, PhoshSettings, quick_settings);
|
|
gtk_widget_class_bind_template_child (widget_class, PhoshSettings, scale_brightness);
|
|
gtk_widget_class_bind_template_child (widget_class, PhoshSettings, sw_notifications);
|
|
+ gtk_widget_class_bind_template_child (widget_class, PhoshSettings, flashlightinfo);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, battery_setting_clicked_cb);
|
|
gtk_widget_class_bind_template_callback (widget_class, bt_setting_clicked_cb);
|
|
@@ -538,6 +564,7 @@ phosh_settings_class_init (PhoshSettings
|
|
gtk_widget_class_bind_template_callback (widget_class, feedback_setting_long_pressed_cb);
|
|
gtk_widget_class_bind_template_callback (widget_class, on_media_player_raised);
|
|
gtk_widget_class_bind_template_callback (widget_class, rotation_setting_clicked_cb);
|
|
+ gtk_widget_class_bind_template_callback (widget_class, flashlight_setting_clicked_cb);
|
|
gtk_widget_class_bind_template_callback (widget_class, torch_setting_clicked_cb);
|
|
gtk_widget_class_bind_template_callback (widget_class, wifi_setting_clicked_cb);
|
|
gtk_widget_class_bind_template_callback (widget_class, wwan_setting_clicked_cb);
|
|
diff -Npur phosh.orig/src/ui/settings-menu.ui phosh/src/ui/settings-menu.ui
|
|
--- phosh.orig/src/ui/settings-menu.ui 2020-10-18 18:06:42.700688000 +0200
|
|
+++ phosh/src/ui/settings-menu.ui 2020-10-18 18:07:23.400688118 +0200
|
|
@@ -120,13 +120,13 @@
|
|
</object>
|
|
</child>
|
|
<child>
|
|
- <object class="PhoshQuickSetting" id="torch_quick_setting">
|
|
+ <object class="PhoshQuickSetting">
|
|
<property name="visible">True</property>
|
|
- <property name="sensitive" bind-source="torchinfo" bind-property="present" bind-flags="sync-create"/>
|
|
<property name="can_focus">False</property>
|
|
- <signal name="clicked" handler="torch_setting_clicked_cb" object="PhoshSettings" swapped="yes"/>
|
|
+ <signal name="clicked" handler="flashlight_setting_clicked_cb" object="PhoshSettings" swapped="yes"/>
|
|
+
|
|
<child>
|
|
- <object class="PhoshTorchInfo" id="torchinfo">
|
|
+ <object class="PhoshFlashlightInfo" id="flashlightinfo">
|
|
<property name="visible">True</property>
|
|
<property name="can_focus">False</property>
|
|
<property name="icon-size">GTK_ICON_SIZE_LARGE_TOOLBAR</property>
|