From dc9269f96153e4e91af0c3507f5bc838f0e69d52 Mon Sep 17 00:00:00 2001 From: Jeffrey Middleton Date: Mon, 23 Mar 2009 10:48:05 -0500 Subject: [PATCH] screen swap works with song/lyrics screens The screen swap command now gets handled outside of screen.c when appropriate, to allow passing the currently selected song to the song/lyrics screens. --- src/screen.c | 18 +++++++++++++++++- src/screen.h | 2 ++ src/screen_browser.c | 8 ++++++++ src/screen_lyrics.c | 3 +++ src/screen_play.c | 3 +++ src/screen_song.c | 10 +++++++++- 6 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/screen.c b/src/screen.c index 57b22cf..6225825 100644 --- a/src/screen.c +++ b/src/screen.c @@ -91,6 +91,22 @@ screen_switch(const struct screen_functions *sf, struct mpdclient *c) screen_paint(c); } +void +screen_swap(struct mpdclient *c, const struct mpd_song *song) +{ + if (song != NULL) + { + if (mode_fn_prev == &screen_song) + screen_song_switch(c, song); + else if (mode_fn_prev == &screen_lyrics) + screen_lyrics_switch(c, song); + else + screen_switch(mode_fn_prev, c); + } + else + screen_switch(mode_fn_prev, c); +} + static int find_configured_screen(const char *name) { @@ -863,7 +879,7 @@ screen_cmd(mpdclient_t *c, command_t cmd) screen_switch(&screen_outputs, c); break; case CMD_SCREEN_SWAP: - screen_switch(mode_fn_prev, c); + screen_swap(c, NULL); break; #endif diff --git a/src/screen.h b/src/screen.h index d414548..601548c 100644 --- a/src/screen.h +++ b/src/screen.h @@ -115,6 +115,8 @@ gint screen_get_id(const char *name); void screen_switch(const struct screen_functions *sf, struct mpdclient *c); +void +screen_swap(struct mpdclient *c, const struct mpd_song *song); gboolean screen_is_visible(const struct screen_functions *sf); diff --git a/src/screen_browser.c b/src/screen_browser.c index b118a7e..b616c58 100644 --- a/src/screen_browser.c +++ b/src/screen_browser.c @@ -511,6 +511,14 @@ browser_cmd(struct screen_browser *browser, screen_lyrics_switch(c, entry->entity->info.song); return true; #endif + case CMD_SCREEN_SWAP: + entry = browser_get_selected(browser); + if (entry->entity != NULL && + entry->entity->type == MPD_INFO_ENTITY_TYPE_SONG) + screen_swap(c, entry->entity->info.song); + else + screen_swap(c, NULL); + return true; default: break; diff --git a/src/screen_lyrics.c b/src/screen_lyrics.c index 1cb392f..221b7cd 100644 --- a/src/screen_lyrics.c +++ b/src/screen_lyrics.c @@ -256,6 +256,9 @@ lyrics_cmd(mpdclient_t *c, command_t cmd) break; #endif + case CMD_SCREEN_SWAP: + screen_swap(c, current.song); + return true; case CMD_LOCATE: if (current.song != NULL) { diff --git a/src/screen_play.c b/src/screen_play.c index 4201fb8..d80c351 100644 --- a/src/screen_play.c +++ b/src/screen_play.c @@ -728,6 +728,9 @@ play_cmd(mpdclient_t *c, command_t cmd) break; #endif + case CMD_SCREEN_SWAP: + screen_swap(c, playlist_get(&c->playlist, lw->selected)); + return true; default: break; diff --git a/src/screen_song.c b/src/screen_song.c index cc4d538..74d2652 100644 --- a/src/screen_song.c +++ b/src/screen_song.c @@ -362,10 +362,18 @@ screen_song_cmd(mpdclient_t *c, command_t cmd) screen_lyrics_switch(c, current.played_song); return true; } - return false; + #endif + case CMD_SCREEN_SWAP: + if (current.selected_song != NULL) + screen_swap(c, current.selected_song); + else + // No need to check if this is null - we'd pass null anyway + screen_swap(c, current.played_song); + return true; + default: break; } -- 2.30.2