summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorMichał Cichoń <michcic@gmail.com>2019-05-03 16:57:20 +0200
committerMichał Cichoń <michcic@gmail.com>2019-05-03 17:00:30 +0200
commit166056799c20ec66cdf94124e8c8cb3ef8114c84 (patch)
treef4709c48aae471993383832c82f37a75b9f5a109 /src/main.c
parent4d06dac5843651d755a4010691a60c68390e6ce0 (diff)
downloadpianobar-windows-166056799c20ec66cdf94124e8c8cb3ef8114c84.tar.gz
pianobar-windows-166056799c20ec66cdf94124e8c8cb3ef8114c84.tar.bz2
pianobar-windows-166056799c20ec66cdf94124e8c8cb3ef8114c84.zip
Add support for hotkeys. #20
Hotkeys can be assigned to action in configuration file ex: hk_<action_name> = g + shift + alt + ctrl
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c52
1 files changed, 50 insertions, 2 deletions
diff --git a/src/main.c b/src/main.c
index a75388e..6dacba5 100644
--- a/src/main.c
+++ b/src/main.c
@@ -28,6 +28,7 @@ THE SOFTWARE.
#include "main.h"
#include "console.h"
+#include "hotkey.h"
#include "ui.h"
#include "ui_dispatch.h"
#include "ui_readline.h"
@@ -179,17 +180,61 @@ static void BarMainGetInitialStation (BarApp_t *app) {
}
}
+static int BarMainHandleVirtualKey(int virtualKey, void *userData)
+{
+ BarApp_t *app = (BarApp_t *)userData;
+
+ switch (virtualKey)
+ {
+ case /*VK_VOLUME_MUTE*/ 0xAD: return 0;
+ case /*VK_VOLUME_DOWN*/ 0xAE: return 0;//app->settings.keys[BAR_KS_VOLDOWN];
+ case /*VK_VOLUME_UP*/ 0xAF: return 0;//app->settings.keys[BAR_KS_VOLUP];
+ case /*VK_MEDIA_NEXT_TRACK*/ 0xB0: return 0;//app->settings.keys[BAR_KS_SKIP];
+ case /*VK_MEDIA_PREV_TRACK*/ 0xB1: return 0;
+ case /*VK_MEDIA_STOP*/ 0xB2: return 0;
+ case /*VK_MEDIA_PLAY_PAUSE*/ 0xB3: return 0;//app->settings.keys[BAR_KS_PLAYPAUSE];
+ case /*VK_LAUNCH_MAIL*/ 0xB4: return 0;
+ case /*VK_LAUNCH_MEDIA_SELECT*/ 0xB5: return 0;
+ case /*VK_LAUNCH_APP1*/ 0xB6: return 0;
+ case /*VK_LAUNCH_APP2*/ 0xB7: return 0;
+ default: return 0;
+ }
+}
+
+static void BarMainHotKeyHandler(int hotKeyId, void *userData)
+{
+ if (hotKeyId == 0)
+ return;
+
+ BarApp_t *app = (BarApp_t *)userData;
+
+ BarUiDispatch(app, app->settings.keys[hotKeyId], app->curStation, app->playlist, true,
+ BAR_DC_GLOBAL);
+}
+
/* wait for user rl
*/
static void BarMainHandleUserInput(BarApp_t *app)
{
char buf[2];
- if (BarReadline(buf, sizeof(buf), NULL, app->rl,
- BAR_RL_FULLRETURN | BAR_RL_NOECHO, 1) > 0)
+ size_t readSize = 0;
+
+ BarReadlineSetVirtualKeyHandler(app->rl, BarMainHandleVirtualKey, app);
+
+ readSize = BarReadline(buf, sizeof(buf), NULL, app->rl,
+ BAR_RL_FULLRETURN | BAR_RL_NOECHO, 1);
+
+ BarReadlineSetVirtualKeyHandler(app->rl, NULL, NULL);
+
+ if (readSize > 0)
{
BarUiDispatch(app, buf[0], app->curStation, app->playlist, true,
BAR_DC_GLOBAL);
}
+ else
+ {
+ BarHotKeyPool(BarMainHotKeyHandler, app);
+ }
}
/* fetch new playlist
@@ -375,6 +420,8 @@ int main(int argc, char **argv)
BarConsoleSetTitle(TITLE);
+ BarHotKeyInit();
+
/* init some things */
BarSettingsInit(&app.settings);
BarSettingsRead(&app.settings);
@@ -432,6 +479,7 @@ int main(int argc, char **argv)
HttpDestroy(app.http2);
BarPlayer2Destroy(app.player);
BarSettingsDestroy(&app.settings);
+ BarHotKeyDestroy();
BarConsoleDestroy();
return 0;