diff options
author | Leon Henrik Plickat <leonhenrik.plickat@stud.uni-goettingen.de> | 2021-12-13 19:44:02 +0100 |
---|---|---|
committer | Leon Henrik Plickat <leonhenrik.plickat@stud.uni-goettingen.de> | 2021-12-13 19:44:02 +0100 |
commit | 2f606b50fb216a31df7e6717aae733970ba3e650 (patch) | |
tree | 6001a2fb1526ab9926b94675fe741f3d81e83be5 /src | |
parent | 15e0751dffc5b112318fd156c40ca4d77aa108be (diff) | |
download | wlclock-2f606b50fb216a31df7e6717aae733970ba3e650.tar.gz wlclock-2f606b50fb216a31df7e6717aae733970ba3e650.tar.bz2 |
Do not update unrelated layer surface settings on configure event
Before this patch, wlclock would always update all layer surface settings on
every configure event. This is known to create a feedback loop with faulty
compositors (see https://github.com/swaywm/sway/pull/6709). While wlclock did
nothing wrong before, not updating these settings is more idiomatic.
Diffstat (limited to 'src')
-rw-r--r-- | src/output.c | 2 | ||||
-rw-r--r-- | src/render.c | 1 | ||||
-rw-r--r-- | src/surface.c | 103 | ||||
-rw-r--r-- | src/surface.h | 1 |
4 files changed, 53 insertions, 54 deletions
diff --git a/src/output.c b/src/output.c index 708c98f..e9c5f51 100644 --- a/src/output.c +++ b/src/output.c @@ -39,8 +39,6 @@ static void output_update_surface (struct Wlclock_output *output) if ( context.output == NULL || ! strcmp(context.output, output->name) ) create_surface(output); } - else - update_surface(output->surface); } static void output_handle_done (void *data, struct wl_output *wl_output) diff --git a/src/render.c b/src/render.c index cecb829..9ed1963 100644 --- a/src/render.c +++ b/src/render.c @@ -260,4 +260,3 @@ void render_hands_frame (struct Wlclock_surface *surface) wl_surface_damage_buffer(surface->hands_surface, 0, 0, INT32_MAX, INT32_MAX); wl_surface_attach(surface->hands_surface, surface->current_hands_buffer->buffer, 0, 0); } - diff --git a/src/surface.c b/src/surface.c index f736504..79c8b6b 100644 --- a/src/surface.c +++ b/src/surface.c @@ -21,16 +21,30 @@ #include"buffer.h" #include"render.h" + static void layer_surface_handle_configure (void *data, struct zwlr_layer_surface_v1 *layer_surface, uint32_t serial, uint32_t w, uint32_t h) { struct Wlclock_surface *surface = (struct Wlclock_surface *)data; - clocklog(1, "[surface] Layer surface configure request: global_name=%d w=%d h=%d serial=%d\n", + clocklog(1, "[surface] Layer surface configure request: output=%d w=%d h=%d serial=%d\n", surface->output->global_name, w, h, serial); + zwlr_layer_surface_v1_ack_configure(layer_surface, serial); - if ( (w != (uint32_t)surface->dimensions.w || h != (uint32_t)surface->dimensions.h) - && (w > 0 && h > 0) ) + + bool dimensions_changed = false; + if ( w != (uint32_t)surface->dimensions.w ) + { + surface->dimensions.w = w == 0 ? context.dimensions.w : (int32_t)w; + dimensions_changed = true; + } + if ( h != (uint32_t)surface->dimensions.h ) + { + surface->dimensions.h = h == 0 ? context.dimensions.h : (int32_t)h; + dimensions_changed = true; + } + + if (dimensions_changed) { /* Try to fit into the space the compositor wants us to occupy * while also keeping the center square and not changing the @@ -41,10 +55,22 @@ static void layer_surface_handle_configure (void *data, surface->dimensions.center_size = size_a < size_b ? size_a : size_b; if ( surface->dimensions.center_size < 10 ) surface->dimensions.center_size = 10; + + 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->configured = true; - update_surface(surface); + if ( dimensions_changed || !surface->configured ) + { + surface->configured = true; + + render_background_frame(surface); + render_hands_frame(surface); + wl_surface_commit(surface->hands_surface); + wl_surface_commit(surface->background_surface); + } } static void layer_surface_handle_closed (void *data, struct zwlr_layer_surface_v1 *layer_surface) @@ -79,37 +105,6 @@ static int32_t get_exclusive_zone (struct Wlclock_surface *surface) return context.exclusive_zone; } -static void configure_subsurface (struct Wlclock_surface *surface) -{ - clocklog(1, "[surface] Configuring sub surface: global_name=%d\n", - surface->output->global_name); - wl_subsurface_set_position(surface->subsurface, - surface->dimensions.center_x, surface->dimensions.center_y); - struct wl_region *region = wl_compositor_create_region(context.compositor); - wl_surface_set_input_region(surface->hands_surface, region); - wl_region_destroy(region); -} - -static void configure_layer_surface (struct Wlclock_surface *surface) -{ - clocklog(1, "[surface] Configuring layer surface: global_name=%d\n", - surface->output->global_name); - zwlr_layer_surface_v1_set_size(surface->layer_surface, - surface->dimensions.w, surface->dimensions.h); - zwlr_layer_surface_v1_set_anchor(surface->layer_surface, context.anchor); - zwlr_layer_surface_v1_set_margin(surface->layer_surface, - context.margin_top, context.margin_right, - context.margin_bottom, context.margin_left); - zwlr_layer_surface_v1_set_exclusive_zone(surface->layer_surface, - get_exclusive_zone(surface)); - if (! context.input) - { - struct wl_region *region = wl_compositor_create_region(context.compositor); - wl_surface_set_input_region(surface->background_surface, region); - wl_region_destroy(region); - } -} - bool create_surface (struct Wlclock_output *output) { clocklog(1, "[surface] Creating surface: global_name=%d\n", output->global_name); @@ -158,8 +153,28 @@ bool create_surface (struct Wlclock_output *output) return false; } - configure_layer_surface(surface); - configure_subsurface(surface); + /* Set up layer surface. */ + zwlr_layer_surface_v1_set_size(surface->layer_surface, + surface->dimensions.w, surface->dimensions.h); + zwlr_layer_surface_v1_set_anchor(surface->layer_surface, context.anchor); + zwlr_layer_surface_v1_set_margin(surface->layer_surface, + context.margin_top, context.margin_right, + context.margin_bottom, context.margin_left); + zwlr_layer_surface_v1_set_exclusive_zone(surface->layer_surface, + get_exclusive_zone(surface)); + if (! context.input) + { + struct wl_region *region = wl_compositor_create_region(context.compositor); + wl_surface_set_input_region(surface->background_surface, region); + wl_region_destroy(region); + } + + /* Set up subsurface. */ + wl_subsurface_set_position(surface->subsurface, + surface->dimensions.center_x, surface->dimensions.center_y); + struct wl_region *region = wl_compositor_create_region(context.compositor); + wl_surface_set_input_region(surface->hands_surface, region); + wl_region_destroy(region); wl_surface_commit(surface->hands_surface); wl_surface_commit(surface->background_surface); @@ -187,18 +202,6 @@ void destroy_surface (struct Wlclock_surface *surface) free(surface); } -void update_surface (struct Wlclock_surface *surface) -{ - if ( surface == NULL || ! surface->configured ) - return; - configure_layer_surface(surface); - configure_subsurface(surface); - render_background_frame(surface); - render_hands_frame(surface); - wl_surface_commit(surface->hands_surface); - wl_surface_commit(surface->background_surface); -} - void update_all_hands (void) { clocklog(1, "[surface] Updating all hands.\n"); diff --git a/src/surface.h b/src/surface.h index 716697f..50e29b8 100644 --- a/src/surface.h +++ b/src/surface.h @@ -29,7 +29,6 @@ struct Wlclock_surface bool create_surface (struct Wlclock_output *output); void destroy_surface (struct Wlclock_surface *surface); -void update_surface (struct Wlclock_surface *surface); void update_all_hands (void); #endif |