From 3a6bed0d03a3e73a6ad2704d1f858174520863c6 Mon Sep 17 00:00:00 2001 From: Rudy Bousset Date: Thu, 23 Jan 2020 17:36:01 +0100 Subject: window now closes --- Makefile | 1 + inc/cub3d.h | 1 + src/ft_key_events.c | 18 ++++++++++++++++++ src/main.c | 1 + 4 files changed, 21 insertions(+) create mode 100644 src/ft_key_events.c diff --git a/Makefile b/Makefile index 4ff78cc..d6f894e 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,7 @@ INCS = cub3d.h #------------------------------------------------------------------------------# SRCS_NAME = main.c SRCS_NAME += ft_init_lists.c +SRCS_NAME += ft_key_events.c # SRCS_NAME += ft_parse_map.c #------------------------------------------------------------------------------# SRCS = $(addprefix ${SRCS_DIR},${SRCS_NAME}) diff --git a/inc/cub3d.h b/inc/cub3d.h index eaac735..ca12f8a 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -17,5 +17,6 @@ typedef struct s_cublist t_cublist *ft_init_cublist(void); t_winlist *ft_init_winlist(void); void ft_parse_map(t_cublist *clist); +int ft_key_event(int keycode, void *param); #endif diff --git a/src/ft_key_events.c b/src/ft_key_events.c new file mode 100644 index 0000000..f333cd0 --- /dev/null +++ b/src/ft_key_events.c @@ -0,0 +1,18 @@ +#include +#include +#include + +int +ft_key_event(int keycode, void *param) +{ + (void)param; + ft_printf("Key [%d] pressed\n", keycode); + if (keycode == 53) + { + /* ft_memdel(param->wlx); */ + /* ft_memdel(param->winptr); */ + /* ft_memdel(param); */ + exit(0); + } + return (0); +} diff --git a/src/main.c b/src/main.c index 16c96ef..05cab80 100644 --- a/src/main.c +++ b/src/main.c @@ -11,6 +11,7 @@ int wlist = ft_init_winlist(); clist = ft_init_cublist(); + mlx_key_hook(wlist->winptr, ft_key_event, wlist); mlx_loop(wlist->wlx); ft_memdel(wlist->wlx); ft_memdel(wlist->winptr); -- cgit v1.2.3