Skip to content

Commit

Permalink
Merge branch 'release/2020.04.20'
Browse files Browse the repository at this point in the history
Release 2020.04.20:
 - Add support for multimedia keys in hotkeys
 - backport: piano: Request all stations
  • Loading branch information
thedmd committed Apr 20, 2020
2 parents eaa10a3 + a135a42 commit 7810790
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 17 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* package name */
#define PACKAGE "pianobar"

#define VERSION "2019.05.03"
#define VERSION "2020.04.20"

#define TITLE "Pianobar"

Expand Down
89 changes: 85 additions & 4 deletions src/hotkey.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright (c) 2019
Micha³ Cichoñ <thedmd@interia.pl>
Michał Cichoń <thedmd@interia.pl>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -28,9 +28,76 @@ THE SOFTWARE.
#include <io.h>
#include <windows.h>

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 ()
{
Expand All @@ -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;
Expand All @@ -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 };
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/hotkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ typedef enum {

typedef struct {
int id;
char key;
unsigned int key;
BarHotKeyMods_t mods;
} BarHotKey_t;

Expand Down
3 changes: 3 additions & 0 deletions src/libpiano/request.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
9 changes: 6 additions & 3 deletions src/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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];
Expand Down
11 changes: 4 additions & 7 deletions src/ui_readline.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
}
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 7810790

Please sign in to comment.