Skip to content

Clients: Replace 'confine' client to showcase pointer constraints in general

Sergio Gómez requested to merge SergioGDR/weston:new_constraints_client into main

This commit introduces "constraints.c" and removes "confine.c". The explanation for this is in the commit message.

The new client implements basic confinement and locking on a Wayland surface and corresponding sub-surface.

Its overt behavior is that it draws the surface as a white rectangle, and a sub-surface in its middle as a grey rectangle. Upon the pointer entering any of the surfaces, it continuously draws a line on the surface, until the pointer leaves that surface, in which case it resets it. The mouse button event (left clicking) on any of the surface transitions the pointer state from unconstrained -> confined -> locked, and back to unconstrained. When locked, the relative motion events are used to draw a vector in the direction of the motion, also hiding the pointer's cursor and showing it again in the next transition. The 'esc' key is used to close the app.

Internally, the state transitioning is implemented as a very simple state machine that goes from STATE_CONSTRAINED -> STATE_CONFINED -> STATE_LOCKED, and back. constraint->surface_constrained is a pointer to the surface abstraction to which all subsequent pointer requests will apply. This surface is set in the wl_pointer's enter event. For buffer management it uses wl_shm: for each surface it creates a wl_pool. The pool size makes space for 3 buffers. When a buffer is needed, it looks for the first free one and allocates resources for it (the cairo surface and wl_buffer). It then makes it the 'current buffer'. The buffer is marked free to use in the buffer_release event. In future redraws, it will try to reuse the last used buffer. If it is used, it will pick another one and copy the contents of the previous resources, but it won't try to free those resources; they'll live until the end of the app's life. In the very unlikely case of no free buffers, it will simply return without redrawing.

Merge request reports

Loading