Skip to content

Commit 3b5c52b

Browse files
committed
Fix window scale lost on move.
On Windows 11 I observe the window scaling goes away when the window is moved. Also it wasn't being set on start-up correctly.
1 parent aea3876 commit 3b5c52b

File tree

1 file changed

+35
-9
lines changed

1 file changed

+35
-9
lines changed

src/main.rs

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ struct MyApp {
5454
font8x16: Vec<TextureId>,
5555
font8x8: Vec<TextureId>,
5656
sender: mpsc::Sender<AppEvent>,
57+
reset: bool,
5758
}
5859

5960
#[derive(Debug, PartialEq, Eq)]
@@ -233,20 +234,27 @@ fn main() {
233234
*CONFIG_FILE_PATH.lock().unwrap() = Some(config_path);
234235
}
235236

237+
let default_mode = unsafe { common::video::Mode::from_u8(0) };
238+
let width = (default_mode.horizontal_pixels() as f32) * SCALE_FACTOR;
239+
let height = (default_mode.vertical_lines() as f32) * SCALE_FACTOR;
240+
info!("Default Window set to {} x {}", width, height);
241+
236242
// Make a window
237243
let mut engine = Engine::builder()
238-
.dimensions(640, 480)
244+
.dimensions(width as u32, height as u32)
245+
.scale(SCALE_FACTOR, SCALE_FACTOR)
239246
.title("Neotron Desktop BIOS")
240247
.show_frame_rate()
241248
.target_frame_rate(60)
242249
.build()
243250
.unwrap();
244251
let (sender, receiver) = mpsc::channel();
245252
let mut app = MyApp {
246-
mode: unsafe { common::video::Mode::from_u8(0) },
253+
mode: default_mode,
247254
font8x16: Vec::new(),
248255
font8x8: Vec::new(),
249256
sender,
257+
reset: true,
250258
};
251259

252260
EV_QUEUE.lock().unwrap().replace(receiver);
@@ -425,11 +433,16 @@ extern "C" fn configuration_set(buffer: common::FfiByteSlice) -> common::ApiResu
425433

426434
/// Does this Neotron BIOS support this video mode?
427435
extern "C" fn video_is_valid_mode(mode: common::video::Mode) -> bool {
428-
debug!("video_is_valid_mode()");
429-
mode == common::video::Mode::new(
430-
common::video::Timing::T640x480,
431-
common::video::Format::Text8x16,
432-
)
436+
let result = match mode.as_u8() {
437+
// 640x480 80x30 text mode
438+
0 => true,
439+
// 640x480 80x60 text mode
440+
1 => true,
441+
// nothing else will work
442+
_ => false,
443+
};
444+
debug!("video_is_valid_mode({:?}) = {}", mode, result);
445+
result
433446
}
434447

435448
/// Switch to a new video mode.
@@ -1125,7 +1138,18 @@ impl PixEngine for MyApp {
11251138
self.sender.send(AppEvent::KeyDown(*key)).unwrap();
11261139
Ok(true)
11271140
}
1128-
_ => Ok(false),
1141+
Event::Window {
1142+
win_event: WindowEvent::Moved(_, _),
1143+
..
1144+
} => {
1145+
// need to reset the scale when the window is moved?
1146+
self.reset = true;
1147+
Ok(true)
1148+
}
1149+
_ => {
1150+
debug!("Didn't know about {:?}", event);
1151+
Ok(false)
1152+
}
11291153
}
11301154
}
11311155

@@ -1135,7 +1159,9 @@ impl PixEngine for MyApp {
11351159
fn on_update(&mut self, s: &mut PixState) -> PixResult<()> {
11361160
let mode_value = VIDEO_MODE.load(Ordering::Relaxed);
11371161
let new_mode = unsafe { common::video::Mode::from_u8(mode_value) };
1138-
if new_mode != self.mode {
1162+
if new_mode != self.mode || self.reset {
1163+
info!("New video mode detected, or needs reset");
1164+
self.reset = false;
11391165
self.mode = new_mode;
11401166
let width = (new_mode.horizontal_pixels() as f32) * SCALE_FACTOR;
11411167
let height = (new_mode.vertical_lines() as f32) * SCALE_FACTOR;

0 commit comments

Comments
 (0)