Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mlx_mouse_hide causes memory leaks #48

Open
aenglert42 opened this issue Jun 4, 2022 · 2 comments
Open

mlx_mouse_hide causes memory leaks #48

aenglert42 opened this issue Jun 4, 2022 · 2 comments

Comments

@aenglert42
Copy link

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

@CarloCattano
Copy link

Agree

@ejacquem
Copy link

ejacquem commented Jun 20, 2024

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);
}
....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants