From 9e27391e321912878f7cddaa92f2c8201c6e91de Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 25 Sep 2008 17:40:29 +0200 Subject: [PATCH] list_window: removed property "clear" Without clearing previous screen contents, there may be corruptions, make this mandatory and optimize screen clearing. --- src/list_window.c | 24 +++++++++--------------- src/list_window.h | 3 +-- src/screen_artist.c | 4 ---- src/screen_file.c | 2 -- src/screen_help.c | 1 - src/screen_keydef.c | 3 --- src/screen_lyrics.c | 2 -- src/screen_play.c | 13 +++---------- src/screen_search.c | 2 -- 9 files changed, 13 insertions(+), 41 deletions(-) diff --git a/src/list_window.c b/src/list_window.c index 5a4ccf3..e69f6ac 100644 --- a/src/list_window.c +++ b/src/list_window.c @@ -41,7 +41,6 @@ list_window_init(WINDOW *w, unsigned width, unsigned height) lw->w = w; lw->cols = width; lw->rows = height; - lw->clear = 1; return lw; } @@ -60,7 +59,6 @@ list_window_reset(struct list_window *lw) lw->selected = 0; lw->xoffset = 0; lw->start = 0; - lw->clear = 1; } void @@ -95,7 +93,7 @@ list_window_center(struct list_window *lw, unsigned rows, unsigned n) lw->start = 0; } - lw->repaint = lw->clear = 1; + lw->repaint = 1; } void @@ -172,15 +170,11 @@ list_window_paint(struct list_window *lw, int show_cursor = !(lw->flags & LW_HIDE_CURSOR); if (show_cursor) { - if (lw->selected < lw->start) { + if (lw->selected < lw->start) lw->start = lw->selected; - lw->clear=1; - } - if (lw->selected >= lw->start + lw->rows) { + if (lw->selected >= lw->start + lw->rows) lw->start = lw->selected - lw->rows + 1; - lw->clear=1; - } } for (i = 0; i < lw->rows; i++) { @@ -189,8 +183,6 @@ list_window_paint(struct list_window *lw, label = callback(lw->start + i, &highlight, callback_data); wmove(lw->w, i, 0); - if( lw->clear && (!fill || !label) ) - wclrtoeol(lw->w); if (label) { int selected = lw->start + i == lw->selected; @@ -211,10 +203,12 @@ list_window_paint(struct list_window *lw, if (selected) wattroff(lw->w, A_REVERSE); - } - } - lw->clear=0; + if (!fill && len < lw->cols) + wclrtoeol(lw->w); + } else + wclrtoeol(lw->w); + } } int @@ -359,7 +353,7 @@ list_window_scroll_cmd(struct list_window *lw, unsigned rows, command_t cmd) return 0; } - lw->repaint = lw->clear = 1; + lw->repaint = 1; return 1; } diff --git a/src/list_window.h b/src/list_window.h index 25f5362..9a348a2 100644 --- a/src/list_window.h +++ b/src/list_window.h @@ -22,7 +22,6 @@ typedef struct list_window { unsigned start; unsigned selected; unsigned xoffset; - int clear; int repaint; int flags; } list_window_t; @@ -39,7 +38,7 @@ struct list_window *list_window_init(WINDOW *w, /* destroy a list window (returns NULL) */ void list_window_free(struct list_window *lw); -/* reset a list window (selected=0, start=0, clear=1) */ +/* reset a list window (selected=0, start=0) */ void list_window_reset(struct list_window *lw); /* paint a list window */ diff --git a/src/screen_artist.c b/src/screen_artist.c index 4abd585..bf7e54d 100644 --- a/src/screen_artist.c +++ b/src/screen_artist.c @@ -150,7 +150,6 @@ update_metalist(mpdclient_t *c, char *m_artist, char *m_album) mode = LIST_ARTISTS; } metalist_length = g_list_length(metalist); - browser.lw->clear = TRUE; } /* db updated */ @@ -160,7 +159,6 @@ browse_callback(mpdclient_t *c, int event, mpd_unused gpointer data) switch(event) { case BROWSE_DB_UPDATED: D("screen_artist.c> browse_callback() [BROWSE_DB_UPDATED]\n"); - browser.lw->clear = 1; update_metalist(c, g_strdup(artist), g_strdup(album)); break; default: @@ -215,8 +213,6 @@ resize(int cols, int rows) static void paint(mpd_unused screen_t *screen, mpd_unused mpdclient_t *c) { - browser.lw->clear = 1; - if (browser.filelist) { list_window_paint(browser.lw, browser_lw_callback, browser.filelist); diff --git a/src/screen_file.c b/src/screen_file.c index f2384ec..8f9c6c8 100644 --- a/src/screen_file.c +++ b/src/screen_file.c @@ -177,8 +177,6 @@ browse_title(char *str, size_t size) static void browse_paint(mpd_unused screen_t *screen, mpd_unused mpdclient_t *c) { - browser.lw->clear = 1; - list_window_paint(browser.lw, browser_lw_callback, browser.filelist); wnoutrefresh(browser.lw->w); } diff --git a/src/screen_help.c b/src/screen_help.c index e440672..eec76d1 100644 --- a/src/screen_help.c +++ b/src/screen_help.c @@ -210,7 +210,6 @@ help_title(mpd_unused char *str, mpd_unused size_t size) static void help_paint(mpd_unused screen_t *screen, mpd_unused mpdclient_t *c) { - lw->clear = 1; list_window_paint(lw, list_callback, NULL); wrefresh(lw->w); } diff --git a/src/screen_keydef.c b/src/screen_keydef.c index 3dda0ec..38ba315 100644 --- a/src/screen_keydef.c +++ b/src/screen_keydef.c @@ -134,7 +134,6 @@ delete_key(int cmd_index, int key_index) cmds[cmd_index].keys[key_index] = 0; cmds[cmd_index].flags |= COMMAND_KEY_MODIFIED; check_subcmd_length(); - lw->clear = 1; lw->repaint = 1; /* update key conflict flags */ check_key_bindings(cmds, NULL, 0); @@ -281,7 +280,6 @@ keydef_title(char *str, size_t size) static void keydef_paint(mpd_unused screen_t *screen, mpd_unused mpdclient_t *c) { - lw->clear = 1; list_window_paint(lw, list_callback, NULL); wrefresh(lw->w); } @@ -327,7 +325,6 @@ keydef_cmd(screen_t *screen, mpd_unused mpdclient_t *c, command_t cmd) lw->selected - STATIC_SUB_ITEMS); } lw->repaint = 1; - lw->clear = 1; return 1; case CMD_DELETE: if (subcmd >= 0 && lw->selected >= STATIC_SUB_ITEMS) diff --git a/src/screen_lyrics.c b/src/screen_lyrics.c index 9b9ea03..1525800 100644 --- a/src/screen_lyrics.c +++ b/src/screen_lyrics.c @@ -126,7 +126,6 @@ screen_lyrics_set(const GString *str) /* paint new data */ if (get_cur_mode_id() == 104) { /* XXX don't use the literal number */ - lw->clear = 1; list_window_paint(lw, list_callback, NULL); wrefresh(lw->w); @@ -265,7 +264,6 @@ lyrics_title(char *str, size_t size) static void lyrics_paint(mpd_unused screen_t *screen, mpd_unused mpdclient_t *c) { - lw->clear = 1; list_window_paint(lw, list_callback, NULL); wrefresh(lw->w); } diff --git a/src/screen_play.c b/src/screen_play.c index 6df8c9f..579d4f4 100644 --- a/src/screen_play.c +++ b/src/screen_play.c @@ -67,8 +67,7 @@ playlist_changed_callback(mpdclient_t *c, int event, gpointer data) default: break; } - /* make shure the playlist is repainted */ - lw->clear = 1; + list_window_check_selected(lw, c->playlist.list->len); } @@ -139,10 +138,8 @@ save_post_completion_cb(mpd_unused GCompletion *gcmp, mpd_unused gchar *line, completion_callback_data_t *tmp = (completion_callback_data_t *)data; screen_t *screen = tmp->screen; - if (g_list_length(items) >= 1) { + if (g_list_length(items) >= 1) screen_display_completion_list(screen, items); - lw->clear = 1; - } } int @@ -266,10 +263,8 @@ static void add_post_completion_cb(GCompletion *gcmp, gchar *line, screen_t *screen = tmp->screen; D("post_completion()...\n"); - if (g_list_length(items) >= 1) { + if (g_list_length(items) >= 1) screen_display_completion_list(screen, items); - lw->clear = 1; - } if (line && line[0] && line[strlen(line) - 1] == '/' && string_list_find(*dir_list, line) == NULL) { @@ -366,8 +361,6 @@ play_title(char *str, size_t size) static void play_paint(mpd_unused screen_t *screen, mpdclient_t *c) { - lw->clear = 1; - list_window_paint(lw, list_callback, (void *) c); wnoutrefresh(lw->w); } diff --git a/src/screen_search.c b/src/screen_search.c index 8242f13..5995b79 100644 --- a/src/screen_search.c +++ b/src/screen_search.c @@ -389,8 +389,6 @@ resize(int cols, int rows) static void paint(mpd_unused screen_t *screen, mpdclient_t *c) { - browser.lw->clear = 1; - if (browser.filelist) { browser.lw->flags = 0; list_window_paint(browser.lw, browser_lw_callback, browser.filelist); -- 2.30.2