1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
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
)
50 int ret
= ACTION_UNKNOWN
;
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
;
71 inline int get_next_context(const struct button_mapping
*items
, int i
)
73 while (items
[i
].button_code
!= BUTTON_NONE
)
75 return (items
[i
].action_code
== ACTION_NONE
) ?
80 * int get_action_worker(int context, struct button_mapping *user_mappings,
82 This function searches the button list for the given context for the just
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
;
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);
108 button
= button_get_w_tmo(timeout
);
111 if (button
== BUTTON_NONE
|| button
&SYS_EVENT
)
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
;
133 gui_syncsplash(HZ
/2, true, str(LANG_KEYLOCK_OFF_PLAYER
));
134 return ACTION_REDRAW
;
137 #if (BUTTON_REMOTE != 0)
138 if ((button
&BUTTON_REMOTE
) == 0)
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
;
157 if ((context
&CONTEXT_CUSTOM
) && get_context_map
)
158 items
= get_context_map(context
);
160 items
= get_context_mapping(context
);
162 ret
= do_button_check(items
,button
,last_button
,&i
);
164 if (context
==(int)CONTEXT_STOPSEARCHING
)
167 if (ret
== ACTION_UNKNOWN
)
169 context
= get_next_context(items
,i
);
174 /* DEBUGF("ret = %x\n",ret); */
175 #ifndef HAS_BUTTON_HOLD
176 if (screen_has_lock
&& (ret
== ACTION_STD_KEYLOCK
))
178 unlock_combo
= button
;
180 action_signalscreenchange();
181 gui_syncsplash(HZ
/2, true, str(LANG_KEYLOCK_ON_PLAYER
));
183 button_clear_queue();
184 return ACTION_REDRAW
;
187 last_button
= button
;
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();
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));