aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYaroslav de la Peña Smirnov <yps@yaroslavps.com>2024-09-21 20:58:44 +0300
committerYaroslav de la Peña Smirnov <yps@yaroslavps.com>2024-09-21 20:58:44 +0300
commitec63d69cdbeb0098b6c726c4391696a712d383ed (patch)
treeb757b503be66495e4f0aa60cb4dc5a35085468bf /src
parent5b1d5fc0325dc5e20ccb7b1ce445721762256848 (diff)
downloadzigway-ec63d69cdbeb0098b6c726c4391696a712d383ed.tar.gz
zigway-ec63d69cdbeb0098b6c726c4391696a712d383ed.zip
gl: make viewport resize with windowgl/triangle
Keep it square, but make it so the sides of the viewport are equal to shorter side of the window.
Diffstat (limited to 'src')
-rw-r--r--src/main.zig25
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