Improved FPS unlocker support

- added fullscreen and priority options
- added fps unlocker folder creation
This commit is contained in:
Observer KRypt0n_ 2022-09-14 09:32:56 +02:00
parent 41dc6532d8
commit 368710fd9d
No known key found for this signature in database
GPG key ID: 844DA47BA25FE1E2
5 changed files with 78 additions and 4 deletions

View file

@ -120,5 +120,30 @@ Adw.PreferencesPage page {
valign: center;
}
}
Adw.ActionRow {
title: "Fullscreen";
subtitle: "Open game window in fullscreen mode";
Gtk.Switch fps_unlocker_fullscreen_switcher {
valign: center;
}
}
Adw.ComboRow fps_unlocker_priority_combo {
title: "Priority";
subtitle: "Game process priority";
model: Gtk.StringList {
strings [
"Realtime",
"High",
"Above normal",
"Normal",
"Below normal",
"Low"
]
};
}
}
}

View file

@ -10,14 +10,18 @@ pub mod prelude {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Config {
pub fps: u64,
pub power_saving: bool
pub power_saving: bool,
pub fullscreen: bool,
pub priority: u64
}
impl Default for Config {
fn default() -> Self {
Self {
fps: 120,
power_saving: false
power_saving: false,
fullscreen: false,
priority: 3
}
}
}
@ -35,6 +39,16 @@ impl From<&JsonValue> for Config {
power_saving: match value.get("power_saving") {
Some(value) => value.as_bool().unwrap_or(default.power_saving),
None => default.power_saving
},
fullscreen: match value.get("fullscreen") {
Some(value) => value.as_bool().unwrap_or(default.fullscreen),
None => default.fullscreen
},
priority: match value.get("priority") {
Some(value) => value.as_u64().unwrap_or(default.priority),
None => default.priority
}
}
}

View file

@ -53,6 +53,8 @@ impl ConfigSchema {
Self {
FPSTarget: config.fps,
UsePowerSave: config.power_saving,
Fullscreen: config.fullscreen,
Priority: config.priority,
..Self::default()
}

View file

@ -35,6 +35,11 @@ impl FpsUnlocker {
pub fn download<T: ToString>(dir: T) -> anyhow::Result<Self> {
let mut downloader = Downloader::new(LATEST_INFO.1)?;
// Create FPS unlocker folder if needed
if !std::path::Path::new(&dir.to_string()).exists() {
std::fs::create_dir_all(dir.to_string())?;
}
match downloader.download_to(format!("{}/unlocker.exe", dir.to_string()), |_, _| {}) {
Ok(_) => Ok(Self {
dir: dir.to_string()

View file

@ -42,7 +42,9 @@ pub struct AppWidgets {
pub fps_unlocker_combo: adw::ComboRow,
pub fps_unlocker_switcher: gtk::Switch,
pub fps_unlocker_power_saving_switcher: gtk::Switch
pub fps_unlocker_power_saving_switcher: gtk::Switch,
pub fps_unlocker_fullscreen_switcher: gtk::Switch,
pub fps_unlocker_priority_combo: adw::ComboRow
}
impl AppWidgets {
@ -73,7 +75,9 @@ impl AppWidgets {
fps_unlocker_combo: get_object(&builder, "fps_unlocker_combo")?,
fps_unlocker_switcher: get_object(&builder, "fps_unlocker_switcher")?,
fps_unlocker_power_saving_switcher: get_object(&builder, "fps_unlocker_power_saving_switcher")?
fps_unlocker_power_saving_switcher: get_object(&builder, "fps_unlocker_power_saving_switcher")?,
fps_unlocker_fullscreen_switcher: get_object(&builder, "fps_unlocker_fullscreen_switcher")?,
fps_unlocker_priority_combo: get_object(&builder, "fps_unlocker_priority_combo")?
};
// Set availale wine languages
@ -267,6 +271,24 @@ impl App {
}
});
// FPS unlocker -> fullscreen swithing
self.widgets.fps_unlocker_fullscreen_switcher.connect_state_notify(move |switch| {
if let Ok(mut config) = config::get() {
config.game.enhancements.fps_unlocker.config.fullscreen = switch.state();
config::update(config);
}
});
// FPS unlocker -> priority combo
self.widgets.fps_unlocker_priority_combo.connect_selected_notify(move |row| {
if let Ok(mut config) = config::get() {
config.game.enhancements.fps_unlocker.config.priority = row.selected() as u64;
config::update(config);
}
});
self
}
@ -349,6 +371,12 @@ impl App {
// Switch FPS unlocker -> power saving
self.widgets.fps_unlocker_power_saving_switcher.set_state(config.game.enhancements.fps_unlocker.config.power_saving);
// Switch FPS unlocker -> fullscreen
self.widgets.fps_unlocker_fullscreen_switcher.set_state(config.game.enhancements.fps_unlocker.config.fullscreen);
// Switch FPS unlocker -> priority
self.widgets.fps_unlocker_priority_combo.set_selected(config.game.enhancements.fps_unlocker.config.priority as u32);
// Prepare gamescope settings app
self.widgets.gamescope_app.prepare(status_page)?;