aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/conf.c7
-rw-r--r--src/screen.c32
-rw-r--r--src/screen_list.c20
-rw-r--r--src/screen_list.h8
4 files changed, 32 insertions, 35 deletions
diff --git a/src/conf.c b/src/conf.c
index c02df52cf..557024dc5 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -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]);
diff --git a/src/screen.c b/src/screen.c
index 02df03b52..2124a2b74 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -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;
}
diff --git a/src/screen_list.c b/src/screen_list.c
index 46e624418..76ae8b155 100644
--- a/src/screen_list.c
+++ b/src/screen_list.c
@@ -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;
diff --git a/src/screen_list.h b/src/screen_list.h
index 7efed89b0..763b4ee9b 100644
--- a/src/screen_list.h
+++ b/src/screen_list.h
@@ -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