summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars-Dominik Braun <PromyLOPh@lavabit.com>2009-04-04 15:26:12 +0200
committerLars-Dominik Braun <PromyLOPh@lavabit.com>2009-04-04 15:26:12 +0200
commit2a76ecfb59b3ca52ed59070e6cddade407279b6b (patch)
tree1cabfb59fe9e36eb41fe0d7e497c1f28fef23b6f /src
parent2e6a6526065732a03288923e60f81646133ae7b6 (diff)
downloadpianobar-windows-2a76ecfb59b3ca52ed59070e6cddade407279b6b.tar.gz
pianobar-windows-2a76ecfb59b3ca52ed59070e6cddade407279b6b.tar.bz2
pianobar-windows-2a76ecfb59b3ca52ed59070e6cddade407279b6b.zip
Initial remote control support
Diffstat (limited to 'src')
-rw-r--r--src/main.c41
-rw-r--r--src/settings.h3
2 files changed, 36 insertions, 8 deletions
diff --git a/src/main.c b/src/main.c
index c1d904b..270e00f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -29,6 +29,10 @@ THE SOFTWARE.
#include <poll.h>
#include <time.h>
#include <ctype.h>
+/* open () */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
/* last.fm scrobbling library */
#include <wardrobe.h>
@@ -53,17 +57,22 @@ THE SOFTWARE.
#include "ui.h"
int main (int argc, char **argv) {
+ /* handles */
PianoHandle_t ph;
static struct audioPlayer player;
BarSettings_t settings;
- PianoSong_t *curSong = NULL;
- PianoStation_t *curStation = NULL;
- char doQuit = 0;
pthread_t playerThread;
WardrobeHandle_t wh;
+ /* currently playing */
+ PianoSong_t *curSong = NULL;
+ PianoStation_t *curStation = NULL;
WardrobeSong_t scrobbleSong;
- /* needed in main loop */
- struct pollfd polls = {fileno (stdin), POLLIN, POLLIN};
+ char doQuit = 0;
+ /* polls */
+ /* FIXME: max path length? */
+ char ctlPath[1024];
+ struct pollfd polls[2];
+ nfds_t pollsLen = 0;
char buf = '\0';
BarKeyShortcut_t *curShortcut = NULL;
@@ -76,9 +85,21 @@ int main (int argc, char **argv) {
PianoInit (&ph);
WardrobeInit (&wh);
BarSettingsInit (&settings);
-
BarSettingsRead (&settings);
+ /* init polls */
+ polls[0].fd = fileno (stdin);
+ polls[0].events = POLLIN;
+ ++pollsLen;
+ BarGetXdgConfigDir (PACKAGE "/ctl", ctlPath, sizeof (ctlPath));
+ /* FIXME: O_RDONLY blocks while opening :/ */
+ polls[1].fd = open (ctlPath, O_RDWR);
+ polls[1].events = POLLIN;
+ if (polls[1].fd != -1) {
+ ++pollsLen;
+ BarUiMsg (MSG_INFO, "Control fifo at %s opened\n", ctlPath);
+ }
+
if (settings.username == NULL) {
BarUiMsg (MSG_QUESTION, "Username: ");
settings.username = readline (NULL);
@@ -219,8 +240,12 @@ int main (int argc, char **argv) {
/* in the meantime: wait for user actions;
* 1000ms == 1s => refresh time display every second */
- if (poll (&polls, 1, 1000) > 0) {
- read (fileno (stdin), &buf, sizeof (buf));
+ if (poll (polls, pollsLen, 1000) > 0) {
+ if (polls[0].revents & POLLIN) {
+ read (fileno (stdin), &buf, sizeof (buf));
+ } else if (polls[1].revents & POLLIN) {
+ read (polls[1].fd, &buf, sizeof (buf));
+ }
curShortcut = settings.keys;
/* don't show what the user enters here, we could disable
* echoing too... */
diff --git a/src/settings.h b/src/settings.h
index ef3b93f..1bea648 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -62,4 +62,7 @@ void BarSettingsDestroy (BarSettings_t *settings);
void BarSettingsRead (BarSettings_t *settings);
+void BarGetXdgConfigDir (const char *filename, char *retDir,
+ size_t retDirN);
+
#endif /* _SETTINGS_H */