feedback-vibra: Add and track max-haptic-strength gsetting

Signed-off-by: Guido Günther <agx@sigxcpu.org>
This commit is contained in:
Guido Günther
2025-03-09 12:28:08 +01:00
parent 8e4f15758b
commit bb1b5d0e1f
4 changed files with 66 additions and 3 deletions
+10
View File
@@ -41,6 +41,16 @@
setting the 'important' hint on the submitted event. setting the 'important' hint on the submitted event.
</description> </description>
</key> </key>
<key name="max-haptic-strength" type="d">
<range min="0.0" max="1.0"/>
<default>1.0</default>
<summary>Maximum haptic strength</summary>
<description>
The maximum haptic strength to use when providing feedback.
</description>
</key>
</schema> </schema>
<schema id="org.sigxcpu.feedbackd.application"> <schema id="org.sigxcpu.feedbackd.application">
+2
View File
@@ -54,6 +54,8 @@ These gsettings are used by ``feedbackd``:
- `prefer-flash`: Prefer camera flash over status LED - `prefer-flash`: Prefer camera flash over status LED
- `theme`: The feedback theme to use. This can be used to override - `theme`: The feedback theme to use. This can be used to override
the feedback theme picked by feedbackd based on device information. the feedback theme picked by feedbackd based on device information.
- `max-haptic-strength`: Limits th maximum strenght used for the
haptic motor `[0.0, 1.0]`.
- `org.sigxcpu.feedbackd.application` - `org.sigxcpu.feedbackd.application`
+2 -1
View File
@@ -9,6 +9,7 @@
G_BEGIN_DECLS G_BEGIN_DECLS
void fbd_feedback_vibra_set_duration (FbdFeedbackVibra *self, guint duration); void fbd_feedback_vibra_set_duration (FbdFeedbackVibra *self, guint duration);
double fbd_feedback_vibra_get_max_strength (FbdFeedbackVibra *self);
G_END_DECLS G_END_DECLS
+52 -2
View File
@@ -6,6 +6,7 @@
#define G_LOG_DOMAIN "fbd-feedback-vibra" #define G_LOG_DOMAIN "fbd-feedback-vibra"
#include "fbd.h"
#include "fbd-enums.h" #include "fbd-enums.h"
#include "fbd-feedback-vibra.h" #include "fbd-feedback-vibra.h"
#include "fbd-feedback-vibra-priv.h" #include "fbd-feedback-vibra-priv.h"
@@ -29,13 +30,26 @@ enum {
static GParamSpec *props[PROP_LAST_PROP]; static GParamSpec *props[PROP_LAST_PROP];
typedef struct _FbdFeedbackVibraPrivate { typedef struct _FbdFeedbackVibraPrivate {
guint duration; guint duration;
guint timer_id; guint timer_id;
double max_strength;
GSettings *settings;
} FbdFeedbackVibraPrivate; } FbdFeedbackVibraPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (FbdFeedbackVibra, fbd_feedback_vibra, FBD_TYPE_FEEDBACK_BASE); G_DEFINE_TYPE_WITH_PRIVATE (FbdFeedbackVibra, fbd_feedback_vibra, FBD_TYPE_FEEDBACK_BASE);
static void
on_max_haptic_strength_changed (FbdFeedbackVibra *self)
{
FbdFeedbackVibraPrivate *priv = fbd_feedback_vibra_get_instance_private (self);
priv->max_strength = g_settings_get_double (priv->settings, "max-haptic-strength");
g_debug ("Max haptic strength: %f", priv->max_strength);
}
static void static void
on_timeout_expired (FbdFeedbackVibra *self) on_timeout_expired (FbdFeedbackVibra *self)
{ {
@@ -122,12 +136,26 @@ fbd_feedback_vibra_get_property (GObject *object,
} }
} }
static void
fbd_feedback_vibra_finalize (GObject *object)
{
FbdFeedbackVibra *self = FBD_FEEDBACK_VIBRA (object);
FbdFeedbackVibraPrivate *priv = fbd_feedback_vibra_get_instance_private (self);
g_clear_object (&priv->settings);
G_OBJECT_CLASS (fbd_feedback_vibra_parent_class)->finalize (object);
}
static void static void
fbd_feedback_vibra_class_init (FbdFeedbackVibraClass *klass) fbd_feedback_vibra_class_init (FbdFeedbackVibraClass *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
FbdFeedbackBaseClass *base_class = FBD_FEEDBACK_BASE_CLASS (klass); FbdFeedbackBaseClass *base_class = FBD_FEEDBACK_BASE_CLASS (klass);
object_class->finalize = fbd_feedback_vibra_finalize;
object_class->set_property = fbd_feedback_vibra_set_property; object_class->set_property = fbd_feedback_vibra_set_property;
object_class->get_property = fbd_feedback_vibra_get_property; object_class->get_property = fbd_feedback_vibra_get_property;
@@ -151,6 +179,15 @@ fbd_feedback_vibra_class_init (FbdFeedbackVibraClass *klass)
static void static void
fbd_feedback_vibra_init (FbdFeedbackVibra *self) fbd_feedback_vibra_init (FbdFeedbackVibra *self)
{ {
FbdFeedbackVibraPrivate *priv = fbd_feedback_vibra_get_instance_private (self);
priv->settings = g_settings_new (FEEDBACKD_SCHEMA_ID);
g_signal_connect_object (priv->settings,
"changed::max-haptic-strength",
G_CALLBACK (on_max_haptic_strength_changed),
self,
G_CONNECT_SWAPPED);
on_max_haptic_strength_changed (self);
} }
guint guint
@@ -179,3 +216,16 @@ fbd_feedback_vibra_set_duration (FbdFeedbackVibra *self, guint duration)
priv->duration = duration; priv->duration = duration;
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_DURATION]); g_object_notify_by_pspec (G_OBJECT (self), props[PROP_DURATION]);
} }
double
fbd_feedback_vibra_get_max_strength (FbdFeedbackVibra *self)
{
FbdFeedbackVibraPrivate *priv;
g_return_val_if_fail (FBD_IS_FEEDBACK_VIBRA (self), 1.0);
priv = fbd_feedback_vibra_get_instance_private (self);
return priv->max_strength;
}