diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.zig | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/main.zig b/src/main.zig index 564fe37..7543090 100644 --- a/src/main.zig +++ b/src/main.zig @@ -247,11 +247,28 @@ pub const Window = struct { /// Resize this window fn resize(win: *Window, width: i32, height: i32) !void { - win.height = if (height != 0) height else win.height; - win.width = if (width != 0) width else win.width; - if (width == 0 and height == 0) return; + const new_height = if (height != 0) height else win.height; + const new_width = if (width != 0) width else win.width; + if (win.width == new_width and win.height == new_height) return; + + win.width = new_width; + win.height = new_height; win.egl_win.resize(win.width, win.height, 0, 0); - c.glViewport(@divTrunc(win.width, 2) - 160, @divTrunc(win.height, 2) - 160, 320, 320); + if (win.width < win.height) { + c.glViewport( + 0, + @divTrunc(win.height, 2) - @divTrunc(win.width, 2), + win.width, + win.width, + ); + } else { + c.glViewport( + @divTrunc(win.width, 2) - @divTrunc(win.height, 2), + 0, + win.height, + win.height, + ); + } } /// XDG Surface callbacks |