@@ -152,15 +152,26 @@ pub const Context = struct {
152
152
// }
153
153
154
154
pub fn tick (core : * Core ) ! void {
155
- _ = core ; // autofix
155
+ var windows = core .windows .slice ();
156
+ while (windows .next ()) | window_id | {
157
+ const native_opt : ? Native = core .windows .get (window_id , .native );
156
158
159
+ if (native_opt ) | native | {
160
+ _ = native ; // autofix
161
+
162
+ // Handle resizing the window when the user changes width or height
163
+ if (core .windows .updated (window_id , .width ) or core .windows .updated (window_id , .height )) {}
164
+ } else {
165
+ try initWindow (core , window_id );
166
+ }
167
+ }
157
168
}
158
169
159
170
fn initWindow (
160
171
core : * Core ,
161
172
window_id : mach.ObjectID ,
162
173
) ! void {
163
- const core_window = core .windows .getValue (window_id );
174
+ var core_window = core .windows .getValue (window_id );
164
175
165
176
const hInstance = w .GetModuleHandleW (null );
166
177
const class_name = w .L ("mach" );
@@ -227,11 +238,19 @@ fn initWindow(
227
238
228
239
_ = w .SetWindowLongPtrW (native_window , w .GWLP_USERDATA , @bitCast (@intFromPtr (& context )));
229
240
241
+ _ = w .ShowWindow (native_window , w .SW_SHOW );
242
+
243
+ restoreWindowPosition (core , window_id );
244
+
230
245
const size = getClientRect (core , window_id );
231
246
core_window .width = size .width ;
232
247
core_window .height = size .height ;
233
248
234
249
_ = w .GetWindowRect (native .window , & native .saved_window_rect );
250
+
251
+ core_window .native = native ;
252
+ core .windows .setValueRaw (window_id , core_window );
253
+ try core .initWindow (window_id );
235
254
}
236
255
237
256
// pub fn update(self: *Win32) !void {
@@ -406,12 +425,12 @@ fn wndProc(wnd: w.HWND, msg: u32, wParam: w.WPARAM, lParam: w.LPARAM) callconv(w
406
425
const core = context .core ;
407
426
const window_id = context .window_id ;
408
427
409
- const window = core .windows .getValue (window_id );
428
+ var window = core .windows .getValue (window_id );
410
429
defer core .windows .setValueRaw (window_id , window );
411
430
412
431
switch (msg ) {
413
432
w .WM_CLOSE = > {
414
- core .pushEvent (.close );
433
+ core .pushEvent (.{ . close = .{ . window_id = window_id } } );
415
434
return 0 ;
416
435
},
417
436
w .WM_SIZE = > {
@@ -437,7 +456,7 @@ fn wndProc(wnd: w.HWND, msg: u32, wParam: w.WPARAM, lParam: w.LPARAM) callconv(w
437
456
if (vkey == w .VK_PROCESSKEY ) return 0 ;
438
457
439
458
if (msg == w .WM_SYSKEYDOWN and vkey == w .VK_F4 ) {
440
- core .pushEvent (.close );
459
+ core .pushEvent (.{ . close = .{ . window_id = window_id } } );
441
460
return 0 ;
442
461
}
443
462
@@ -489,7 +508,7 @@ fn wndProc(wnd: w.HWND, msg: u32, wParam: w.WPARAM, lParam: w.LPARAM) callconv(w
489
508
return 0 ;
490
509
},
491
510
w .WM_CHAR = > {
492
- if (window .native ) | native | {
511
+ if (window .native ) | * native | {
493
512
const char : u16 = @truncate (wParam );
494
513
var chars : []const u16 = undefined ;
495
514
if (native .surrogate != 0 ) {
@@ -596,6 +615,7 @@ fn wndProc(wnd: w.HWND, msg: u32, wParam: w.WPARAM, lParam: w.LPARAM) callconv(w
596
615
},
597
616
else = > return w .DefWindowProcW (wnd , msg , wParam , lParam ),
598
617
}
618
+ return w .DefWindowProcW (wnd , msg , wParam , lParam );
599
619
}
600
620
601
621
fn keyFromScancode (scancode : u9 ) Key {
0 commit comments