Commit 5ae35c36 authored by Guido Gunther's avatar Guido Gunther
Browse files

Fade in layer surfaces

Makes e.g. the screen lock a bit smoother
parent a59571f5
Pipeline #455 passed with stage
in 3 minutes and 26 seconds
......@@ -18,6 +18,9 @@ struct roots_layer_surface {
bool configured;
struct wlr_box geo;
struct wl_event_source *fade_source;
float alpha;
};
struct roots_layer_popup {
......
......@@ -10,6 +10,7 @@ struct phosh {
struct wl_listener layer_shell_surface;
struct wlr_layer_surface *panel;
struct wl_event_loop *event_loop;
};
struct phosh* phosh_create(struct roots_desktop *desktop, struct wl_display *display);
......
......@@ -11,6 +11,8 @@
#include "rootston/output.h"
#include "rootston/server.h"
#define ALPHA_FADE_INTERVAL 25.0
static void apply_exclusive(struct wlr_box *usable_area,
uint32_t anchor, int32_t exclusive,
int32_t margin_top, int32_t margin_right,
......@@ -278,11 +280,39 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
free(layer);
}
static int layer_surface_fade_in(void *data)
{
struct roots_layer_surface *layer = data;
struct wlr_layer_surface *layer_surface = layer->layer_surface;
struct wlr_output *wlr_output = layer->layer_surface->output;
struct roots_output *output = wlr_output->data;
if (layer_surface->mapped && layer->alpha < 1.0) {
layer->alpha += 0.025;
wl_event_source_timer_update(layer->fade_source, ALPHA_FADE_INTERVAL);
output_damage_whole_local_surface(output, layer_surface->surface,
layer->geo.x, layer->geo.y, 0);
} else {
wl_event_source_remove(layer->fade_source);
layer->fade_source = NULL;
}
return 0;
}
static void handle_map(struct wl_listener *listener, void *data) {
struct wlr_layer_surface *layer_surface = data;
struct roots_layer_surface *layer = layer_surface->data;
struct wlr_output *wlr_output = layer_surface->output;
struct roots_output *output = wlr_output->data;
struct phosh *phosh = output->desktop->phosh;
if (!layer->fade_source) {
layer->fade_source =
wl_event_loop_add_timer(phosh->event_loop, layer_surface_fade_in, layer);
}
layer->alpha = 0.0;
wl_event_source_timer_update(layer->fade_source, ALPHA_FADE_INTERVAL);
output_damage_whole_local_surface(output, layer_surface->surface,
layer->geo.x, layer->geo.y, 0);
wlr_surface_send_enter(layer_surface->surface, wlr_output);
......
......@@ -365,6 +365,7 @@ static void render_layer(struct roots_output *output,
wl_list_for_each(roots_surface, layer, link) {
struct wlr_layer_surface *layer = roots_surface->layer_surface;
data->alpha = roots_surface->alpha;
surface_for_each_surface(layer->surface,
roots_surface->geo.x + output_layout_box->x,
roots_surface->geo.y + output_layout_box->y,
......@@ -449,6 +450,13 @@ static void render_output(struct roots_output *output) {
.alpha = 1.0,
};
struct render_data data_layer = {
.output = output,
.when = &now,
.damage = &damage,
/* alpha will be set by the layer surface */
};
if (!needs_swap) {
// Output doesn't need swap and isn't damaged, skip rendering completely
goto damage_finish;
......@@ -472,9 +480,9 @@ static void render_output(struct roots_output *output) {
wlr_renderer_clear(renderer, clear_color);
}
render_layer(output, output_box, &data,
render_layer(output, output_box, &data_layer,
&output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND]);
render_layer(output, output_box, &data,
render_layer(output, output_box, &data_layer,
&output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM]);
// If a view is fullscreen on this output, render it
......@@ -506,7 +514,7 @@ static void render_output(struct roots_output *output) {
render_view(view, &data);
}
// Render top layer above shell views
render_layer(output, output_box, &data,
render_layer(output, output_box, &data_layer,
&output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]);
}
......@@ -515,7 +523,7 @@ static void render_output(struct roots_output *output) {
drag_icons_for_each_surface(server->input, render_surface, &data.layout,
&data);
render_layer(output, output_box, &data,
render_layer(output, output_box, &data_layer,
&output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]);
renderer_end:
......
......@@ -107,6 +107,7 @@ phosh_create(struct roots_desktop *desktop, struct wl_display *display) {
wl_signal_add(&desktop->layer_shell->events.new_surface,
&shell->layer_shell_surface);
shell->layer_shell_surface.notify = handle_phosh_layer_shell_surface;
shell->event_loop = wl_display_get_event_loop(display);
desktop->phosh = shell;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment