summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Gordon <rockbox@jdgordon.info>2012-01-12 22:28:36 +1100
committerJonathan Gordon <rockbox@jdgordon.info>2012-01-12 22:28:36 +1100
commiteb2ea7f9ad4c4e2cce390f8fe73e17698fa9a906 (patch)
tree64cd1f227d75a5758b52d9b49ae7bdf23f6dbf83
parent5ef27368f1bcbe31fb27072983d7a29df8de6845 (diff)
keyclick: Add a callback so screens can cancel a click. Add a generic list callback to stop clicks when we are at the end of the list
Change-Id: Iabb44a861dd7506cd883c1bdb0241303fa646746
-rw-r--r--apps/action.c12
-rw-r--r--apps/gui/list.c22
-rw-r--r--apps/gui/list.h4
-rw-r--r--apps/menu.c3
-rw-r--r--apps/misc.c20
-rw-r--r--apps/misc.h4
-rw-r--r--apps/tree.c3
7 files changed, 59 insertions, 9 deletions
diff --git a/apps/action.c b/apps/action.c
index e192daae4e..44980cdd9e 100644
--- a/apps/action.c
+++ b/apps/action.c
@@ -246,12 +246,6 @@ static int get_action_worker(int context, int timeout,
return ACTION_NONE;
}
-
-#if CONFIG_CODEC == SWCODEC
- /* Produce keyclick */
- keyclick_click(button);
-#endif
-
if ((context != last_context) && ((last_button & BUTTON_REL) == 0)
#ifdef HAVE_SCROLLWHEEL
/* Scrollwheel doesn't generate release events */
@@ -371,6 +365,12 @@ static int get_action_worker(int context, int timeout,
last_action = ret;
last_data = button_get_data();
last_action_tick = current_tick;
+
+#if CONFIG_CODEC == SWCODEC
+ /* Produce keyclick */
+ keyclick_click(ret);
+#endif
+
return ret;
}
diff --git a/apps/gui/list.c b/apps/gui/list.c
index c53a1f559c..d1b2748a60 100644
--- a/apps/gui/list.c
+++ b/apps/gui/list.c
@@ -576,6 +576,25 @@ static void gui_synclist_scroll_left(struct gui_synclist * lists)
}
#endif /* HAVE_LCD_BITMAP */
+#if CONFIG_CODEC == SWCODEC
+bool gui_synclist_keyclick_callback(int action, void* data)
+{
+ struct gui_synclist *lists = (struct gui_synclist *)data;
+
+ /* block the beep if we are at the end of the list and we are not wrapping.
+ * CAVEAT: mosts lists don't set limit_scroll untill it sees a repeat
+ * press at the end of the list so this can cause an extra beep.
+ */
+ if (lists->limit_scroll == false)
+ return true;
+ if (lists->selected_item == 0)
+ return (action != ACTION_STD_PREV && action != ACTION_STD_PREVREPEAT);
+ if (lists->selected_item == lists->nb_items - lists->selected_size)
+ return (action != ACTION_STD_NEXT && action != ACTION_STD_NEXTREPEAT);
+
+ return action != ACTION_NONE;
+}
+#endif
bool gui_synclist_do_button(struct gui_synclist * lists,
int *actionptr, enum list_wrap wrap)
@@ -774,6 +793,9 @@ bool list_do_action(int context, int timeout,
do_button, and places the action from get_action in *action. */
{
timeout = list_do_action_timeout(lists, timeout);
+#if CONFIG_CODEC == SWCODEC
+ keyclick_set_callback(gui_synclist_keyclick_callback, lists);
+#endif
*action = get_action(context, timeout);
return gui_synclist_do_button(lists, action, wrap);
}
diff --git a/apps/gui/list.h b/apps/gui/list.h
index c53604659e..d9df008956 100644
--- a/apps/gui/list.h
+++ b/apps/gui/list.h
@@ -165,6 +165,10 @@ extern void gui_synclist_set_title(struct gui_synclist * lists, char * title,
enum themable_icons icon);
extern void gui_synclist_hide_selection_marker(struct gui_synclist *lists,
bool hide);
+
+#if CONFIG_CODEC == SWCODEC
+extern bool gui_synclist_keyclick_callback(int action, void* data);
+#endif
/*
* Do the action implied by the given button,
* returns true if the action was handled.
diff --git a/apps/menu.c b/apps/menu.c
index a1e32f4625..ae318b2ffc 100644
--- a/apps/menu.c
+++ b/apps/menu.c
@@ -381,6 +381,9 @@ int do_menu(const struct menu_item_ex *start_menu, int *start_selected,
gui_buttonbar_draw(&buttonbar);
#endif
}
+#if CONFIG_CODEC == SWCODEC
+ keyclick_set_callback(gui_synclist_keyclick_callback, &lists);
+#endif
action = get_action(CONTEXT_MAINMENU,
list_do_action_timeout(&lists, HZ));
diff --git a/apps/misc.c b/apps/misc.c
index 3c55395a42..52e891e0c2 100644
--- a/apps/misc.c
+++ b/apps/misc.c
@@ -876,12 +876,23 @@ void system_sound_play(enum system_sound sound)
params->amplitude * *params->setting);
}
}
-
+
+static keyclick_callback keyclick_current_callback = NULL;
+static void* keyclick_data = NULL;
+void keyclick_set_callback(keyclick_callback cb, void* data)
+{
+ keyclick_current_callback = cb;
+ keyclick_data = data;
+}
+
/* Produce keyclick based upon button and global settings */
-void keyclick_click(int button)
+void keyclick_click(int action)
{
+ int button;
static long last_button = BUTTON_NONE;
bool do_beep = false;
+
+ get_action_statuscode(&button);
/* Settings filters */
if (
#ifdef HAVE_HARDWARE_CLICK
@@ -915,6 +926,11 @@ void keyclick_click(int button)
last_button = button;
else
last_button = BUTTON_NONE;
+
+ if (do_beep && keyclick_current_callback)
+ do_beep = keyclick_current_callback(action, keyclick_data);
+ keyclick_current_callback = NULL;
+
if (do_beep)
{
#ifdef HAVE_HARDWARE_CLICK
diff --git a/apps/misc.h b/apps/misc.h
index 2206894304..a41a8319ac 100644
--- a/apps/misc.h
+++ b/apps/misc.h
@@ -144,8 +144,10 @@ enum system_sound
/* Play a standard sound */
void system_sound_play(enum system_sound sound);
+typedef bool (*keyclick_callback)(int action, void* data);
+void keyclick_set_callback(keyclick_callback cb, void* data);
/* Produce keyclick based upon button and global settings */
-void keyclick_click(int button);
+void keyclick_click(int action);
#endif /* CONFIG_CODEC == SWCODEC */
void push_current_activity(enum current_activity screen);
diff --git a/apps/tree.c b/apps/tree.c
index 4431db2c4a..cc080ac7fa 100644
--- a/apps/tree.c
+++ b/apps/tree.c
@@ -652,6 +652,9 @@ static int dirbrowse(void)
if (tc.dirlevel < 0)
tc.dirlevel = 0; /* shouldnt be needed.. this code needs work! */
+#if CONFIG_CODEC == SWCODEC
+ keyclick_set_callback(gui_synclist_keyclick_callback, &tree_lists);
+#endif
button = get_action(CONTEXT_TREE,
list_do_action_timeout(&tree_lists, HZ/2));
#ifdef HAVE_LCD_BITMAP