From ed51c35c9fc4c45c42f75c02323ffc1d8afa63b5 Mon Sep 17 00:00:00 2001 From: Calvin Morrison Date: Wed, 27 Jul 2022 22:24:04 -0400 Subject: update header and moc_x11.c to show length and server status --- moc_library.h | 2 ++ moc_x11.c | 41 ++++++++++++++++++++++++++++------------- 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); } }; -- cgit v1.2.1