Skip to content

API reference

Every function in malibx, one page each. malibx has the complete MiniLibX API: all 30 functions, with the mlx_ prefix dropped and the arguments in the same order. Where MiniLibX returns values through pointers (int *x), malibx returns them as a tuple.

Setup and loop

Function Does
init() Creates the connection handle
loop(mlx) Runs the main loop until the windows close or loop_end is called
loop_hook(mlx, f, param=None) Calls f(param) once per frame
loop_end(mlx) Makes loop return
do_sync(mlx) Shows what's drawn right away, without waiting for the loop
destroy_display(mlx) Closes every window and removes the loop hook
get_screen_size(mlx) Returns the main screen's (width, height)

Windows and drawing

Function Does
new_window(mlx, size_x, size_y, title) Opens a window
destroy_window(mlx, win) Closes a window
clear_window(mlx, win) Fills a window with black
pixel_put(mlx, win, x, y, color) Sets one pixel
string_put(mlx, win, x, y, color, string) Draws text; y is the baseline
set_font(mlx, win, name) Sets the text size: "8x8" to "64x64"
get_color_value(mlx, color) Converts a color for the display (always 0xRRGGBB in malibx)

Images

Function Does
new_image(mlx, width, height) Creates a black off-screen image
get_data_addr(img) Returns (buffer, bits_per_pixel, size_line, endian)
put_image_to_window(mlx, win, img, x, y) Draws an image into a window
destroy_image(mlx, img) Frees an image
xpm_file_to_image(mlx, filename) Loads an .xpm file → (img, width, height)
xpm_to_image(mlx, xpm_data) Same, from a list of strings

Events

Function Does
hook(win, x_event, x_mask, f, param=None) Calls f on any supported X11 event
key_hook(win, f, param=None) f(keysym, param) on key release
mouse_hook(win, f, param=None) f(button, x, y, param) on button press
expose_hook(win, f, param=None) f(param) when the window is first shown
do_key_autorepeatoff(mlx) KeyPress fires once per press
do_key_autorepeaton(mlx) KeyPress repeats while a key is held (the default)

Mouse

Function Does
mouse_get_pos(mlx, win) Returns the pointer's (x, y) relative to the window
mouse_move(mlx, win, x, y) Moves the pointer
mouse_hide(mlx, win) Hides the pointer over the window
mouse_show(mlx, win) Shows it again

Types

malibx has three handle types. You get them from functions; you can't create them directly.

Mlx

The connection, returned by init. It's MiniLibX's void *mlx_ptr and owns the windows and the loop hook.

Window

A window, returned by new_window. It's MiniLibX's void *win_ptr. A window remembers its Mlx, so the hook functions only need the window. Once it's closed, by the user or by destroy_window, functions that use it raise RuntimeError: window is closed.

Image

An off-screen image, returned by new_image, xpm_file_to_image and xpm_to_image. It's MiniLibX's void *img_ptr. Its pixels are reached through get_data_addr.