Code

screen: pass screen_functions pointer to switch_screen_mode()
authorMax Kellermann <max@duempel.org>
Thu, 25 Sep 2008 19:21:00 +0000 (21:21 +0200)
committerMax Kellermann <max@duempel.org>
Thu, 25 Sep 2008 19:21:00 +0000 (21:21 +0200)
Trying to get rid of the screen ids.  A pointer to screen_functions is
better for identifying a screen.

src/conf.c
src/screen.c
src/screen_list.c
src/screen_list.h

index c02df52cf42f79e19273c0b8ca96aef27076f8d9..557024dc52967ce726fda045552ea9dab03bb62a 100644 (file)
@@ -25,6 +25,7 @@
 #include "support.h"
 #include "command.h"
 #include "colors.h"
+#include "screen_list.h"
 
 #include <ctype.h>
 #include <stdio.h>
@@ -81,10 +82,6 @@ typedef enum {
   KEY_PARSER_DONE
 } key_parser_state_t;
 
-
-extern gint screen_get_id(char *name);
-
-
 static gboolean
 str2bool(char *str)
 {
@@ -337,7 +334,7 @@ check_screen_list(char *value)
        j=0;
        while( tmp && tmp[i] ) {
                tmp[i] = lowerstr(tmp[i]);
-               if( screen_get_id(tmp[i]) == -1 )
+               if (screen_lookup_name(tmp[i]) == NULL)
                        fprintf(stderr,
                                _("Error: Unsupported screen \"%s\"\n"),
                                tmp[i]);
index 02df03b528df4a0a4231527c8210a1ab5019e777..2124a2b7489c81cc0709616a6d5ede22af50b638 100644 (file)
@@ -54,14 +54,14 @@ screen_is_visible(const struct screen_functions *sf)
 }
 
 static void
-switch_screen_mode(gint id, mpdclient_t *c)
+switch_screen_mode(const struct screen_functions *sf, mpdclient_t *c)
 {
        gint new_mode;
 
-       if (id == screen_get_id_by_index(screen.mode))
+       if (sf == mode_fn)
                return;
 
-       new_mode = lookup_mode(id);
+       new_mode = lookup_mode(sf);
        if (new_mode < 0)
                return;
 
@@ -70,7 +70,7 @@ switch_screen_mode(gint id, mpdclient_t *c)
                mode_fn->close();
 
        /* get functions for the new mode */
-       mode_fn = screen_get_functions(new_mode);
+       mode_fn = sf;
        screen.mode = new_mode;
        screen.painted = 0;
 
@@ -106,7 +106,7 @@ 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_get_id(options.screen_list[next]), c);
+       switch_screen_mode(screen_lookup_name(options.screen_list[next]), c);
 }
 
 static void
@@ -792,26 +792,34 @@ screen_cmd(mpdclient_t *c, command_t cmd)
                screen_next_mode(c, 1);
                break;
        case CMD_SCREEN_PLAY:
-               switch_screen_mode(SCREEN_PLAYLIST_ID, c);
+               switch_screen_mode(&screen_playlist, c);
                break;
        case CMD_SCREEN_FILE:
-               switch_screen_mode(SCREEN_BROWSE_ID, c);
+               switch_screen_mode(&screen_browse, c);
                break;
        case CMD_SCREEN_HELP:
-               switch_screen_mode(SCREEN_HELP_ID, c);
+               switch_screen_mode(&screen_help, c);
                break;
+#ifdef ENABLE_SEARCH_SCREEN
        case CMD_SCREEN_SEARCH:
-               switch_screen_mode(SCREEN_SEARCH_ID, c);
+               switch_screen_mode(&screen_search, c);
                break;
+#endif
+#ifdef ENABLE_ARTIST_SCREEN
        case CMD_SCREEN_ARTIST:
-               switch_screen_mode(SCREEN_ARTIST_ID, c);
+               switch_screen_mode(&screen_artist, c);
                break;
+#endif
+#ifdef ENABLE_KEYDEF_SCREEN
        case CMD_SCREEN_KEYDEF:
-               switch_screen_mode(SCREEN_KEYDEF_ID, c);
+               switch_screen_mode(&screen_keydef, c);
                break;
+#endif
+#ifdef ENABLE_LYRICS_SCREEN
        case CMD_SCREEN_LYRICS:
-               switch_screen_mode(SCREEN_LYRICS_ID, c);
+               switch_screen_mode(&screen_lyrics, c);
                break;
+#endif
        default:
                break;
        }
index 46e6244180756fbc72614626afc4761e2489eb30..76ae8b155c53978580ac3237364fcbfe18771e19 100644 (file)
@@ -86,14 +86,6 @@ screen_list_resize(unsigned cols, unsigned rows)
        }
 }
 
-int
-screen_get_id_by_index(unsigned i)
-{
-       assert(i < NUM_SCREENS);
-
-       return screens[i].id;
-}
-
 const char *
 screen_get_name(unsigned i)
 {
@@ -102,16 +94,16 @@ screen_get_name(unsigned i)
        return screens[i].name;
 }
 
-int
-screen_get_id(const char *name)
+const struct screen_functions *
+screen_lookup_name(const char *name)
 {
        unsigned i;
 
        for (i = 0; i < NUM_SCREENS; ++i)
                if (strcmp(name, screens[i].name) == 0)
-                       return screens[i].id;
+                       return screens[i].functions;
 
-       return -1;
+       return NULL;
 }
 
 const struct screen_functions *
@@ -123,12 +115,12 @@ screen_get_functions(unsigned i)
 }
 
 int
-lookup_mode(int id)
+lookup_mode(const struct screen_functions *sf)
 {
        unsigned i;
 
        for (i = 0; i < NUM_SCREENS; ++i)
-               if (screens[i].id == id)
+               if (screens[i].functions == sf)
                        return i;
 
        return -1;
index 7efed89b06c4bc12a858f41f1326b9e0abb4b321..763b4ee9be84ce033b26c896b4bedee890709f0f 100644 (file)
@@ -57,12 +57,12 @@ screen_list_exit(void);
 void
 screen_list_resize(unsigned cols, unsigned rows);
 
-int
-screen_get_id_by_index(unsigned i);
-
 const char *
 screen_get_name(unsigned i);
 
+const struct screen_functions *
+screen_lookup_name(const char *name);
+
 int
 screen_get_id(const char *name);
 
@@ -70,6 +70,6 @@ const struct screen_functions *
 screen_get_functions(unsigned i);
 
 int
-lookup_mode(int id);
+lookup_mode(const struct screen_functions *sf);
 
 #endif