diff --git a/data/meson.build b/data/meson.build
index f96f754..a41fdc2 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -22,7 +22,7 @@ dbus_inc = include_directories('.')
install_data(dbus_interfaces, install_dir: ifacedir)
schemas = ['org.sigxcpu.feedbackd.gschema.xml']
-compiled = gnome.compile_schemas(build_by_default: true)
+compiled = gnome.compile_schemas(depend_files: schemas, build_by_default: true)
compile_schemas = find_program('glib-compile-schemas', required: false)
if compile_schemas.found()
diff --git a/data/org.sigxcpu.feedbackd.gschema.xml b/data/org.sigxcpu.feedbackd.gschema.xml
index 732726b..6f6cf16 100644
--- a/data/org.sigxcpu.feedbackd.gschema.xml
+++ b/data/org.sigxcpu.feedbackd.gschema.xml
@@ -41,6 +41,16 @@
setting the 'important' hint on the submitted event.
+
+
+
+ 1.0
+ Maximum haptic strength
+
+ The maximum haptic strength to use when providing feedback.
+
+
+
diff --git a/doc/feedbackd.rst b/doc/feedbackd.rst
index 56ed589..d7713d1 100644
--- a/doc/feedbackd.rst
+++ b/doc/feedbackd.rst
@@ -54,6 +54,8 @@ These gsettings are used by ``feedbackd``:
- `prefer-flash`: Prefer camera flash over status LED
- `theme`: The feedback theme to use. This can be used to override
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`
diff --git a/src/fbd-feedback-vibra-pattern.c b/src/fbd-feedback-vibra-pattern.c
index 4807ede..ff84644 100644
--- a/src/fbd-feedback-vibra-pattern.c
+++ b/src/fbd-feedback-vibra-pattern.c
@@ -199,8 +199,12 @@ do_pattern_step (FbdFeedbackVibraPattern *self)
/* Removing any pending effect */
fbd_dev_vibra_remove_effect (dev);
- if (*magnitude != 0.0)
+ if (*magnitude != 0.0) {
+ double max_strength = fbd_feedback_vibra_get_max_strength (FBD_FEEDBACK_VIBRA (self));
+
+ *magnitude = MIN (*magnitude, max_strength);
fbd_dev_vibra_rumble (dev, *magnitude, *duration, TRUE);
+ }
self->timer_id = g_timeout_add_once (*duration,
on_timer_expired,
diff --git a/src/fbd-feedback-vibra-periodic.c b/src/fbd-feedback-vibra-periodic.c
index 0df6d11..bb7c69f 100644
--- a/src/fbd-feedback-vibra-periodic.c
+++ b/src/fbd-feedback-vibra-periodic.c
@@ -7,6 +7,7 @@
#define G_LOG_DOMAIN "fbd-feedback-vibra-periodic"
#include "fbd-enums.h"
+#include "fbd-feedback-vibra-priv.h"
#include "fbd-feedback-vibra-periodic.h"
#include "fbd-feedback-manager.h"
@@ -20,6 +21,8 @@
* #FbdDevVibra for that.
*/
+#define MAX_MAGNITUDE 0xFFFF
+
enum {
PROP_0,
PROP_MAGNITUDE,
@@ -103,13 +106,18 @@ fbd_feedback_vibra_periodic_start_vibra (FbdFeedbackVibra *vibra)
FbdFeedbackManager *manager = fbd_feedback_manager_get_default ();
FbdDevVibra *dev = fbd_feedback_manager_get_dev_vibra (manager);
guint duration = fbd_feedback_vibra_get_duration (vibra);
+ double max_strength = fbd_feedback_vibra_get_max_strength (FBD_FEEDBACK_VIBRA (self));
+ double fade_in_ratio = (double)self->fade_in_level / self->magnitude;
+ guint max_magnitude, fade_in_level;
g_return_if_fail (FBD_IS_DEV_VIBRA (dev));
- g_debug ("Periodic Vibra: %d %d %d %d",
- duration, self->magnitude, self->fade_in_level, self->fade_in_time);
+ max_magnitude = MIN (MAX_MAGNITUDE * max_strength, self->magnitude);
+ fade_in_level = MIN (max_magnitude * fade_in_ratio, self->fade_in_level);
- fbd_dev_vibra_periodic (dev, duration, self->magnitude, self->fade_in_level,
- self->fade_in_time);
+ g_debug ("Periodic Vibra: %d %d %d %d",
+ duration, max_magnitude, fade_in_level, self->fade_in_time);
+
+ fbd_dev_vibra_periodic (dev, duration, max_magnitude, fade_in_level, self->fade_in_time);
}
static gboolean
@@ -141,7 +149,7 @@ fbd_feedback_vibra_periodic_class_init (FbdFeedbackVibraPeriodicClass *klass)
"magnitude",
"Magnitude",
"total magnitude",
- 0, 0xFFFF, 0x7FFF,
+ 0, MAX_MAGNITUDE, 0x7FFF,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
props[PROP_FADE_IN_TIME] =
@@ -157,7 +165,7 @@ fbd_feedback_vibra_periodic_class_init (FbdFeedbackVibraPeriodicClass *klass)
"fade-in-level",
"Fade in level",
"Fade in start level",
- 0, 0xFFFF, 0x7FFF,
+ 0, MAX_MAGNITUDE, 0x7FFF,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
diff --git a/src/fbd-feedback-vibra-priv.h b/src/fbd-feedback-vibra-priv.h
index 445bf3d..2d71036 100644
--- a/src/fbd-feedback-vibra-priv.h
+++ b/src/fbd-feedback-vibra-priv.h
@@ -9,6 +9,7 @@
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
diff --git a/src/fbd-feedback-vibra-rumble.c b/src/fbd-feedback-vibra-rumble.c
index e81b097..a35da03 100644
--- a/src/fbd-feedback-vibra-rumble.c
+++ b/src/fbd-feedback-vibra-rumble.c
@@ -7,6 +7,7 @@
#define G_LOG_DOMAIN "fbd-feedback-vibra-rumble"
#include "fbd-enums.h"
+#include "fbd-feedback-vibra-priv.h"
#include "fbd-feedback-vibra-rumble.h"
#include "fbd-feedback-manager.h"
@@ -119,6 +120,7 @@ fbd_feedback_vibra_rumble_start_vibra (FbdFeedbackVibra *vibra)
FbdFeedbackManager *manager = fbd_feedback_manager_get_default ();
FbdDevVibra *dev = fbd_feedback_manager_get_dev_vibra (manager);
guint duration = fbd_feedback_vibra_get_duration (vibra);
+ double strength = fbd_feedback_vibra_get_max_strength (FBD_FEEDBACK_VIBRA (self));
guint period;
self->rumble = (duration / self->count) - self->pause;
@@ -130,9 +132,9 @@ fbd_feedback_vibra_rumble_start_vibra (FbdFeedbackVibra *vibra)
period = self->rumble + self->pause;
self->periods = self->count;
- g_debug ("Rumble Vibra event: duration %d, rumble: %d, pause: %d, period: %d",
- duration, self->rumble, self->pause, period);
- fbd_dev_vibra_rumble (dev, 1.0, self->rumble, TRUE);
+ g_debug ("Rumble Vibra event: duration %d, rumble: %d, pause: %d, period: %d, strength %f",
+ duration, self->rumble, self->pause, period, strength);
+ fbd_dev_vibra_rumble (dev, strength, self->rumble, TRUE);
self->periods--;
if (self->periods) {
self->timer_id = g_timeout_add (period, (GSourceFunc) on_period_ended, self);
diff --git a/src/fbd-feedback-vibra.c b/src/fbd-feedback-vibra.c
index a04a902..c2dc9d2 100644
--- a/src/fbd-feedback-vibra.c
+++ b/src/fbd-feedback-vibra.c
@@ -6,6 +6,7 @@
#define G_LOG_DOMAIN "fbd-feedback-vibra"
+#include "fbd.h"
#include "fbd-enums.h"
#include "fbd-feedback-vibra.h"
#include "fbd-feedback-vibra-priv.h"
@@ -29,13 +30,26 @@ enum {
static GParamSpec *props[PROP_LAST_PROP];
typedef struct _FbdFeedbackVibraPrivate {
- guint duration;
- guint timer_id;
+ guint duration;
+ guint timer_id;
+ double max_strength;
+
+ GSettings *settings;
} FbdFeedbackVibraPrivate;
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
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
fbd_feedback_vibra_class_init (FbdFeedbackVibraClass *klass)
{
GObjectClass *object_class = G_OBJECT_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->get_property = fbd_feedback_vibra_get_property;
@@ -151,6 +179,15 @@ fbd_feedback_vibra_class_init (FbdFeedbackVibraClass *klass)
static void
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
@@ -179,3 +216,16 @@ fbd_feedback_vibra_set_duration (FbdFeedbackVibra *self, guint duration)
priv->duration = 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;
+}