212 lines
7.7 KiB
Diff
212 lines
7.7 KiB
Diff
From c11bddfedd9d62410cd64720be91b1a3a5096231 Mon Sep 17 00:00:00 2001
|
|
From: =?UTF-8?q?Guido=20G=C3=BCnther?= <agx@sigxcpu.org>
|
|
Date: Tue, 29 Sep 2020 16:30:24 +0200
|
|
Subject: [PATCH] settings: Add torch brightness slider
|
|
MIME-Version: 1.0
|
|
Content-Type: text/plain; charset=UTF-8
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
This adds brightness slider when the torch is enabled.
|
|
|
|
Closes: #386
|
|
|
|
Signed-off-by: Guido Günther <guido.gunther@puri.sm>
|
|
---
|
|
src/settings.c | 65 +++++++++++++++++++++++++++++++++++++++++
|
|
src/ui/settings-menu.ui | 49 +++++++++++++++++++++++++++++++
|
|
2 files changed, 114 insertions(+)
|
|
|
|
diff --git a/src/settings.c b/src/settings.c
|
|
index 5dd823b8..bcfbe6f9 100644
|
|
--- a/src/settings.c
|
|
+++ b/src/settings.c
|
|
@@ -16,6 +16,8 @@
|
|
#include "quick-setting.h"
|
|
#include "settings/brightness.h"
|
|
#include "settings/gvc-channel-bar.h"
|
|
+#include "torch-info.h"
|
|
+#include "torch-manager.h"
|
|
#include "wwan/phosh-wwan-mm.h"
|
|
#include "feedback-manager.h"
|
|
#include "notifications/notify-manager.h"
|
|
@@ -64,6 +66,11 @@ typedef struct _PhoshSettings
|
|
GtkWidget *list_notifications;
|
|
GtkWidget *sw_notifications;
|
|
LfbEvent *notify_event;
|
|
+
|
|
+ /* Torch */
|
|
+ PhoshTorchManager *torch_manager;
|
|
+ GtkWidget *scale_torch;
|
|
+ gboolean setting_torch;
|
|
} PhoshSettings;
|
|
|
|
|
|
@@ -401,6 +408,41 @@ end_notify_feedback (PhoshSettings *self)
|
|
}
|
|
|
|
|
|
+static void
|
|
+on_torch_scale_value_changed (PhoshSettings *self, GtkScale *scale_torch)
|
|
+{
|
|
+ double value;
|
|
+
|
|
+ g_return_if_fail (PHOSH_IS_SETTINGS (self));
|
|
+ g_return_if_fail (PHOSH_IS_TORCH_MANAGER (self->torch_manager));
|
|
+
|
|
+ /* Only react to scale changes when torch is enabled */
|
|
+ if (!phosh_torch_manager_get_enabled (self->torch_manager))
|
|
+ return;
|
|
+
|
|
+ self->setting_torch = TRUE;
|
|
+ value = gtk_range_get_value (GTK_RANGE (self->scale_torch));
|
|
+ g_debug ("Setting torch brightness to %.2f", value);
|
|
+ phosh_torch_manager_set_scaled_brightness (self->torch_manager, value / 100.0);
|
|
+}
|
|
+
|
|
+
|
|
+static void
|
|
+on_torch_brightness_changed (PhoshSettings *self, GParamSpec *pspec, PhoshTorchManager *manager)
|
|
+{
|
|
+ g_return_if_fail (PHOSH_IS_SETTINGS (self));
|
|
+ g_return_if_fail (PHOSH_IS_TORCH_MANAGER (manager));
|
|
+
|
|
+ if (self->setting_torch) {
|
|
+ self->setting_torch = FALSE;
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ gtk_range_set_value (GTK_RANGE (self->scale_torch),
|
|
+ 100.0 * phosh_torch_manager_get_scaled_brightness (self->torch_manager));
|
|
+}
|
|
+
|
|
+
|
|
static void
|
|
on_notifcation_items_changed (PhoshSettings *self,
|
|
guint position,
|
|
@@ -441,6 +483,24 @@ setup_brightness_range (PhoshSettings *self)
|
|
}
|
|
|
|
|
|
+static void
|
|
+setup_torch (PhoshSettings *self)
|
|
+{
|
|
+ PhoshShell *shell = phosh_shell_get_default ();
|
|
+
|
|
+ self->torch_manager = g_object_ref(phosh_shell_get_torch_manager (shell));
|
|
+
|
|
+ gtk_range_set_range (GTK_RANGE (self->scale_torch), 40, 100);
|
|
+ gtk_range_set_value (GTK_RANGE (self->scale_torch),
|
|
+ phosh_torch_manager_get_scaled_brightness (self->torch_manager) * 100.0);
|
|
+ g_signal_connect_object (self->torch_manager,
|
|
+ "notify::brightness",
|
|
+ G_CALLBACK(on_torch_brightness_changed),
|
|
+ self,
|
|
+ G_CONNECT_SWAPPED);
|
|
+}
|
|
+
|
|
+
|
|
static void
|
|
setup_volume_bar (PhoshSettings *self)
|
|
{
|
|
@@ -477,6 +537,7 @@ phosh_settings_constructed (GObject *object)
|
|
|
|
setup_brightness_range (self);
|
|
setup_volume_bar (self);
|
|
+ setup_torch (self);
|
|
|
|
g_signal_connect (self->quick_settings,
|
|
"child-activated",
|
|
@@ -515,6 +576,8 @@ phosh_settings_dispose (GObject *object)
|
|
g_clear_object (&self->notify_event);
|
|
}
|
|
|
|
+ g_clear_object (&self->torch_manager);
|
|
+
|
|
G_OBJECT_CLASS (phosh_settings_parent_class)->dispose (object);
|
|
}
|
|
|
|
@@ -552,6 +615,7 @@ phosh_settings_class_init (PhoshSettingsClass *klass)
|
|
gtk_widget_class_bind_template_child (widget_class, PhoshSettings, list_notifications);
|
|
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, scale_torch);
|
|
gtk_widget_class_bind_template_child (widget_class, PhoshSettings, sw_notifications);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, battery_setting_clicked_cb);
|
|
@@ -568,6 +632,7 @@ phosh_settings_class_init (PhoshSettingsClass *klass)
|
|
gtk_widget_class_bind_template_callback (widget_class, wifi_setting_clicked_cb);
|
|
gtk_widget_class_bind_template_callback (widget_class, wifi_setting_long_pressed_cb);
|
|
gtk_widget_class_bind_template_callback (widget_class, wwan_setting_clicked_cb);
|
|
+ gtk_widget_class_bind_template_callback (widget_class, on_torch_scale_value_changed);
|
|
}
|
|
|
|
|
|
diff --git a/src/ui/settings-menu.ui b/src/ui/settings-menu.ui
|
|
index 38aa0d97..ba549be0 100644
|
|
--- a/src/ui/settings-menu.ui
|
|
+++ b/src/ui/settings-menu.ui
|
|
@@ -200,6 +200,52 @@
|
|
<property name="position">2</property>
|
|
</packing>
|
|
</child>
|
|
+ <child>
|
|
+ <object class="GtkRevealer" id="revealer">
|
|
+ <property name="visible">True</property>
|
|
+ <property name="reveal-child" bind-source="torchinfo" bind-property="enabled" bind-flags="sync-create"/>
|
|
+ <child>
|
|
+ <object class="GtkBox">
|
|
+ <property name="visible">True</property>
|
|
+ <property name="can_focus">False</property>
|
|
+ <property name="margin_bottom">5</property>
|
|
+ <child>
|
|
+ <object class="GtkImage">
|
|
+ <property name="visible">True</property>
|
|
+ <property name="can_focus">False</property>
|
|
+ <property name="margin_right">6</property>
|
|
+ <property name="icon_name">torch-enabled-symbolic</property>
|
|
+ </object>
|
|
+ <packing>
|
|
+ <property name="expand">False</property>
|
|
+ <property name="fill">True</property>
|
|
+ <property name="position">0</property>
|
|
+ </packing>
|
|
+ </child>
|
|
+ <child>
|
|
+ <object class="GtkScale" id="scale_torch">
|
|
+ <property name="visible">True</property>
|
|
+ <property name="can_focus">True</property>
|
|
+ <property name="adjustment">adj_torch</property>
|
|
+ <property name="round_digits">0</property>
|
|
+ <property name="draw_value">False</property>
|
|
+ <signal name="value-changed" handler="on_torch_scale_value_changed" object="PhoshSettings" swapped="yes"/>
|
|
+ </object>
|
|
+ <packing>
|
|
+ <property name="expand">True</property>
|
|
+ <property name="fill">True</property>
|
|
+ <property name="position">1</property>
|
|
+ </packing>
|
|
+ </child>
|
|
+ </object>
|
|
+ </child>
|
|
+ </object>
|
|
+ <packing>
|
|
+ <property name="expand">False</property>
|
|
+ <property name="fill">True</property>
|
|
+ <property name="position">3</property>
|
|
+ </packing>
|
|
+ </child>
|
|
<child>
|
|
<object class="GtkScrolledWindow" id="sw_notifications">
|
|
<property name="visible">False</property>
|
|
@@ -234,4 +280,7 @@
|
|
<class name="phosh-settings-menu"/>
|
|
</style>
|
|
</template>
|
|
+ <object class="GtkAdjustment" id="adj_torch">
|
|
+ <property name="step-increment">1</property>
|
|
+ </object>
|
|
</interface>
|
|
--
|
|
GitLab
|
|
|