дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-28 21:42:27 +02:00
fix(windows): open a project window no larger than the screen's work area (#5817)
On Windows a project window opened at the configured 1440x900 and Restore Down returned to it, which ran under the taskbar on small or scaled screens (1920x1080 at 150%). The new window's size and minimum size are now shrunk to the primary monitor's work area. Fixes #5750
Цей коміт міститься в:
1 джерело
57eac70018
коміт
d33ee53c92
1 file changed
+35
@@ -850,6 +850,16 @@ fn build_project_window(app: &AppHandle, mut config: WindowConfig) -> IdeResult<
|
||||
}
|
||||
#[cfg(target_os = "linux")]
|
||||
let show_after_build = crate::linux_window_state::prepare(app, &mut config);
|
||||
// Windows opens a project window at the configured size (window-state restores only the
|
||||
// maximized flag there), which Restore Down returns to.
|
||||
#[cfg(windows)]
|
||||
if let Ok(Some(monitor)) = app.primary_monitor() {
|
||||
let area = monitor.work_area().size.to_logical::<f64>(monitor.scale_factor());
|
||||
let min = (config.min_width.unwrap_or(0.0), config.min_height.unwrap_or(0.0));
|
||||
let (size, min) = fit_new_window((config.width, config.height), min, (area.width, area.height));
|
||||
(config.width, config.height) = size;
|
||||
(config.min_width, config.min_height) = (Some(min.0), Some(min.1));
|
||||
}
|
||||
let window = WebviewWindowBuilder::from_config(app, &config)
|
||||
.and_then(|b| dev_font_preferences(b).on_new_window(open_popup_in_browser).build())
|
||||
.map_err(|e| IdeError::internal(format!("cannot create window: {e}")))?;
|
||||
@@ -2104,6 +2114,18 @@ fn fit_over_parent(
|
||||
rx.recv_timeout(FIT_ON_MAIN_TIMEOUT).map_err(|_| tauri::Error::FailedToReceiveMessage)
|
||||
}
|
||||
|
||||
/// A new window's size and minimum size (logical pixels) shrunk to fit `area`, the work area of
|
||||
/// the monitor it opens on: the default 1440×900 is taller than a 1920×1080 laptop screen at
|
||||
/// 150 % scaling once the taskbar is taken off.
|
||||
#[cfg_attr(not(windows), allow(dead_code))]
|
||||
fn fit_new_window(size: (f64, f64), min: (f64, f64), area: (f64, f64)) -> ((f64, f64), (f64, f64)) {
|
||||
if area.0 <= 0.0 || area.1 <= 0.0 {
|
||||
return (size, min);
|
||||
}
|
||||
let size = (size.0.min(area.0), size.1.min(area.1));
|
||||
(size, (min.0.min(size.0), min.1.min(size.1)))
|
||||
}
|
||||
|
||||
/// Centres the settings window over its owner, inside the owner's monitor work area. The window
|
||||
/// may still be on another display with a different scale, so its size is converted with its own
|
||||
/// scale and its position is given in physical pixels.
|
||||
@@ -2926,6 +2948,19 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_new_window_fits_the_work_area() {
|
||||
// 1920×1080 at 150 % with a 48-pixel taskbar (#5750).
|
||||
let area = (1280.0, 1032.0 / 1.5);
|
||||
assert_eq!(fit_new_window((1440.0, 900.0), (400.0, 500.0), area), ((1280.0, 688.0), (400.0, 500.0)));
|
||||
// A minimum larger than the screen gives way too.
|
||||
assert_eq!(fit_new_window((1440.0, 900.0), (400.0, 800.0), area).1, (400.0, 688.0));
|
||||
// A large screen keeps the configured size; an unknown work area changes nothing.
|
||||
let big = ((1440.0, 900.0), (400.0, 500.0));
|
||||
assert_eq!(fit_new_window(big.0, big.1, (2560.0, 1400.0)), big);
|
||||
assert_eq!(fit_new_window(big.0, big.1, (0.0, 0.0)), big);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn settings_bounds_fit_current_work_area() {
|
||||
for (parent, size, work, expected) in [
|
||||
|
||||
Reference in new issue
Заблокувати користувача