~novakane/public-inbox

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH zig-fcft-example] making the state of variables lasting on next method call https://www.reddit.com/r/Zig/comments/ard50a/static_local_variables_in_zig/

Details
Message ID
<169046837016.10686.13547186007197664019-0@git.sr.ht>
DKIM signature
missing
Download raw message
Patch: +8 -6
From: Alberto <zanovello2002@gmail.com>

---
 src/main.zig | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/main.zig b/src/main.zig
index af54641..48dc103 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -440,14 +440,16 @@ fn xdg_surface_listener(xdg_surface: *xdg.Surface, event: xdg.Surface.Event, wl_
}

fn xdg_surface_event(xdg_surface: *xdg.Surface, event: xdg.Surface.Event, wl_surface: *wl.Surface) !void {
    const state = struct {
        var last_width: i32 = -1;
        var last_height: i32 = -1;
    };

    switch (event) {
        .configure => |ev| {
            xdg_surface.ackConfigure(ev.serial);

            var last_width: i32 = -1;
            var last_height: i32 = -1;

            if (last_width == surface_width and last_height == surface_height) {
            if (state.last_width == surface_width and state.last_height == surface_height) {
                wl_surface.commit();
                return;
            }
@@ -455,8 +457,8 @@ fn xdg_surface_event(xdg_surface: *xdg.Surface, event: xdg.Surface.Event, wl_sur
            const w = if (surface_width == 0) 100 else surface_width;
            const h = if (surface_height == 0) 100 else surface_height;

            last_width = w;
            last_height = h;
            state.last_width = w;
            state.last_height = h;

            const buffer = try ctx.gpa.create(Buffer);
            try buffer.init(ctx.shm.?, w, h, 0xdeadbeef);
-- 
2.38.5
Details
Message ID
<CUD7H2PH71QQ.24CA40VH7PI4U@void>
In-Reply-To
<169046837016.10686.13547186007197664019-0@git.sr.ht> (view parent)
DKIM signature
missing
Download raw message
Thanks for the patch, it would have been an improvement but I removed
this part sometime ago and apparently forgot to push it.
I think it is not really needed as the wayland part of this example
is not the main point.
Reply to thread Export thread (mbox)