X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fscreen.c;h=a08cf595dab01ad5c1616aeff53b2ffa8b362f52;hb=655cd7831d0226c2e223280c61228be26f1bb8f8;hp=793eec93a0ddbe2e3ac9548bf97302e016ed8d73;hpb=93001c8e449461edaf891bee4d371dc0da57d38a;p=ncmpc.git diff --git a/src/screen.c b/src/screen.c index 793eec9..a08cf59 100644 --- a/src/screen.c +++ b/src/screen.c @@ -55,43 +55,39 @@ 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; +static const unsigned SCREEN_MIN_COLS = 14; +static const unsigned SCREEN_MIN_ROWS = 5; /* screens */ -struct screen screen; -static const struct screen_functions *mode_fn = &screen_queue; -static const struct screen_functions *mode_fn_prev = &screen_queue; +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); - if (sf == mode_fn) + if (sf == screen.current_page) return; - mode_fn_prev = mode_fn; + mode_fn_prev = screen.current_page; /* 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 */ - mode_fn = sf; + screen.current_page = sf; /* 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 @@ -134,7 +130,7 @@ screen_next_mode(struct mpdclient *c, int offset) int max = g_strv_length(options.screen_list); /* find current screen */ - int current = find_configured_screen(screen_get_name(mode_fn)); + int current = find_configured_screen(screen_get_name(screen.current_page)); int next = current + offset; if (next<0) next = max-1; @@ -148,9 +144,18 @@ screen_next_mode(struct mpdclient *c, int offset) } 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 + screen.current_page->get_title != NULL + ? screen.current_page->get_title(screen.buf, screen.buf_size) + : ""; + assert(title != NULL); + + title_bar_paint(&screen.title_bar, title, c->status); } static void @@ -176,8 +181,8 @@ update_progress_window(struct mpdclient *c, bool repaint) void screen_exit(void) { - if (mode_fn->close != NULL) - mode_fn->close(); + if (screen.current_page->close != NULL) + screen.current_page->close(); screen_list_exit(); @@ -199,37 +204,35 @@ screen_exit(void) void screen_resize(struct mpdclient *c) { - if (COLSget_title != NULL - ? mode_fn->get_title(screen.buf, screen.buf_size) - : "", - c); + paint_top_window(c); doupdate(); return false; @@ -264,30 +262,28 @@ welcome_timer_callback(gpointer data) 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); @@ -295,11 +291,10 @@ screen_init(struct mpdclient *c) keypad(screen.main_window.w, TRUE); /* create progress window */ - progress_bar_init(&screen.progress_bar, screen.cols, - screen.rows - 2, 0); + 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_init(&screen.status_bar, cols, rows - 1, 0); #ifdef ENABLE_COLORS if (options.enable_colors) { @@ -318,23 +313,15 @@ screen_init(struct mpdclient *c) screen_list_init(screen.main_window.w, screen.main_window.cols, screen.main_window.rows); - if (mode_fn->open != NULL) - mode_fn->open(c); + if (screen.current_page->open != NULL) + screen.current_page->open(c); } -static void -screen_refresh(struct mpdclient *c, bool main_dirty) +void +screen_paint(struct mpdclient *c, bool main_dirty) { /* update title/header window */ - 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); - paint_top_window(title, c); + paint_top_window(c); /* paint the bottom window */ @@ -345,8 +332,8 @@ screen_refresh(struct mpdclient *c, bool main_dirty) if (main_dirty) { wclear(screen.main_window.w); - if (mode_fn->paint != NULL) - mode_fn->paint(); + if (screen.current_page->paint != NULL) + screen.current_page->paint(); } /* move the cursor to the origin */ @@ -360,12 +347,6 @@ screen_refresh(struct mpdclient *c, bool main_dirty) doupdate(); } -void -screen_paint(struct mpdclient *c) -{ - screen_refresh(c, true); -} - void screen_update(struct mpdclient *c) { @@ -436,10 +417,10 @@ screen_update(struct mpdclient *c) #endif /* update the main window */ - if (mode_fn->update != NULL) - mode_fn->update(c); + if (screen.current_page->update != NULL) + screen.current_page->update(c); - screen_refresh(c, false); + screen_paint(c, false); } #ifdef HAVE_GETMOUSE @@ -478,7 +459,8 @@ screen_cmd(struct mpdclient *c, command_t cmd) } #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)) @@ -498,7 +480,7 @@ screen_cmd(struct mpdclient *c, command_t cmd) _("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);