Update several codec Makefiles so that the codec libs build again on Coldfire targets...
[Rockbox.git] / apps / action.c
blob0f332a29f5141ba4a84693027f6aa19471137167
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2006 Jonathan Gordon
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
19 #include <stdio.h>
20 #include <string.h>
21 #include <stdlib.h>
23 #include "config.h"
24 #include "lang.h"
26 #include "button.h"
27 #include "action.h"
28 #include "kernel.h"
29 #include "debug.h"
30 #include "splash.h"
32 bool ignore_until_release = false;
33 int last_button = BUTTON_NONE;
35 /* software keylock stuff */
36 #ifndef HAS_BUTTON_HOLD
37 bool keys_locked = false;
38 int unlock_combo = BUTTON_NONE;
39 bool screen_has_lock = false;
40 #endif /* HAVE_SOFTWARE_KEYLOCK */
43 * do_button_check is the worker function for get_default_action.
44 * returns ACTION_UNKNOWN or the requested return value from the list.
46 inline int do_button_check(const struct button_mapping *items,
47 int button, int last_button, int *start)
49 int i = 0;
50 int ret = ACTION_UNKNOWN;
51 if (items == NULL)
52 return ACTION_UNKNOWN;
54 while (items[i].button_code != BUTTON_NONE)
56 if (items[i].button_code == button)
58 if ((items[i].pre_button_code == BUTTON_NONE)
59 || (items[i].pre_button_code == last_button))
61 ret = items[i].action_code;
62 break;
65 i++;
67 *start = i;
68 return ret;
71 inline int get_next_context(const struct button_mapping *items, int i)
73 while (items[i].button_code != BUTTON_NONE)
74 i++;
75 return (items[i].action_code == ACTION_NONE ) ?
76 CONTEXT_STD :
77 items[i].action_code;
80 * int get_action_worker(int context, struct button_mapping *user_mappings,
81 int timeout)
82 This function searches the button list for the given context for the just
83 pressed button.
84 If there is a match it returns the value from the list.
85 If there is no match..
86 the last item in the list "points" to the next context in a chain
87 so the "chain" is followed until the button is found.
88 putting ACTION_NONE will get CONTEXT_STD which is always the last list checked.
90 Timeout can be TIMEOUT_NOBLOCK to return immediatly
91 TIMEOUT_BLOCK to wait for a button press
92 Any number >0 to wait that many ticks for a press
95 int get_action_worker(int context, int timeout,
96 const struct button_mapping* (*get_context_map)(int) )
98 const struct button_mapping *items = NULL;
99 int button;
100 int i=0;
101 int ret = ACTION_UNKNOWN;
103 if (timeout == TIMEOUT_NOBLOCK)
104 button = button_get(false);
105 else if (timeout == TIMEOUT_BLOCK)
106 button = button_get(true);
107 else
108 button = button_get_w_tmo(timeout);
111 if (button == BUTTON_NONE || button&SYS_EVENT)
113 return button;
116 if (ignore_until_release == true)
118 if (button&BUTTON_REL)
120 ignore_until_release = false;
122 return ACTION_NONE; /* "safest" return value */
125 #ifndef HAS_BUTTON_HOLD
126 screen_has_lock = ((context&ALLOW_SOFTLOCK)==ALLOW_SOFTLOCK);
127 if (screen_has_lock && (keys_locked == true))
129 if (button == unlock_combo)
131 last_button = BUTTON_NONE;
132 keys_locked = false;
133 gui_syncsplash(HZ/2, true, str(LANG_KEYLOCK_OFF_PLAYER));
134 return ACTION_REDRAW;
136 else
137 #if (BUTTON_REMOTE != 0)
138 if ((button&BUTTON_REMOTE) == 0)
139 #endif
141 if ((button&BUTTON_REL))
142 gui_syncsplash(HZ/2, true, str(LANG_KEYLOCK_ON_PLAYER));
143 return ACTION_REDRAW;
146 context &= ~ALLOW_SOFTLOCK;
147 #endif /* HAS_BUTTON_HOLD */
149 /* logf("%x,%x",last_button,button); */
152 /* logf("context = %x",context); */
153 #if (BUTTON_REMOTE != 0)
154 if (button&BUTTON_REMOTE)
155 context |= CONTEXT_REMOTE;
156 #endif
157 if ((context&CONTEXT_CUSTOM) && get_context_map)
158 items = get_context_map(context);
159 else
160 items = get_context_mapping(context);
162 ret = do_button_check(items,button,last_button,&i);
164 if (context ==(int)CONTEXT_STOPSEARCHING)
165 break;
167 if (ret == ACTION_UNKNOWN )
169 context = get_next_context(items,i);
170 i = 0;
172 else break;
173 } while (1);
174 /* DEBUGF("ret = %x\n",ret); */
175 #ifndef HAS_BUTTON_HOLD
176 if (screen_has_lock && (ret == ACTION_STD_KEYLOCK))
178 unlock_combo = button;
179 keys_locked = true;
180 action_signalscreenchange();
181 gui_syncsplash(HZ/2, true, str(LANG_KEYLOCK_ON_PLAYER));
183 button_clear_queue();
184 return ACTION_REDRAW;
186 #endif
187 last_button = button;
188 return ret;
191 int get_action(int context, int timeout)
193 return get_action_worker(context,timeout,NULL);
196 int get_custom_action(int context,int timeout,
197 const struct button_mapping* (*get_context_map)(int))
199 return get_action_worker(context,timeout,get_context_map);
202 bool action_userabort(int timeout)
204 action_signalscreenchange();
205 int action = get_action_worker(CONTEXT_STD,timeout,NULL);
206 bool ret = (action == ACTION_STD_CANCEL);
207 action_signalscreenchange();
208 return ret;
211 void action_signalscreenchange(void)
213 if ((last_button != BUTTON_NONE) &&
214 !(last_button&BUTTON_REL))
216 ignore_until_release = true;
218 last_button = BUTTON_NONE;
220 #ifndef HAS_BUTTON_HOLD
221 bool is_keys_locked(void)
223 return (screen_has_lock && (keys_locked == true));
225 #endif