Index: apps/gui/viewport.c =================================================================== --- apps/gui/viewport.c (revision 18145) +++ apps/gui/viewport.c (working copy) @@ -33,7 +33,20 @@ #include "viewport.h" #include "statusbar.h" #include "screen_access.h" +#include "debug.h" +#define VP_STRUCTURE_PARAM_ERROR 0 +static struct viewport viewports[NB_SCREENS][VPDIM_COUNT]; +static int viewport_setup[NB_SCREENS]; +static const char* setting_strings[] = { + [VPDIM_DEFAULT] = "default", + [VPDIM_GENERICLIST] = "lists", + [VPDIM_MENUS] = "menus", + [VPDIM_BROWSERS] = "browsers", + [VPDIM_WPS] = "wps", + [VPDIM_QUICKSCREEN] = "quickscreen" +}; + int viewport_get_nb_lines(struct viewport *vp) { #ifdef HAVE_LCD_BITMAP @@ -44,7 +57,6 @@ #endif } - void viewport_set_defaults(struct viewport *vp, enum screen_type screen) { vp->x = 0; @@ -82,3 +94,151 @@ } #endif } + +static void parse_viewport_config_file(const char *filename, enum screen_type screen) +{ + char buf[MAX_PATH]; + int i = 0; + char* name; + char* value; + int fd = open(filename, O_RDONLY); + if (fd < 0) + return; + + while (read_line(fd, buf, MAX_PATH) > 0) + { + if (!settings_parseline(buf, &name, &value)) + continue; + for (i=VPDIM_FIRSTCONFIGURABLE; ix, &vp->y, &vp->width, + &vp->height, &vp->font, &vp->fg_pattern,&vp->bg_pattern))) + return VP_STRUCTURE_PARAM_ERROR; + } + else +#endif +#if (LCD_DEPTH == 2) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 2) + if (depth == 2) { + if (!(ptr = parse_list("dddddgg", &set, seperator, ptr, &vp->x, &vp->y, &vp->width, + &vp->height, &vp->font, &vp->fg_pattern, &vp->bg_pattern))) + return VP_STRUCTURE_PARAM_ERROR; + } + else +#endif +#if (LCD_DEPTH == 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 1) + if (depth == 1) + { + if (!(ptr = parse_list("ddddd", &set, seperator, ptr, &vp->x, &vp->y, &vp->width, + &vp->height, &vp->font))) + return VP_STRUCTURE_PARAM_ERROR; + } + else +#endif + {} + + if (!LIST_VALUE_PARSED(set, PL_X) || !LIST_VALUE_PARSED(set, PL_Y)) + return VP_STRUCTURE_PARAM_ERROR; + + /* fix defaults */ + if (!LIST_VALUE_PARSED(set, PL_WIDTH)) + vp->width = screens[screen].lcdwidth - vp->x; + if (!LIST_VALUE_PARSED(set, PL_HEIGHT)) + vp->height = screens[screen].lcdheight - vp->y; + +#if (LCD_DEPTH == 16) + if (!LIST_VALUE_PARSED(set, PL_FG)) + vp->fg_pattern = global_settings.fg_color; + if (!LIST_VALUE_PARSED(set, PL_BG)) + vp->bg_pattern = global_settings.bg_color; +#endif + /* Validate the viewport dimensions - we know that the numbers are + non-negative integers */ + if ((vp->x >= screens[screen].lcdwidth) || + ((vp->x + vp->width) > screens[screen].lcdwidth) || + (vp->y >= screens[screen].lcdheight) || + ((vp->y + vp->height) > screens[screen].lcdheight)) + { + return VP_STRUCTURE_PARAM_ERROR; + } + + /* Default to using the user font if the font was an invalid number */ + + if ((vp->font != FONT_SYSFIXED) && (vp->font != FONT_UI)) + vp->font = FONT_UI; + + return ptr; +} + +#endif Index: apps/gui/viewport.h =================================================================== --- apps/gui/viewport.h (revision 18145) +++ apps/gui/viewport.h (working copy) @@ -28,15 +28,37 @@ #include "misc.h" #include "screen_access.h" +#ifndef _VIEWPORT_H_ +#define _VIEWPORT_H_ + +enum viewport_dimension_config { + VPDIM_FULLSCREEN = 0, /* gets the viewport that contains the full display */ + + VPDIM_FIRSTCONFIGURABLE, + VPDIM_DEFAULT = VPDIM_FIRSTCONFIGURABLE, + VPDIM_GENERICLIST, + VPDIM_MENUS, + VPDIM_BROWSERS, + VPDIM_WPS, /* probably not needed */ + VPDIM_QUICKSCREEN, + + /* this should be safe, but if this becomes more than 32 viewport_setup in viewport.c needs fixing */ + + VPDIM_COUNT, +}; + + /* return the number of text lines in the vp viewport */ int viewport_get_nb_lines(struct viewport *vp); -#define VP_ERROR 0 -#define VP_DIMENSIONS 0x1 -#define VP_COLORS 0x2 -#define VP_SELECTIONCOLORS 0x4 -/* load a viewport struct from a config string. - returns a combination of the above to say which were loaded ok from the string */ -int viewport_load_config(const char *config, struct viewport *vp); +void viewport_set_defaults(struct viewport *vp, /*enum viewport_dimension_config, + */enum screen_type screen); -void viewport_set_defaults(struct viewport *vp, enum screen_type screen); +const struct viewport* viewport_get_viewport(enum viewport_dimension_config viewport_type, + enum screen_type screen); +const char* viewport_parse_viewport(struct viewport *vp, + const char *ptr, char seperator, enum screen_type screen); + +void viewport_init(void); + +#endif /* _VIEWPORT_H_ */ Index: apps/gui/wps_parser.c =================================================================== --- apps/gui/wps_parser.c (revision 18145) +++ apps/gui/wps_parser.c (working copy) @@ -26,6 +26,7 @@ #include "file.h" #include "misc.h" #include "plugin.h" +#include "viewport.h" #ifdef __PCTOOL__ #define DEBUGF printf @@ -566,26 +567,6 @@ { (void)token; /* Kill warnings */ const char *ptr = wps_bufptr; - struct viewport* vp; - int depth; - uint32_t set = 0; - enum { - PL_X = 0, - PL_Y, - PL_WIDTH, - PL_HEIGHT, - PL_FONT, - PL_FG, - PL_BG, - }; - int lcd_width = LCD_WIDTH, lcd_height = LCD_HEIGHT; -#ifdef HAVE_REMOTE_LCD - if (wps_data->remote_wps) - { - lcd_width = LCD_REMOTE_WIDTH; - lcd_height = LCD_REMOTE_HEIGHT; - } -#endif if (wps_data->num_viewports >= WPS_MAX_VIEWPORTS) return WPS_ERROR_INVALID_PARAM; @@ -614,7 +595,7 @@ return WPS_ERROR_INVALID_PARAM; ptr++; - vp = &wps_data->viewports[wps_data->num_viewports].vp; + struct viewport *vp = &wps_data->viewports[wps_data->num_viewports].vp; /* format: %V|x|y|width|height|font|fg_pattern|bg_pattern| */ /* Set the defaults for fields not user-specified */ @@ -622,80 +603,27 @@ /* Work out the depth of this display */ #ifdef HAVE_REMOTE_LCD - depth = (wps_data->remote_wps ? LCD_REMOTE_DEPTH : LCD_DEPTH); -#else - depth = LCD_DEPTH; -#endif - -#ifdef HAVE_LCD_COLOR - if (depth == 16) + if (!(wps_data->remote_wps)) { - if (!(ptr = parse_list("dddddcc", &set, '|', ptr, &vp->x, &vp->y, &vp->width, - &vp->height, &vp->font, &vp->fg_pattern,&vp->bg_pattern))) - return WPS_ERROR_INVALID_PARAM; - } - else #endif -#if (LCD_DEPTH == 2) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 2) - if (depth == 2) { - /* Default to black on white */ - vp->fg_pattern = 0; - vp->bg_pattern = 3; - if (!(ptr = parse_list("dddddgg", &set, '|', ptr, &vp->x, &vp->y, &vp->width, - &vp->height, &vp->font, &vp->fg_pattern, &vp->bg_pattern))) + if (!(ptr = viewport_parse_viewport(vp, ptr, '|', SCREEN_MAIN))) return WPS_ERROR_INVALID_PARAM; +#ifdef HAVE_REMOTE_LCD } - else -#endif -#if (LCD_DEPTH == 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 1) - if (depth == 1) + else { - if (!(ptr = parse_list("ddddd", &set, '|', ptr, &vp->x, &vp->y, - &vp->width, &vp->height, &vp->font))) + if (!(ptr = viewport_parse_viewport(vp, ptr, '|', SCREEN_REMOTE))) return WPS_ERROR_INVALID_PARAM; } - else + #endif - {} + /* Check for trailing | */ if (*ptr != '|') return WPS_ERROR_INVALID_PARAM; - if (!LIST_VALUE_PARSED(set, PL_X) || !LIST_VALUE_PARSED(set, PL_Y)) - return WPS_ERROR_INVALID_PARAM; - - /* fix defaults */ - if (!LIST_VALUE_PARSED(set, PL_WIDTH)) - vp->width = lcd_width - vp->x; - if (!LIST_VALUE_PARSED(set, PL_HEIGHT)) - vp->height = lcd_height - vp->y; - - /* Default to using the user font if the font was an invalid number */ - if (!LIST_VALUE_PARSED(set, PL_FONT) || - ((vp->font != FONT_SYSFIXED) && (vp->font != FONT_UI))) - vp->font = FONT_UI; - /* Validate the viewport dimensions - we know that the numbers are - non-negative integers */ - if ((vp->x >= lcd_width) || - ((vp->x + vp->width) > lcd_width) || - (vp->y >= lcd_height) || - ((vp->y + vp->height) > lcd_height)) - { - return WPS_ERROR_INVALID_PARAM; - } - -#ifdef HAVE_LCD_COLOR - if (depth == 16) - { - if (!LIST_VALUE_PARSED(set, PL_FG)) - vp->fg_pattern = global_settings.fg_color; - if (!LIST_VALUE_PARSED(set, PL_BG)) - vp->bg_pattern = global_settings.bg_color; - } -#endif - wps_data->viewports[wps_data->num_viewports-1].last_line = wps_data->num_lines - 1; wps_data->viewports[wps_data->num_viewports].first_line = wps_data->num_lines; Index: apps/root_menu.c =================================================================== --- apps/root_menu.c (revision 18145) +++ apps/root_menu.c (working copy) @@ -46,6 +46,7 @@ #include "buttonbar.h" #include "action.h" #include "yesno.h" +#include "viewport.h" #include "tree.h" #if CONFIG_TUNER @@ -498,7 +499,11 @@ { int previous_browser = GO_TO_FILEBROWSER; int next_screen = GO_TO_ROOT; - int selected = 0; + int selected = 0, i; + struct viewport vp[NB_SCREENS]; + + FOR_NB_SCREENS(i) + vp[i] = *viewport_get_viewport(VPDIM_MENUS, i); if (global_settings.start_in_screen == 0) next_screen = (int)global_status.last_screen; @@ -539,7 +544,7 @@ case GO_TO_ROOT: if (last_screen != GO_TO_ROOT) selected = get_selection(last_screen); - next_screen = do_menu(&root_menu_, &selected, NULL, false); + next_screen = do_menu(&root_menu_, &selected, vp, false); if (next_screen != GO_TO_PREVIOUS) last_screen = GO_TO_ROOT; break; Index: apps/main.c =================================================================== --- apps/main.c (revision 18145) +++ apps/main.c (working copy) @@ -130,6 +130,7 @@ screens[i].clear_display(); screens[i].update(); } + viewport_init(); tree_gui_init(); #ifdef HAVE_TOUCHPAD touchpad_set_mode(TOUCHPAD_BUTTON);