A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 457 lines 16 kB view raw
1/*************************************************************************** 2 * __________ __ ___. 3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 * \/ \/ \/ \/ \/ 8 * 9 * Copyright (C) 2004 Brent Coutts 10 * 11 * This program is free software; you can redistribute it and/or 12 * modify it under the terms of the GNU General Public License 13 * as published by the Free Software Foundation; either version 2 14 * of the License, or (at your option) any later version. 15 * 16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 17 * KIND, either express or implied. 18 * 19 ****************************************************************************/ 20#ifndef __ACTION_H__ 21#define __ACTION_H__ 22 23#include "stdbool.h" 24#include "button.h" 25#include "viewport.h" 26 27#define TIMEOUT_BLOCK -1 28#define TIMEOUT_NOBLOCK 0 29 30#define CONTEXT_STOPSEARCHING 0xFFFFFFFF 31 32#define CONTEXT_REMOTE 0x80000000 /* | this against another context to get remote buttons for that context */ 33#define CONTEXT_CUSTOM 0x40000000 /* | this against anything to get your context number */ 34#define CONTEXT_CUSTOM2 0x20000000 /* as above */ 35#define CONTEXT_PLUGIN 0x10000000 /* for plugins using get_custom_action */ 36#define CONTEXT_REMAPPED 0x08000000 /* marker for key remap context table */ 37#define CORE_CONTEXT_REMAP(context) (CONTEXT_REMAPPED | context) 38#define CONTEXT_LOCKED 0x04000000 /* flag to use alternate keymap when screen is locked */ 39 40 41#define LAST_ITEM_IN_LIST { CONTEXT_STOPSEARCHING, BUTTON_NONE, BUTTON_NONE } 42#define LAST_ITEM_IN_LIST__NEXTLIST(a) { a, BUTTON_NONE, BUTTON_NONE } 43 44#if !defined(HAS_BUTTON_HOLD) 45#define ALLOW_SOFTLOCK 0x08000000 /* will be stripped.. never needed except in calls to get_action() */ 46#else 47#define ALLOW_SOFTLOCK 0 48#endif 49 50#if defined(HAVE_BACKLIGHT) || !defined(HAS_BUTTON_HOLD) 51/* Selective action selection flags */ 52#define SEL_ACTION_NONE 0 53#define SEL_ACTION_VOL 0x001U 54#define SEL_ACTION_PLAY 0x002U 55#define SEL_ACTION_SEEK 0x004U 56#define SEL_ACTION_SKIP 0x008U 57#define SEL_ACTION_NOUNMAPPED 0x010U/* disable backlight on unmapped buttons */ 58#define SEL_ACTION_ALLNONOTIFY 0x020U/* disable switch for all softlock notifications */ 59#define SEL_ACTION_ALWAYSAUTOLOCK 0x040U/* always prime autolock, requires autolock enabled */ 60#define SEL_ACTION_NOTOUCH 0x080U/* disable touch screen/pad on screen lock */ 61#define SEL_ACTION_AUTOLOCK 0x100U/* autolock on backlight off */ 62#define SEL_ACTION_NOEXT 0x200U/* disable selective backlight while charge*/ 63#define SEL_ACTION_NONOTIFY 0x200U/* don't notify user softlock is active */ 64/* Flags below are internal to selective functions */ 65#define SEL_ACTION_ALOCK_OK 0x400U/*autolock only active after key lock once*/ 66#define SEL_ACTION_FFKEYPRESS 0x400U/* backlight Filter First Keypress active*/ 67#define SEL_ACTION_ENABLED 0x800U 68/* Selective Actions flags */ 69 70#if !defined(HAS_BUTTON_HOLD) 71/* returns true if keys_locked and screen_has_lock */ 72bool is_keys_locked(void); 73 74/* Enable selected actions to bypass a locked state 75* mask is combination of Selective action selection flags */ 76void set_selective_softlock_actions(bool selective, unsigned int mask); 77 78/* search the standard and wps contexts for ACTION_STD_KEYLOCK, 79 * load it into unlock_combo if we find it, 80 * also arm autolock if enabled. */ 81void action_autosoftlock_init(void); 82 83#endif /* !defined(HAS_BUTTON_HOLD) */ 84 85#if defined(HAVE_BACKLIGHT) 86/* Enable selected actions to leave the backlight off 87* mask is combination of Selective action selection flags */ 88void set_selective_backlight_actions(bool selective, unsigned int mask, 89 bool filter_fkp); 90#endif 91 92#endif /* defined(HAVE_BACKLIGHT) || !defined(HAS_BUTTON_HOLD) */ 93 94enum { 95 CONTEXT_STD = 0, 96 /* These CONTEXT_ values were here before me, 97 their values may have significance, so dont touch! */ 98 CONTEXT_WPS = 1, 99 CONTEXT_TREE = 2, 100 CONTEXT_RECORD = 3, 101 CONTEXT_MAINMENU = 4, /* uses CONTEXT_TREE and ACTION_TREE_* */ 102 CONTEXT_ID3DB = 5, 103 /* Add new contexts here, no need to explicitly define a value for them */ 104 CONTEXT_LIST, 105 CONTEXT_SETTINGS, /* regular setting screens (and debug screens) */ 106 /* bellow are setting screens which may need to redefine the standard 107 setting screen keys, targets should return the CONTEXT_SETTINGS 108 keymap unless they are not adequate for the screen 109 NOTE: uses ACTION_STD_[NEXT|PREV] so make sure they are there also 110 and (possibly) ACTION_SETTINGS_[INC|DEC] */ 111 CONTEXT_SETTINGS_EQ, 112 CONTEXT_SETTINGS_COLOURCHOOSER, 113 CONTEXT_SETTINGS_TIME, 114 CONTEXT_SETTINGS_RECTRIGGER, 115 116 /* The following contexts should use ACTION_STD_[NEXT|PREV] 117 and (possibly) ACTION_SETTINGS_[INC|DEC] 118 Also add any extra actions they need */ 119 CONTEXT_BOOKMARKSCREEN, /* uses ACTION_BMS_ defines */ 120 CONTEXT_ALARMSCREEN, /* uses ACTION_AS_ defines */ 121 CONTEXT_QUICKSCREEN, /* uses ACTION_QS_ defines below */ 122 CONTEXT_PITCHSCREEN, /* uses ACTION_PS_ defines below */ 123 124 CONTEXT_YESNOSCREEN, /*NOTE: make sure your target has this and ACTION_YESNO_ACCEPT */ 125 CONTEXT_RECSCREEN, 126 CONTEXT_KEYBOARD, 127 CONTEXT_MORSE_INPUT, 128 CONTEXT_FM, 129 CONTEXT_USB_HID, 130 CONTEXT_USB_HID_MODE_MULTIMEDIA, 131 CONTEXT_USB_HID_MODE_PRESENTATION, 132 CONTEXT_USB_HID_MODE_BROWSER, 133 CONTEXT_USB_HID_MODE_MOUSE, 134 LAST_CONTEXT_PLACEHOLDER, 135}; 136 137 138enum { 139 140 ACTION_NONE = BUTTON_NONE, 141 ACTION_UNKNOWN, 142 ACTION_REDRAW, /* returned if keys are locked and we splash()'ed */ 143 ACTION_TOUCHSCREEN, 144 ACTION_TOUCHSCREEN_MODE, /* toggle the touchscreen mode */ 145 ACTION_TOUCHSCREEN_IGNORE, /* used for the 'none' action in skins */ 146 147 /* standard actions, use these first */ 148 ACTION_STD_PREV, 149 ACTION_STD_PREVREPEAT, 150 ACTION_STD_NEXT, 151 ACTION_STD_NEXTREPEAT, 152 153 ACTION_STD_OK, 154 ACTION_STD_CANCEL, 155 ACTION_STD_CONTEXT, 156 ACTION_STD_MENU, 157 ACTION_STD_QUICKSCREEN, 158 ACTION_STD_KEYLOCK, 159 ACTION_STD_REC, 160 ACTION_STD_HOTKEY, 161 162 /* code context actions */ 163 164 /* WPS codes */ 165 ACTION_WPS_BROWSE, 166 ACTION_WPS_PLAY, 167 ACTION_WPS_SEEKBACK, 168 ACTION_WPS_SEEKFWD, 169 ACTION_WPS_STOPSEEK, 170 ACTION_WPS_SKIPNEXT, 171 ACTION_WPS_SKIPPREV, 172 ACTION_WPS_STOP, 173 ACTION_WPS_VOLDOWN, 174 ACTION_WPS_VOLUP, 175 ACTION_WPS_PITCHSCREEN,/* optional */ 176 ACTION_WPS_ID3SCREEN,/* optional */ 177 ACTION_WPS_CONTEXT, 178 ACTION_WPS_QUICKSCREEN,/* optional */ 179 ACTION_WPS_MENU, /*this should be the same as ACTION_STD_MENU */ 180 ACTION_WPS_VIEW_PLAYLIST, 181 ACTION_WPS_LIST_BOOKMARKS,/* optional */ 182 ACTION_WPS_CREATE_BOOKMARK,/* optional */ 183 ACTION_WPS_REC, 184#if 0 185 ACTION_WPSAB_SINGLE, /* This needs to be #defined in 186 the config-<target>.h to one of the ACTION_WPS_ actions 187 so it can be used */ 188#endif 189 ACTION_WPS_ABSETA_PREVDIR, /* these should be safe to put together seen as */ 190 ACTION_WPS_ABSETB_NEXTDIR, /* you shouldnt want to change dir in ab-mode */ 191 ACTION_WPS_ABRESET, 192 ACTION_WPS_HOTKEY, 193 194 /* list and tree page up/down */ 195 ACTION_LISTTREE_PGUP,/* optional */ 196 ACTION_LISTTREE_PGDOWN,/* optional */ 197#ifdef HAVE_VOLUME_IN_LIST 198 ACTION_LIST_VOLUP, 199 ACTION_LIST_VOLDOWN, 200#endif 201 202 /* tree */ 203 ACTION_TREE_ROOT_INIT, 204 ACTION_TREE_PGLEFT,/* optional */ 205 ACTION_TREE_PGRIGHT,/* optional */ 206 ACTION_TREE_STOP, 207 ACTION_TREE_WPS, 208 ACTION_TREE_HOTKEY, 209 210 /* radio */ 211 ACTION_FM_MENU, 212 ACTION_FM_PRESET, 213 ACTION_FM_RECORD, 214 ACTION_FM_FREEZE, 215 ACTION_FM_STOP, 216 ACTION_FM_MODE, 217 ACTION_FM_EXIT, 218 ACTION_FM_PLAY, 219 ACTION_FM_RECORD_DBLPRE, 220 ACTION_FM_NEXT_PRESET, 221 ACTION_FM_PREV_PRESET, 222 223 /* recording screen */ 224 ACTION_REC_LCD, 225 ACTION_REC_PAUSE, 226 ACTION_REC_NEWFILE, 227 ACTION_REC_F2, 228 ACTION_REC_F3, 229 230 /* main menu */ 231 /* These are not strictly actions, but must be here 232 so they dont conflict with real actions in the menu code */ 233 ACTION_REQUEST_MENUITEM, 234 ACTION_EXIT_MENUITEM, 235 ACTION_EXIT_AFTER_THIS_MENUITEM, /* if a menu returns this the menu will exit 236 once the subitem returns */ 237 ACTION_ENTER_MENUITEM, 238 239 /* id3db */ 240 241 /* list */ 242 243 /* settings */ 244 ACTION_SETTINGS_INC, 245 ACTION_SETTINGS_INCREPEAT, 246 ACTION_SETTINGS_INCBIGSTEP, 247 ACTION_SETTINGS_DEC, 248 ACTION_SETTINGS_DECREPEAT, 249 ACTION_SETTINGS_DECBIGSTEP, 250 ACTION_SETTINGS_SET, /* Used by touchscreen targets */ 251 252 /* bookmark screen */ 253 ACTION_BMS_DELETE, 254 255 /* quickscreen */ 256 ACTION_QS_LEFT, 257 ACTION_QS_RIGHT, 258 ACTION_QS_DOWN, 259 ACTION_QS_TOP, 260 ACTION_QS_VOLUP, 261 ACTION_QS_VOLDOWN, 262 263 /* pitchscreen */ 264 /* obviously ignore if you dont have thise screen */ 265 ACTION_PS_INC_SMALL, 266 ACTION_PS_INC_BIG, 267 ACTION_PS_DEC_SMALL, 268 ACTION_PS_DEC_BIG, 269 ACTION_PS_NUDGE_LEFT, 270 ACTION_PS_NUDGE_RIGHT, 271 ACTION_PS_NUDGE_LEFTOFF, 272 ACTION_PS_NUDGE_RIGHTOFF, 273 ACTION_PS_TOGGLE_MODE, 274 ACTION_PS_RESET, 275 ACTION_PS_EXIT, /* _STD_* isnt going to work here */ 276 ACTION_PS_SLOWER, 277 ACTION_PS_FASTER, 278 279 /* yesno screen */ 280 ACTION_YESNO_ACCEPT, 281 282 /* keyboard screen */ 283 ACTION_KBD_LEFT, 284 ACTION_KBD_RIGHT, 285 ACTION_KBD_CURSOR_LEFT, 286 ACTION_KBD_CURSOR_RIGHT, 287 ACTION_KBD_SELECT, 288 ACTION_KBD_PAGE_FLIP, 289 ACTION_KBD_DONE, 290 ACTION_KBD_ABORT, 291 ACTION_KBD_BACKSPACE, 292 ACTION_KBD_UP, 293 ACTION_KBD_DOWN, 294 ACTION_KBD_MORSE_INPUT, 295 ACTION_KBD_MORSE_SELECT, 296 297#ifdef HAVE_TOUCHSCREEN 298 /* the following are helper actions for touchscreen targets, 299 * These are for actions which are not doable or required if buttons are 300 * being used, but are nice additions if the touchscreen is used */ 301 ACTION_TOUCH_SHUFFLE, 302 ACTION_TOUCH_REPMODE, 303 ACTION_TOUCH_MUTE, 304 ACTION_TOUCH_SCROLLBAR, 305 ACTION_TOUCH_VOLUME, 306 ACTION_TOUCH_SOFTLOCK, 307 ACTION_TOUCH_SETTING, 308#endif 309 310 /* USB HID codes */ 311 ACTION_USB_HID_FIRST, /* Place holder */ 312 ACTION_USB_HID_NONE, 313 ACTION_USB_HID_MODE_SWITCH_NEXT, 314 ACTION_USB_HID_MODE_SWITCH_PREV, 315 ACTION_USB_HID_MULTIMEDIA_VOLUME_UP, 316 ACTION_USB_HID_MULTIMEDIA_VOLUME_DOWN, 317 ACTION_USB_HID_MULTIMEDIA_VOLUME_MUTE, 318 ACTION_USB_HID_MULTIMEDIA_PLAYBACK_PLAY_PAUSE, 319 ACTION_USB_HID_MULTIMEDIA_PLAYBACK_STOP, 320 ACTION_USB_HID_MULTIMEDIA_PLAYBACK_TRACK_PREV, 321 ACTION_USB_HID_MULTIMEDIA_PLAYBACK_TRACK_NEXT, 322 ACTION_USB_HID_PRESENTATION_SLIDESHOW_START, 323 ACTION_USB_HID_PRESENTATION_SLIDESHOW_LEAVE, 324 ACTION_USB_HID_PRESENTATION_SLIDE_PREV, 325 ACTION_USB_HID_PRESENTATION_SLIDE_NEXT, 326 ACTION_USB_HID_PRESENTATION_SLIDE_FIRST, 327 ACTION_USB_HID_PRESENTATION_SLIDE_LAST, 328 ACTION_USB_HID_PRESENTATION_SCREEN_BLACK, 329 ACTION_USB_HID_PRESENTATION_SCREEN_WHITE, 330 ACTION_USB_HID_PRESENTATION_LINK_PREV, 331 ACTION_USB_HID_PRESENTATION_LINK_NEXT, 332 ACTION_USB_HID_PRESENTATION_MOUSE_CLICK, 333 ACTION_USB_HID_PRESENTATION_MOUSE_OVER, 334 ACTION_USB_HID_BROWSER_SCROLL_UP, 335 ACTION_USB_HID_BROWSER_SCROLL_DOWN, 336 ACTION_USB_HID_BROWSER_SCROLL_PAGE_DOWN, 337 ACTION_USB_HID_BROWSER_SCROLL_PAGE_UP, 338 ACTION_USB_HID_BROWSER_ZOOM_IN, 339 ACTION_USB_HID_BROWSER_ZOOM_OUT, 340 ACTION_USB_HID_BROWSER_ZOOM_RESET, 341 ACTION_USB_HID_BROWSER_TAB_PREV, 342 ACTION_USB_HID_BROWSER_TAB_NEXT, 343 ACTION_USB_HID_BROWSER_TAB_CLOSE, 344 ACTION_USB_HID_BROWSER_HISTORY_BACK, 345 ACTION_USB_HID_BROWSER_HISTORY_FORWARD, 346 ACTION_USB_HID_BROWSER_VIEW_FULL_SCREEN, 347 ACTION_USB_HID_MOUSE_UP, 348 ACTION_USB_HID_MOUSE_UP_REP, 349 ACTION_USB_HID_MOUSE_DOWN, 350 ACTION_USB_HID_MOUSE_DOWN_REP, 351 ACTION_USB_HID_MOUSE_LEFT, 352 ACTION_USB_HID_MOUSE_LEFT_REP, 353 ACTION_USB_HID_MOUSE_RIGHT, 354 ACTION_USB_HID_MOUSE_RIGHT_REP, 355 ACTION_USB_HID_MOUSE_LDRAG_UP, 356 ACTION_USB_HID_MOUSE_LDRAG_UP_REP, 357 ACTION_USB_HID_MOUSE_LDRAG_DOWN, 358 ACTION_USB_HID_MOUSE_LDRAG_DOWN_REP, 359 ACTION_USB_HID_MOUSE_LDRAG_LEFT, 360 ACTION_USB_HID_MOUSE_LDRAG_LEFT_REP, 361 ACTION_USB_HID_MOUSE_LDRAG_RIGHT, 362 ACTION_USB_HID_MOUSE_LDRAG_RIGHT_REP, 363 ACTION_USB_HID_MOUSE_RDRAG_UP, 364 ACTION_USB_HID_MOUSE_RDRAG_UP_REP, 365 ACTION_USB_HID_MOUSE_RDRAG_DOWN, 366 ACTION_USB_HID_MOUSE_RDRAG_DOWN_REP, 367 ACTION_USB_HID_MOUSE_RDRAG_LEFT, 368 ACTION_USB_HID_MOUSE_RDRAG_LEFT_REP, 369 ACTION_USB_HID_MOUSE_RDRAG_RIGHT, 370 ACTION_USB_HID_MOUSE_RDRAG_RIGHT_REP, 371 ACTION_USB_HID_MOUSE_BUTTON_LEFT, 372 ACTION_USB_HID_MOUSE_BUTTON_LEFT_REL, 373 ACTION_USB_HID_MOUSE_BUTTON_RIGHT, 374 ACTION_USB_HID_MOUSE_BUTTON_RIGHT_REL, 375 ACTION_USB_HID_MOUSE_WHEEL_SCROLL_UP, 376 ACTION_USB_HID_MOUSE_WHEEL_SCROLL_DOWN, 377 ACTION_USB_HID_LAST, /* Place holder */ 378 379 LAST_ACTION_PLACEHOLDER, /* custom actions should be this + something */ 380}; 381 382struct button_mapping { 383 int action_code; 384 int button_code; 385 int pre_button_code; 386}; 387 388/* use if you want to supply your own button mappings, PLUGINS ONLY */ 389/* get_context_map is a function which returns a button_mapping* depedning on the given context */ 390/* custom button_mappings may "chain" to inbuilt CONTEXT's */ 391int get_custom_action(int context,int timeout, 392 const struct button_mapping* (*get_context_map)(int)); 393/* use if one of the standard CONTEXT_ mappings will work (ALL the core should be using this! */ 394int get_action(int context, int timeout); 395 396/* call this if you need to check for ACTION_STD_CANCEL only (i.e user abort! */ 397bool action_userabort(int timeout); 398 399/* no other code should need this apart from action.c */ 400const struct button_mapping* get_context_mapping(int context); 401 402/* load a key map to allow buttons for actions to be remapped see: core_keymap */ 403int action_set_keymap(struct button_mapping* core_keymap, int count); 404/* load keymap in a handle: takes ownership of the handle on success */ 405int action_set_keymap_handle(int handle, int count); 406 407/* returns the status code variable from action.c for the button just pressed 408 If button != NULL it will be set to the actual button code */ 409#define ACTION_REMOTE 0x1 /* remote was pressed */ 410#define ACTION_REPEAT 0x2 /* action was repeated (NOT button) */ 411int get_action_statuscode(int *button); 412 413/* returns the data value associated with the last action that is not 414 BUTTON_NONE or flagged with SYS_EVENT */ 415intptr_t get_action_data(void); 416 417#ifdef HAVE_TOUCHSCREEN 418/* return BUTTON_NONE on error 419 * BUTTON_REPEAT if repeated press 420 * BUTTON_REPEAT|BUTTON_REL if release after repeated press 421 * BUTTON_REL if it's a short press = release after press 422 * BUTTON_TOUCHSCREEN if press 423 */ 424int action_get_touchscreen_press(short *x, short *y); 425 426/* 427 * wrapper action_get_touchscreen_press() 428 * to filter the touchscreen coordinates through a viewport 429 * 430 * returns the action and x1, y1 relative to the viewport if 431 * the press was within the viewport, 432 * ACTION_UNKNOWN (and x1, y1 untouched) if the press was outside 433 * BUTTON_NONE else 434 * 435 **/ 436int action_get_touchscreen_press_in_vp(short *x1, short *y1, struct viewport *vp); 437#endif 438 439/******************************************************* 440* action_wait_for_release will not allow 441* get_action(|_custom)() to return 442* any ACTION_* values until the current buttons 443* have been released. 444* SYS_* and BUTTON_NONE will pass through. 445* but, any actions relying on _RELEASE won't be seen. 446* 447* Note this doesn't currently work for 448* touchscreen targets if called when the 449* screen isn't currently touched because, 450* if the touch coordinates change they can send 451* normal (non-BUTTON_REPEAT) events repeatedly, 452* this cannot be distinguished 453* from normal button events. 454*/ 455void action_wait_for_release(void); 456 457#endif /* __ACTION_H__ */