Callbacks. That's the most important word to keep in mind when creating a wayland compositor. A compositor is a state machine that update its state according to external events. This is event simpler when using wlroots, which provied wrapper functions to simplify these events handling. These events can be generated from differents endpoints (monitor, touch devices, keyboard, client applications, …), which can be classified in 3 categories: - inputs - outputs - clients # Compositor state The compositor must keep an internal state of what's going on, in order to be useful. This is usually done with a structure holding all needed informations: struct state { /* wayland resources */ struct wl_display *display; struct wlr_backend *backend; struct wlr_renderer *renderer; … /* event listeners */ struct wl_listener new_input; struct wl_listener new_output; struct wl_listener new_window; … /* dynamic input, output and client lists */ struct wl_list keyboards; struct wl_list monitors; struct wl_list windows; … }; # Events and callbacks Every single event happening has to be handled through a callback function. Every callback is attached to a listener, which you attach to one of your compositor resource. it typically works like this example, to handle cursor events: struct wlr_cursor *c; struct wl_listener click; struct wl_listener scroll; struct wl_listener change; /* setup callbacks */ click.notify = callback_cursor_click; scroll.notify = callback_cursor_scroll; change.notify = callback_cursor_change; /* link callbacks to cursor events */ wl_signal_add(&(c->events.button), &click); wl_signal_add(&(c->events.axis), &scroll); wl_signal_add(&(c->events.request_set_cursor), &change); The callback functions are defined as such: void callback_cursor_click(struct wl_listener *l, void *data); void callback_cursor_scroll(struct wl_listener *l, void *data); void callback_cursor_change(struct wl_listener *l, void *data); Each callback function will then do whatever job it had to do, and update the internal compositor state accordingly.