From: Max Kellermann Date: Thu, 2 Oct 2008 13:20:19 +0000 (+0200) Subject: screen_lyrics: add screen_lyrics_switch() X-Git-Tag: v0.12_alpha1~116 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=b1a8ff5269e42088b1530ccacb52a55b60754578;p=ncmpc.git screen_lyrics: add screen_lyrics_switch() screen_lyrics_switch() opens the lyrics screen and displays the lyrics of the specified song. This way, the user may view the lyrics of any song in the database browser. --- diff --git a/src/screen.h b/src/screen.h index e6f0ee7..6d26457 100644 --- a/src/screen.h +++ b/src/screen.h @@ -90,4 +90,10 @@ screen_is_visible(const struct screen_functions *sf); int screen_get_mouse_event(mpdclient_t *c, unsigned long *bstate, int *row); + +#ifdef ENABLE_LYRICS_SCREEN +void +screen_lyrics_switch(struct mpdclient *c, const struct mpd_song *song); +#endif + #endif diff --git a/src/screen_browser.c b/src/screen_browser.c index d7dea63..694987f 100644 --- a/src/screen_browser.c +++ b/src/screen_browser.c @@ -455,6 +455,8 @@ bool browser_cmd(struct screen_browser *browser, struct screen *screen, struct mpdclient *c, command_t cmd) { + struct filelist_entry *entry; + switch (cmd) { case CMD_PLAY: browser_handle_enter(browser, c); @@ -494,6 +496,20 @@ browser_cmd(struct screen_browser *browser, struct screen *screen, browser_handle_mouse_event(browser, c); return true; +#ifdef ENABLE_LYRICS_SCREEN + case CMD_SCREEN_LYRICS: + entry = browser_get_selected(browser); + if (entry == NULL) + return false; + + if (entry->entity == NULL || + entry->entity->type != MPD_INFO_ENTITY_TYPE_SONG) + return true; + + screen_lyrics_switch(c, entry->entity->info.song); + return true; +#endif + default: break; } diff --git a/src/screen_lyrics.c b/src/screen_lyrics.c index dbfe4ea..83bffdf 100644 --- a/src/screen_lyrics.c +++ b/src/screen_lyrics.c @@ -38,6 +38,8 @@ static list_window_t *lw = NULL; +static const struct mpd_song *next_song; + static struct { const struct mpd_song *song; @@ -256,8 +258,13 @@ lyrics_exit(void) static void lyrics_open(mpd_unused screen_t *screen, mpdclient_t *c) { - if (c->song != NULL && c->song != current.song) - screen_lyrics_load(c->song); + if (next_song == NULL) + next_song = c->song; + + if (next_song != NULL && next_song != current.song) + screen_lyrics_load(next_song); + + next_song = NULL; } @@ -334,3 +341,12 @@ const struct screen_functions screen_lyrics = { .cmd = lyrics_cmd, .get_title = lyrics_title, }; + +void +screen_lyrics_switch(struct mpdclient *c, const struct mpd_song *song) +{ + assert(song != NULL); + + next_song = song; + screen_switch(&screen_lyrics, c); +} diff --git a/src/screen_play.c b/src/screen_play.c index 1bc2034..67de5fa 100644 --- a/src/screen_play.c +++ b/src/screen_play.c @@ -528,6 +528,17 @@ play_cmd(screen_t *screen, mpdclient_t *c, command_t cmd) case CMD_MOUSE_EVENT: return handle_mouse_event(screen,c); + +#ifdef ENABLE_LYRICS_SCREEN + case CMD_SCREEN_LYRICS: + if (lw->selected < playlist_length(&c->playlist)) { + screen_lyrics_switch(c, playlist_get(&c->playlist, lw->selected)); + return 1; + } + + break; +#endif + default: break; }