fix: display rotation

This commit is contained in:
2025-03-03 20:44:00 +00:00
parent cde0752da2
commit 9669fc3905
3 changed files with 16 additions and 11 deletions

View File

@ -158,6 +158,8 @@ pub async fn init_profile(
if let Some(new_profile) = Profile::new(exe_path) { if let Some(new_profile) = Profile::new(exe_path) {
new_profile.save().await; new_profile.save().await;
appd.profile = Some(new_profile.clone()); appd.profile = Some(new_profile.clone());
fs::create_dir_all(new_profile.dir()).await
.map_err(|e| format!("Unable to create the profile directory: {}", e))?;
Ok(new_profile) Ok(new_profile)
} else { } else {

View File

@ -5,7 +5,7 @@ use anyhow::{Result, anyhow};
pub struct DisplayInfo { pub struct DisplayInfo {
primary: String, primary: String,
target: String, target: String,
target_rotation: displayz::Orientation target_settings: displayz::DisplaySettings
} }
#[cfg(not(target_os = "windows"))] #[cfg(not(target_os = "windows"))]
@ -15,7 +15,7 @@ pub async fn prepare_display(p: &Profile) -> Result<()> {
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
pub async fn prepare_display(p: &Profile) -> Result<Option<DisplayInfo>> { pub async fn prepare_display(p: &Profile) -> Result<Option<DisplayInfo>> {
use displayz::{query_displays, Orientation}; use displayz::{query_displays, Orientation, Resolution};
let display_name = p.get_str("display", "default"); let display_name = p.get_str("display", "default");
let rotation = p.get_int("display-rotation", 0); let rotation = p.get_int("display-rotation", 0);
@ -44,14 +44,16 @@ pub async fn prepare_display(p: &Profile) -> Result<Option<DisplayInfo>> {
let res = DisplayInfo { let res = DisplayInfo {
primary: primary.name().to_owned(), primary: primary.name().to_owned(),
target: target.name().to_owned(), target: target.name().to_owned(),
target_rotation: settings.borrow().orientation target_settings: settings.borrow().clone()
}; };
match rotation { if rotation == 90 || rotation == 270 {
90 => settings.borrow_mut().orientation = Orientation::Portrait, let rez = settings.borrow_mut().resolution;
270 => settings.borrow_mut().orientation = Orientation::PortraitFlipped, settings.borrow_mut().orientation = if rotation == 90 { Orientation::PortraitFlipped } else { Orientation::Portrait };
_ => () if rez.height < rez.width {
}; settings.borrow_mut().resolution = Resolution::new(rez.height, rez.width);
}
}
display_set.apply()?; display_set.apply()?;
displayz::refresh()?; displayz::refresh()?;
@ -63,7 +65,7 @@ pub async fn prepare_display(p: &Profile) -> Result<Option<DisplayInfo>> {
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
pub async fn undo_display(info: DisplayInfo) -> Result<()> { pub async fn undo_display(info: DisplayInfo) -> Result<()> {
use displayz::query_displays; use displayz::{query_displays, Resolution};
let display_set = query_displays()?; let display_set = query_displays()?;
@ -82,7 +84,7 @@ pub async fn undo_display(info: DisplayInfo) -> Result<()> {
let settings = target.settings() let settings = target.settings()
.as_ref() .as_ref()
.ok_or_else(|| anyhow!("Unable to query display settings"))?; .ok_or_else(|| anyhow!("Unable to query display settings"))?;
settings.borrow_mut().orientation = info.target_rotation; settings.replace_with(|_| info.target_settings);
display_set.apply()?; display_set.apply()?;
displayz::refresh()?; displayz::refresh()?;

View File

@ -5,6 +5,7 @@ import InputText from 'primevue/inputtext';
import Select from 'primevue/select'; import Select from 'primevue/select';
import SelectButton from 'primevue/selectbutton'; import SelectButton from 'primevue/selectbutton';
import Toggle from 'primevue/toggleswitch'; import Toggle from 'primevue/toggleswitch';
import { invoke as unproxied_invoke } from '@tauri-apps/api/core';
import OptionCategory from './OptionCategory.vue'; import OptionCategory from './OptionCategory.vue';
import OptionRow from './OptionRow.vue'; import OptionRow from './OptionRow.vue';
import { invoke } from '../invoke'; import { invoke } from '../invoke';
@ -49,7 +50,7 @@ const displayList: Ref<{ title: string; value: string }[]> = ref([
}, },
]); ]);
invoke('read_profile_data', { unproxied_invoke('read_profile_data', {
path: 'aime.txt', path: 'aime.txt',
}) })
.then((v: unknown) => { .then((v: unknown) => {