aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCalvin Morrison <calvin@fastmailteam.com>2022-07-27 22:24:04 -0400
committerCalvin Morrison <calvin@fastmailteam.com>2022-07-27 22:24:04 -0400
commited51c35c9fc4c45c42f75c02323ffc1d8afa63b5 (patch)
treef64db8ded9db11573da0566b7e60d35b4743b61c
parent32838e89fc892ab8baa5d01294a9f90a0a21c4d5 (diff)
update header and moc_x11.c to show length and server status
-rw-r--r--moc_library.h2
-rw-r--r--moc_x11.c41
2 files changed, 30 insertions, 13 deletions
diff --git a/moc_library.h b/moc_library.h
index 60a9c09..c545927 100644
--- a/moc_library.h
+++ b/moc_library.h
@@ -40,8 +40,10 @@ struct moc {
int track;
int time;
int filled;
+ int length;
};
+extern const char * moc_str_status(enum moc_status s);
extern const char * moc_str_state(enum moc_state s);
extern struct moc * moc_init();
diff --git a/moc_x11.c b/moc_x11.c
index 76384aa..efff073 100644
--- a/moc_x11.c
+++ b/moc_x11.c
@@ -110,34 +110,49 @@ int main() {
XEvent e;
while(1) {
- int got_event = XNextEventTimed(dpy, &e, 250);
+ XNextEventTimed(dpy, &e, 250);
+ XClearWindow(dpy, win);
if(mh->status != CONNECTED) {
- printf("can't connect\n");
+ XDrawString(dpy, win, DefaultGC(dpy, s), 0, 20, moc_str_status(mh->status), strlen(moc_str_status(mh->status)));
+ continue;
}
- XClearWindow(dpy, win);
- int y_offset = 20;
- int x = 10;
- pthread_mutex_lock(&mh->lock);
+ int y_offset = 20;
+ int x = 10;
+ pthread_mutex_lock(&mh->lock);
- XDrawString(dpy, win, DefaultGC(dpy, s), x, y_offset, moc_str_state(mh->state), strlen(moc_str_state(mh->state)));
- y_offset += 15;
- if(mh->state == PLAYING || mh->state == PAUSED) {
- char *timestr= time_format(mh->time);
+ XDrawString(dpy, win, DefaultGC(dpy, s), x, y_offset, moc_str_state(mh->state), strlen(moc_str_state(mh->state)));
+ y_offset += 15;
+ if(mh->state == PLAYING || mh->state == PAUSED) {
+ if(mh->title) {
XDrawString(dpy, win, DefaultGC(dpy, s), x, y_offset, mh->title, strlen(mh->title));
y_offset += 15;
+ }
+ if(mh->artist) {
XDrawString(dpy, win, DefaultGC(dpy, s), x, y_offset, mh->artist, strlen(mh->artist));
y_offset += 15;
+ }
+ if(mh->artist) {
XDrawString(dpy, win, DefaultGC(dpy, s), x, y_offset, mh->album, strlen(mh->album));
y_offset += 15;
+ }
+ if(mh->time >= 0) {
+ char *timestr= time_format(mh->time);
+ XDrawString(dpy, win, DefaultGC(dpy, s), x, y_offset, timestr, strlen(timestr));
+ free(timestr);
+ y_offset += 15;
+ }
+ if(mh->length >= 0) {
+ char *timestr= time_format(mh->length);
XDrawString(dpy, win, DefaultGC(dpy, s), x, y_offset, timestr, strlen(timestr));
+ free(timestr);
y_offset += 15;
+ }
- free(timestr);
- }
- pthread_mutex_unlock(&mh->lock);
+ }
+ pthread_mutex_unlock(&mh->lock);
}
};