diff options
author | Leon Henrik Plickat <leonhenrik.plickat@stud.uni-goettingen.de> | 2021-12-13 20:30:55 +0100 |
---|---|---|
committer | Leon Henrik Plickat <leonhenrik.plickat@stud.uni-goettingen.de> | 2021-12-13 20:30:55 +0100 |
commit | 82a85116611092adf5c5f1f1f2ce6a02174fa6d3 (patch) | |
tree | 886b7e1a3ef5b14042b7a71a0b27f4335db62901 /src/surface.c | |
parent | ff8142eeb28178deae0e92dee1a619356721c21e (diff) | |
download | wlclock-82a85116611092adf5c5f1f1f2ce6a02174fa6d3.tar.gz wlclock-82a85116611092adf5c5f1f1f2ce6a02174fa6d3.tar.bz2 |
Even more cleanup and commenting things
Diffstat (limited to 'src/surface.c')
-rw-r--r-- | src/surface.c | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/src/surface.c b/src/surface.c index e3b16cb..5a491ca 100644 --- a/src/surface.c +++ b/src/surface.c @@ -35,6 +35,9 @@ static void layer_surface_handle_configure (void *data, bool dimensions_changed = false; if ( w != (uint32_t)surface->dimensions.w ) { + /* A size of 0 means we are free to use whatever size we want. + * So let's just use the one the user configured. + */ surface->dimensions.w = w == 0 ? context.dimensions.w : (int32_t)w; dimensions_changed = true; } @@ -56,12 +59,21 @@ static void layer_surface_handle_configure (void *data, if ( surface->dimensions.center_size < 10 ) surface->dimensions.center_size = 10; + /* The size of the layer surface and the positioning of the + * subsurface may need to be updated. + */ zwlr_layer_surface_v1_set_size(surface->layer_surface, surface->dimensions.w, surface->dimensions.h); wl_subsurface_set_position(surface->subsurface, - surface->dimensions.center_x, surface->dimensions.center_y); + surface->dimensions.center_x, + surface->dimensions.center_y); } + /* We can only attach buffers to a surface after it has received a + * configure event. A new layer surface will get a configure event + * immediately. As a clean way to do the first render, we therefore + * always render on the first configure event. + */ if ( dimensions_changed || !surface->configured ) { surface->configured = true; @@ -75,6 +87,11 @@ static void layer_surface_handle_configure (void *data, static void layer_surface_handle_closed (void *data, struct zwlr_layer_surface_v1 *layer_surface) { + /* This event is received when the compositor closed our surface, for + * example because the output is was on disappeared. We now need to + * cleanup the surfaces remains. Should the output re-appear, then it + * will receive a new one. + */ struct Wlclock_surface *surface = (struct Wlclock_surface *)data; clocklog(1, "[surface] Layer surface has been closed: global_name=%d\n", surface->output->global_name); @@ -124,34 +141,17 @@ bool create_surface (struct Wlclock_output *output) surface->layer_surface = NULL; surface->configured = false; - if ( NULL == (surface->background_surface = wl_compositor_create_surface(context.compositor)) ) - { - clocklog(0, "ERROR: Compositor did not create wl_surface (background).\n"); - return false; - } - if ( NULL == (surface->layer_surface = zwlr_layer_shell_v1_get_layer_surface( - context.layer_shell, surface->background_surface, - output->wl_output, context.layer, - context.namespace)) ) - { - clocklog(0, "ERROR: Compositor did not create layer_surface.\n"); - return false; - } + surface->background_surface = wl_compositor_create_surface(context.compositor); + surface->layer_surface = zwlr_layer_shell_v1_get_layer_surface( + context.layer_shell, surface->background_surface, + output->wl_output, context.layer, context.namespace); zwlr_layer_surface_v1_add_listener(surface->layer_surface, &layer_surface_listener, surface); - if ( NULL == (surface->hands_surface = wl_compositor_create_surface(context.compositor)) ) - { - clocklog(0, "ERROR: Compositor did not create wl_surface (hands).\n"); - return false; - } - if ( NULL == (surface->subsurface = wl_subcompositor_get_subsurface( - context.subcompositor, surface->hands_surface, - surface->background_surface)) ) - { - clocklog(0, "ERROR: Compositor did not create wl_subsurface.\n"); - return false; - } + surface->hands_surface = wl_compositor_create_surface(context.compositor); + surface->subsurface = wl_subcompositor_get_subsurface( + context.subcompositor, surface->hands_surface, + surface->background_surface); /* Set up layer surface. */ zwlr_layer_surface_v1_set_size(surface->layer_surface, |