diff --git a/ChangeLog b/ChangeLog index 6dc0da36..685cc567 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Release 2020.04.20: + - Add support for multimedia keys in hotkeys + - backport: piano: Request all stations + Release 2018.10.30 - Sync with 2018.10.15 pianobar state diff --git a/src/config.h b/src/config.h index b0661028..a0772107 100644 --- a/src/config.h +++ b/src/config.h @@ -3,7 +3,7 @@ /* package name */ #define PACKAGE "pianobar" -#define VERSION "2019.05.03" +#define VERSION "2020.04.20" #define TITLE "Pianobar" diff --git a/src/hotkey.c b/src/hotkey.c index b630b885..8bdf70b6 100644 --- a/src/hotkey.c +++ b/src/hotkey.c @@ -1,6 +1,6 @@ /* Copyright (c) 2019 - Micha³ Cichoñ + MichaÅ‚ CichoÅ„ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -28,9 +28,76 @@ THE SOFTWARE. #include #include +typedef struct BarVirtualKeyMap +{ + const char* name; + UINT vk; +} BarVirtualKeyMap; + static BarHotKey_t* g_HotKeys = NULL; static int g_HotKeyCapacity = 0; static int g_HotKeyCount = 0; +static const BarVirtualKeyMap g_VirtualKeyMap[] = +{ + { "NUMPAD0", VK_NUMPAD0 }, + { "NUMPAD1", VK_NUMPAD1 }, + { "NUMPAD2", VK_NUMPAD2 }, + { "NUMPAD3", VK_NUMPAD3 }, + { "NUMPAD4", VK_NUMPAD4 }, + { "NUMPAD5", VK_NUMPAD5 }, + { "NUMPAD6", VK_NUMPAD6 }, + { "NUMPAD7", VK_NUMPAD7 }, + { "NUMPAD8", VK_NUMPAD8 }, + { "NUMPAD9", VK_NUMPAD9 }, + { "MULTIPLY", VK_MULTIPLY }, + { "ADD", VK_ADD }, + { "SEPARATOR", VK_SEPARATOR }, + { "SUBTRACT", VK_SUBTRACT }, + { "DECIMAL", VK_DECIMAL }, + { "DIVIDE", VK_DIVIDE }, + { "F1", VK_F1 }, + { "F2", VK_F2 }, + { "F3", VK_F3 }, + { "F4", VK_F4 }, + { "F5", VK_F5 }, + { "F6", VK_F6 }, + { "F7", VK_F7 }, + { "F8", VK_F8 }, + { "F9", VK_F9 }, + { "F10", VK_F10 }, + { "F11", VK_F11 }, + { "F12", VK_F12 }, + { "F13", VK_F13 }, + { "F14", VK_F14 }, + { "F15", VK_F15 }, + { "F16", VK_F16 }, + { "F17", VK_F17 }, + { "F18", VK_F18 }, + { "F19", VK_F19 }, + { "F20", VK_F20 }, + { "F21", VK_F21 }, + { "F22", VK_F22 }, + { "F23", VK_F23 }, + { "F24", VK_F24 }, + { "BROWSER_BACK", VK_BROWSER_BACK }, + { "BROWSER_FORWARD", VK_BROWSER_FORWARD }, + { "BROWSER_REFRESH", VK_BROWSER_REFRESH }, + { "BROWSER_STOP", VK_BROWSER_STOP }, + { "BROWSER_SEARCH", VK_BROWSER_SEARCH }, + { "BROWSER_FAVORITES", VK_BROWSER_FAVORITES }, + { "BROWSER_HOME", VK_BROWSER_HOME }, + { "VOLUME_MUTE", VK_VOLUME_MUTE }, + { "VOLUME_DOWN", VK_VOLUME_DOWN }, + { "VOLUME_UP", VK_VOLUME_UP }, + { "MEDIA_NEXT_TRACK", VK_MEDIA_NEXT_TRACK }, + { "MEDIA_PREV_TRACK", VK_MEDIA_PREV_TRACK }, + { "MEDIA_STOP", VK_MEDIA_STOP }, + { "MEDIA_PLAY_PAUSE", VK_MEDIA_PLAY_PAUSE }, + { "LAUNCH_MAIL", VK_LAUNCH_MAIL }, + { "LAUNCH_MEDIA_SELECT", VK_LAUNCH_MEDIA_SELECT }, + { "LAUNCH_APP1", VK_LAUNCH_APP1 }, + { "LAUNCH_APP2", VK_LAUNCH_APP2 }, +}; void BarHotKeyInit () { @@ -56,7 +123,7 @@ void BarHotKeyPool (BarHotKeyHandler handler, void * userData) bool BarHotKeyRegister (BarHotKey_t hk) { UINT modifiers = 0; - SHORT mappedVirtualKey = VkKeyScanA(tolower(hk.key)); + SHORT mappedVirtualKey = hk.key; BYTE keyCode = LOBYTE(mappedVirtualKey); if (keyCode == 0) return false; @@ -80,6 +147,20 @@ void BarHotKeyUnregister (int id) UnregisterHotKey(NULL, id); } +static UINT BarFindKeyByName(const char* name, size_t nameLength) +{ + for (int i = 0; i < sizeof(g_VirtualKeyMap) / sizeof(*g_VirtualKeyMap); ++i) + { + if (strlen(g_VirtualKeyMap[i].name) != nameLength) + continue; + + if (strnicmp(g_VirtualKeyMap[i].name, name, nameLength) == 0) + return g_VirtualKeyMap[i].vk; + } + + return 0; +} + bool BarHotKeyParse (BarHotKey_t* result, const char *value) { BarHotKey_t parsed = { 0 }; @@ -95,8 +176,8 @@ bool BarHotKeyParse (BarHotKey_t* result, const char *value) else if ((s == 3 && strnicmp(p, "alt", 3) == 0)) parsed.mods |= BAR_HK_MOD_ALT; else if (s == 1) - parsed.key = *p; - else + parsed.key = VkKeyScanA(tolower(*p)); + else if ((parsed.key = BarFindKeyByName(p, s)) == 0) return false; p += s; diff --git a/src/hotkey.h b/src/hotkey.h index fb59bc09..926146d5 100644 --- a/src/hotkey.h +++ b/src/hotkey.h @@ -38,7 +38,7 @@ typedef enum { typedef struct { int id; - char key; + unsigned int key; BarHotKeyMods_t mods; } BarHotKey_t; diff --git a/src/libpiano/request.c b/src/libpiano/request.c index 0df70050..9bb612b9 100644 --- a/src/libpiano/request.c +++ b/src/libpiano/request.c @@ -157,6 +157,9 @@ PianoReturn_t PianoRequest (PianoHandle_t *ph, PianoRequest_t *req, /* get stations, user must be authenticated */ assert (ph->user.listenerId != NULL); + json_object_object_add (j, "returnAllStations", + json_object_new_boolean (true)); + method = "user.getStationList"; break; } diff --git a/src/main.c b/src/main.c index 6dacba55..6470eae6 100644 --- a/src/main.c +++ b/src/main.c @@ -222,7 +222,7 @@ static void BarMainHandleUserInput(BarApp_t *app) BarReadlineSetVirtualKeyHandler(app->rl, BarMainHandleVirtualKey, app); readSize = BarReadline(buf, sizeof(buf), NULL, app->rl, - BAR_RL_FULLRETURN | BAR_RL_NOECHO, 1); + BAR_RL_FULLRETURN | BAR_RL_NOECHO, 100); BarReadlineSetVirtualKeyHandler(app->rl, NULL, NULL); diff --git a/src/settings.c b/src/settings.c index a2ce3fb9..914a6b89 100644 --- a/src/settings.c +++ b/src/settings.c @@ -349,9 +349,12 @@ void BarSettingsRead (BarSettings_t *settings) { if (streq (dispatchActions[i].configKey, actionKey)) { BarHotKey_t hk = { 0 }; if (BarHotKeyParse(&hk, val)) { - hk.id = i; - BarHotKeyRegister(hk); + hk.id = (int)i; + if (!BarHotKeyRegister(hk)) + BarUiMsg(settings, MSG_ERR, "Failed to register %s hotkey. It is probably used by another application.\n", key); } + else + BarUiMsg(settings, MSG_ERR, "Failed to parse %s hotkey\n", key); break; } } @@ -433,7 +436,7 @@ void BarSettingsRead (BarSettings_t *settings) { for (size_t i = 0; i < sizeof (mapping) / sizeof (*mapping); i++) { if (streq (typeStart, mapping[i])) { const char *formatPos = strstr (val, "%s"); - + /* keep default if there is no format character */ if (formatPos != NULL) { BarMsgFormatStr_t *format = &settings->msgFormat[i]; diff --git a/src/ui_readline.c b/src/ui_readline.c index 687258a2..be6c26aa 100644 --- a/src/ui_readline.c +++ b/src/ui_readline.c @@ -111,7 +111,7 @@ static size_t BarReadlinePrevUtf8 (char *ptr) { * @param accept these characters * @param readline * @param flags - * @param timeout (seconds) or -1 (no timeout) + * @param timeout (milliseconds) or -1 (no timeout) * @return number of bytes read from stdin */ size_t BarReadline (char *buf, const size_t bufSize, const char *mask, @@ -131,9 +131,6 @@ size_t BarReadline (char *buf, const size_t bufSize, const char *mask, memset(buf, 0, bufSize); if (timeout != INFINITE) { - // convert timeout to ms - timeout *= 1000; - // get time stamp, required for simulating non-locking input timeouts timeStamp = GetTickCount(); } @@ -211,7 +208,7 @@ size_t BarReadline (char *buf, const size_t bufSize, const char *mask, case VK_BACK: if (bufPos > 0) { - int moveSize; + size_t moveSize; char* oldBufOut = bufOut; bufOut = BarReadlinePriorUtf8(bufOut); @@ -231,7 +228,7 @@ size_t BarReadline (char *buf, const size_t bufSize, const char *mask, case VK_DELETE: if (bufPos < bufLen) { - int moveSize; + size_t moveSize; if (echo) { BarConsoleEraseCharacter(); @@ -321,7 +318,7 @@ size_t BarReadlineStr (char *buf, const size_t bufSize, * @return number of bytes read from stdin */ size_t BarReadlineInt (int *ret, BarReadline_t input) { - int rlRet = 0; + size_t rlRet = 0; char buf[16]; rlRet = BarReadline (buf, sizeof (buf), "0123456789", input,