Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: implement flush and poll #1293

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
28 changes: 27 additions & 1 deletion src/core/linux/Wayland.zig
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ state: *Core,
core: *Core,
title: [:0]const u8,
size: *Core.Size,
pending_size: ?Core.Size = null,
surface_descriptor: *gpu.Surface.DescriptorFromWaylandSurface,
configured: bool = false,

Expand Down Expand Up @@ -178,6 +179,27 @@ pub fn deinit(
}

pub fn update(wl: *Wayland) !void {
while (wl.libwaylandclient.wl_display_flush(wl.display) == -1) {
if (std.posix.errno(-1) == std.posix.E.AGAIN) {
log.err("flush error", .{});
return error.FlushError;
}
var pollfd = [_]std.posix.pollfd{
std.posix.pollfd{
.fd = wl.libwaylandclient.wl_display_get_fd(wl.display),
.events = std.posix.POLL.OUT,
.revents = 0,
},
};
while (try std.posix.poll(&pollfd, 1) == -1) {
const errno = std.posix.errno(-1);
if (errno == std.posix.E.INTR or errno == std.posix.E.AGAIN) {
log.err("poll error", .{});
return error.PollError;
}
}
}

_ = wl.libwaylandclient.wl_display_roundtrip(wl.display);

wl.core.input.tick();
Expand Down Expand Up @@ -716,6 +738,10 @@ const xdg_surface_listener = struct {
wl.configured = true;
}

if (wl.pending_size) |pending_size| {
wl.size.* = pending_size;
wl.pending_size = null;
}
setContentAreaOpaque(wl, wl.size.*);
}

Expand All @@ -733,7 +759,7 @@ const xdg_toplevel_listener = struct {
_ = states;

if (width > 0 and height > 0) {
wl.size.* = .{ .width = @intCast(width), .height = @intCast(height) };
wl.pending_size = .{ .width = @intCast(width), .height = @intCast(height) };
}
}

Expand Down
Loading