~novakane/public-inbox

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/ v1 REJECTED

~zanovello: 1
 making the state of variables lasting on next method call https://www.reddit.com/r/Zig/comments/ard50a/static_local_variables_in_zig/

 1 files changed, 8 insertions(+), 6 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~novakane/public-inbox/patches/43042/mbox | git am -3
Learn more about email & git

[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/ Export this patch

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
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.