Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new key haptic.repeat and implement the key in ffmemless plugin. #7

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AC_PREREQ(2.61)
AC_INIT(ngfd, 1.4.0)
AC_INIT(ngfd, 1.5.0)
AM_INIT_AUTOMAKE([subdir-objects])

AC_CONFIG_MACRO_DIR([m4])
Expand Down
2 changes: 1 addition & 1 deletion data/plugins.d/50-ffmemless.ini
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ supported_effects = touch;touch_weak;touch_strong;release;release_weak;release_s
# _DELAY = [0,65535], milliseconds before starting playback, defaults to 0
#
# _REPEAT = [1,4294967295], how many times to repeat effect, defaults to 1
# Please note that if the event has "sound.repeat" enabled,
# Please note that if the event has "haptic.repeat" enabled,
# the effect is repeated until stop signal regardless of _REPEAT
# value.
#
Expand Down
2 changes: 1 addition & 1 deletion rpm/ngfd.spec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Name: ngfd

Summary: Non-graphic feedback service for sounds and other events
Version: 1.4.0
Version: 1.5.0
Release: 1
License: LGPLv2+
URL: https://github.com/sailfishos/ngfd
Expand Down
73 changes: 47 additions & 26 deletions src/include/ngf/haptic.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,35 @@
* The haptic event type is used to filter out playback in case user has
* disabled the setting for certain type of haptic feedback.
*/
#define N_HAPTIC_TYPE_KEY "haptic.type"
#define N_HAPTIC_TYPE_KEY "haptic.type"

#define N_HAPTIC_TYPE_TOUCH "touch"
#define N_HAPTIC_TYPE_EVENT "event"
#define N_HAPTIC_TYPE_TOUCH "touch"
#define N_HAPTIC_TYPE_EVENT "event"

#define N_HAPTIC_EFFECT_KEY "haptic.effect"
#define N_HAPTIC_EFFECT_KEY "haptic.effect"

#define N_HAPTIC_EFFECT_DEFAULT "default"
#define N_HAPTIC_EFFECT_DEFAULT "default"

/**
* haptic.repeat is generic catch-all boolean that when defined and set
* as false all repeats in haptic sequences are changed to play out only
* once, even if the sequence would be defined with unlimited repeats.
*
* In case of non-repeating sequence with the key defined as true will
* change the sequence to have unlimited repeats.
*/
#define N_HAPTIC_REPEAT_KEY "haptic.repeat"

/**
* haptic.duration defines the maximum time an effect is played, in
* milliseconds.
*/
#define N_HAPTIC_DURATION_KEY "haptic.duration"

/** Sequence for the haptic effect, overriding possible system-wide
* definitions for an event.
*/
#define N_HAPTIC_SEQUENCE_KEY "haptic.sequence"

