void SettingsWindow::onButtonToggled(MyGUI::Widget* _sender) { std::string on = MWBase::Environment::get().getWindowManager()->getGameSettingString("sOn", "On"); std::string off = MWBase::Environment::get().getWindowManager()->getGameSettingString("sOff", "On"); bool newState; if (_sender->castType<MyGUI::Button>()->getCaption() == on) { _sender->castType<MyGUI::Button>()->setCaption(off); newState = false; } else { _sender->castType<MyGUI::Button>()->setCaption(on); newState = true; } if (_sender == mFullscreenButton) { // check if this resolution is supported in fullscreen if (mResolutionList->getIndexSelected() != MyGUI::ITEM_NONE) { std::string resStr = mResolutionList->getItemNameAt(mResolutionList->getIndexSelected()); int resX, resY; parseResolution (resX, resY, resStr); Settings::Manager::setInt("resolution x", "Video", resX); Settings::Manager::setInt("resolution y", "Video", resY); } bool supported = false; for (unsigned int i=0; i<mResolutionList->getItemCount(); ++i) { std::string resStr = mResolutionList->getItemNameAt(i); int resX, resY; parseResolution (resX, resY, resStr); if (resX == Settings::Manager::getInt("resolution x", "Video") && resY == Settings::Manager::getInt("resolution y", "Video")) supported = true; } if (!supported) { std::string msg = "This resolution is not supported in Fullscreen mode. Please select a resolution from the list."; MWBase::Environment::get().getWindowManager()-> messageBox(msg); _sender->castType<MyGUI::Button>()->setCaption(off); return; } mWindowBorderButton->setEnabled(!newState); } if (getSettingType(_sender) == checkButtonType) { Settings::Manager::setBool(getSettingName(_sender), getSettingCategory(_sender), newState); apply(); return; } }
bool ExternalDisplay::readResolution() { int hdmiEDIDFile = open(SYSFS_EDID_MODES, O_RDONLY, 0); int len = -1; if (hdmiEDIDFile < 0) { ALOGE("%s: edid_modes file '%s' not found", __FUNCTION__, SYSFS_EDID_MODES); return false; } else { len = read(hdmiEDIDFile, mEDIDs, sizeof(mEDIDs)-1); ALOGD_IF(DEBUG, "%s: EDID string: %s length = %d", __FUNCTION__, mEDIDs, len); if ( len <= 0) { ALOGE("%s: edid_modes file empty '%s'", __FUNCTION__, SYSFS_EDID_MODES); } else { while (len > 1 && isspace(mEDIDs[len-1])) --len; mEDIDs[len] = 0; } } close(hdmiEDIDFile); if(len > 0) { // GEt EDID modes from the EDID strings mModeCount = parseResolution(mEDIDs, mEDIDModes); ALOGD_IF(DEBUG, "%s: mModeCount = %d", __FUNCTION__, mModeCount); } return (strlen(mEDIDs) > 0); }
bool HDMIDisplay::readResolution() { ssize_t len = -1; char edidStr[128] = {'\0'}; int hdmiEDIDFile = openDeviceNode("edid_modes", O_RDONLY); if (hdmiEDIDFile < 0) { return false; } else { len = read(hdmiEDIDFile, edidStr, sizeof(edidStr)-1); ALOGD_IF(DEBUG, "%s: EDID string: %s length = %zu", __FUNCTION__, edidStr, len); if (len <= 0) { ALOGE("%s: edid_modes file empty", __FUNCTION__); edidStr[0] = '\0'; } else { while (len > 1 && isspace(edidStr[len-1])) { --len; } edidStr[len] = '\0'; } close(hdmiEDIDFile); } if(len > 0) { // Get EDID modes from the EDID strings mModeCount = parseResolution(edidStr); ALOGD_IF(DEBUG, "%s: mModeCount = %d", __FUNCTION__, mModeCount); } return (len > 0); }
void SettingsWindow::onResolutionAccept() { std::string resStr = mResolutionList->getItemNameAt(mResolutionList->getIndexSelected()); int resX, resY; parseResolution (resX, resY, resStr); Settings::Manager::setInt("resolution x", "Video", resX); Settings::Manager::setInt("resolution y", "Video", resY); apply(); }
void SettingsWindow::highlightCurrentResolution() { mResolutionList->setIndexSelected(MyGUI::ITEM_NONE); int currentX = Settings::Manager::getInt("resolution x", "Video"); int currentY = Settings::Manager::getInt("resolution y", "Video"); for (size_t i=0; i<mResolutionList->getItemCount(); ++i) { int resX, resY; parseResolution (resX, resY, mResolutionList->getItemNameAt(i)); if (resX == currentX && resY == currentY) { mResolutionList->setIndexSelected(i); break; } } }
bool ExternalDisplay::readResolution() { char sysFsEDIDFilePath[255]; sprintf(sysFsEDIDFilePath , "/sys/devices/virtual/graphics/fb%d/edid_modes", mHdmiFbNum); int hdmiEDIDFile = open(sysFsEDIDFilePath, O_RDONLY, 0); int len = -1; if (hdmiEDIDFile < 0) { ALOGE("%s: edid_modes file '%s' not found", __FUNCTION__, sysFsEDIDFilePath); return false; } else { len = read(hdmiEDIDFile, mEDIDs, sizeof(mEDIDs)-1); ALOGD_IF(DEBUG, "%s: EDID string: %s length = %d", __FUNCTION__, mEDIDs, len); if ( len <= 0) { ALOGE("%s: edid_modes file empty '%s'", __FUNCTION__, sysFsEDIDFilePath); } else { while (len > 1 && isspace(mEDIDs[len-1])) --len; mEDIDs[len] = 0; } } close(hdmiEDIDFile); if(len > 0) { // Get EDID modes from the EDID strings mModeCount = parseResolution(mEDIDs, mEDIDModes); ALOGD_IF(DEBUG, "%s: mModeCount = %d", __FUNCTION__, mModeCount); } return (strlen(mEDIDs) > 0); }
int HDMIDaemon::processFrameworkCommand() { char buffer[128]; int ret; ssize_t totlen; ssize_t commandlen; ssize_t datalen; if ((ret = read(mAcceptedConnection, buffer, sizeof(buffer) -1)) < 0) { ALOGE("Unable to read framework command (%s)", strerror(errno)); return -1; } else if (!ret) return -1; totlen = (ssize_t)ret; ALOGE("Read framework command (%ld bytes)", totlen); /* Null terminate after read bytes */ buffer[totlen] = 0; if (!strncmp(buffer, HDMI_CMD_SET_RESOLUTION, strlen(HDMI_CMD_SET_RESOLUTION))) { __u16 width; __u16 height; __u16 rr = 0; int cea, vesaceanr; ALOGD(HDMI_CMD_SET_RESOLUTION); commandlen = (ssize_t)(strlen(HDMI_CMD_SET_RESOLUTION) + 1); /* Skip the null terminator */ datalen = totlen - commandlen - 1; ALOGE("Command length: %ld bytes, data length: %ld bytes", commandlen, datalen); if (datalen > 0) { if (parseResolution(&buffer[commandlen], datalen, &width, &height) < 0) { ALOGE("Failed to parse resolution from input buffer (%ld bytes)", datalen); return 0; } if (getResolutionFromList(width, height, rr, &cea, &vesaceanr) < 0) { ALOGE("Failed to get cea and vesaceanr from list, w:%d h:%d rr:%d" ", selecting default resolution", width, height, rr); cea = mResolutionListHead->mEntry.cea; vesaceanr = mResolutionListHead->mEntry.vesaceanr; width = mResolutionListHead->mEntry.width; height = mResolutionListHead->mEntry.height; rr = mResolutionListHead->mEntry.refreshrate; } ALOGD("Setting resolution w:%d, h:%d, prr:%d, cea:%d, vesaceanr:%d", width, height, rr, cea, vesaceanr); if (hdmi_resolution_set(cea, vesaceanr) < 0) { ALOGE("Failed to set resolution with cea:%d vesaceanr:%d", cea, vesaceanr); return 0; } } else { ALOGE("Data missing from package, no preferred " "resolution will be set"); } } else if (!strcmp(buffer, HDMI_CMD_DEFAULT_RESOLUTION)) { ALOGD(HDMI_CMD_DEFAULT_RESOLUTION); int cea, vesaceanr; if (mResolutionListHead == NULL) { cea = 0; vesaceanr = 0; } else { cea = mResolutionListHead->mEntry.cea; vesaceanr = mResolutionListHead->mEntry.vesaceanr; } ALOGD("Setting resolution cea:%d, vesaceanr:%d", cea, vesaceanr); if (hdmi_resolution_set(cea, vesaceanr) < 0) { ALOGE("Failed to set resolution with cea:%d vesaceanr:%d", cea, vesaceanr); return 0; } } return 0; }
bool Config::init(const fs::path & file) { fs::ifstream ifs; ifs.open(file); bool loaded = ifs.is_open(); ConfigReader reader; if(!reader.read(ifs)) { LogWarning << "Errors while parsing config file"; } // Get locale language language = reader.getKey(Section::Language, Key::language, Default::language); // Get video settings std::string resolution = reader.getKey(Section::Video, Key::resolution, Default::resolution); if(resolution == "auto") { video.resolution = Vec2i_ZERO; } else { video.resolution = parseResolution(resolution); } video.fullscreen = reader.getKey(Section::Video, Key::fullscreen, Default::fullscreen); video.levelOfDetail = reader.getKey(Section::Video, Key::levelOfDetail, Default::levelOfDetail); video.fogDistance = reader.getKey(Section::Video, Key::fogDistance, Default::fogDistance); video.showCrosshair = reader.getKey(Section::Video, Key::showCrosshair, Default::showCrosshair); video.antialiasing = reader.getKey(Section::Video, Key::antialiasing, Default::antialiasing); video.vsync = reader.getKey(Section::Video, Key::vsync, Default::vsync); video.maxAnisotropicFiltering = reader.getKey(Section::Video, Key::maxAnisotropicFiltering, Default::maxAnisotropicFiltering); video.maxAnisotropicFiltering = std::max(0, video.maxAnisotropicFiltering); video.colorkeyAlphaToCoverage = reader.getKey(Section::Video, Key::colorkeyAlphaToCoverage, Default::colorkeyAlphaToCoverage); video.colorkeyAntialiasing = reader.getKey(Section::Video, Key::colorkeyAntialiasing, Default::colorkeyAntialiasing); video.limitSpeechWidth = reader.getKey(Section::Video, Key::limitSpeechWidth, Default::limitSpeechWidth); int cinematicMode = reader.getKey(Section::Video, Key::cinematicWidescreenMode, Default::cinematicWidescreenMode); video.cinematicWidescreenMode = CinematicWidescreenMode(glm::clamp(cinematicMode, 0, 2)); video.hudScale = reader.getKey(Section::Video, Key::hudScale, Default::hudScale); // Get window settings window.framework = reader.getKey(Section::Window, Key::windowFramework, Default::windowFramework); std::string windowSize = reader.getKey(Section::Window, Key::windowSize, Default::windowSize); window.size = parseResolution(windowSize); // Get audio settings audio.backend = reader.getKey(Section::Audio, Key::audioBackend, Default::audioBackend); audio.device = reader.getKey(Section::Audio, Key::audioDevice, Default::audioDevice); audio.volume = reader.getKey(Section::Audio, Key::volume, Default::volume); audio.sfxVolume = reader.getKey(Section::Audio, Key::sfxVolume, Default::sfxVolume); audio.speechVolume = reader.getKey(Section::Audio, Key::speechVolume, Default::speechVolume); audio.ambianceVolume = reader.getKey(Section::Audio, Key::ambianceVolume, Default::ambianceVolume); audio.eax = reader.getKey(Section::Audio, Key::eax, Default::eax); // Get input settings input.invertMouse = reader.getKey(Section::Input, Key::invertMouse, Default::invertMouse); input.autoReadyWeapon = reader.getKey(Section::Input, Key::autoReadyWeapon, Default::autoReadyWeapon); input.mouseLookToggle = reader.getKey(Section::Input, Key::mouseLookToggle, Default::mouseLookToggle); input.mouseSensitivity = reader.getKey(Section::Input, Key::mouseSensitivity, Default::mouseSensitivity); input.autoDescription = reader.getKey(Section::Input, Key::autoDescription, Default::autoDescription); // Get action key settings for(size_t i = 0; i < NUM_ACTION_KEY; i++) { actions[i] = reader.getActionKey(Section::Key, (ControlAction)i); } // Get miscellaneous settings misc.forceToggle = reader.getKey(Section::Misc, Key::forceToggle, Default::forceToggle); misc.migration = (MigrationStatus)reader.getKey(Section::Misc, Key::migration, Default::migration); misc.quicksaveSlots = std::max(reader.getKey(Section::Misc, Key::quicksaveSlots, Default::quicksaveSlots), 1); misc.debug = reader.getKey(Section::Misc, Key::debugLevels, Default::debugLevels); return loaded; }
int main(int argc, char* argv[]){ int opt; int res[2] = {640,480}; double width = 4; double height = 4; double center[2] = {0,0}; char* outDir = NULL; FILE* file = stdout; int parseCenterResult = 0; int parseResolutionResult = 0; int noArguments = 0; static struct option long_options[] ={ {"version", no_argument, 0, 'V'}, {"help", no_argument, 0, 'h'}, {"resolution", required_argument, 0, 'r'}, {"center", required_argument, 0, 'c'}, {"width", required_argument, 0, 'w'}, {"height", required_argument, 0, 'H'}, {"output", required_argument, 0, 'o'}, {0, 0, 0, 0} }; while ((opt = getopt_long (argc, argv, "r:c:w:H:o:Vh", long_options, NULL)) != -1){ switch(opt){ case 'r': noArguments++; parseResolutionResult = parseResolution(optarg, res); break; case 'w': noArguments++; width = atof(optarg); break; case 'H': noArguments++; height = atof(optarg); break; case 'o': noArguments++; outDir = optarg; break; case 'c': noArguments++; parseCenterResult = parseCenter(optarg, center); break; case 'h': usage(argv[0]); return 0; case 'V': version(argv[0]); return 0; case '?': printf("Error\n"); return USAGE_ERROR; } } if (noArguments == 0) { usage(argv[0]); return 0; } if (parseCenterResult == -1){ usage(argv[0]); if (fprintf(stderr, "fatal: invalid center specification.\n") < 0) return IO_ERROR; return USAGE_ERROR; } if (parseResolutionResult == -1){ usage(argv[0]); if (fprintf(stderr, "fatal: invalid resolution specification.\n") < 0) return IO_ERROR; return USAGE_ERROR; } if (outDir == NULL){ return USAGE_ERROR; } if (strcmp(outDir,"-") != 0){ file = fopen(outDir,"w"); if (!file){ usage(argv[0]); if (fprintf(stderr, "fatal: cannot open output file.\n") < 1) return IO_ERROR; return USAGE_ERROR; } } if (res[0] <= 0 || res[1] <= 0) usage(argv[0]); else{ if (fprintf(file, "P2\n%d\n%d\n%d\n", res[0],res[1],MAX_VAL) < 0) return IO_ERROR; print(res,center,width,height,file); } if (file != stdout) if (fclose(file) < 0) return IO_ERROR; return 0; }