Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Core.zig
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ windows: mach.Objects(
// TODO: allocation/free strategy
title: [:0]const u8 = "Mach Window",

// XDG application ID of the window
app_id: [:0]const u8 = "",

/// Texture format of the framebuffer (read-only)
framebuffer_format: gpu.Texture.Format = .bgra8_unorm,

Expand Down
46 changes: 36 additions & 10 deletions src/core/linux/Wayland.zig
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,12 @@ pub fn initWindow(
return error.ListenerHasAlreadyBeenSet;
}

// Wait for events to get pushed
_ = libwaylandclient.?.wl_display_roundtrip(wl.display);

core_window = core.windows.getValue(window_id);
wl = &core_window.native.?.wayland;

c.xdg_toplevel_set_title(wl.toplevel, @ptrCast(core_window.title));
c.xdg_toplevel_set_app_id(wl.toplevel, @ptrCast(core_window.app_id));

// Commit changes to surface
c.wl_surface_commit(wl.surface);

Expand All @@ -191,8 +191,6 @@ pub fn initWindow(
if (result != -1 and wl.configured) break;
}

c.xdg_toplevel_set_title(wl.toplevel, @ptrCast(core_window.title));

const decoration = c.zxdg_decoration_manager_v1_get_toplevel_decoration(
wl.interfaces.zxdg_decoration_manager_v1,
wl.toplevel,
Expand All @@ -203,10 +201,16 @@ pub fn initWindow(
// Commit changes to surface
c.wl_surface_commit(wl.surface);

_ = libwaylandclient.?.wl_display_roundtrip(wl.display);
// _ = libwaylandclient.?.wl_display_roundtrip(wl.display);
// // Wait for events to get pushed
// _ = libwaylandclient.?.wl_display_roundtrip(wl.display);

core.windows.setValue(window_id, core_window);
try core.initWindow(window_id);
_ = libwaylandclient.?.wl_display_roundtrip(wl.display);

core_window = core.windows.getValue(window_id);
core.windows.setValue(window_id, core_window);
}

pub fn tick(window_id: mach.ObjectID) !void {
Expand Down Expand Up @@ -805,15 +809,37 @@ const xdg_surface_listener = struct {
var core_window = core_ptr.windows.getValue(window_id);
const wl = &core_window.native.?.wayland;

if (wl.configured) {
c.wl_surface_commit(wl.surface);
} else {
if (!wl.configured) {
wl.configured = true;
core_ptr.windows.setValue(window_id, core_window);
core_window = core_ptr.windows.getValue(window_id);
// core_window = core_ptr.windows.getValue(window_id);
return;
}

setContentAreaOpaque(wl, Core.Size{ .width = core_window.width, .height = core_window.height });

if (core_window.framebuffer_width != core_window.width or core_window.framebuffer_height != core_window.height) {
core_window.framebuffer_width = core_window.width;
core_window.framebuffer_height = core_window.height;

core_window.swap_chain_descriptor.width = core_window.framebuffer_width;
core_window.swap_chain_descriptor.height = core_window.framebuffer_height;

core_window.swap_chain.release();
core_window.swap_chain = core_window.device.createSwapChain(core_window.surface, &core_window.swap_chain_descriptor);
core_ptr.windows.setValueRaw(window_id, core_window);

core_ptr.pushEvent(.{
.window_resize = .{
.window_id = window_id,
.size = .{
.width = core_window.width,
.height = core_window.height,
},
},
});
}
c.wl_surface_commit(wl.surface);
}

const listener = c.xdg_surface_listener{ .configure = @ptrCast(&xdgSurfaceHandleConfigure) };
Expand Down