/* System-defined haptic effects. Preferably all plugins implementing
* haptic functionality should be able to handle all the effects
Expand All @@ -62,29 +83,29 @@
*
* alarm and ringtone effects should repeat indefinitely.
*/
#define N_HAPTIC_EFFECT_DRAG_START "drag_start"
#define N_HAPTIC_EFFECT_RELEASE_WEAK "release_weak"
#define N_HAPTIC_EFFECT_DRAG_FAIL "drag_fail"
#define N_HAPTIC_EFFECT_DRAG_BOUNDARY "drag_boundary"
#define N_HAPTIC_EFFECT_TOUCH_WEAK "touch_weak"
#define N_HAPTIC_EFFECT_DRAG_END "drag_end"
#define N_HAPTIC_EFFECT_RELEASE "release"
#define N_HAPTIC_EFFECT_TOUCH "touch"
#define N_HAPTIC_EFFECT_RELEASE_STRONG "release_strong"
#define N_HAPTIC_EFFECT_TOUCH_STRONG "touch_strong"
#define N_HAPTIC_EFFECT_SHORT "short"
#define N_HAPTIC_EFFECT_STRONG "strong"
#define N_HAPTIC_EFFECT_LONG "long"
#define N_HAPTIC_EFFECT_NOTICE "notice"
#define N_HAPTIC_EFFECT_MESSAGE "message"
#define N_HAPTIC_EFFECT_ATTENTION "attention"
#define N_HAPTIC_EFFECT_ALARM "alarm"
#define N_HAPTIC_EFFECT_RINGTONE "ringtone"
#define N_HAPTIC_EFFECT_DRAG_START "drag_start"
#define N_HAPTIC_EFFECT_RELEASE_WEAK "release_weak"
#define N_HAPTIC_EFFECT_DRAG_FAIL "drag_fail"
#define N_HAPTIC_EFFECT_DRAG_BOUNDARY "drag_boundary"
#define N_HAPTIC_EFFECT_TOUCH_WEAK "touch_weak"
#define N_HAPTIC_EFFECT_DRAG_END "drag_end"
#define N_HAPTIC_EFFECT_RELEASE "release"
#define N_HAPTIC_EFFECT_TOUCH "touch"
#define N_HAPTIC_EFFECT_RELEASE_STRONG "release_strong"
#define N_HAPTIC_EFFECT_TOUCH_STRONG "touch_strong"
#define N_HAPTIC_EFFECT_SHORT "short"
#define N_HAPTIC_EFFECT_STRONG "strong"
#define N_HAPTIC_EFFECT_LONG "long"
#define N_HAPTIC_EFFECT_NOTICE "notice"
#define N_HAPTIC_EFFECT_MESSAGE "message"
#define N_HAPTIC_EFFECT_ATTENTION "attention"
#define N_HAPTIC_EFFECT_ALARM "alarm"
#define N_HAPTIC_EFFECT_RINGTONE "ringtone"

/* Supported haptic classes */
#define N_HAPTIC_CLASS_UNDEFINED (0)
#define N_HAPTIC_CLASS_TOUCH (1)
#define N_HAPTIC_CLASS_EVENT (2)
#define N_HAPTIC_CLASS_UNDEFINED (0)
#define N_HAPTIC_CLASS_TOUCH (1)
#define N_HAPTIC_CLASS_EVENT (2)

/**
* Convenience function to filter haptic depending on settings and call state
Expand Down
18 changes: 15 additions & 3 deletions src/plugins/ffmemless/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ static int ffm_sink_prepare(NSinkInterface *iface, NRequest *request)
const NProplist *props = n_request_get_properties (request);
const struct ffm_effect_data *data;
struct ffm_effect_data *copy;
gboolean repeat;
gint repeat = -1; /* -1 not set, 1 TRUE, 0 FALSE */
guint playback_time;
const gchar *key;

Expand All @@ -679,9 +679,21 @@ static int ffm_sink_prepare(NSinkInterface *iface, NRequest *request)
copy->request = request;
copy->iface = iface;

repeat = n_proplist_get_bool (props, FFM_SOUND_REPEAT_KEY);
/* If new haptic.repeat key is defined use that, otherwise revert to
* following sound.repeat to determine looping. */
if (n_proplist_has_key (props, N_HAPTIC_REPEAT_KEY))
repeat = n_proplist_get_bool (props, N_HAPTIC_REPEAT_KEY) ? 1 : 0;
else
repeat = n_proplist_get_bool (props, FFM_SOUND_REPEAT_KEY) ? 1 : 0;

playback_time = n_proplist_get_uint (props, FFM_HAPTIC_DURATION_KEY);
if (repeat || playback_time) {

/* If haptic.repeat is explicitly set to false then, if
* repeats were infinite -> set repeat to 2 (effectively repeats once)
* repeats was defined -> repeat the original repeat count */
if (repeat == 0) {
copy->repeat = data->repeat == INT32_MAX ? 2 : data->repeat;
} else if (repeat == 1 || playback_time > 0) {
/*
* If duration was not defined, it's zero and we don't report playback
* done. Otherwise, as effects are already stored by the kernel we just
Expand Down