feat(win32 gui): issue quit command on window close and exit cleanly

This commit is contained in:
CJ van den Berg 2025-01-06 10:05:19 +01:00
parent 21a7106fe3
commit a6b29e4fe9
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
2 changed files with 14 additions and 2 deletions

View file

@ -125,8 +125,8 @@ pub fn render(self: *Self) error{}!void {
}
}
pub fn stop(self: *Self) void {
_ = self;
std.log.warn("TODO: implement stop", .{});
gui.stop();
if (self.thread) |thread| thread.join();
}
pub fn stdplane(self: *Self) Plane {

View file

@ -16,6 +16,8 @@ const windowmsg = @import("windowmsg.zig");
const HResultError = ddui.HResultError;
const WM_APP_EXIT = win32.WM_APP + 1;
pub const DropWriter = struct {
pub const WriteError = error{};
pub const Writer = std.io.Writer(DropWriter, WriteError, write);
@ -492,6 +494,11 @@ pub const Win32Error = struct {
}
};
pub fn stop() void {
const hwnd = global.hwnd orelse return;
_ = win32.SendMessageW(hwnd, WM_APP_EXIT, 0, 0);
}
pub fn setWindowTitle(title: [*:0]const u16, err: *Win32Error) error{ NoWindow, Win32 }!void {
global.mutex.lock();
defer global.mutex.unlock();
@ -1116,6 +1123,11 @@ fn WndProc(
return 1; // background erased
},
win32.WM_CLOSE => {
const state = stateFromHwnd(hwnd);
state.pid.send(.{ "cmd", "quit" }) catch |e| onexit(e);
return 0;
},
WM_APP_EXIT => {
win32.PostQuitMessage(0);
return 0;
},