42Paris/minilibx-linux

mlx_mouse_hide causes memory leaks

Opened this issue · 2 comments

It seems that mlx_mouse_hide allocates memory but has no function to free it.

you can fix the leak with the library Xfixes

  • include the library (<X11/extensions/Xfixes.h>) in the mlx_mouse.c
  • add the functions XFixesHideCursor(xvar->display, win->window); and XFixesShowCursor(xvar->display, win->window); in the corresponding minilibx functions.
  • compile your project with the flag -lXfixes
    Be advised the cursor will disappear even outside the program until it is closed.
    the mlx_mouse.c should look like this :
#include "mlx_int.h"
#include <X11/extensions/Xfixes.h>

int		mlx_mouse_move(t_xvar *xvar, t_win_list *win, int x, int y)
{
	XWarpPointer(xvar->display, None, win->window, 0, 0, 0, 0, x, y);
	return (0);
}

int		mlx_mouse_hide(t_xvar *xvar, t_win_list *win)
{
	XFixesHideCursor(xvar->display, win->window);
}

int		mlx_mouse_show(t_xvar *xvar, t_win_list *win)
{
	XFixesShowCursor(xvar->display, win->window);
}
....