Skip to content

Commit d2968d3

Browse files
Dave Hornerdave horner
authored andcommitted
feat(e_window): integrate cross-platform screen size detection with e_window_native module
Refactored the e_window app.rs to use the newly created e_window_native module for cross-platform screen size detection. Added e_window_native as a new module with appropriate functions and updated relevant code sections for better code organization and maintenance.
1 parent 898b528 commit d2968d3

12 files changed

Lines changed: 174 additions & 78 deletions

File tree

Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ members = [
44
"cargo-e",
55
"addendum/e_crate_version_checker",
66
"addendum/e_ai_summarize",
7-
"addendum/e_window",
7+
# "addendum/e_window",
88
"addendum/e_window_api",
99
"addendum/e_window_types",
10+
"addendum/e_window_native",
1011
"addendum/e_obs",
1112
]
1213
exclude = ["addenda"]

addendum/e_window/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.1.15](https://github.com/davehorner/cargo-e/compare/e_window-v0.1.14...e_window-v0.1.15) - 2025-10-12
11+
12+
### Added
13+
14+
- *(e_window)* integrate cross-platform screen size detection with e_window_native module
15+
1016
## [0.1.14](https://github.com/davehorner/cargo-e/compare/e_window-v0.1.13...e_window-v0.1.14) - 2025-10-11
1117

1218
### Added

addendum/e_window/Cargo.toml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ edition = "2021"
33
name = "e_window"
44
description = "A window tool. Think WinAPI ShowMessageBox; but more than that."
55
license = "MIT"
6-
version = "0.1.14"
6+
version = "0.1.15"
77
authors = ["David Horner"]
88
publish = true
99

@@ -51,26 +51,17 @@ raven-uxn = { version = "0.1.0", optional = true }
5151
raven-varvara = { version = "0.1.0", optional = true }
5252

5353
[target.'cfg(windows)'.dependencies]
54-
winapi = { version = "0.3", features = ["winuser","processthreadsapi"] }
54+
winapi = { version = "0.3", features = ["winuser", "processthreadsapi"] }
5555
eframe = { version = "0.33.0", features = ["persistence"] }
5656
# Enabled the `persistence` feature for `eframe` to support `get_value` and `set_value`.
5757
windows = { version = "0.62.2", features = ["Win32"] }
5858
e_grid = "0.2.1"
5959
#e_grid = { path = "e_grid"}
60-
61-
[target.'cfg(target_os = "macos")'.dependencies]
62-
core-graphics = "0.25.0"
63-
64-
[target.'cfg(target_os = "linux")'.dependencies]
65-
x11 = { version = "2.21.0", features = ["xlib"] }
66-
60+
e_window_native = "0.1.0"
6761

6862
[target.'cfg(unix)'.dependencies]
6963
eframe = { version = "0.33.0", features = ["persistence", "serde", "wayland"] }
7064

7165
[lib]
7266
name = "e_window"
7367
path = "src/lib.rs"
74-
75-
76-

addendum/e_window/src/app.rs

Lines changed: 8 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ impl eframe::App for App {
649649
eprintln!("[DEBUG] Applying auto-centering with content size: {}x{}", actual_size.x, actual_size.y);
650650

651651
// Cross-platform screen size detection
652-
let (screen_width, screen_height, method_used) = get_cross_platform_screen_size();
652+
let (screen_width, screen_height, method_used) = e_window_native::get_cross_platform_screen_size();
653653

654654
// Check if the window should be resized to fit content instead of using default size
655655
// This handles the case where egui applies a default size (like 1024x768) instead of content size
@@ -666,15 +666,15 @@ impl eframe::App for App {
666666

667667
// Resize window to fit content
668668
ctx.send_viewport_cmd(egui::ViewportCommand::InnerSize(egui::vec2(target_width, target_height)));
669-
(target_width, target_height)
669+
(target_width as u32, target_height as u32)
670670
} else {
671-
(actual_size.x, actual_size.y)
671+
(actual_size.x as u32, actual_size.y as u32)
672672
};
673673

674674
// Calculate center position based on final window size
675675
if screen_width > final_width && screen_height > final_height {
676-
let center_x = (screen_width - final_width) / 2.0;
677-
let center_y = (screen_height - final_height) / 2.0;
676+
let center_x = (screen_width as f32 - final_width as f32) / 2.0;
677+
let center_y = (screen_height as f32 - final_height as f32) / 2.0;
678678

679679
eprintln!("[DEBUG] Auto-centering ({}): screen={}x{}, window={}x{}, center=({}, {})",
680680
method_used, screen_width, screen_height, final_width, final_height, center_x, center_y);
@@ -712,9 +712,9 @@ impl eframe::App for App {
712712
// and we're still at origin position AND auto-centering is enabled
713713
if self.should_auto_center && old_size != new_size && current_pos.x as i32 == 0 && current_pos.y as i32 == 0 {
714714
// Use cross-platform screen detection
715-
let (screen_width, screen_height, method_used) = get_cross_platform_screen_size();
716-
let new_center_x = ((screen_width - new_size.0 as f32) / 2.0) as i32;
717-
let new_center_y = ((screen_height - new_size.1 as f32) / 2.0) as i32;
715+
let (screen_width, screen_height, method_used) = e_window_native::get_cross_platform_screen_size();
716+
let new_center_x = ((screen_width as f32 - new_size.0 as f32) / 2.0).round() as i32;
717+
let new_center_y = ((screen_height as f32 - new_size.1 as f32) / 2.0).round() as i32;
718718

719719
eprintln!("[App] Auto-centering ({}): old_size={}x{}, new_size={}x{}, screen={}x{}, new_center=({}, {})",
720720
method_used, old_size.0, old_size.1, new_size.0, new_size.1, screen_width, screen_height, new_center_x, new_center_y);
@@ -1542,59 +1542,3 @@ anchor: Click me! | e_window --title "you clicked!" --width 800 --height 600 --x
15421542
pub fn default_card_with_hwnd(hwnd: usize) -> String {
15431543
DEFAULT_CARD_TEMPLATE.replace("{PARENT_HWND}", &format!("0x{:X}", hwnd))
15441544
}
1545-
1546-
/// Cross-platform screen size detection
1547-
fn get_cross_platform_screen_size() -> (f32, f32, &'static str) {
1548-
#[cfg(target_os = "windows")]
1549-
{
1550-
use winapi::um::winuser::{GetSystemMetrics, SM_CXSCREEN, SM_CYSCREEN};
1551-
1552-
let width = unsafe { GetSystemMetrics(SM_CXSCREEN) } as f32;
1553-
let height = unsafe { GetSystemMetrics(SM_CYSCREEN) } as f32;
1554-
1555-
eprintln!("[DEBUG] Windows GetSystemMetrics screen size: {}x{}", width, height);
1556-
(width, height, "windows_getsystemmetrics")
1557-
}
1558-
1559-
#[cfg(target_os = "macos")]
1560-
{
1561-
// macOS screen detection using Core Graphics
1562-
use core_graphics::display::CGMainDisplay;
1563-
1564-
let display = CGMainDisplay();
1565-
let width = display.pixels_wide() as f32;
1566-
let height = display.pixels_high() as f32;
1567-
1568-
eprintln!("[DEBUG] macOS Core Graphics screen size: {}x{}", width, height);
1569-
(width, height, "macos_coregraphics")
1570-
}
1571-
1572-
#[cfg(target_os = "linux")]
1573-
{
1574-
// Linux screen detection using X11
1575-
use x11::xlib::*;
1576-
use std::ptr;
1577-
1578-
unsafe {
1579-
let display = XOpenDisplay(ptr::null());
1580-
if !display.is_null() {
1581-
let screen = XDefaultScreen(display);
1582-
let width = XDisplayWidth(display, screen) as f32;
1583-
let height = XDisplayHeight(display, screen) as f32;
1584-
XCloseDisplay(display);
1585-
1586-
eprintln!("[DEBUG] Linux X11 screen size: {}x{}", width, height);
1587-
(width, height, "linux_x11")
1588-
} else {
1589-
eprintln!("[DEBUG] Failed to open X11 display, using fallback");
1590-
(1920.0, 1080.0, "linux_fallback")
1591-
}
1592-
}
1593-
}
1594-
1595-
#[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))]
1596-
{
1597-
eprintln!("[DEBUG] Unsupported platform, using fallback screen size");
1598-
(1920.0, 1080.0, "platform_fallback")
1599-
}
1600-
}

addendum/e_window_api/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88

9+
## [0.1.3](https://github.com/davehorner/cargo-e/compare/e_window_api-v0.1.2...e_window_api-v0.1.3) - 2025-10-12
10+
11+
### Added
12+
13+
- *(e_window)* integrate cross-platform screen size detection with e_window_native module
14+
915
## [0.1.2](https://github.com/davehorner/cargo-e/compare/e_window_api-v0.1.1...e_window_api-v0.1.2) - 2025-10-12
1016

1117
### Fixed

addendum/e_window_api/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "e_window_api"
3-
version = "0.1.2"
3+
version = "0.1.3"
44
edition = "2021"
55
description = "A Rust API wrapper for e_window providing high-level abstraction"
66
license = "MIT"
@@ -18,6 +18,7 @@ ratatui = "0.29.0"
1818

1919
[target.'cfg(windows)'.dependencies]
2020
winapi = { version = "0.3", features = ["winuser"] }
21+
e_window_native = { path = "../e_window_native" }
2122

2223
[target.'cfg(target_os = "macos")'.dependencies]
2324
core-graphics = "0.25.0"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target/
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
## [0.1.0](https://github.com/davehorner/cargo-e/releases/tag/e_window_native-v0.1.0) - 2025-10-12
11+
12+
### Added
13+
14+
- *(e_window)* integrate cross-platform screen size detection with e_window_native module
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "e_window_native"
3+
version = "0.1.0"
4+
edition = "2021"
5+
description = "e_window shared native methods for screen size and other native needs."
6+
license = "MIT"
7+
authors = ["David Horner"]
8+
publish = true
9+
10+
[target.'cfg(windows)'.dependencies]
11+
winapi = { version = "0.3", features = ["winuser"] }
12+
13+
[target.'cfg(target_os = "macos")'.dependencies]
14+
core-graphics = "0.25.0"
15+
16+
[target.'cfg(target_os = "linux")'.dependencies]
17+
x11 = { version = "2.21.0", features = ["xlib"] }

0 commit comments

Comments
 (0)