From: Max Kellermann Date: Wed, 30 Sep 2009 06:21:57 +0000 (+0200) Subject: screen: moved more (de)initialization code to progress_bar.c X-Git-Tag: release-0.16~284 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=eb14b2787be41d58e19316976e2d6b117b040993;p=ncmpc.git screen: moved more (de)initialization code to progress_bar.c --- diff --git a/src/progress_bar.c b/src/progress_bar.c index 8fe2784..37a3977 100644 --- a/src/progress_bar.c +++ b/src/progress_bar.c @@ -40,13 +40,11 @@ progress_bar_paint(const struct progress_bar *p) wnoutrefresh(p->window.w); } -bool -progress_bar_resize(struct progress_bar *p) +static bool +progress_bar_calc(struct progress_bar *p) { unsigned old_width; - assert(p != NULL); - if (p->max == 0) return false; @@ -57,6 +55,18 @@ progress_bar_resize(struct progress_bar *p) return p->width != old_width; } +void +progress_bar_resize(struct progress_bar *p, unsigned width, int y, int x) +{ + assert(p != NULL); + + p->window.cols = width; + wresize(p->window.w, 1, width); + mvwin(p->window.w, y, x); + + progress_bar_calc(p); +} + bool progress_bar_set(struct progress_bar *p, unsigned current, unsigned max) { @@ -72,5 +82,5 @@ progress_bar_set(struct progress_bar *p, unsigned current, unsigned max) p->max = max; p->current = current; - return progress_bar_resize(p) || modified; + return progress_bar_calc(p) || modified; } diff --git a/src/progress_bar.h b/src/progress_bar.h index d6fdba5..94a7600 100644 --- a/src/progress_bar.h +++ b/src/progress_bar.h @@ -33,21 +33,27 @@ struct progress_bar { }; static inline void -progress_bar_init(struct progress_bar *p, unsigned height, unsigned width, - int y, int x) +progress_bar_init(struct progress_bar *p, unsigned width, int y, int x) { - window_init(&p->window, height, width, y, x); + window_init(&p->window, 1, width, y, x); + leaveok(p->window.w, TRUE); p->current = 0; p->max = 0; p->width = 0; } +static inline void +progress_bar_deinit(struct progress_bar *p) +{ + delwin(p->window.w); +} + void progress_bar_paint(const struct progress_bar *p); -bool -progress_bar_resize(struct progress_bar *p); +void +progress_bar_resize(struct progress_bar *p, unsigned width, int y, int x); bool progress_bar_set(struct progress_bar *p, unsigned current, unsigned max); diff --git a/src/screen.c b/src/screen.c index 15a98d0..a4f0a89 100644 --- a/src/screen.c +++ b/src/screen.c @@ -454,7 +454,7 @@ screen_exit(void) delwin(screen.top_window.w); delwin(screen.main_window.w); - delwin(screen.progress_bar.window.w); + progress_bar_deinit(&screen.progress_bar); delwin(screen.status_window.w); } @@ -483,10 +483,8 @@ screen_resize(struct mpdclient *c) wclear(screen.main_window.w); /* progress window */ - screen.progress_bar.window.cols = screen.cols; - wresize(screen.progress_bar.window.w, 1, screen.cols); - mvwin(screen.progress_bar.window.w, screen.rows-2, 0); - progress_bar_resize(&screen.progress_bar); + progress_bar_resize(&screen.progress_bar, screen.cols, + screen.rows - 2, 0); progress_bar_paint(&screen.progress_bar); /* status window */ @@ -562,12 +560,10 @@ screen_init(struct mpdclient *c) keypad(screen.main_window.w, TRUE); /* create progress window */ - progress_bar_init(&screen.progress_bar, 1, screen.cols, + progress_bar_init(&screen.progress_bar, screen.cols, screen.rows - 2, 0); progress_bar_paint(&screen.progress_bar); - leaveok(screen.progress_bar.window.w, TRUE); - /* create status window */ window_init(&screen.status_window, 1, screen.cols, screen.rows - 1, 0);