static cairo_test_status_t draw (cairo_t *cr, int width, int height) { settings_t check; settings_set (cr, &settings[0]); cairo_save (cr); { settings_set (cr, &settings[1]); if (settings_get (cr, &check)) return CAIRO_TEST_FAILURE; if (!settings_equal (&settings[1], &check)) return CAIRO_TEST_FAILURE; } cairo_restore (cr); if (settings_get (cr, &check)) return CAIRO_TEST_FAILURE; if (!settings_equal (&settings[0], &check)) return CAIRO_TEST_FAILURE; return CAIRO_TEST_SUCCESS; }
/** * Reads settings from environment variables. Right now, these are not * generic variables, but only a few specific variables are read. These are: * * http_proxy - proxy URL * ZEN_INTERFACE - interface name * ZEN_DEFAULT_PAGE - default URL */ static void interpret_environment(void) { char *value; value = getenv("http_proxy"); if(value != NULL) settings_set("http_proxy", (void *)value, SETTING_STRING); value = getenv("ZEN_INTERFACE"); if(value != NULL) settings_set("interface", (void *)value, SETTING_STRING); value = getenv("ZEN_DEFAULT_PAGE"); if(value != NULL) settings_set("default_page", (void *)value, SETTING_STRING); }
void state_changed() { hotkey_t hk; REFRESH_KEY_SETTING(trigger); settings_set(TRIGGER_KEY, &hk); REFRESH_KEY_SETTING(english); settings_set(ENG_KEY, &hk); varchar colorstr; REFRESH_COLOR_SETTING(background_color_btn); settings_set(PREEDIT_COLOR, colorstr); REFRESH_COLOR_SETTING(font_color_btn); settings_set(PREEDIT_FONT_COLOR, colorstr); /* font and size information */ settings_set(PREEDIT_FONT, (void*) gtk_font_button_get_font_name(font_btn)); /* font color information */ double scale = gtk_adjustment_get_value(opacity_value); settings_set(PREEDIT_OPACITY, &scale); int ncandi = gtk_adjustment_get_value(ncandidates); settings_set(CANDIDATES_SIZE, &ncandi); settings_save(); /* notify all running xsunpinyin with this user */ char cmd[256]; snprintf(cmd, 256, "/usr/bin/pkill -10 '^xsunpinyin$' -u %d", getuid()); system(cmd); }
static GString* cb_write_compat(HSAttribute* attr, const char* new_value) { SettingsPair* sp = (SettingsPair*)attr->data; GString* out = NULL; if (0 != settings_set(sp, new_value)) { out = g_string_new(""); g_string_append_printf(out, "Can not set %s to \"%s\"\n", sp->name, new_value); } return out; }
static bool set_eui64_to_eeprom(const uint8_t macptr[8]) { #if JACKDAW_CONF_USE_SETTINGS return settings_set(SETTINGS_KEY_EUI64, macptr, 8)==SETTINGS_STATUS_OK; #else eeprom_write_block((void *)macptr, &mac_address, 8); return true; #endif }
//TODO -implement me static bool cmd_settings_symbol(Serial* pSer, char* value, size_t len) { if(len >= 2) { settings_set(SETTINGS_SYMBOL,value,2); settings_save(); } uint8_t symbol[2]; uint8_t bufLen = 2; settings_get(SETTINGS_SYMBOL,symbol,&bufLen); SERIAL_PRINTF_P(pSer,PSTR("SYMBOL: %c%c\r\n"),symbol[0],symbol[1]); return true; }
//------------------------------------------------------------------------------ static int set_value(const char* key, const char* value) { const setting_decl_t* decl = settings_get_decl_by_name(g_settings, key); if (decl == NULL) { printf("ERROR: Setting '%s' not found.\n", key); return 1; } settings_set(g_settings, key, value); printf("Settings '%s' set to '%s'\n", key, settings_get_str(g_settings, key)); return 0; }
static bool cmd_settings_beacon_interval(Serial* pSer, char* value, size_t valueLen) { uint16_t i = 0; if(valueLen > 0) { i = atoi((const char*) value) & 0xffff; settings_set(SETTINGS_BEACON_INTERVAL,&i,2); settings_save(); } uint8_t bufLen = 2; settings_get(SETTINGS_BEACON_INTERVAL,&i,&bufLen); SERIAL_PRINTF_P(pSer,PSTR("Beacon Interval: %d seconds\r\n"),i); return true; }
/** * Sets the default settings for this particular program, called Zen. * These are the hard coded default values. They are likely to be * overridden by configuration files, environment variables and/or * command line options. */ static void set_defaults(void) { settings_set("dump_source", (void *)0, SETTING_BOOLEAN); //2 settings_set("dump_config", (void *)0, SETTING_BOOLEAN); //2 settings_set("interface", (void *)"dump", SETTING_STRING);//3 settings_set("default_page", (void *)"http://www.nocrew.org/software/zen/", SETTING_STRING);//3 settings_set("screen_gamma", (void *)"2.42", SETTING_STRING);//3 settings_set("png_gamma", (void *)"0.45455", SETTING_STRING);//3 }
static void __init_default_values() { hotkey_t hk; position_t pos; double d; varchar str; int i; /* trigger key */ hk.modifiers = ControlMask; hk.keysym = XK_space; settings_set(TRIGGER_KEY, &hk); /* eng key */ hk.modifiers = 0; hk.keysym = XK_Shift_L; settings_set(ENG_KEY, &hk); get_screen_size(&(pos.x), &(pos.y)); pos.x -= 100; pos.y -= 70; settings_set(ICBAR_POS, &pos); /* preedit opacity */ d = 1.0; settings_set(PREEDIT_OPACITY, &d); memset(str, 0, sizeof(varchar)); strcpy(str, "#FFFFB3"); settings_set(PREEDIT_COLOR, str); memset(str, 0, sizeof(varchar)); strcpy(str, "Sans 10"); settings_set(PREEDIT_FONT, str); memset(str, 0, sizeof(varchar)); strcpy(str, "#000000"); settings_set(PREEDIT_FONT_COLOR, str); i = 10; settings_set(CANDIDATES_SIZE, &i); }
int settings_set_command(int argc, const char** argv, GString* output) { if (argc < 3) { return HERBST_NEED_MORE_ARGS; } SettingsPair* pair = settings_find(argv[1]); if (!pair) { if (output != NULL) { g_string_append_printf(output, "%s: Setting \"%s\" not found\n", argv[0], argv[1]); } return HERBST_SETTING_NOT_FOUND; } int ret = settings_set(pair, argv[2]); if (ret == HERBST_INVALID_ARGUMENT) { g_string_append_printf(output, "%s: Invalid value for setting \"%s\"\n", argv[0], argv[1]); } return ret; }
int settings_cycle_value(int argc, char** argv, GString* output) { if (argc < 3) { return HERBST_NEED_MORE_ARGS; } char* cmd_name = argv[0]; char* setting_name = argv[1]; // save this before shifting SettingsPair* pair = settings_find(argv[1]); if (!pair) { g_string_append_printf(output, "%s: Setting \"%s\" not found\n", argv[0], argv[1]); return HERBST_SETTING_NOT_FOUND; } (void)SHIFT(argc, argv); (void)SHIFT(argc, argv); char** pcurrent = (char**)table_find(argv, sizeof(*argv), argc, 0, memberequals_settingspair, pair); int i = pcurrent ? ((INDEX_OF(argv, pcurrent) + 1) % argc) : 0; int ret = settings_set(pair, argv[i]); if (ret == HERBST_INVALID_ARGUMENT) { g_string_append_printf(output, "%s: Invalid value for setting \"%s\"\n", cmd_name, setting_name); } return ret; }
// Main page CGI handler static void httpd_main_cgi_handler( char *pars ) { char *p, *arg, *val; SETTINGS new_settings; new_settings = *settings_get(); new_settings.static_mode = 1; p = pars; httpd_resp_buf[ 0 ] = '\0'; while( 1 ) { // Get a single argument/value pair p = httpd_get_cgi_data( p, &arg, &val ); if( arg[ 0 ] && val[ 0 ] ) { // Process this pair if( strcmp( arg, "sip" ) == 0 ) // source ip { if( utils_string_to_ip( val, &new_settings.ip ) == 0 ) { strcpy( httpd_last_err, "Invalid source IP" ); return; } } else if( strcmp( arg, "gwip" ) == 0 ) // gateway { if( utils_string_to_ip( val, &new_settings.gw ) == 0 ) { strcpy( httpd_last_err, "Invalid gateway IP" ); return; } } else if( strcmp( arg, "sn" ) == 0 ) // netmask { if( utils_string_to_ip( val, &new_settings.mask ) == 0 ) { strcpy( httpd_last_err, "Invalid network mask" ); return; } } else if( strcmp( arg, "dns" ) == 0 ) // dns { if( utils_string_to_ip( val, &new_settings.dns ) == 0 ) { strcpy( httpd_last_err, "Invalid DNS IP" ); return; } } else if( strcmp( arg, "hwaddr" ) == 0 ) // MAC { if( utils_string_to_mac( val, &new_settings.mac ) == 0 ) { strcpy( httpd_last_err, "Invalid MAC address" ); return; } } else if( strcmp( arg, "isdhcp" ) == 0 && strcmp( val, "on" ) == 0 ) new_settings.static_mode = 0; else if( strcmp( arg, "bname" ) == 0 ) { new_settings.name[ SETTINGS_MAX_NAME_LEN ] = '\0'; strncpy( new_settings.name, val, SETTINGS_MAX_NAME_LEN ); } else if( strcmp( arg, "username" ) == 0 ) { new_settings.username[ SETTINGS_MAX_USERNAME_LEN ] = '\0'; strncpy( new_settings.username, val, SETTINGS_MAX_USERNAME_LEN ); } else if( strcmp( arg, "password" ) == 0 ) { new_settings.password[ SETTINGS_MAX_PASSWORD_LEN ] = '\0'; strncpy( new_settings.password, val, SETTINGS_MAX_PASSWORD_LEN ); } else { strcpy( httpd_last_err, "Invalid argument found in CGI list" ); return; } } if( p == NULL ) break; } settings_set( &new_settings ); settings_write(); strcpy( httpd_last_err, "Configuration updated" ); }
void state_changed() { hotkey_t hk; REFRESH_KEY_SETTING(trigger); settings_set(TRIGGER_KEY, &hk); REFRESH_KEY_SETTING(english); settings_set(ENG_KEY, &hk); varchar colorstr; REFRESH_COLOR_SETTING(background_color_btn); settings_set(PREEDIT_COLOR, colorstr); REFRESH_COLOR_SETTING(font_color_btn); settings_set(PREEDIT_FONT_COLOR, colorstr); /* font and size information */ settings_set(PREEDIT_FONT, (void*) gtk_font_button_get_font_name(font_btn)); /* font color information */ settings_set_double(PREEDIT_OPACITY, gtk_adjustment_get_value(opacity_value)); settings_set_int(CANDIDATES_SIZE, gtk_adjustment_get_value(ncandidates)); /* page up and down trigger */ settings_set_int(PAGE_MINUS_PLUS, gtk_toggle_button_get_active(minus_plus_check)); settings_set_int(PAGE_COMMA_PERIOD, gtk_toggle_button_get_active(comma_period_check)); settings_set_int(PAGE_PAREN, gtk_toggle_button_get_active(paren_check)); /* fuzzy segmentation */ settings_set_int(FUZZY_SEGMENTATION, gtk_toggle_button_get_active(fuzzy_seg_check)); settings_set_int(FUZZY_INNER_SEGMENTATION, gtk_toggle_button_get_active(fuzzy_inner_seg_check)); /* cancel on backspace */ settings_set_int(CANCEL_ON_BACKSPACE, gtk_toggle_button_get_active(cancel_on_backspace_check)); /* smart punctuation */ settings_set_int(SMART_PUNCT, gtk_toggle_button_get_active(smart_punct_check)); settings_set_int(SHUANGPIN, gtk_toggle_button_get_active(shuangpin_check)); int sche_idx = gtk_combo_box_get_active(shuangpin_combo); if (sche_idx < UI_SHUANGPIN_SCHEMES_NUM) settings_set_string(SHUANGPIN_SCHEME, ui_shuangpin_schemes[sche_idx]); /* skins */ settings_set_string(SKIN_NAME, gtk_combo_box_get_active_text(skin_combo)); /* whether hide icbar */ settings_set_int(HIDE_ICBAR, gtk_toggle_button_get_active(hide_icbar_check)); /* init status */ settings_set_int(INIT_PUNC_TYPE, gtk_toggle_button_get_active(punc_english_radio)); settings_set_int(INIT_WIDTH, gtk_toggle_button_get_active(half_width_radio)); settings_set_int(INIT_LANGUAGE, gtk_toggle_button_get_active(lang_english_radio)); settings_save(); send_reload(); }
/** * Read a configuration file into the global settings struct. * * @param filename The filename of the configuration file to read. * @param warn_missing A non-zero value makes this function warn the * @param warn_missing user, if the specified file cannot be found. */ static void read_configuration(char *filename, int warn_missing) { int fd, len, ret; char c, *setting, *value; enum configuration_state state; setting = (char *)malloc(1024); if(setting == NULL) { return; } value = (char *)malloc(1024); if(value == NULL) { free(setting); return; } fd = open(filename, O_RDONLY); /* if(fd < 0) { if(warn_missing) { fprintf(stderr, "%s: Warning! Opening configuration file '%s': ", program_name, filename); perror(""); } */ if(fd < 0) { if(warn_missing) { fprintf(stderr, "%s: Warning! Opening configuration file '%s': ", program_name, filename); perror(""); } free(setting); free(value); return; } /* Below, we read the configuration file, and through this state machine, * we perform parsing and putting the settings into place. Very advanced * stuff. You would not comprehend it, if I tried to explain. */ state = NEWLINE; while((ret = read(fd, &c, 1)) >= 0) { /* At end of file, we fake an end of line. */ if(ret == 0) c = '\n'; if(state == COMMENT) { if(c == '\n' || c == '\r') { state = NEWLINE; } } else if(state == NEWLINE) { if(c == '\n' || c == '\r') { state = NEWLINE; } else if(c == '#') { state = COMMENT; } else if(!IS_SPACE_ALPHA((int)c)) { setting[0] = c; setting[1] = '\0'; state = SETTING; } } else if(state == SETTING) { if(c == '\n' || c == '\r') { state = NEWLINE; } else if(c == '=') { value[0] = '\0'; state = VALUE; } else if(!IS_SPACE_ALPHA((int)c)) { len = strlen(setting); if(len < 1023) { setting[len] = c; setting[len + 1] = '\0'; } } } else if(state == VALUE) { if(c == '\n' || c == '\r') { char *tmp_value; state = NEWLINE; /* Remove whitespaces at the beginning and end, * and set the setting. */ tmp_value = value; while(IS_SPACE_ALPHA((int)*tmp_value)) tmp_value++; while(strlen(tmp_value) > 0 && IS_SPACE_ALPHA((int)tmp_value[strlen(tmp_value) - 1])) value[strlen(tmp_value) - 1] = '\0'; if(strlen(tmp_value) <= 0) continue; switch(find_type(setting)) { case SETTING_NUMBER: settings_set(setting, (void *)atoi(tmp_value), SETTING_NUMBER); break; case SETTING_BOOLEAN: if(!strcmp(value, "true") || !strcmp(tmp_value, "t") || !strcmp(tmp_value, "#t") || !strcmp(tmp_value, "y") || !strcmp(tmp_value, "yes") || !strcmp(tmp_value, "1")) settings_set(setting, (void *)1, SETTING_BOOLEAN); else settings_set(setting, (void *)0, SETTING_BOOLEAN); break; case SETTING_STRING: default: settings_set(setting, (void *)tmp_value, SETTING_STRING); break; } } else { len = strlen(value); if(len < 1023) { value[len] = c; value[len + 1] = '\0'; } } } /* At end of file, we want to end the reading here. */ if(ret == 0) break; } close(fd); free(setting); free(value); }
/** * Interpret the options given to the program on the command line. * * @param argc The number of arguments given to the program. * @param argv An array of strings with the given arguments. * * @return the index of the first argument which did not contain an option. */ static int interpret_options(int argc, char *argv[]) { int setting_dump_source = 0; int setting_dump_config = 0; char *setting_interface = ""; int set_dump_source=0, set_dump_config=0, set_interface=0; #ifdef HAVE_GETOPT_LONG struct option long_options[] = { { "interface", required_argument, NULL, 'i' }, { "source", no_argument, NULL, 's' }, { "config", required_argument, NULL, 'c' }, { "dump-config", no_argument, NULL, 'd' }, { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'V' }, { NULL, 0, NULL, 0 } }; #endif /* HAVE_GETOPT_LONG */ char *short_options = "i:sc:dhV"; /* First check if we have started Zen as another name than "zen". This * can happen, since we create symbolic links for some interfaces when * installing Zen. These symbolic links are: * * gzen - GTK+ user interface * fbzen - oFBis user interface * pszen - PostScript dump interface * * The symbolic name can still be overridden by the command line option * --interface (-i), but not by the environment variable ZEN_INTERFACE. */ /* real_program_name = strrchr(program_name, '/'); if(real_program_name == NULL) real_program_name = program_name; else real_program_name++; if(!strcmp(real_program_name, "gzen")) { setting_interface = "gtk"; set_interface = 1; } else if(!strcmp(real_program_name, "fbzen")) { setting_interface = "ofbis"; set_interface = 1; } else if(!strcmp(real_program_name, "pszen")) { setting_interface = "psdump"; set_interface = 1; } */ // arg = 0; // while(arg != EOF) { #ifdef HAVE_GETOPT_LONG arg = getopt_long(argc, argv, short_options, long_options, NULL); #else /* !HAVE_GETOPT_LONG */ //arg = getopt(argc, argv, short_options); #endif /* !HAVE_GETOPT_LONG */ /* switch(arg) { case EOF: //* End of arguments // break; case 'i': ///* --interface // setting_interface = optarg; set_interface = 1; break; case 's': ///* --source // setting_dump_source = 1; set_dump_source = 1; break; case 'c': ///* --config / read_configuration(optarg, 1); break; case 'd': ///* --dump-config // setting_dump_config = 1; set_dump_config = 1; break; case 'h': ///* --help // print_usage(); exit(0); case 'V': ///* --version // print_version(); exit(0); default: fprintf(stderr, "-%c: Unknown option skipped\n", arg); } } */ setting_interface = "ofbis"; set_interface = 1; /* Read and interpret environment variables. This has to be done here, * to be able to get it to read the configurations in the order we have * specified above and in the manpage. */ interpret_environment(); /* At this point, we have treated all command line options, and put the * settings for them into the local struct command_line_settings. We do * that, because we always want the command line options to override the * settings from any configuration file, even those read through the * --config (-c) option. * So, what we do here, is copy the command line settings into the main * settings struct. */ if(set_dump_source) settings_set("dump_source", (void *)setting_dump_source, SETTING_BOOLEAN); if(set_dump_config) settings_set("dump_config", (void *)setting_dump_config, SETTING_BOOLEAN); if(set_interface) settings_set("interface", (void *)setting_interface, SETTING_STRING); /* If the user put something that could be interpreted as a URL on * the command line, then we put that into the default_page setting. */ /* if(optind < argc) { settings_set("default_page", (void *)argv[optind], SETTING_STRING); } return optind; */ return 0; }
void OS_setPref(const char *name, const char *value) { settings_set(name, value); }
int menu_set_settings(unsigned setting, unsigned action) { unsigned port = rgui->current_pad; switch (setting) { case RGUI_START_SCREEN: if (action == RGUI_ACTION_OK) rgui_list_push(rgui->menu_stack, "", RGUI_START_SCREEN, 0); break; case RGUI_SETTINGS_REWIND_ENABLE: if (action == RGUI_ACTION_OK || action == RGUI_ACTION_LEFT || action == RGUI_ACTION_RIGHT) { settings_set(1ULL << S_REWIND); if (g_settings.rewind_enable) rarch_init_rewind(); else rarch_deinit_rewind(); } else if (action == RGUI_ACTION_START) { g_settings.rewind_enable = false; rarch_deinit_rewind(); } break; #ifdef HAVE_SCREENSHOTS case RGUI_SETTINGS_GPU_SCREENSHOT: if (action == RGUI_ACTION_OK || action == RGUI_ACTION_LEFT || action == RGUI_ACTION_RIGHT) g_settings.video.gpu_screenshot = !g_settings.video.gpu_screenshot; else if (action == RGUI_ACTION_START) g_settings.video.gpu_screenshot = true; break; #endif case RGUI_SETTINGS_REWIND_GRANULARITY: if (action == RGUI_ACTION_OK || action == RGUI_ACTION_RIGHT) settings_set(1ULL << S_REWIND_GRANULARITY_INCREMENT); else if (action == RGUI_ACTION_LEFT) settings_set(1ULL << S_REWIND_GRANULARITY_DECREMENT); else if (action == RGUI_ACTION_START) settings_set(1ULL << S_DEF_REWIND_GRANULARITY); break; case RGUI_SETTINGS_CONFIG_SAVE_ON_EXIT: if (action == RGUI_ACTION_OK || action == RGUI_ACTION_RIGHT || action == RGUI_ACTION_LEFT) { g_extern.config_save_on_exit = !g_extern.config_save_on_exit; } else if (action == RGUI_ACTION_START) g_extern.config_save_on_exit = true; break; #if defined(HAVE_THREADS) && !defined(RARCH_CONSOLE) case RGUI_SETTINGS_SRAM_AUTOSAVE: if (action == RGUI_ACTION_OK || action == RGUI_ACTION_RIGHT || action == RGUI_ACTION_LEFT) { rarch_deinit_autosave(); g_settings.autosave_interval = (!g_settings.autosave_interval) * 10; if (g_settings.autosave_interval) rarch_init_autosave(); } else if (action == RGUI_ACTION_START) { rarch_deinit_autosave(); g_settings.autosave_interval = 0; } break; #endif case RGUI_SETTINGS_SAVESTATE_SAVE: case RGUI_SETTINGS_SAVESTATE_LOAD: if (action == RGUI_ACTION_OK) { if (setting == RGUI_SETTINGS_SAVESTATE_SAVE) rarch_save_state(); else rarch_load_state(); g_extern.lifecycle_mode_state |= (1ULL << MODE_GAME); return -1; } else if (action == RGUI_ACTION_START) settings_set(1ULL << S_DEF_SAVE_STATE); else if (action == RGUI_ACTION_LEFT) settings_set(1ULL << S_SAVESTATE_DECREMENT); else if (action == RGUI_ACTION_RIGHT) settings_set(1ULL << S_SAVESTATE_INCREMENT); break; #ifdef HAVE_SCREENSHOTS case RGUI_SETTINGS_SCREENSHOT: if (action == RGUI_ACTION_OK) rarch_take_screenshot(); break; #endif case RGUI_SETTINGS_RESTART_GAME: if (action == RGUI_ACTION_OK) { rarch_game_reset(); g_extern.lifecycle_mode_state |= (1ULL << MODE_GAME); return -1; } break; case RGUI_SETTINGS_AUDIO_MUTE: if (action == RGUI_ACTION_START) settings_set(1ULL << S_DEF_AUDIO_MUTE); else settings_set(1ULL << S_AUDIO_MUTE); break; case RGUI_SETTINGS_AUDIO_CONTROL_RATE_DELTA: if (action == RGUI_ACTION_START) settings_set(1ULL << S_DEF_AUDIO_CONTROL_RATE); else if (action == RGUI_ACTION_LEFT) settings_set(1ULL << S_AUDIO_CONTROL_RATE_DECREMENT); else if (action == RGUI_ACTION_RIGHT) settings_set(1ULL << S_AUDIO_CONTROL_RATE_INCREMENT); break; case RGUI_SETTINGS_DEBUG_TEXT: if (action == RGUI_ACTION_START) g_settings.fps_show = false; else if (action == RGUI_ACTION_LEFT || action == RGUI_ACTION_RIGHT) g_settings.fps_show = !g_settings.fps_show; break; case RGUI_SETTINGS_DISK_INDEX: { const struct retro_disk_control_callback *control = &g_extern.system.disk_control; unsigned num_disks = control->get_num_images(); unsigned current = control->get_image_index(); int step = 0; if (action == RGUI_ACTION_RIGHT || action == RGUI_ACTION_OK) step = 1; else if (action == RGUI_ACTION_LEFT) step = -1; if (step) { unsigned next_index = (current + num_disks + 1 + step) % (num_disks + 1); rarch_disk_control_set_eject(true, false); rarch_disk_control_set_index(next_index); rarch_disk_control_set_eject(false, false); } break; } case RGUI_SETTINGS_RESTART_EMULATOR: if (action == RGUI_ACTION_OK) { #if defined(GEKKO) && defined(HW_RVL) fill_pathname_join(g_extern.fullpath, default_paths.core_dir, SALAMANDER_FILE, sizeof(g_extern.fullpath)); #endif g_extern.lifecycle_mode_state &= ~(1ULL << MODE_GAME); g_extern.lifecycle_mode_state |= (1ULL << MODE_EXITSPAWN); return -1; } break; case RGUI_SETTINGS_RESUME_GAME: if (action == RGUI_ACTION_OK) { g_extern.lifecycle_mode_state |= (1ULL << MODE_GAME); return -1; } break; case RGUI_SETTINGS_QUIT_RARCH: if (action == RGUI_ACTION_OK) { g_extern.lifecycle_mode_state &= ~(1ULL << MODE_GAME); return -1; } break; case RGUI_SETTINGS_SAVE_CONFIG: if (action == RGUI_ACTION_OK) menu_save_new_config(); break; #ifdef HAVE_OVERLAY case RGUI_SETTINGS_OVERLAY_PRESET: switch (action) { case RGUI_ACTION_OK: rgui_list_push(rgui->menu_stack, g_extern.overlay_dir, setting, rgui->selection_ptr); rgui->selection_ptr = 0; rgui->need_refresh = true; break; #ifndef __QNX__ // FIXME: Why ifndef QNX? case RGUI_ACTION_START: if (driver.overlay) input_overlay_free(driver.overlay); driver.overlay = NULL; *g_settings.input.overlay = '\0'; break; #endif default: break; } break; case RGUI_SETTINGS_OVERLAY_OPACITY: { bool changed = true; switch (action) { case RGUI_ACTION_LEFT: settings_set(1ULL << S_INPUT_OVERLAY_OPACITY_DECREMENT); break; case RGUI_ACTION_RIGHT: case RGUI_ACTION_OK: settings_set(1ULL << S_INPUT_OVERLAY_OPACITY_INCREMENT); break; case RGUI_ACTION_START: settings_set(1ULL << S_DEF_INPUT_OVERLAY_OPACITY); break; default: changed = false; break; } if (changed && driver.overlay) input_overlay_set_alpha_mod(driver.overlay, g_settings.input.overlay_opacity); break; } case RGUI_SETTINGS_OVERLAY_SCALE: { bool changed = true; switch (action) { case RGUI_ACTION_LEFT: settings_set(1ULL << S_INPUT_OVERLAY_SCALE_DECREMENT); break; case RGUI_ACTION_RIGHT: case RGUI_ACTION_OK: settings_set(1ULL << S_INPUT_OVERLAY_SCALE_INCREMENT); break; case RGUI_ACTION_START: settings_set(1ULL << S_DEF_INPUT_OVERLAY_SCALE); break; default: changed = false; break; } if (changed && driver.overlay) input_overlay_set_scale_factor(driver.overlay, g_settings.input.overlay_scale); break; } #endif // controllers case RGUI_SETTINGS_BIND_PLAYER: if (action == RGUI_ACTION_START) rgui->current_pad = 0; else if (action == RGUI_ACTION_LEFT) { if (rgui->current_pad != 0) rgui->current_pad--; } else if (action == RGUI_ACTION_RIGHT) { if (rgui->current_pad < MAX_PLAYERS - 1) rgui->current_pad++; } #ifdef HAVE_RGUI if (port != rgui->current_pad) rgui->need_refresh = true; #endif port = rgui->current_pad; break; case RGUI_SETTINGS_BIND_DEVICE: // If set_keybinds is supported, we do it more fancy, and scroll through // a list of supported devices directly. if (driver.input->set_keybinds) { g_settings.input.device[port] += DEVICE_LAST; if (action == RGUI_ACTION_START) g_settings.input.device[port] = 0; else if (action == RGUI_ACTION_LEFT) g_settings.input.device[port]--; else if (action == RGUI_ACTION_RIGHT) g_settings.input.device[port]++; // DEVICE_LAST can be 0, avoid modulo. if (g_settings.input.device[port] >= DEVICE_LAST) g_settings.input.device[port] -= DEVICE_LAST; unsigned keybind_action = (1ULL << KEYBINDS_ACTION_SET_DEFAULT_BINDS); driver.input->set_keybinds(driver.input_data, g_settings.input.device[port], port, 0, keybind_action); } else { // When only straight g_settings.input.joypad_map[] style // mapping is supported. int *p = &g_settings.input.joypad_map[port]; if (action == RGUI_ACTION_START) *p = port; else if (action == RGUI_ACTION_LEFT) (*p)--; else if (action == RGUI_ACTION_RIGHT) (*p)++; if (*p < -1) *p = -1; else if (*p >= MAX_PLAYERS) *p = MAX_PLAYERS - 1; } break; case RGUI_SETTINGS_BIND_DEVICE_TYPE: { static const unsigned device_types[] = { RETRO_DEVICE_NONE, RETRO_DEVICE_JOYPAD, RETRO_DEVICE_ANALOG, RETRO_DEVICE_MOUSE, RETRO_DEVICE_JOYPAD_MULTITAP, RETRO_DEVICE_LIGHTGUN_SUPER_SCOPE, RETRO_DEVICE_LIGHTGUN_JUSTIFIER, RETRO_DEVICE_LIGHTGUN_JUSTIFIERS, }; unsigned current_device, current_index, i; current_device = g_settings.input.libretro_device[port]; current_index = 0; for (i = 0; i < ARRAY_SIZE(device_types); i++) { if (current_device == device_types[i]) { current_index = i; break; } } bool updated = true; switch (action) { case RGUI_ACTION_START: current_device = RETRO_DEVICE_JOYPAD; break; case RGUI_ACTION_LEFT: current_device = device_types[(current_index + ARRAY_SIZE(device_types) - 1) % ARRAY_SIZE(device_types)]; break; case RGUI_ACTION_RIGHT: case RGUI_ACTION_OK: current_device = device_types[(current_index + 1) % ARRAY_SIZE(device_types)]; break; default: updated = false; } if (updated) { g_settings.input.libretro_device[port] = current_device; pretro_set_controller_port_device(port, current_device); } break; } case RGUI_SETTINGS_CUSTOM_BIND_ALL: if (action == RGUI_ACTION_OK) { rgui->binds.target = &g_settings.input.binds[port][0]; rgui->binds.begin = RGUI_SETTINGS_BIND_BEGIN; rgui->binds.last = RGUI_SETTINGS_BIND_LAST; rgui_list_push(rgui->menu_stack, "", RGUI_SETTINGS_CUSTOM_BIND, rgui->selection_ptr); menu_poll_bind_get_rested_axes(&rgui->binds); menu_poll_bind_state(&rgui->binds); } break; case RGUI_SETTINGS_CUSTOM_BIND_DEFAULT_ALL: if (action == RGUI_ACTION_OK) { unsigned i; struct retro_keybind *target = &g_settings.input.binds[port][0]; rgui->binds.begin = RGUI_SETTINGS_BIND_BEGIN; rgui->binds.last = RGUI_SETTINGS_BIND_LAST; for (i = RGUI_SETTINGS_BIND_BEGIN; i <= RGUI_SETTINGS_BIND_LAST; i++, target++) { target->joykey = NO_BTN; target->joyaxis = AXIS_NONE; } } break; case RGUI_SETTINGS_BIND_UP: case RGUI_SETTINGS_BIND_DOWN: case RGUI_SETTINGS_BIND_LEFT: case RGUI_SETTINGS_BIND_RIGHT: case RGUI_SETTINGS_BIND_A: case RGUI_SETTINGS_BIND_B: case RGUI_SETTINGS_BIND_X: case RGUI_SETTINGS_BIND_Y: case RGUI_SETTINGS_BIND_START: case RGUI_SETTINGS_BIND_SELECT: case RGUI_SETTINGS_BIND_L: case RGUI_SETTINGS_BIND_R: case RGUI_SETTINGS_BIND_L2: case RGUI_SETTINGS_BIND_R2: case RGUI_SETTINGS_BIND_L3: case RGUI_SETTINGS_BIND_R3: case RGUI_SETTINGS_BIND_ANALOG_LEFT_X_PLUS: case RGUI_SETTINGS_BIND_ANALOG_LEFT_X_MINUS: case RGUI_SETTINGS_BIND_ANALOG_LEFT_Y_PLUS: case RGUI_SETTINGS_BIND_ANALOG_LEFT_Y_MINUS: case RGUI_SETTINGS_BIND_ANALOG_RIGHT_X_PLUS: case RGUI_SETTINGS_BIND_ANALOG_RIGHT_X_MINUS: case RGUI_SETTINGS_BIND_ANALOG_RIGHT_Y_PLUS: case RGUI_SETTINGS_BIND_ANALOG_RIGHT_Y_MINUS: case RGUI_SETTINGS_BIND_MENU_TOGGLE: if (driver.input->set_keybinds) { unsigned keybind_action = KEYBINDS_ACTION_NONE; if (action == RGUI_ACTION_START) keybind_action = (1ULL << KEYBINDS_ACTION_SET_DEFAULT_BIND); // FIXME: The array indices here look totally wrong ... Fixed it so it looks kind of sane for now. if (keybind_action != KEYBINDS_ACTION_NONE) driver.input->set_keybinds(driver.input_data, g_settings.input.device[port], port, setting - RGUI_SETTINGS_BIND_BEGIN, keybind_action); } else { struct retro_keybind *bind = &g_settings.input.binds[port][setting - RGUI_SETTINGS_BIND_BEGIN]; if (action == RGUI_ACTION_OK) { rgui->binds.begin = setting; rgui->binds.last = setting; rgui->binds.target = bind; rgui->binds.player = port; rgui_list_push(rgui->menu_stack, "", RGUI_SETTINGS_CUSTOM_BIND, rgui->selection_ptr); menu_poll_bind_get_rested_axes(&rgui->binds); menu_poll_bind_state(&rgui->binds); } else if (action == RGUI_ACTION_START) { bind->joykey = NO_BTN; bind->joyaxis = AXIS_NONE; } } break; case RGUI_BROWSER_DIR_PATH: if (action == RGUI_ACTION_START) { *g_settings.rgui_browser_directory = '\0'; *rgui->base_path = '\0'; } break; #ifdef HAVE_SCREENSHOTS case RGUI_SCREENSHOT_DIR_PATH: if (action == RGUI_ACTION_START) *g_settings.screenshot_directory = '\0'; break; #endif case RGUI_SAVEFILE_DIR_PATH: if (action == RGUI_ACTION_START) *g_extern.savefile_dir = '\0'; break; #ifdef HAVE_OVERLAY case RGUI_OVERLAY_DIR_PATH: if (action == RGUI_ACTION_START) *g_extern.overlay_dir = '\0'; break; #endif case RGUI_SAVESTATE_DIR_PATH: if (action == RGUI_ACTION_START) *g_extern.savestate_dir = '\0'; break; #ifdef HAVE_DYNAMIC case RGUI_LIBRETRO_DIR_PATH: if (action == RGUI_ACTION_START) { *rgui->libretro_dir = '\0'; menu_init_core_info(rgui); } break; #endif case RGUI_LIBRETRO_INFO_DIR_PATH: if (action == RGUI_ACTION_START) { *g_settings.libretro_info_path = '\0'; menu_init_core_info(rgui); } break; case RGUI_CONFIG_DIR_PATH: if (action == RGUI_ACTION_START) *g_settings.rgui_config_directory = '\0'; break; case RGUI_SHADER_DIR_PATH: if (action == RGUI_ACTION_START) *g_settings.video.shader_dir = '\0'; break; case RGUI_SYSTEM_DIR_PATH: if (action == RGUI_ACTION_START) *g_settings.system_directory = '\0'; break; case RGUI_SETTINGS_VIDEO_ROTATION: if (action == RGUI_ACTION_START) { settings_set(1ULL << S_DEF_ROTATION); video_set_rotation_func((g_settings.video.rotation + g_extern.system.rotation) % 4); } else if (action == RGUI_ACTION_LEFT) { settings_set(1ULL << S_ROTATION_DECREMENT); video_set_rotation_func((g_settings.video.rotation + g_extern.system.rotation) % 4); } else if (action == RGUI_ACTION_RIGHT) { settings_set(1ULL << S_ROTATION_INCREMENT); video_set_rotation_func((g_settings.video.rotation + g_extern.system.rotation) % 4); } break; case RGUI_SETTINGS_VIDEO_FILTER: if (action == RGUI_ACTION_START) settings_set(1ULL << S_DEF_HW_TEXTURE_FILTER); else settings_set(1ULL << S_HW_TEXTURE_FILTER); if (driver.video_poke->set_filtering) driver.video_poke->set_filtering(driver.video_data, 1, g_settings.video.smooth); break; case RGUI_SETTINGS_VIDEO_GAMMA: if (action == RGUI_ACTION_START) { g_extern.console.screen.gamma_correction = 0; if (driver.video_poke->apply_state_changes) driver.video_poke->apply_state_changes(driver.video_data); } else if (action == RGUI_ACTION_LEFT) { if(g_extern.console.screen.gamma_correction > 0) { g_extern.console.screen.gamma_correction--; if (driver.video_poke->apply_state_changes) driver.video_poke->apply_state_changes(driver.video_data); } } else if (action == RGUI_ACTION_RIGHT) { if(g_extern.console.screen.gamma_correction < MAX_GAMMA_SETTING) { g_extern.console.screen.gamma_correction++; if (driver.video_poke->apply_state_changes) driver.video_poke->apply_state_changes(driver.video_data); } } break; case RGUI_SETTINGS_VIDEO_INTEGER_SCALE: if (action == RGUI_ACTION_START) settings_set(1ULL << S_DEF_SCALE_INTEGER); else if (action == RGUI_ACTION_LEFT || action == RGUI_ACTION_RIGHT || action == RGUI_ACTION_OK) settings_set(1ULL << S_SCALE_INTEGER_TOGGLE); if (driver.video_poke->apply_state_changes) driver.video_poke->apply_state_changes(driver.video_data); break; case RGUI_SETTINGS_VIDEO_ASPECT_RATIO: if (action == RGUI_ACTION_START) settings_set(1ULL << S_DEF_ASPECT_RATIO); else if (action == RGUI_ACTION_LEFT) settings_set(1ULL << S_ASPECT_RATIO_DECREMENT); else if (action == RGUI_ACTION_RIGHT) settings_set(1ULL << S_ASPECT_RATIO_INCREMENT); if (driver.video_poke->set_aspect_ratio) driver.video_poke->set_aspect_ratio(driver.video_data, g_settings.video.aspect_ratio_idx); break; case RGUI_SETTINGS_TOGGLE_FULLSCREEN: if (action == RGUI_ACTION_OK) rarch_set_fullscreen(!g_settings.video.fullscreen); break; #if defined(GEKKO) case RGUI_SETTINGS_VIDEO_RESOLUTION: if (action == RGUI_ACTION_LEFT) { if(rgui_current_gx_resolution > 0) { rgui_current_gx_resolution--; gx_set_video_mode(rgui_gx_resolutions[rgui_current_gx_resolution][0], rgui_gx_resolutions[rgui_current_gx_resolution][1]); } } else if (action == RGUI_ACTION_RIGHT) { if (rgui_current_gx_resolution < GX_RESOLUTIONS_LAST - 1) { #ifdef HW_RVL if ((rgui_current_gx_resolution + 1) > GX_RESOLUTIONS_640_480) if (CONF_GetVideo() != CONF_VIDEO_PAL) return 0; #endif rgui_current_gx_resolution++; gx_set_video_mode(rgui_gx_resolutions[rgui_current_gx_resolution][0], rgui_gx_resolutions[rgui_current_gx_resolution][1]); } } break; #elif defined(__CELLOS_LV2__) case RGUI_SETTINGS_VIDEO_RESOLUTION: if (action == RGUI_ACTION_LEFT) settings_set(1ULL << S_RESOLUTION_PREVIOUS); else if (action == RGUI_ACTION_RIGHT) settings_set(1ULL << S_RESOLUTION_NEXT); else if (action == RGUI_ACTION_OK) { if (g_extern.console.screen.resolutions.list[g_extern.console.screen.resolutions.current.idx] == CELL_VIDEO_OUT_RESOLUTION_576) { if (g_extern.console.screen.pal_enable) g_extern.lifecycle_mode_state |= (1ULL<< MODE_VIDEO_PAL_ENABLE); } else { g_extern.lifecycle_mode_state &= ~(1ULL << MODE_VIDEO_PAL_ENABLE); g_extern.lifecycle_mode_state &= ~(1ULL << MODE_VIDEO_PAL_TEMPORAL_ENABLE); } driver.video->restart(); rgui_init_textures(); } break; #endif #ifdef HW_RVL case RGUI_SETTINGS_VIDEO_SOFT_FILTER: if (g_extern.lifecycle_mode_state & (1ULL << MODE_VIDEO_SOFT_FILTER_ENABLE)) g_extern.lifecycle_mode_state &= ~(1ULL << MODE_VIDEO_SOFT_FILTER_ENABLE); else g_extern.lifecycle_mode_state |= (1ULL << MODE_VIDEO_SOFT_FILTER_ENABLE); if (driver.video_poke->apply_state_changes) driver.video_poke->apply_state_changes(driver.video_data); break; #endif case RGUI_SETTINGS_VIDEO_VSYNC: switch (action) { case RGUI_ACTION_START: settings_set(1ULL << S_DEF_VIDEO_VSYNC); break; case RGUI_ACTION_LEFT: case RGUI_ACTION_RIGHT: case RGUI_ACTION_OK: settings_set(1ULL << S_VIDEO_VSYNC_TOGGLE); break; default: break; } break; case RGUI_SETTINGS_VIDEO_HARD_SYNC: switch (action) { case RGUI_ACTION_START: g_settings.video.hard_sync = false; break; case RGUI_ACTION_LEFT: case RGUI_ACTION_RIGHT: case RGUI_ACTION_OK: g_settings.video.hard_sync = !g_settings.video.hard_sync; break; default: break; } break; case RGUI_SETTINGS_VIDEO_BLACK_FRAME_INSERTION: switch (action) { case RGUI_ACTION_START: g_settings.video.black_frame_insertion = false; break; case RGUI_ACTION_LEFT: case RGUI_ACTION_RIGHT: case RGUI_ACTION_OK: g_settings.video.black_frame_insertion = !g_settings.video.black_frame_insertion; break; default: break; } break; case RGUI_SETTINGS_VIDEO_CROP_OVERSCAN: switch (action) { case RGUI_ACTION_START: g_settings.video.crop_overscan = true; break; case RGUI_ACTION_LEFT: case RGUI_ACTION_RIGHT: case RGUI_ACTION_OK: g_settings.video.crop_overscan = !g_settings.video.crop_overscan; break; default: break; } break; case RGUI_SETTINGS_VIDEO_WINDOW_SCALE_X: case RGUI_SETTINGS_VIDEO_WINDOW_SCALE_Y: { float *scale = setting == RGUI_SETTINGS_VIDEO_WINDOW_SCALE_X ? &g_settings.video.xscale : &g_settings.video.yscale; float old_scale = *scale; switch (action) { case RGUI_ACTION_START: *scale = 3.0f; break; case RGUI_ACTION_LEFT: *scale -= 1.0f; break; case RGUI_ACTION_RIGHT: *scale += 1.0f; break; default: break; } *scale = roundf(*scale); *scale = max(*scale, 1.0f); if (old_scale != *scale && !g_settings.video.fullscreen) rarch_set_fullscreen(g_settings.video.fullscreen); // Reinit video driver. break; } #ifdef HAVE_THREADS case RGUI_SETTINGS_VIDEO_THREADED: { bool old = g_settings.video.threaded; if (action == RGUI_ACTION_OK || action == RGUI_ACTION_LEFT || action == RGUI_ACTION_RIGHT) g_settings.video.threaded = !g_settings.video.threaded; else if (action == RGUI_ACTION_START) g_settings.video.threaded = false; if (g_settings.video.threaded != old) rarch_set_fullscreen(g_settings.video.fullscreen); // Reinit video driver. break; } #endif case RGUI_SETTINGS_VIDEO_SWAP_INTERVAL: { unsigned old = g_settings.video.swap_interval; switch (action) { case RGUI_ACTION_START: g_settings.video.swap_interval = 1; break; case RGUI_ACTION_LEFT: g_settings.video.swap_interval--; break; case RGUI_ACTION_RIGHT: case RGUI_ACTION_OK: g_settings.video.swap_interval++; break; default: break; } g_settings.video.swap_interval = min(g_settings.video.swap_interval, 4); g_settings.video.swap_interval = max(g_settings.video.swap_interval, 1); if (old != g_settings.video.swap_interval && driver.video && driver.video_data) video_set_nonblock_state_func(false); // This will update the current swap interval. Since we're in RGUI now, always apply VSync. break; } case RGUI_SETTINGS_VIDEO_HARD_SYNC_FRAMES: switch (action) { case RGUI_ACTION_START: g_settings.video.hard_sync_frames = 0; break; case RGUI_ACTION_LEFT: if (g_settings.video.hard_sync_frames > 0) g_settings.video.hard_sync_frames--; break; case RGUI_ACTION_RIGHT: case RGUI_ACTION_OK: if (g_settings.video.hard_sync_frames < 3) g_settings.video.hard_sync_frames++; break; default: break; } break; case RGUI_SETTINGS_VIDEO_REFRESH_RATE_AUTO: switch (action) { case RGUI_ACTION_START: g_extern.measure_data.frame_time_samples_count = 0; break; case RGUI_ACTION_OK: { double refresh_rate = 0.0; double deviation = 0.0; unsigned sample_points = 0; if (driver_monitor_fps_statistics(&refresh_rate, &deviation, &sample_points)) { driver_set_monitor_refresh_rate(refresh_rate); // Incase refresh rate update forced non-block video. video_set_nonblock_state_func(false); } break; } default: break; } break; #ifdef HAVE_SHADER_MANAGER case RGUI_SETTINGS_SHADER_PASSES: switch (action) { case RGUI_ACTION_START: rgui->shader.passes = 0; break; case RGUI_ACTION_LEFT: if (rgui->shader.passes) rgui->shader.passes--; break; case RGUI_ACTION_RIGHT: case RGUI_ACTION_OK: if (rgui->shader.passes < RGUI_MAX_SHADERS) rgui->shader.passes++; break; default: break; } #ifndef HAVE_RMENU rgui->need_refresh = true; #endif break; case RGUI_SETTINGS_SHADER_APPLY: { if (!driver.video->set_shader || action != RGUI_ACTION_OK) return 0; RARCH_LOG("Applying shader ...\n"); enum rarch_shader_type type = shader_manager_get_type(&rgui->shader); if (rgui->shader.passes && type != RARCH_SHADER_NONE) { const char *conf_path = type == RARCH_SHADER_GLSL ? rgui->default_glslp : rgui->default_cgp; char config_directory[PATH_MAX]; if (*g_extern.config_path) fill_pathname_basedir(config_directory, g_extern.config_path, sizeof(config_directory)); else *config_directory = '\0'; char cgp_path[PATH_MAX]; const char *dirs[] = { g_settings.video.shader_dir, g_settings.rgui_config_directory, config_directory, }; config_file_t *conf = config_file_new(NULL); if (!conf) return 0; gfx_shader_write_conf_cgp(conf, &rgui->shader); bool ret = false; unsigned d; for (d = 0; d < ARRAY_SIZE(dirs); d++) { if (!*dirs[d]) continue; fill_pathname_join(cgp_path, dirs[d], conf_path, sizeof(cgp_path)); if (config_file_write(conf, cgp_path)) { RARCH_LOG("Saved shader preset to %s.\n", cgp_path); shader_manager_set_preset(NULL, type, cgp_path); ret = true; break; } else RARCH_LOG("Failed writing shader preset to %s.\n", cgp_path); } config_file_free(conf); if (!ret) RARCH_ERR("Failed to save shader preset. Make sure config directory and/or shader dir are writable.\n"); } else { type = gfx_shader_parse_type("", DEFAULT_SHADER_TYPE); if (type == RARCH_SHADER_NONE) { #if defined(HAVE_GLSL) type = RARCH_SHADER_GLSL; #elif defined(HAVE_CG) || defined(HAVE_HLSL) type = RARCH_SHADER_CG; #endif } shader_manager_set_preset(NULL, type, NULL); } } break; #endif default: break; } return 0; }