Fixed centering of the window.

This commit is contained in:
Revertron
2025-10-27 22:09:11 +01:00
parent 19f67e8b77
commit 8e11f63479
4 changed files with 20 additions and 5 deletions
Generated
+1 -1
View File
@@ -45,7 +45,7 @@ dependencies = [
[[package]]
name = "alfis"
version = "0.8.6"
version = "0.8.7"
dependencies = [
"bincode",
"blakeout",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "alfis"
version = "0.8.6"
version = "0.8.7"
authors = ["Revertron <alfis@revertron.com>"]
edition = "2021"
build = "build.rs"
Binary file not shown.
+18 -3
View File
@@ -27,6 +27,7 @@ use tao::{
event_loop::{ControlFlow, EventLoopBuilder, EventLoopProxy},
window::WindowBuilder,
};
use tao::dpi::PhysicalPosition;
use wry::WebViewBuilder;
pub fn run_interface(context: Arc<Mutex<Context>>, miner: Arc<Mutex<Miner>>) {
@@ -43,22 +44,36 @@ pub fn run_interface(context: Arc<Mutex<Context>>, miner: Arc<Mutex<Miner>>) {
let event_loop = EventLoopBuilder::<UserEvent>::with_user_event().build();
let proxy = event_loop.create_proxy();
// Get primary monitor and calculate center position
let primary_monitor = event_loop.primary_monitor().unwrap();
let monitor_size = primary_monitor.size();
let monitor_position = primary_monitor.position();
let window_size = tao::dpi::LogicalSize::new(1024, 720);
let scaled = window_size.to_physical::<i32>(primary_monitor.scale_factor());
let center_x = monitor_position.x + (monitor_size.width as i32 - scaled.width) / 2;
let center_y = monitor_position.y + (monitor_size.height as i32 - scaled.height) / 2;
let window = WindowBuilder::new()
.with_title(&title)
.with_inner_size(tao::dpi::LogicalSize::new(1023, 720))
.with_inner_size(window_size)
.with_min_inner_size(tao::dpi::LogicalSize::new(773, 350))
.with_position(PhysicalPosition::new(center_x, center_y))
.with_resizable(true)
.with_visible(true)
.build(&event_loop)
.expect("Failed to create window");
.expect("Failed to create the window");
#[cfg(windows)]
{
use tao::platform::windows::WindowExtWindows;
use winapi::um::shellscalingapi::SetProcessDpiAwareness;
unsafe {
SetProcessDpiAwareness(2);
}
use tao::platform::windows::IconExtWindows;
use tao::window::Icon;
let icon = Icon::from_resource(1, None).unwrap();
window.set_window_icon(Some(icon));
}
// Clone for the IPC handler