diff options
Diffstat (limited to 'src/surface.c')
-rw-r--r-- | src/surface.c | 103 |
1 files changed, 53 insertions, 50 deletions
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"); |