diff --git a/src/screen.c b/src/screen.c
index d9e7fdbe86ed0510a61ffd7d856e652b2e678a0b..6d2610ad1770e461bd72a503ada7a016407bec3e 100644 (file)
--- a/src/screen.c
+++ b/src/screen.c
/* ncmpc (Ncurses MPD Client)
/* ncmpc (Ncurses MPD Client)
- * (c) 2004-2009 The Music Player Daemon Project
+ * (c) 2004-2017 The Music Player Daemon Project
* Project homepage: http://musicpd.org
* Project homepage: http://musicpd.org
-
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
-
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-
+ *
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
+ */
#include "screen.h"
#include "screen_interface.h"
#include "screen_list.h"
#include "screen.h"
#include "screen_interface.h"
#include "screen_list.h"
-#include "screen_utils.h"
+#include "screen_status.h"
#include "config.h"
#include "i18n.h"
#include "charset.h"
#include "mpdclient.h"
#include "config.h"
#include "i18n.h"
#include "charset.h"
#include "mpdclient.h"
-#include "utils.h"
#include "options.h"
#include "options.h"
-#include "colors.h"
#include "player_command.h"
#include "player_command.h"
+#include "screen_help.h"
+#include "screen_queue.h"
+#include "screen_file.h"
+#include "screen_artist.h"
+#include "screen_search.h"
+#include "screen_song.h"
+#include "screen_keydef.h"
+#include "screen_lyrics.h"
+#include "screen_outputs.h"
+#include "screen_chat.h"
#include <mpd/client.h>
#include <stdlib.h>
#include <unistd.h>
#include <mpd/client.h>
#include <stdlib.h>
#include <unistd.h>
-#include <stdarg.h>
#include <string.h>
#include <time.h>
#include <string.h>
#include <time.h>
-#include <locale.h>
-
-#ifndef NCMPC_MINI
-/** welcome message time [s] */
-static const GTime SCREEN_WELCOME_TIME = 10;
-#endif
-
-/* minimum window size */
-static const int SCREEN_MIN_COLS = 14;
-static const int SCREEN_MIN_ROWS = 5;
/* screens */
/* screens */
-#ifndef NCMPC_MINI
-static gboolean welcome = TRUE;
-#endif
-
-struct screen screen;
-static const struct screen_functions *mode_fn = &screen_playlist;
-static const struct screen_functions *mode_fn_prev = &screen_playlist;
+struct screen screen = {
+ .current_page = &screen_queue,
+};
-gboolean
-screen_is_visible(const struct screen_functions *sf)
-{
- return sf == mode_fn;
-}
+static const struct screen_functions *mode_fn_prev = &screen_queue;
void
screen_switch(const struct screen_functions *sf, struct mpdclient *c)
{
assert(sf != NULL);
void
screen_switch(const struct screen_functions *sf, struct mpdclient *c)
{
assert(sf != NULL);
- if (sf == mode_fn)
+ if (sf == screen.current_page)
return;
return;
- mode_fn_prev = mode_fn;
+ mode_fn_prev = screen.current_page;
/* close the old mode */
/* close the old mode */
- if (mode_fn->close != NULL)
- mode_fn->close();
+ if (screen.current_page->close != NULL)
+ screen.current_page->close();
/* get functions for the new mode */
/* get functions for the new mode */
- mode_fn = sf;
+ screen.current_page = sf;
/* open the new mode */
/* open the new mode */
- if (mode_fn->open != NULL)
- mode_fn->open(c);
+ if (sf->open != NULL)
+ sf->open(c);
- screen_paint(c);
+ screen_paint(c, true);
}
void
}
void
screen_next_mode(struct mpdclient *c, int offset)
{
int max = g_strv_length(options.screen_list);
screen_next_mode(struct mpdclient *c, int offset)
{
int max = g_strv_length(options.screen_list);
- int current, next;
- const struct screen_functions *sf;
/* find current screen */
/* find current screen */
- current = find_configured_screen(screen_get_name(mode_fn));
- next = current + offset;
+ int current = find_configured_screen(screen_get_name(screen.current_page));
+ int next = current + offset;
if (next<0)
next = max-1;
else if (next>=max)
next = 0;
if (next<0)
next = max-1;
else if (next>=max)
next = 0;
- sf = screen_lookup_name(options.screen_list[next]);
+ const struct screen_functions *sf =
+ screen_lookup_name(options.screen_list[next]);
if (sf != NULL)
screen_switch(sf, c);
}
if (sf != NULL)
screen_switch(sf, c);
}
-static inline int
-volume_length(int volume)
-{
- if (volume == 100)
- return 3;
- if (volume >= 10 && volume < 100)
- return 2;
- if (volume >= 0 && volume < 10)
- return 1;
- return -1;
-}
-
-static void
-paint_top_window(const char *header, const struct mpdclient *c)
-{
- title_bar_paint(&screen.title_bar, header, c->status);
-}
-
-static void
-paint_progress_window(struct mpdclient *c)
-{
- unsigned elapsed, duration;
-
- if (c->song != NULL && seek_id == (int)mpd_song_get_id(c->song))
- elapsed = seek_target_time;
- else if (c->status != NULL)
- elapsed = mpd_status_get_elapsed_time(c->status);
- else
- elapsed = 0;
-
- duration = c->status != NULL &&
- !IS_STOPPED(mpd_status_get_state(c->status))
- ? mpd_status_get_total_time(c->status)
- : 0;
-
- if (progress_bar_set(&screen.progress_bar, elapsed, duration))
- progress_bar_paint(&screen.progress_bar);
-}
-
-void
-screen_exit(void)
-{
- if (mode_fn->close != NULL)
- mode_fn->close();
-
- screen_list_exit();
-
- string_list_free(screen.find_history);
- g_free(screen.buf);
- g_free(screen.findbuf);
-
- title_bar_deinit(&screen.title_bar);
- delwin(screen.main_window.w);
- progress_bar_deinit(&screen.progress_bar);
- status_bar_deinit(&screen.status_bar);
-}
-
-void
-screen_resize(struct mpdclient *c)
-{
- if (COLS<SCREEN_MIN_COLS || LINES<SCREEN_MIN_ROWS) {
- screen_exit();
- fprintf(stderr, "%s", _("Error: Screen too small"));
- exit(EXIT_FAILURE);
- }
-
- resizeterm(LINES, COLS);
-
- screen.cols = COLS;
- screen.rows = LINES;
-
- title_bar_resize(&screen.title_bar, screen.cols);
-
- /* main window */
- screen.main_window.cols = screen.cols;
- screen.main_window.rows = screen.rows-4;
- wresize(screen.main_window.w, screen.main_window.rows, screen.cols);
- wclear(screen.main_window.w);
-
- /* progress window */
- progress_bar_resize(&screen.progress_bar, screen.cols,
- screen.rows - 2, 0);
- progress_bar_paint(&screen.progress_bar);
-
- /* status window */
- status_bar_resize(&screen.status_bar, screen.cols, screen.rows - 1, 0);
- status_bar_paint(&screen.status_bar, c->status, c->song);
-
- screen.buf_size = screen.cols;
- g_free(screen.buf);
- screen.buf = g_malloc(screen.cols);
-
- /* resize all screens */
- screen_list_resize(screen.main_window.cols, screen.main_window.rows);
-
- /* ? - without this the cursor becomes visible with aterm & Eterm */
- curs_set(1);
- curs_set(0);
-
- screen_paint(c);
-}
-
-void
-screen_status_message(const char *msg)
-{
- status_bar_message(&screen.status_bar, msg);
-}
-
-void
-screen_status_printf(const char *format, ...)
-{
- char *msg;
- va_list ap;
-
- va_start(ap,format);
- msg = g_strdup_vprintf(format,ap);
- va_end(ap);
- screen_status_message(msg);
- g_free(msg);
-}
-
-void
-screen_init(struct mpdclient *c)
-{
- if (COLS < SCREEN_MIN_COLS || LINES < SCREEN_MIN_ROWS) {
- fprintf(stderr, "%s\n", _("Error: Screen too small"));
- exit(EXIT_FAILURE);
- }
-
- screen.cols = COLS;
- screen.rows = LINES;
-
- screen.buf = g_malloc(screen.cols);
- screen.buf_size = screen.cols;
- screen.findbuf = NULL;
- screen.start_timestamp = time(NULL);
-
- /* create top window */
- title_bar_init(&screen.title_bar, screen.cols, 0, 0);
-
- /* create main window */
- window_init(&screen.main_window, screen.rows - 4, screen.cols, 2, 0);
-
- // leaveok(screen.main_window.w, TRUE); temporary disabled
- keypad(screen.main_window.w, TRUE);
-
- /* create progress window */
- progress_bar_init(&screen.progress_bar, screen.cols,
- screen.rows - 2, 0);
- progress_bar_paint(&screen.progress_bar);
-
- /* create status window */
- status_bar_init(&screen.status_bar, screen.cols, screen.rows - 1, 0);
- status_bar_paint(&screen.status_bar, c->status, c->song);
-
-#ifdef ENABLE_COLORS
- if (options.enable_colors) {
- /* set background attributes */
- wbkgd(stdscr, COLOR_PAIR(COLOR_LIST));
- wbkgd(screen.main_window.w, COLOR_PAIR(COLOR_LIST));
- wbkgd(screen.title_bar.window.w, COLOR_PAIR(COLOR_TITLE));
- wbkgd(screen.progress_bar.window.w,
- COLOR_PAIR(COLOR_PROGRESSBAR));
- wbkgd(screen.status_bar.window.w, COLOR_PAIR(COLOR_STATUS));
- colors_use(screen.progress_bar.window.w, COLOR_PROGRESSBAR);
- }
-#endif
-
- doupdate();
-
- /* initialize screens */
- screen_list_init(screen.main_window.w,
- screen.main_window.cols, screen.main_window.rows);
-
- if (mode_fn->open != NULL)
- mode_fn->open(c);
-}
-
-void
-screen_paint(struct mpdclient *c)
-{
- const char *title = NULL;
-
- if (mode_fn->get_title != NULL)
- title = mode_fn->get_title(screen.buf, screen.buf_size);
-
- /* paint the title/header window */
- if( title )
- paint_top_window(title, c);
- else
- paint_top_window("", c);
-
- /* paint the bottom window */
-
- paint_progress_window(c);
- status_bar_paint(&screen.status_bar, c->status, c->song);
-
- /* paint the main window */
-
- wclear(screen.main_window.w);
- if (mode_fn->paint != NULL)
- mode_fn->paint();
-
- /* move the cursor to the origin */
-
- if (!options.hardware_cursor)
- wmove(screen.main_window.w, 0, 0);
-
- wnoutrefresh(screen.main_window.w);
-
- /* tell curses to update */
- doupdate();
-}
-
void
screen_update(struct mpdclient *c)
{
#ifndef NCMPC_MINI
void
screen_update(struct mpdclient *c)
{
#ifndef NCMPC_MINI
+ static bool was_connected;
static bool initialized = false;
static bool repeat;
static bool random_enabled;
static bool initialized = false;
static bool repeat;
static bool random_enabled;
crossfade = mpd_status_get_crossfade(c->status);
}
crossfade = mpd_status_get_crossfade(c->status);
}
- if (c->events & MPD_IDLE_DATABASE)
+ if ((c->events & MPD_IDLE_DATABASE) != 0 && was_connected &&
+ mpdclient_is_connected(c))
screen_status_printf(_("Database updated"));
screen_status_printf(_("Database updated"));
-
- /* update title/header window */
- if (welcome && options.welcome_screen_list &&
- time(NULL)-screen.start_timestamp <= SCREEN_WELCOME_TIME)
- paint_top_window("", c);
- else
+ was_connected = mpdclient_is_connected(c);
#endif
#endif
- if (mode_fn->get_title != NULL) {
- paint_top_window(mode_fn->get_title(screen.buf,screen.buf_size), c);
-#ifndef NCMPC_MINI
- welcome = FALSE;
-#endif
- } else
- paint_top_window("", c);
-
- /* update progress window */
- paint_progress_window(c);
-
- /* update status window */
- status_bar_paint(&screen.status_bar, c->status, c->song);
/* update the main window */
/* update the main window */
- if (mode_fn->update != NULL)
- mode_fn->update(c);
-
- /* move the cursor to the origin */
-
- if (!options.hardware_cursor)
- wmove(screen.main_window.w, 0, 0);
-
- wnoutrefresh(screen.main_window.w);
+ if (screen.current_page->update != NULL)
+ screen.current_page->update(c);
- /* tell curses to update */
- doupdate();
+ screen_paint(c, false);
}
#ifdef HAVE_GETMOUSE
}
#ifdef HAVE_GETMOUSE
{
MEVENT event;
{
MEVENT event;
- /* retrieve the mouse event from ncurses */
+ /* retrieve the mouse event from curses */
+#ifdef PDCURSES
+ nc_getmouse(&event);
+#else
getmouse(&event);
getmouse(&event);
+#endif
/* calculate the selected row in the list window */
*row = event.y - screen.title_bar.window.rows;
/* copy button state bits */
/* calculate the selected row in the list window */
*row = event.y - screen.title_bar.window.rows;
/* copy button state bits */
screen_cmd(struct mpdclient *c, command_t cmd)
{
#ifndef NCMPC_MINI
screen_cmd(struct mpdclient *c, command_t cmd)
{
#ifndef NCMPC_MINI
- welcome = FALSE;
+ if (screen.welcome_source_id != 0) {
+ g_source_remove(screen.welcome_source_id);
+ screen.welcome_source_id = 0;
+ }
#endif
#endif
- if (mode_fn->cmd != NULL && mode_fn->cmd(c, cmd))
+ if (screen.current_page->cmd != NULL &&
+ screen.current_page->cmd(c, cmd))
return;
if (handle_player_command(c, cmd))
return;
if (handle_player_command(c, cmd))
_("Auto center mode: Off"));
break;
case CMD_SCREEN_UPDATE:
_("Auto center mode: Off"));
break;
case CMD_SCREEN_UPDATE:
- screen_paint(c);
+ screen_paint(c, true);
break;
case CMD_SCREEN_PREVIOUS:
screen_next_mode(c, -1);
break;
case CMD_SCREEN_PREVIOUS:
screen_next_mode(c, -1);
screen_next_mode(c, 1);
break;
case CMD_SCREEN_PLAY:
screen_next_mode(c, 1);
break;
case CMD_SCREEN_PLAY:
- screen_switch(&screen_playlist, c);
+ screen_switch(&screen_queue, c);
break;
case CMD_SCREEN_FILE:
screen_switch(&screen_browse, c);
break;
case CMD_SCREEN_FILE:
screen_switch(&screen_browse, c);
case CMD_SCREEN_OUTPUTS:
screen_switch(&screen_outputs, c);
break;
case CMD_SCREEN_OUTPUTS:
screen_switch(&screen_outputs, c);
break;
+#endif
+#ifdef ENABLE_CHAT_SCREEN
+ case CMD_SCREEN_CHAT:
+ screen_switch(&screen_chat, c);
+ break;
+#endif
case CMD_SCREEN_SWAP:
screen_swap(c, NULL);
break;
case CMD_SCREEN_SWAP:
screen_swap(c, NULL);
break;
-#endif
default:
break;
default:
break;