diff --git a/src/screen.c b/src/screen.c
index b272935fe2c04bda83531609fbc87016c60d14f6..0d242de017fe6d1d34110a74250a664ef92183cc 100644 (file)
--- a/src/screen.c
+++ b/src/screen.c
/* ncmpc (Ncurses MPD Client)
- * (c) 2004-2010 The Music Player Daemon Project
+ * (c) 2004-2017 The Music Player Daemon Project
* Project homepage: http://musicpd.org
*
* This program is free software; you can redistribute it and/or modify
#endif
/* minimum window size */
-static const int SCREEN_MIN_COLS = 14;
-static const int SCREEN_MIN_ROWS = 5;
+static const unsigned SCREEN_MIN_COLS = 14;
+static const unsigned SCREEN_MIN_ROWS = 5;
/* screens */
if (mode_fn->open != NULL)
mode_fn->open(c);
- screen_paint(c);
+ screen_paint(c, true);
}
void
}
static void
-paint_top_window(const char *header, const struct mpdclient *c)
+paint_top_window(const struct mpdclient *c)
{
- title_bar_paint(&screen.title_bar, header, c->status);
+ const char *title =
+#ifndef NCMPC_MINI
+ screen.welcome_source_id == 0 &&
+#endif
+ mode_fn->get_title != NULL
+ ? mode_fn->get_title(screen.buf, screen.buf_size)
+ : "";
+ assert(title != NULL);
+
+ title_bar_paint(&screen.title_bar, title, c->status);
}
static void
void
screen_resize(struct mpdclient *c)
{
- if (COLS<SCREEN_MIN_COLS || LINES<SCREEN_MIN_ROWS) {
+ const unsigned cols = COLS, rows = LINES;
+ if (cols < SCREEN_MIN_COLS || rows < SCREEN_MIN_ROWS) {
screen_exit();
fprintf(stderr, "%s\n", _("Error: Screen too small"));
exit(EXIT_FAILURE);
}
+
#ifdef PDCURSES
- resize_term(LINES, COLS);
+ resize_term(rows, cols);
#else
- resizeterm(LINES, COLS);
+ resizeterm(rows, cols);
#endif
- screen.cols = COLS;
- screen.rows = LINES;
-
- title_bar_resize(&screen.title_bar, screen.cols);
+ title_bar_resize(&screen.title_bar, 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);
+ screen.main_window.cols = cols;
+ screen.main_window.rows = rows - 4;
+ wresize(screen.main_window.w, screen.main_window.rows, cols);
/* progress window */
- progress_bar_resize(&screen.progress_bar, screen.cols,
- screen.rows - 2, 0);
- progress_bar_paint(&screen.progress_bar);
+ progress_bar_resize(&screen.progress_bar, cols, rows - 2, 0);
/* status window */
- status_bar_resize(&screen.status_bar, screen.cols, screen.rows - 1, 0);
- status_bar_paint(&screen.status_bar, c->status, c->song);
+ status_bar_resize(&screen.status_bar, cols, rows - 1, 0);
- screen.buf_size = screen.cols;
+ screen.buf_size = cols;
g_free(screen.buf);
- screen.buf = g_malloc(screen.cols);
+ screen.buf = g_malloc(cols);
/* resize all screens */
screen_list_resize(screen.main_window.cols, screen.main_window.rows);
curs_set(1);
curs_set(0);
- screen_paint(c);
+ screen_paint(c, true);
}
#ifndef NCMPC_MINI
{
struct mpdclient *c = data;
-#ifndef NCMPC_MINI
screen.welcome_source_id = 0;
-#endif
- paint_top_window(mode_fn->get_title != NULL
- ? mode_fn->get_title(screen.buf, screen.buf_size)
- : "",
- c);
+ paint_top_window(c);
doupdate();
return false;
void
screen_init(struct mpdclient *c)
{
- if (COLS < SCREEN_MIN_COLS || LINES < SCREEN_MIN_ROWS) {
+ const unsigned cols = COLS, rows = LINES;
+ if (cols < SCREEN_MIN_COLS || rows < 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.buf = g_malloc(cols);
+ screen.buf_size = cols;
screen.findbuf = NULL;
#ifndef NCMPC_MINI
if (options.welcome_screen_list)
screen.welcome_source_id =
- g_timeout_add(SCREEN_WELCOME_TIME * 1000,
- welcome_timer_callback, c);
+ g_timeout_add_seconds(SCREEN_WELCOME_TIME,
+ welcome_timer_callback, c);
#endif
/* create top window */
- title_bar_init(&screen.title_bar, screen.cols, 0, 0);
+ title_bar_init(&screen.title_bar, cols, 0, 0);
/* create main window */
- window_init(&screen.main_window, screen.rows - 4, screen.cols, 2, 0);
+ window_init(&screen.main_window, rows - 4, cols, 2, 0);
if (!options.hardware_cursor)
leaveok(screen.main_window.w, TRUE);
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);
+ progress_bar_init(&screen.progress_bar, cols, rows - 2, 0);
/* 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);
+ status_bar_init(&screen.status_bar, cols, rows - 1, 0);
#ifdef ENABLE_COLORS
if (options.enable_colors) {
}
#endif
- doupdate();
-
/* initialize screens */
screen_list_init(screen.main_window.w,
screen.main_window.cols, screen.main_window.rows);
}
void
-screen_paint(struct mpdclient *c)
+screen_paint(struct mpdclient *c, bool main_dirty)
{
- 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);
+ /* update title/header window */
+ paint_top_window(c);
/* paint the bottom window */
/* paint the main window */
- wclear(screen.main_window.w);
- if (mode_fn->paint != NULL)
- mode_fn->paint();
+ if (main_dirty) {
+ wclear(screen.main_window.w);
+ if (mode_fn->paint != NULL)
+ mode_fn->paint();
+ }
/* move the cursor to the origin */
mpdclient_is_connected(c))
screen_status_printf(_("Database updated"));
was_connected = mpdclient_is_connected(c);
-
- /* update title/header window */
- if (screen.welcome_source_id != 0)
- paint_top_window("", c);
- else
#endif
- if (mode_fn->get_title != NULL) {
- paint_top_window(mode_fn->get_title(screen.buf,screen.buf_size), c);
- } else
- paint_top_window("", c);
-
- /* update progress window */
- update_progress_window(c, false);
-
- /* update status window */
- status_bar_paint(&screen.status_bar, c->status, c->song);
/* 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);
-
- /* tell curses to update */
- doupdate();
+ screen_paint(c, false);
}
#ifdef HAVE_GETMOUSE
_("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);