From: Max Kellermann Date: Thu, 25 Sep 2008 19:21:29 +0000 (+0200) Subject: screen: removed screen.mode X-Git-Tag: v0.12_alpha1~143 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=fb70ff1a3441d1076ba9eafe61d94b81190dda44;p=ncmpc.git screen: removed screen.mode Everything is now managed with a pointer to the screen_functions struct. --- diff --git a/src/screen.c b/src/screen.c index 2124a2b..9c7ca50 100644 --- a/src/screen.c +++ b/src/screen.c @@ -56,22 +56,17 @@ screen_is_visible(const struct screen_functions *sf) static void switch_screen_mode(const struct screen_functions *sf, mpdclient_t *c) { - gint new_mode; + assert(sf != NULL); if (sf == mode_fn) return; - new_mode = lookup_mode(sf); - if (new_mode < 0) - return; - /* close the old mode */ if (mode_fn->close != NULL) mode_fn->close(); /* get functions for the new mode */ mode_fn = sf; - screen.mode = new_mode; screen.painted = 0; /* open the new mode */ @@ -96,9 +91,10 @@ screen_next_mode(mpdclient_t *c, int offset) { int max = g_strv_length(options.screen_list); int current, next; + const struct screen_functions *sf; /* find current screen */ - current = find_configured_screen(screen_get_name(screen.mode)); + current = find_configured_screen(screen_get_name(mode_fn)); next = current + offset; if (next<0) next = max-1; @@ -106,7 +102,9 @@ screen_next_mode(mpdclient_t *c, int offset) next = 0; D("current mode: %d:%d next:%d\n", current, max, next); - switch_screen_mode(screen_lookup_name(options.screen_list[next]), c); + sf = screen_lookup_name(options.screen_list[next]); + if (sf != NULL) + switch_screen_mode(sf, c); } static void @@ -447,7 +445,6 @@ screen_init(mpdclient_t *c) exit(EXIT_FAILURE); } - screen.mode = 0; screen.cols = COLS; screen.rows = LINES; diff --git a/src/screen.h b/src/screen.h index dc7e239..1eac4d6 100644 --- a/src/screen.h +++ b/src/screen.h @@ -32,8 +32,6 @@ typedef struct screen { unsigned cols, rows; - int mode; - char *buf; size_t buf_size; diff --git a/src/screen_list.c b/src/screen_list.c index fddeeb0..31e8ada 100644 --- a/src/screen_list.c +++ b/src/screen_list.c @@ -86,11 +86,15 @@ screen_list_resize(unsigned cols, unsigned rows) } const char * -screen_get_name(unsigned i) +screen_get_name(const struct screen_functions *sf) { - assert(i < NUM_SCREENS); + unsigned i; + + for (i = 0; i < NUM_SCREENS; ++i) + if (screens[i].functions == sf) + return screens[i].name; - return screens[i].name; + return NULL; } const struct screen_functions * @@ -104,15 +108,3 @@ screen_lookup_name(const char *name) return NULL; } - -int -lookup_mode(const struct screen_functions *sf) -{ - unsigned i; - - for (i = 0; i < NUM_SCREENS; ++i) - if (screens[i].functions == sf) - return i; - - return -1; -} diff --git a/src/screen_list.h b/src/screen_list.h index 583c225..1293b74 100644 --- a/src/screen_list.h +++ b/src/screen_list.h @@ -50,7 +50,7 @@ void screen_list_resize(unsigned cols, unsigned rows); const char * -screen_get_name(unsigned i); +screen_get_name(const struct screen_functions *sf); const struct screen_functions * screen_lookup_name(const char *name); @@ -58,7 +58,4 @@ screen_lookup_name(const char *name); int screen_get_id(const char *name); -int -lookup_mode(const struct screen_functions *sf); - #endif