mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-12-22 18:09:49 +01:00
Implement layer surface damage
This commit is contained in:
parent
4bf936360d
commit
f444a0d14c
5 changed files with 82 additions and 19 deletions
|
@ -1,8 +1,9 @@
|
|||
#define _POSIX_C_SOURCE 2
|
||||
#define _POSIX_C_SOURCE 199309L
|
||||
#include <GLES2/gl2.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <wayland-client.h>
|
||||
#include <wayland-egl.h>
|
||||
|
@ -25,6 +26,12 @@ static uint32_t layer = ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND;
|
|||
static uint32_t anchor = 0;
|
||||
static int32_t width = 256, height = 256;
|
||||
|
||||
static struct {
|
||||
struct timespec last_frame;
|
||||
float color[3];
|
||||
int dec;
|
||||
} demo;
|
||||
|
||||
static void draw(void);
|
||||
|
||||
static void surface_frame_callback(
|
||||
|
@ -40,17 +47,33 @@ static struct wl_callback_listener frame_listener = {
|
|||
|
||||
static void draw(void) {
|
||||
eglMakeCurrent(egl.display, egl_surface, egl_surface, egl.context);
|
||||
wlr_log(L_DEBUG, "Drawing frame");
|
||||
|
||||
float color[] = {1.0, 0.0, 0.0, 1.0};
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
|
||||
long ms = (ts.tv_sec - demo.last_frame.tv_sec) * 1000 +
|
||||
(ts.tv_nsec - demo.last_frame.tv_nsec) / 1000000;
|
||||
int inc = (demo.dec + 1) % 3;
|
||||
|
||||
demo.color[inc] += ms / 2000.0f;
|
||||
demo.color[demo.dec] -= ms / 2000.0f;
|
||||
|
||||
if (demo.color[demo.dec] < 0.0f) {
|
||||
demo.color[inc] = 1.0f;
|
||||
demo.color[demo.dec] = 0.0f;
|
||||
demo.dec = inc;
|
||||
}
|
||||
|
||||
glViewport(0, 0, width, height);
|
||||
glClearColor(color[0], color[1], color[2], 1.0);
|
||||
glClearColor(demo.color[0], demo.color[1], demo.color[2], 1.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
eglSwapBuffers(egl.display, egl_surface);
|
||||
|
||||
frame_callback = wl_surface_frame(wl_surface);
|
||||
wl_callback_add_listener(frame_callback, &frame_listener, NULL);
|
||||
|
||||
eglSwapBuffers(egl.display, egl_surface);
|
||||
|
||||
demo.last_frame = ts;
|
||||
}
|
||||
|
||||
static void layer_surface_configure(void *data,
|
||||
|
@ -196,7 +219,6 @@ int main(int argc, char **argv) {
|
|||
&layer_surface_listener, layer_surface);
|
||||
// TODO: margin, interactivity, exclusive zone
|
||||
wl_surface_commit(wl_surface);
|
||||
wl_display_dispatch(display);
|
||||
wl_display_roundtrip(display);
|
||||
|
||||
wlr_egl_init(&egl, EGL_PLATFORM_WAYLAND_EXT, display, NULL,
|
||||
|
|
|
@ -36,7 +36,7 @@ void output_damage_from_view(struct roots_output *output,
|
|||
struct roots_view *view);
|
||||
void output_damage_whole_drag_icon(struct roots_output *output,
|
||||
struct roots_drag_icon *icon);
|
||||
void output_damage_whole_surface(struct wlr_surface *surface,
|
||||
double lx, double ly, float rotation, void *data);
|
||||
void output_damage_from_local_surface(struct roots_output *output,
|
||||
struct wlr_surface *surface, double ox, double oy, float rotation);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -95,7 +95,7 @@ static void print_dmabuf_formats(struct wlr_egl *egl) {
|
|||
for (int i = 0; i < num; i++) {
|
||||
snprintf(&str_formats[i*5], (num - i) * 5 + 1, "%.4s ", (char*)&formats[i]);
|
||||
}
|
||||
wlr_log(L_INFO, "Supported dmabuf buffer formats: %s", str_formats);
|
||||
wlr_log(L_DEBUG, "Supported dmabuf buffer formats: %s", str_formats);
|
||||
free(formats);
|
||||
}
|
||||
|
||||
|
|
|
@ -114,12 +114,32 @@ static void arrange_layers(struct wlr_output *_output) {
|
|||
}
|
||||
}
|
||||
|
||||
static void unmap(struct wlr_layer_surface *layer_surface) {
|
||||
struct roots_layer_surface *layer = layer_surface->data;
|
||||
wl_list_remove(&layer->link);
|
||||
|
||||
struct wlr_output *wlr_output = layer_surface->output;
|
||||
struct roots_output *output = wlr_output->data;
|
||||
wlr_output_damage_add_box(output->damage, &layer->geo);
|
||||
}
|
||||
|
||||
static void handle_destroy(struct wl_listener *listener, void *data) {
|
||||
// TODO
|
||||
struct roots_layer_surface *layer = wl_container_of(
|
||||
listener, layer, destroy);
|
||||
if (layer->layer_surface->mapped) {
|
||||
unmap(layer->layer_surface);
|
||||
}
|
||||
free(layer);
|
||||
}
|
||||
|
||||
static void handle_surface_commit(struct wl_listener *listener, void *data) {
|
||||
// TODO
|
||||
struct roots_layer_surface *layer =
|
||||
wl_container_of(listener, layer, surface_commit);
|
||||
struct wlr_layer_surface *layer_surface = layer->layer_surface;
|
||||
struct wlr_output *wlr_output = layer_surface->output;
|
||||
struct roots_output *output = wlr_output->data;
|
||||
output_damage_from_local_surface(output, layer_surface->surface,
|
||||
layer->geo.x, layer->geo.y, 0);
|
||||
}
|
||||
|
||||
static void handle_map(struct wl_listener *listener, void *data) {
|
||||
|
@ -127,13 +147,13 @@ static void handle_map(struct wl_listener *listener, void *data) {
|
|||
struct roots_layer_surface *layer = layer_surface->data;
|
||||
struct wlr_output *wlr_output = layer_surface->output;
|
||||
struct roots_output *output = wlr_output->data;
|
||||
// TODO: This doesn't play right with output layouts and is also stupid
|
||||
output_damage_whole_surface(layer_surface->surface, layer->geo.x,
|
||||
layer->geo.y, 0, output);
|
||||
wlr_output_damage_add_box(output->damage, &layer->geo);
|
||||
}
|
||||
|
||||
static void handle_unmap(struct wl_listener *listener, void *data) {
|
||||
// TODO
|
||||
struct roots_layer_surface *layer = wl_container_of(
|
||||
listener, layer, unmap);
|
||||
unmap(layer->layer_surface);
|
||||
}
|
||||
|
||||
void handle_layer_shell_surface(struct wl_listener *listener, void *data) {
|
||||
|
|
|
@ -433,6 +433,18 @@ static void render_layer(
|
|||
}
|
||||
}
|
||||
|
||||
static void layers_send_done(
|
||||
struct roots_output *output, struct timespec *when) {
|
||||
size_t len = sizeof(output->layers) / sizeof(output->layers[0]);
|
||||
for (size_t i = 0; i < len; ++i) {
|
||||
struct roots_layer_surface *roots_surface;
|
||||
wl_list_for_each(roots_surface, &output->layers[i], link) {
|
||||
struct wlr_layer_surface *layer = roots_surface->layer_surface;
|
||||
wlr_surface_send_frame_done(layer->surface, when);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void render_output(struct roots_output *output) {
|
||||
struct wlr_output *wlr_output = output->wlr_output;
|
||||
struct roots_desktop *desktop = output->desktop;
|
||||
|
@ -595,6 +607,7 @@ damage_finish:
|
|||
drag_icons_for_each_surface(server->input, surface_send_frame_done,
|
||||
&data);
|
||||
}
|
||||
layers_send_done(output, data.when);
|
||||
}
|
||||
|
||||
void output_damage_whole(struct roots_output *output) {
|
||||
|
@ -628,7 +641,7 @@ static bool view_accept_damage(struct roots_output *output,
|
|||
return false;
|
||||
}
|
||||
|
||||
void output_damage_whole_surface(struct wlr_surface *surface,
|
||||
static void damage_whole_surface(struct wlr_surface *surface,
|
||||
double lx, double ly, float rotation, void *data) {
|
||||
struct roots_output *output = data;
|
||||
|
||||
|
@ -672,13 +685,13 @@ void output_damage_whole_view(struct roots_output *output,
|
|||
}
|
||||
|
||||
damage_whole_decoration(view, output);
|
||||
view_for_each_surface(view, output_damage_whole_surface, output);
|
||||
view_for_each_surface(view, damage_whole_surface, output);
|
||||
}
|
||||
|
||||
void output_damage_whole_drag_icon(struct roots_output *output,
|
||||
struct roots_drag_icon *icon) {
|
||||
surface_for_each_surface(icon->wlr_drag_icon->surface, icon->x, icon->y, 0,
|
||||
output_damage_whole_surface, output);
|
||||
damage_whole_surface, output);
|
||||
}
|
||||
|
||||
static void damage_from_surface(struct wlr_surface *surface,
|
||||
|
@ -716,6 +729,14 @@ static void damage_from_surface(struct wlr_surface *surface,
|
|||
pixman_region32_fini(&damage);
|
||||
}
|
||||
|
||||
void output_damage_from_local_surface(struct roots_output *output,
|
||||
struct wlr_surface *surface, double ox, double oy, float rotation) {
|
||||
struct wlr_output_layout_output *layout = wlr_output_layout_get(
|
||||
output->desktop->layout, output->wlr_output);
|
||||
damage_from_surface(surface, ox + layout->x, oy + layout->y,
|
||||
rotation, output);
|
||||
}
|
||||
|
||||
void output_damage_from_view(struct roots_output *output,
|
||||
struct roots_view *view) {
|
||||
if (!view_accept_damage(output, view)) {
|
||||
|
|
Loading…
Reference in a new issue