From 28ac1c0f3ba7cfa1251e3c5c9717ee315edcb009 Mon Sep 17 00:00:00 2001 From: Lukas Jiriste Date: Sat, 11 Nov 2023 18:25:16 +0100 Subject: [PATCH] Add hook to make window closeable by close button --- main.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 2302ee1..cbf446e 100644 --- a/main.c +++ b/main.c @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/10/27 14:29:26 by ljiriste #+# #+# */ -/* Updated: 2023/10/27 14:31:02 by ljiriste ### ########.fr */ +/* Updated: 2023/11/11 17:31:25 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,6 +22,12 @@ #include "color.h" #include "vect2.h" +int close_win(t_session *s) +{ + mlx_destroy_window(s->mlx, s->win); + return (0); +} + void ft_putpx_img(t_img *img, int x, int y, t_color c) { char *px_addr; @@ -133,7 +139,7 @@ void change_zoom(t_view *view, t_vect2 invariant, double d_zoom) int handle_key_press(int keycode, t_session *s) { if (keycode == XK_Escape) - mlx_destroy_window(s->mlx, s->win); + close_win(s); return (0); } @@ -198,6 +204,7 @@ int main(int argc, char **argv) s.img.addr = mlx_get_data_addr(s.img.img, &s.img.bpp, &s.img.bpl, &s.img.endian); mlx_hook(s.win, KeyPress, KeyPressMask, handle_key_press, &s); mlx_hook(s.win, ButtonPress, ButtonPressMask, handle_mouse_press, &s); + mlx_hook(s.win, DestroyNotify, NoEventMask, close_win, &s); mlx_loop_hook(s.mlx, no_event_handle, &s); draw_fractal(&s); mlx_loop(s.mlx); -- 2.30.2