MiniLibX(3)
okay bestie, welcome to the MiniLibX(3) library functions manual page β yes, the one about handling events. grab a strawberry π and letβs go.
π NAME π
MiniLibX β Handle events. thatβs the whole vibe of this page.
β¨ SYNOPSYS β¨
yes bestie, the original heading is spelled SYNOPSYS β weβre keeping it exactly like that π . the function signatures are here, character for character:
int
mlx_loop ( void *mlx_ptr );
int
mlx_key_hook ( void *win_ptr, int (*funct_ptr)(), void *param );
int
mlx_mouse_hook ( void *win_ptr, int (*funct_ptr)(), void *param );
int
mlx_expose_hook ( void *win_ptr, int (*funct_ptr)(), void *param );
int
mlx_loop_hook ( void *mlx_ptr, int (*funct_ptr)(), void *param );
π X-WINDOW EVENTS π
okay so the X-Window system is bi-directional β it goes both ways, no cap. On one hand, your program sends orders to the screen to display pixels, images, and so on. On the other hand, it can get information from the keyboard and mouse associated with the screen. To do that, the program receives "events" from the keyboard or the mouse. π
π DESCRIPTION π
To receive events you gotta use mlx_loop (). This function never returns β itβs an infinite loop that waits for an event, then calls a user-defined function associated with that event. You only need one parameter: the connection identifier mlx_ptr (see the mlx manual, bestie). β¨
You can assign different functions to the three following events:
- a key is pressed
- the mouse button is pressed
- a part of the window should be re-drawn (this is called an "expose" event, and it is your programβs job to handle it)
Each window can define a different function for the same event. periodt.
The three functions mlx_key_hook (), mlx_mouse_hook (), and mlx_expose_hook () work exactly the same way. funct_ptr is a pointer to the function you want to be called when an event occurs. This assignment is specific to the window defined by the win_ptr identifier. The param address will be passed to the function every time it is called, and should be used to store the parameters it might need. π«Ά
The syntax for mlx_loop_hook () is identical to the previous ones, but the given function will be called when no event occurs. lowkey iconic.
When it catches an event, MiniLibX calls the corresponding function with fixed parameters:
expose_hook(void *param);
key_hook(int keycode,void *param);
mouse_hook(int button,int x,int y,void *param);
loop_hook(void *param);
Those function names are arbitrary β theyβre just here to distinguish parameters according to the event. These functions are NOT part of MiniLibX, bestie, donβt forget that. π
param is the address specified in the mlx_*_hook calls. This address is never used nor modified by MiniLibX. On key and mouse events, additional information is passed: keycode tells you which key is pressed (look for the X11 include file "keysymdef.h"), ( x , y ) are the coordinates of the mouse click in the window, and button tells you which mouse button was pressed. πΈ
π¦ GOING FURTHER WITH EVENTS π¦
MiniLibX gives you a much more generic access to all X-Window events. The mlx.h include defines mlx_hook() in the same manner the mlx_*_hook functions work. The event and mask values will be taken from the X11 include file "X.h". π
See the source code of mlx_int_param_event.c to find out how MiniLibX will call your own function for a specific event. iykyk.
πΈ SEE ALSO πΈ
π AUTHOR π
Copyright ol@ - 2002-2014 - Olivier Crouzet
π cute footer sign-off: the footer source/version is MiniLibX(3) and the date is September 19, 2002 β thatβs the footer energy, bestie. mwah π
π¦ where this page comes from
- nixpkgs unstable: minilibx 0-unstable-2026-06-20
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms