don't reload the same image for new songs

This commit is contained in:
Rachel Lambda Samuelsson 2021-01-28 15:21:59 +01:00
parent 5f6bbce060
commit 03819aadad

View File

@ -19,8 +19,7 @@
#define DEFAULTSIZE 256 #define DEFAULTSIZE 256
#endif #endif
/* TODO image metadata images /* TODO image metadata images */
TODO fix stutter on resize */
/* mpd globals */ /* mpd globals */
struct mpd_connection* connection = 0; struct mpd_connection* connection = 0;
@ -86,6 +85,7 @@ char* asprintf(const char* fmt, ...) {
return ret; return ret;
} }
/* set the name of the x window */
void set_window_name(char* name) { void set_window_name(char* name) {
int len = strlen(name); int len = strlen(name);
@ -100,10 +100,19 @@ void set_window_name(char* name) {
XFlush(xdisplay); XFlush(xdisplay);
} }
/* path must be dynamically allocated */
void imlib_update(char* path) { void imlib_update(char* path) {
if (im_image_path) /* if we already have a path we might want to free it */
if (im_image_path) {
/* if the path is the same, just free the new path and return */
if (path && !strcmp(path, im_image_path)) {
free(path);
return;
}
/* otherwise just free the old path */
free(im_image_path); free(im_image_path);
}
im_image_path = path; im_image_path = path;
if (im_image) { if (im_image) {
@ -346,7 +355,8 @@ int main(int argc, char** argv) {
XFree(size_hints); XFree(size_hints);
XSelectInput(xdisplay, xwindow, StructureNotifyMask XSelectInput(xdisplay, xwindow, ExposureMask
| StructureNotifyMask
| ButtonPressMask); | ButtonPressMask);
XMapWindow(xdisplay, xwindow); XMapWindow(xdisplay, xwindow);
set_window_name("mpdart"); set_window_name("mpdart");
@ -412,10 +422,16 @@ int main(int argc, char** argv) {
XNextEvent(xdisplay, &ev); XNextEvent(xdisplay, &ev);
switch (ev.type) { switch (ev.type) {
/* close window */
case ClientMessage: case ClientMessage:
XCloseDisplay(xdisplay); XCloseDisplay(xdisplay);
die("Window Closed"); die("Window Closed");
break; // ? break;
/* redraw when off screen */
case Expose:
render = true;
break;
/* respond to resize */
case ConfigureNotify: case ConfigureNotify:
if (ww != ev.xconfigure.width || wh != ev.xconfigure.height) { if (ww != ev.xconfigure.width || wh != ev.xconfigure.height) {
ww = ev.xconfigure.width; ww = ev.xconfigure.width;
@ -423,6 +439,7 @@ int main(int argc, char** argv) {
render = true; render = true;
} }
break; break;
/* toggle pause on press */
case ButtonPress: case ButtonPress:
printf("Toggling pause\n"); printf("Toggling pause\n");