spkp

Stacking wayland compositor
git clone git://git.z3bra.org/sp:kp.git
Log | Files | Refs

commit 309db35851509a986a45ced6182bb73f2ff18af5
parent 04b58256de532860bd83b89a2137732da40f057b
Author: Willy Goiffon <dev@z3bra.org>
Date:   Tue, 10 Nov 2020 10:37:40 +0100

Cleanup code style and add comments

Diffstat:
Mcompositor.c | 102+++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------
1 file changed, 74 insertions(+), 28 deletions(-)

diff --git a/compositor.c b/compositor.c @@ -34,7 +34,7 @@ enum { RESIZE, }; -/* keep track of internal compositor state */ +/* Internal compositor state */ struct state { struct wl_display *dpy; struct wlr_backend *backend; @@ -67,7 +67,7 @@ struct state { struct wl_list keyboards; }; -/* compositor output */ +/* Display output (usually a monitor) */ struct output { struct state *server; struct wlr_output *wlr_output; @@ -80,7 +80,7 @@ struct output { struct wl_list link; }; -/* client surface window */ +/* Client surface window */ struct window { struct state *server; struct wlr_xdg_surface *surface; @@ -106,6 +106,7 @@ struct keyboard { struct wl_list link; }; +/* Rendering data, used to render window's surfaces */ struct rdata { struct wlr_output *output; struct window *window; @@ -113,6 +114,7 @@ struct rdata { struct timespec when; }; + static void usage(char *); /* callback functions triggered when a new event occur */ @@ -136,6 +138,7 @@ static void cb_click(struct wl_listener *, void *); static void cb_scroll(struct wl_listener *, void *); static void cb_paint_cursor(struct wl_listener *, void *); +/* helper functions, used inside callbacks */ static void add_keyboard(struct state *, struct wlr_input_device *); static void add_pointer(struct state *, struct wlr_input_device *); static void render(struct wlr_surface *, int, int, void *); @@ -151,7 +154,8 @@ usage(char *pgm) } /* - * A new input device is available + * A new input device is available. Each new input type is added to the + * capabilities of the seat. */ void cb_new_input(struct wl_listener *listener, void *data) @@ -226,18 +230,16 @@ cb_new_output(struct wl_listener *listener, void *data) /* create global and arrange outputs from left to right */ wlr_output_layout_add_auto(server->layout, wlr_output); - wlr_xcursor_manager_load(server->cursor_mgr, 1); - wlr_xcursor_manager_set_cursor_image(server->cursor_mgr, "left_ptr", server->cursor); } /* - * Output gets disconnected. Remove it from the list and release memory + * Output gets disconnected. Remove it from the list and release memory. */ void cb_destroy_output(struct wl_listener *listener, void *data) { - struct output *output; (void)data; + struct output *output; output = wl_container_of(listener, output, destroy); @@ -251,6 +253,10 @@ cb_destroy_output(struct wl_listener *listener, void *data) /* * Output is displaying a frame. This would be called 60 times per * seconds on a 60Hz monitor. + * Windows will be rendered on top of each others, starting from the + * bottom of the window list. + * + * TODO: damage tracking */ void cb_frame_output(struct wl_listener *listener, void *data) @@ -298,7 +304,11 @@ cb_frame_output(struct wl_listener *listener, void *data) } /* - * A new application window (or view) is created. + * A new application window is created. Only top-level windows are + * supported and rendered. + * + * TODO: better window placement + * TODO: client size/position hint support */ void cb_new_window(struct wl_listener *listener, void *data) @@ -335,14 +345,13 @@ cb_new_window(struct wl_listener *listener, void *data) } /* - * Request from a client to be mapped on-screen + * Request from a client to be mapped on-screen. */ void cb_map_window(struct wl_listener *listener, void *data) { - struct window *w; - (void)data; + struct window *w; w = wl_container_of(listener, w, map); w->mapped = 1; @@ -351,40 +360,40 @@ cb_map_window(struct wl_listener *listener, void *data) } /* - * Request from a client to be unmapped on-screen + * Request from a client to be unmapped on-screen. */ void cb_unmap_window(struct wl_listener *listener, void *data) { - struct window *w; - (void)data; + struct window *w; w = wl_container_of(listener, w, map); w->mapped = 0; } /* - * Release all resources associated to a window + * Release all resources associated to a window. */ void cb_destroy_window(struct wl_listener *listener, void *data) { - struct window *w; - (void)data; + struct window *w; w = wl_container_of(listener, w, destroy); wl_list_remove(&w->link); free(w); } +/* + * A modifier key is pressed, or depressed. + */ void cb_kb_mod(struct wl_listener *listener, void *data) { - struct keyboard *kb; - (void)data; + struct keyboard *kb; kb = wl_container_of(listener, kb, modifiers); @@ -392,6 +401,9 @@ cb_kb_mod(struct wl_listener *listener, void *data) wlr_seat_keyboard_notify_modifiers(kb->server->seat, &kb->device->keyboard->modifiers); } +/* + * A key is pressed, or depressed. + */ void cb_kb_key(struct wl_listener *listener, void *data) { @@ -425,6 +437,9 @@ cb_kb_key(struct wl_listener *listener, void *data) } } +/* + * Client request to change the cursor frame. + */ void cb_req_cursor(struct wl_listener *listener, void *data) { @@ -440,7 +455,12 @@ cb_req_cursor(struct wl_listener *listener, void *data) wlr_cursor_set_surface(server->cursor, ev->surface, ev->hotspot_x, ev->hotspot_y); } - +/* + * Generic callback for pointer motion (relative or absolute). + * Depending on the server grab mode, windows will be moved or resized. + * If no grab mode is set, motion events are simply passed down to + * the client underneath the pointer. + */ void cb_motion(struct state *server, uint32_t time) { @@ -497,7 +517,9 @@ cb_motion(struct state *server, uint32_t time) } /* - * Cursor moved, reporting relative coordinates. + * Move the cursor according to input device request. This event is + * triggered when the cursor is moving from a relative offset from its + * current position. */ void cb_motion_relative(struct wl_listener *listener, void *data) @@ -512,6 +534,10 @@ cb_motion_relative(struct wl_listener *listener, void *data) cb_motion(server, ev->time_msec); } +/* + * Move the cursor according to input device request. This event is + * triggered when the cursor is given an absolute position to move to. + */ void cb_motion_absolute(struct wl_listener *listener, void *data) { @@ -525,6 +551,12 @@ cb_motion_absolute(struct wl_listener *listener, void *data) cb_motion(server, ev->time_msec); } +/* + * A mouse button is pressed, or released. If the given modifiers are + * pressed wilst pressing the button, the underlying window (if any!) will + * be moved or resized. + * Any mouse event will be ignored until the button is released. + */ void cb_click(struct wl_listener *listener, void *data) { @@ -577,9 +609,11 @@ cb_click(struct wl_listener *listener, void *data) wlr_seat_pointer_notify_enter(server->seat, surface, sx, sy); focus(w, surface); - } +/* + * Mouse scroll. Passed down to the underlying client. + */ void cb_scroll(struct wl_listener *listener, void *data) { @@ -593,12 +627,14 @@ cb_scroll(struct wl_listener *listener, void *data) ev->delta, ev->delta_discrete, ev->source); } +/* + * Request to re-paint the cursor. + */ void cb_paint_cursor(struct wl_listener *listener, void *data) { - struct state *server; - (void)data; + struct state *server; server = wl_container_of(listener, server, paint_cursor); @@ -606,7 +642,7 @@ cb_paint_cursor(struct wl_listener *listener, void *data) } /* - * Configure a newly added keyboard + * Configure a newly added keyboard. */ void add_keyboard(struct state *server, struct wlr_input_device *device) @@ -641,7 +677,7 @@ add_keyboard(struct state *server, struct wlr_input_device *device) } /* - * Configure a newly added pointer device + * Configure a newly added pointer device. */ void add_pointer(struct state *server, struct wlr_input_device *device) @@ -650,6 +686,9 @@ add_pointer(struct state *server, struct wlr_input_device *device) wlr_cursor_attach_input_device(server->cursor, device); } +/* + * Render a full surface on-screen, at the given position. + */ void render(struct wlr_surface *surface, int x, int y, void *data) { @@ -683,7 +722,7 @@ render(struct wlr_surface *surface, int x, int y, void *data) } /* - * Set keyboard focus on the given top-level window + * Set keyboard focus on the given top-level window. */ void focus(struct window *window, struct wlr_surface *surface) @@ -714,6 +753,9 @@ focus(struct window *window, struct wlr_surface *surface) kb->keycodes, kb->num_keycodes, &kb->modifiers); } +/* + * Execute specific functions when an modifier/key combination is pressed. + */ int keybinding(struct state *server, uint32_t mod, uint32_t key) { @@ -729,6 +771,9 @@ keybinding(struct state *server, uint32_t mod, uint32_t key) return 0; } +/* + * Return the topmost window pointer at the given position. + */ struct window * underneath(struct state *server, double x, double y) { @@ -803,6 +848,7 @@ main(int argc, char *argv[]) wl_display_init_shm(server.dpy); wlr_renderer_init_wl_display(server.renderer, server.dpy); + wlr_xcursor_manager_load(server.cursor_mgr, 1); wlr_cursor_attach_output_layout(server.cursor, server.layout); wlr_compositor_create(server.dpy, server.renderer);