WIP surface refactor
This commit is contained in:
parent
502f584fbf
commit
5fcd796e74
2 changed files with 98 additions and 61 deletions
108
wayland.c
108
wayland.c
|
|
@ -41,7 +41,11 @@ static void xdg_toplevel_configure (
|
|||
state->width = width;
|
||||
state->height = height;
|
||||
// resize egl window
|
||||
wl_egl_window_resize(state->egl_window, width, height, 0, 0);
|
||||
struct surface_list *next = state->surface_list;
|
||||
while (next != NULL) {
|
||||
wl_egl_window_resize(next->data.egl_window, width, height, 0, 0);
|
||||
next = next->next;
|
||||
}
|
||||
}
|
||||
|
||||
static void xdg_toplevel_close(void *data, struct xdg_toplevel *xdg_toplevel) {
|
||||
|
|
@ -63,11 +67,11 @@ static const struct xdg_toplevel_listener xdg_toplevel_listener = {
|
|||
};
|
||||
|
||||
static void zwlr_layer_surface_v1_configure(void *data, struct zwlr_layer_surface_v1 *zwlr_layer_surface_v1, uint32_t serial, uint32_t width, uint32_t height) {
|
||||
struct client_state *state = data;
|
||||
state->width = width;
|
||||
state->height = height;
|
||||
wl_egl_window_resize(state->egl_window, width, height, 0, 0);
|
||||
zwlr_layer_surface_v1_ack_configure(zwlr_layer_surface_v1, serial);
|
||||
// struct client_state *state = data;
|
||||
// state->width = width;
|
||||
// state->height = height;
|
||||
// wl_egl_window_resize(state->egl_window, width, height, 0, 0);
|
||||
// zwlr_layer_surface_v1_ack_configure(zwlr_layer_surface_v1, serial);
|
||||
}
|
||||
|
||||
static void zwlr_layer_surface_v1_closed(void *data, struct zwlr_layer_surface_v1 * zwlr_layer_surface_v1) {
|
||||
|
|
@ -96,7 +100,7 @@ static void registry_handle_global(
|
|||
state->wl_compositor = wl_registry_bind(
|
||||
registry, name, &wl_compositor_interface, 4);
|
||||
// Set up wl_surface
|
||||
state->wl_surface = wl_compositor_create_surface(state->wl_compositor);
|
||||
//state->wl_surface = wl_compositor_create_surface(state->wl_compositor);
|
||||
}
|
||||
if ((strcmp(interface, xdg_wm_base_interface.name) == 0) && (state->output_type == OUTPUT_WINDOW)) {
|
||||
state->xdg_wm_base = wl_registry_bind(
|
||||
|
|
@ -104,20 +108,32 @@ static void registry_handle_global(
|
|||
xdg_wm_base_add_listener(state->xdg_wm_base,
|
||||
&xdg_wm_base_listener, state);
|
||||
|
||||
state->xdg_surface = xdg_wm_base_get_xdg_surface(
|
||||
state->xdg_wm_base, state->wl_surface);
|
||||
xdg_surface_add_listener(state->xdg_surface, &xdg_surface_listener, state);
|
||||
state->xdg_toplevel = xdg_surface_get_toplevel(state->xdg_surface);
|
||||
xdg_toplevel_set_title(state->xdg_toplevel, "GLONKERS! 🕴️");
|
||||
xdg_toplevel_add_listener(state->xdg_toplevel, &xdg_toplevel_listener, state);
|
||||
}
|
||||
if ((strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) && (state->output_type == OUTPUT_LAYER)) {
|
||||
state->zwlr_layer_shell_v1 = wl_registry_bind(registry, name, &zwlr_layer_shell_v1_interface, 4);
|
||||
}
|
||||
if (strcmp(interface, wl_output_interface.name) == 0) {
|
||||
state->wl_output = wl_registry_bind(
|
||||
registry, name, &wl_output_interface, 4);
|
||||
// create window
|
||||
struct wl_surface *wl_surface = wl_compositor_create_surface(state->wl_compositor);
|
||||
struct xdg_surface *xdg_surface = xdg_wm_base_get_xdg_surface(
|
||||
state->xdg_wm_base, wl_surface);
|
||||
xdg_surface_add_listener(xdg_surface, &xdg_surface_listener, state);
|
||||
struct xdg_toplevel *xdg_toplevel = xdg_surface_get_toplevel(xdg_surface);
|
||||
xdg_toplevel_set_title(xdg_toplevel, "GLONKERS! 🕴️");
|
||||
xdg_toplevel_add_listener(xdg_toplevel, &xdg_toplevel_listener, state);
|
||||
|
||||
// save all the pointers
|
||||
struct surface surface = {
|
||||
.wl_surface = wl_surface,
|
||||
.xdg_surface = xdg_surface,
|
||||
.xdg_toplevel = xdg_toplevel,
|
||||
};
|
||||
state->surface_list = malloc(sizeof(struct surface_list));
|
||||
state->surface_list->data = surface;
|
||||
state->surface_list->next = NULL;
|
||||
}
|
||||
//if ((strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) && (state->output_type == OUTPUT_LAYER)) {
|
||||
// state->zwlr_layer_shell_v1 = wl_registry_bind(registry, name, &zwlr_layer_shell_v1_interface, 4);
|
||||
//}
|
||||
//if (strcmp(interface, wl_output_interface.name) == 0) {
|
||||
// state->wl_output = wl_registry_bind(
|
||||
// registry, name, &wl_output_interface, 4);
|
||||
//}
|
||||
}
|
||||
|
||||
static void registry_handle_global_remove(
|
||||
|
|
@ -197,26 +213,31 @@ static void egl_init(struct client_state *state) {
|
|||
EGL_NO_CONTEXT, context_attribs);
|
||||
|
||||
// EGL window
|
||||
state->egl_window = wl_egl_window_create(state->wl_surface,
|
||||
struct surface_list *next = state->surface_list;
|
||||
while (next != NULL) {
|
||||
next->data.egl_window = wl_egl_window_create(next->data.wl_surface,
|
||||
state->width, state->height);
|
||||
if (state->egl_window == EGL_NO_SURFACE) {
|
||||
if (next->data.egl_window == EGL_NO_SURFACE) {
|
||||
fprintf(stderr, "Can't create egl window\n");
|
||||
exit(1);
|
||||
} else {
|
||||
fprintf(stderr, "Created egl window\n");
|
||||
}
|
||||
|
||||
state->egl_surface =
|
||||
next->data.egl_surface =
|
||||
eglCreateWindowSurface(state->egl_display,
|
||||
state->egl_config,
|
||||
(unsigned long) state->egl_window, NULL);
|
||||
(unsigned long) next->data.egl_window, NULL);
|
||||
|
||||
if (eglMakeCurrent(state->egl_display, state->egl_surface,
|
||||
state->egl_surface, state->egl_context)) {
|
||||
if (eglMakeCurrent(state->egl_display, next->data.egl_surface,
|
||||
next->data.egl_surface, state->egl_context)) {
|
||||
fprintf(stderr, "Made current\n");
|
||||
} else {
|
||||
fprintf(stderr, "Made current failed\n");
|
||||
}
|
||||
|
||||
next = next->next;
|
||||
}
|
||||
}
|
||||
|
||||
/// Initializes wayland and creates an opengl context
|
||||
|
|
@ -228,22 +249,26 @@ void wayland_init(struct client_state *state, int output_type) {
|
|||
state->output_type = output_type;
|
||||
state->wl_display = wl_display_connect(NULL);
|
||||
state->wl_registry = wl_display_get_registry(state->wl_display);
|
||||
state->wl_output = NULL;
|
||||
state->surface_list = NULL;
|
||||
wl_registry_add_listener(state->wl_registry, &wl_registry_listener, state);
|
||||
wl_display_roundtrip(state->wl_display);
|
||||
|
||||
if (output_type == OUTPUT_LAYER) {
|
||||
// wlr_layer_shell
|
||||
int layer = ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND;
|
||||
state->zwlr_layer_surface_v1 = zwlr_layer_shell_v1_get_layer_surface(state->zwlr_layer_shell_v1, state->wl_surface, state->wl_output, layer, "wallpaper");
|
||||
zwlr_layer_surface_v1_set_anchor(state->zwlr_layer_surface_v1,
|
||||
ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM | ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP
|
||||
| ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT);
|
||||
zwlr_layer_surface_v1_set_size(state->zwlr_layer_surface_v1, 0, 0);
|
||||
zwlr_layer_surface_v1_add_listener(state->zwlr_layer_surface_v1, &zwlr_layer_surface_v1_listener, state);
|
||||
}
|
||||
//if (output_type == OUTPUT_LAYER) {
|
||||
// // wlr_layer_shell
|
||||
// int layer = ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND;
|
||||
// state->zwlr_layer_surface_v1 = zwlr_layer_shell_v1_get_layer_surface(state->zwlr_layer_shell_v1, state->wl_surface, state->wl_output, layer, "wallpaper");
|
||||
// zwlr_layer_surface_v1_set_anchor(state->zwlr_layer_surface_v1,
|
||||
// ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM | ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP
|
||||
// | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT);
|
||||
// zwlr_layer_surface_v1_set_size(state->zwlr_layer_surface_v1, 0, 0);
|
||||
// zwlr_layer_surface_v1_add_listener(state->zwlr_layer_surface_v1, &zwlr_layer_surface_v1_listener, state);
|
||||
//}
|
||||
|
||||
wl_surface_commit(state->wl_surface);
|
||||
struct surface_list *next = state->surface_list;
|
||||
while (next != NULL) {
|
||||
wl_surface_commit(next->data.wl_surface);
|
||||
next = next->next;
|
||||
}
|
||||
|
||||
egl_init(state);
|
||||
}
|
||||
|
|
@ -251,6 +276,11 @@ void wayland_init(struct client_state *state, int output_type) {
|
|||
/// Swaps front/backbuffers and dispatches pending wayland commands.
|
||||
void commit(struct client_state *state) {
|
||||
wl_display_dispatch(state->wl_display);
|
||||
eglSwapBuffers(state->egl_display, state->egl_surface);
|
||||
struct surface_list *next = state->surface_list;
|
||||
while (next != NULL) {
|
||||
// TODO maybe need to set current egl window or whatever
|
||||
eglSwapBuffers(state->egl_display, next->data.egl_surface);
|
||||
next = next->next;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
29
wayland.h
29
wayland.h
|
|
@ -8,6 +8,22 @@
|
|||
/// A desktop layer (wallpaper)
|
||||
#define OUTPUT_LAYER 1
|
||||
|
||||
struct surface {
|
||||
struct wl_surface *wl_surface;
|
||||
struct xdg_surface *xdg_surface;
|
||||
struct xdg_toplevel *xdg_toplevel;
|
||||
struct wl_egl_window *egl_window;
|
||||
struct zwlr_layer_surface_v1 *zwlr_layer_surface_v1;
|
||||
struct wl_output *wl_output;
|
||||
|
||||
EGLSurface egl_surface;
|
||||
};
|
||||
|
||||
struct surface_list {
|
||||
struct surface data;
|
||||
struct surface_list *next;
|
||||
};
|
||||
|
||||
struct client_state {
|
||||
int width, height;
|
||||
int running;
|
||||
|
|
@ -17,21 +33,12 @@ struct client_state {
|
|||
struct wl_registry *wl_registry;
|
||||
struct wl_compositor *wl_compositor;
|
||||
struct xdg_wm_base *xdg_wm_base;
|
||||
/* Objects */
|
||||
struct wl_surface *wl_surface;
|
||||
struct xdg_surface *xdg_surface;
|
||||
struct xdg_toplevel *xdg_toplevel;
|
||||
|
||||
struct wl_egl_window *egl_window;
|
||||
|
||||
// wlr_layer_shell
|
||||
struct zwlr_layer_shell_v1 *zwlr_layer_shell_v1;
|
||||
struct zwlr_layer_surface_v1 *zwlr_layer_surface_v1;
|
||||
struct wl_output *wl_output;
|
||||
|
||||
struct surface_list *surface_list;
|
||||
|
||||
EGLDisplay egl_display;
|
||||
EGLConfig egl_config;
|
||||
EGLSurface egl_surface;
|
||||
EGLContext egl_context;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue