Merge pull request #4476 from fufesou/refact/change_resolution
change resolution, macos needs more tests
This commit is contained in:
commit
cb42edd789
@ -830,7 +830,7 @@ pub fn current_resolution(name: &str) -> ResultType<Resolution> {
|
|||||||
bail!("Failed to find current resolution for {}", name);
|
bail!("Failed to find current resolution for {}", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn change_resolution(name: &str, width: usize, height: usize) -> ResultType<()> {
|
pub fn change_resolution_directly(name: &str, width: usize, height: usize) -> ResultType<()> {
|
||||||
Command::new("xrandr")
|
Command::new("xrandr")
|
||||||
.args(vec![
|
.args(vec![
|
||||||
"--output",
|
"--output",
|
||||||
|
@ -658,7 +658,7 @@ pub fn current_resolution(name: &str) -> ResultType<Resolution> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn change_resolution(name: &str, width: usize, height: usize) -> ResultType<()> {
|
pub fn change_resolution_directly(name: &str, width: usize, height: usize) -> ResultType<()> {
|
||||||
let display = name.parse::<u32>().map_err(|e| anyhow!(e))?;
|
let display = name.parse::<u32>().map_err(|e| anyhow!(e))?;
|
||||||
unsafe {
|
unsafe {
|
||||||
if NO == MacSetMode(display, width as _, height as _) {
|
if NO == MacSetMode(display, width as _, height as _) {
|
||||||
|
@ -44,6 +44,24 @@ pub fn breakdown_callback() {
|
|||||||
crate::input_service::release_device_modifiers();
|
crate::input_service::release_device_modifiers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
|
pub fn change_resolution(name: &str, width: usize, height: usize) -> ResultType<()> {
|
||||||
|
hbb_common::log::warn!("Change resolution of '{}' to ({},{})", name, width, height);
|
||||||
|
|
||||||
|
let cur_resolution = current_resolution(name)?;
|
||||||
|
// For MacOS
|
||||||
|
// to-do: Make sure the following comparison works.
|
||||||
|
// For Linux
|
||||||
|
// Just run "xrandr", dpi may not be taken into consideration.
|
||||||
|
// For Windows
|
||||||
|
// dmPelsWidth and dmPelsHeight is the same to width and height
|
||||||
|
// Because this process is running in dpi awareness mode.
|
||||||
|
if cur_resolution.width as usize == width && cur_resolution.height as usize == height {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
change_resolution_directly(name, width, height)
|
||||||
|
}
|
||||||
|
|
||||||
// Android
|
// Android
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
pub fn get_active_username() -> String {
|
pub fn get_active_username() -> String {
|
||||||
|
@ -1867,10 +1867,10 @@ pub fn resolutions(name: &str) -> Vec<Resolution> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn current_resolution(name: &str) -> ResultType<Resolution> {
|
pub fn current_resolution(name: &str) -> ResultType<Resolution> {
|
||||||
|
let device_name = str_to_device_name(name);
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut dm: DEVMODEW = std::mem::zeroed();
|
let mut dm: DEVMODEW = std::mem::zeroed();
|
||||||
dm.dmSize = std::mem::size_of::<DEVMODEW>() as _;
|
dm.dmSize = std::mem::size_of::<DEVMODEW>() as _;
|
||||||
let device_name = str_to_device_name(name);
|
|
||||||
if EnumDisplaySettingsW(device_name.as_ptr(), ENUM_CURRENT_SETTINGS, &mut dm) == 0 {
|
if EnumDisplaySettingsW(device_name.as_ptr(), ENUM_CURRENT_SETTINGS, &mut dm) == 0 {
|
||||||
bail!(
|
bail!(
|
||||||
"failed to get currrent resolution, errno={}",
|
"failed to get currrent resolution, errno={}",
|
||||||
@ -1886,21 +1886,10 @@ pub fn current_resolution(name: &str) -> ResultType<Resolution> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(super) fn change_resolution_directly(name: &str, width: usize, height: usize) -> ResultType<()> {
|
||||||
|
|
||||||
pub fn change_resolution(name: &str, width: usize, height: usize) -> ResultType<()> {
|
|
||||||
let device_name = str_to_device_name(name);
|
let device_name = str_to_device_name(name);
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut dm: DEVMODEW = std::mem::zeroed();
|
let mut dm: DEVMODEW = std::mem::zeroed();
|
||||||
if FALSE == EnumDisplaySettingsW(device_name.as_ptr() as _, ENUM_CURRENT_SETTINGS, &mut dm)
|
|
||||||
{
|
|
||||||
bail!("EnumDisplaySettingsW failed, errno={}", GetLastError());
|
|
||||||
}
|
|
||||||
// dmPelsWidth and dmPelsHeight is the same to width and height
|
|
||||||
// Because this process is running in dpi awareness mode.
|
|
||||||
if dm.dmPelsWidth == width as u32 && dm.dmPelsHeight == height as u32 {
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
dm.dmPelsWidth = width as _;
|
dm.dmPelsWidth = width as _;
|
||||||
dm.dmPelsHeight = height as _;
|
dm.dmPelsHeight = height as _;
|
||||||
dm.dmFields = DM_PELSHEIGHT | DM_PELSWIDTH;
|
dm.dmFields = DM_PELSHEIGHT | DM_PELSWIDTH;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user