From b23899499694561f2f7c5b3e4ce99ab200b98dff Mon Sep 17 00:00:00 2001 From: tiosgz Date: Mon, 20 Dec 2021 19:07:56 +0000 Subject: [PATCH 1/3] Catch up with wlroots 0.15 breaking changes --- include/desktop/desktop.h | 3 +-- include/desktop/layer_shell.h | 2 +- include/desktop/output.h | 2 +- include/server.h | 3 +++ kiwmi/desktop/desktop.c | 5 +++-- kiwmi/desktop/layer_shell.c | 14 +++++++------- kiwmi/desktop/output.c | 12 +++++++----- kiwmi/desktop/view.c | 6 ++++-- kiwmi/desktop/xdg_shell.c | 8 +++++--- kiwmi/luak/kiwmi_output.c | 2 +- kiwmi/server.c | 10 +++++++--- 11 files changed, 40 insertions(+), 27 deletions(-) diff --git a/include/desktop/desktop.h b/include/desktop/desktop.h index d8628a4..2ad7618 100644 --- a/include/desktop/desktop.h +++ b/include/desktop/desktop.h @@ -9,7 +9,6 @@ #define KIWMI_DESKTOP_DESKTOP_H #include -#include struct kiwmi_desktop { struct wlr_compositor *compositor; @@ -35,7 +34,7 @@ struct kiwmi_desktop { } events; }; -bool desktop_init(struct kiwmi_desktop *desktop, struct wlr_renderer *renderer); +bool desktop_init(struct kiwmi_desktop *desktop); void desktop_fini(struct kiwmi_desktop *desktop); struct kiwmi_server; diff --git a/include/desktop/layer_shell.h b/include/desktop/layer_shell.h index 8a56126..2a1618f 100644 --- a/include/desktop/layer_shell.h +++ b/include/desktop/layer_shell.h @@ -11,8 +11,8 @@ #include #include -#include #include +#include #include "desktop/output.h" diff --git a/include/desktop/output.h b/include/desktop/output.h index cbcdbde..2fd0397 100644 --- a/include/desktop/output.h +++ b/include/desktop/output.h @@ -9,7 +9,7 @@ #define KIWMI_DESKTOP_OUTPUT_H #include -#include +#include struct kiwmi_output { struct wl_list link; diff --git a/include/server.h b/include/server.h index cbc59d2..44aeec7 100644 --- a/include/server.h +++ b/include/server.h @@ -17,6 +17,9 @@ struct kiwmi_server { struct wl_display *wl_display; struct wl_event_loop *wl_event_loop; struct wlr_backend *backend; + struct wlr_renderer *renderer; + struct wlr_allocator *allocator; + const char *socket; char *config_path; struct kiwmi_lua *lua; diff --git a/kiwmi/desktop/desktop.c b/kiwmi/desktop/desktop.c index 35f5ecd..42ac1f7 100644 --- a/kiwmi/desktop/desktop.c +++ b/kiwmi/desktop/desktop.c @@ -30,11 +30,12 @@ #include "server.h" bool -desktop_init(struct kiwmi_desktop *desktop, struct wlr_renderer *renderer) +desktop_init(struct kiwmi_desktop *desktop) { struct kiwmi_server *server = wl_container_of(desktop, server, desktop); - desktop->compositor = wlr_compositor_create(server->wl_display, renderer); + desktop->compositor = + wlr_compositor_create(server->wl_display, server->renderer); desktop->data_device_manager = wlr_data_device_manager_create(server->wl_display); desktop->output_layout = wlr_output_layout_create(); diff --git a/kiwmi/desktop/layer_shell.c b/kiwmi/desktop/layer_shell.c index d35ba6d..c908c6c 100644 --- a/kiwmi/desktop/layer_shell.c +++ b/kiwmi/desktop/layer_shell.c @@ -29,8 +29,6 @@ kiwmi_layer_destroy_notify(struct wl_listener *listener, void *UNUSED(data)) wl_list_remove(&layer->map.link); wl_list_remove(&layer->unmap.link); - wlr_layer_surface_v1_close(layer->layer_surface); - arrange_layers(layer->output); free(layer); @@ -44,7 +42,9 @@ kiwmi_layer_commit_notify(struct wl_listener *listener, void *UNUSED(data)) struct wlr_box old_geom = layer->geom; - arrange_layers(output); + if (layer->layer_surface->current.committed != 0) { + arrange_layers(output); + } bool layer_changed = layer->layer != layer->layer_surface->current.layer; bool geom_changed = memcmp(&old_geom, &layer->geom, sizeof(old_geom)) != 0; @@ -237,7 +237,7 @@ arrange_layer( "Bad width/height: %d, %d", arranged_area.width, arranged_area.height); - wlr_layer_surface_v1_close(layer_surface); + wlr_layer_surface_v1_destroy(layer_surface); continue; } @@ -404,7 +404,7 @@ layer_shell_new_surface_notify(struct wl_listener *listener, void *data) WLR_ERROR, "Bad layer surface layer '%d'", layer_surface->current.layer); - wlr_layer_surface_v1_close(layer_surface); + wlr_layer_surface_v1_destroy(layer_surface); free(layer); return; } @@ -427,10 +427,10 @@ layer_shell_new_surface_notify(struct wl_listener *listener, void *data) wl_list_insert(&output->layers[layer->layer], &layer->link); - // Temporarily set the layer's current state to client_pending + // Temporarily set the layer's current state to pending // So that we can easily arrange it struct wlr_layer_surface_v1_state old_state = layer_surface->current; - layer_surface->current = layer_surface->client_pending; + layer_surface->current = layer_surface->pending; arrange_layers(output); layer_surface->current = old_state; } diff --git a/kiwmi/desktop/output.c b/kiwmi/desktop/output.c index 986cbe2..8aeddfd 100644 --- a/kiwmi/desktop/output.c +++ b/kiwmi/desktop/output.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -191,8 +192,8 @@ output_frame_notify(struct wl_listener *listener, void *data) } struct wlr_output_layout *output_layout = desktop->output_layout; - struct wlr_renderer *renderer = - wlr_backend_get_renderer(wlr_output->backend); + struct kiwmi_server *server = wl_container_of(desktop, server, desktop); + struct wlr_renderer *renderer = server->renderer; int width; int height; @@ -334,9 +335,10 @@ new_output_notify(struct wl_listener *listener, void *data) wlr_log(WLR_DEBUG, "New output %p: %s", wlr_output, wlr_output->name); - if (!wl_list_empty(&wlr_output->modes)) { - struct wlr_output_mode *mode = - wl_container_of(wlr_output->modes.prev, mode, link); + wlr_output_init_render(wlr_output, server->allocator, server->renderer); + + struct wlr_output_mode *mode = wlr_output_preferred_mode(wlr_output); + if (mode) { wlr_output_set_mode(wlr_output, mode); if (!wlr_output_commit(wlr_output)) { diff --git a/kiwmi/desktop/view.c b/kiwmi/desktop/view.c index 15b690b..67d3c64 100644 --- a/kiwmi/desktop/view.c +++ b/kiwmi/desktop/view.c @@ -262,10 +262,12 @@ view_init_subsurfaces(struct kiwmi_view_child *child, struct kiwmi_view *view) } struct wlr_subsurface *subsurface; - wl_list_for_each (subsurface, &surface->subsurfaces_below, parent_link) { + wl_list_for_each ( + subsurface, &surface->current.subsurfaces_below, current.link) { view_child_subsurface_create(child, view, subsurface); } - wl_list_for_each (subsurface, &surface->subsurfaces_above, parent_link) { + wl_list_for_each ( + subsurface, &surface->current.subsurfaces_above, current.link) { view_child_subsurface_create(child, view, subsurface); } } diff --git a/kiwmi/desktop/xdg_shell.c b/kiwmi/desktop/xdg_shell.c index d7f50f6..6439ed0 100644 --- a/kiwmi/desktop/xdg_shell.c +++ b/kiwmi/desktop/xdg_shell.c @@ -302,7 +302,8 @@ surface_for_each_mapped_surface( void *user_data) { struct wlr_subsurface *subsurface; - wl_list_for_each (subsurface, &surface->subsurfaces_below, parent_link) { + wl_list_for_each ( + subsurface, &surface->current.subsurfaces_below, current.link) { if (!subsurface->mapped) { continue; } @@ -317,7 +318,8 @@ surface_for_each_mapped_surface( callback(surface, x, y, user_data); - wl_list_for_each (subsurface, &surface->subsurfaces_above, parent_link) { + wl_list_for_each ( + subsurface, &surface->current.subsurfaces_above, current.link) { if (!subsurface->mapped) { continue; } @@ -534,7 +536,7 @@ xdg_decoration_request_mode_notify( wl_container_of(listener, decoration, request_mode); enum wlr_xdg_toplevel_decoration_v1_mode mode = - decoration->wlr_decoration->client_pending_mode; + decoration->wlr_decoration->requested_mode; if (mode == WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_NONE) { mode = WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE; } diff --git a/kiwmi/luak/kiwmi_output.c b/kiwmi/luak/kiwmi_output.c index 9bf3820..ec38f46 100644 --- a/kiwmi/luak/kiwmi_output.c +++ b/kiwmi/luak/kiwmi_output.c @@ -8,9 +8,9 @@ #include "luak/kiwmi_output.h" #include -#include #include #include +#include #include #include "desktop/output.h" diff --git a/kiwmi/server.c b/kiwmi/server.c index 5262276..6bd9f27 100644 --- a/kiwmi/server.c +++ b/kiwmi/server.c @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -43,12 +44,15 @@ server_init(struct kiwmi_server *server, char *config_path) return false; } - struct wlr_renderer *renderer = wlr_backend_get_renderer(server->backend); - wlr_renderer_init_wl_display(renderer, server->wl_display); + server->renderer = wlr_renderer_autocreate(server->backend); + wlr_renderer_init_wl_display(server->renderer, server->wl_display); + + server->allocator = + wlr_allocator_autocreate(server->backend, server->renderer); wl_signal_init(&server->events.destroy); - if (!desktop_init(&server->desktop, renderer)) { + if (!desktop_init(&server->desktop)) { wlr_log(WLR_ERROR, "Failed to initialize desktop"); wl_display_destroy(server->wl_display); return false; From aa9776f00670b789a0370144452215b405192860 Mon Sep 17 00:00:00 2001 From: tiosgz Date: Wed, 24 Nov 2021 19:55:20 +0000 Subject: [PATCH 2/3] Partly revert "Only render mapped surfaces" This reverts most of commit 520dd5ce029050abc8edf26cb4c6c24b2efd2aec, because it is now handled by wlroots. The iterator -> callback renames have been kept in place. --- include/desktop/view.h | 4 +- kiwmi/desktop/output.c | 5 +- kiwmi/desktop/view.c | 6 +-- kiwmi/desktop/xdg_shell.c | 97 ++++----------------------------------- 4 files changed, 17 insertions(+), 95 deletions(-) diff --git a/include/desktop/view.h b/include/desktop/view.h index 2fdb074..548a651 100644 --- a/include/desktop/view.h +++ b/include/desktop/view.h @@ -71,7 +71,7 @@ struct kiwmi_view { struct kiwmi_view_impl { void (*close)(struct kiwmi_view *view); - void (*for_each_mapped_surface)( + void (*for_each_surface)( struct kiwmi_view *view, wlr_surface_iterator_func_t callback, void *user_data); @@ -131,7 +131,7 @@ struct kiwmi_request_resize_event { }; void view_close(struct kiwmi_view *view); -void view_for_each_mapped_surface( +void view_for_each_surface( struct kiwmi_view *view, wlr_surface_iterator_func_t callback, void *user_data); diff --git a/kiwmi/desktop/output.c b/kiwmi/desktop/output.c index 8aeddfd..432cd67 100644 --- a/kiwmi/desktop/output.c +++ b/kiwmi/desktop/output.c @@ -179,8 +179,7 @@ output_frame_notify(struct wl_listener *listener, void *data) struct kiwmi_view *view; wl_list_for_each (view, &desktop->views, link) { - view_for_each_mapped_surface( - view, send_frame_done_to_surface, &now); + view_for_each_surface(view, send_frame_done_to_surface, &now); } if (render_cursors(wlr_output)) { @@ -227,7 +226,7 @@ output_frame_notify(struct wl_listener *listener, void *data) rdata.data = view; wl_signal_emit(&view->events.pre_render, &rdata); - view_for_each_mapped_surface(view, render_surface, &rdata); + view_for_each_surface(view, render_surface, &rdata); wl_signal_emit(&view->events.post_render, &rdata); } diff --git a/kiwmi/desktop/view.c b/kiwmi/desktop/view.c index 67d3c64..bf2e418 100644 --- a/kiwmi/desktop/view.c +++ b/kiwmi/desktop/view.c @@ -24,13 +24,13 @@ view_close(struct kiwmi_view *view) } void -view_for_each_mapped_surface( +view_for_each_surface( struct kiwmi_view *view, wlr_surface_iterator_func_t callback, void *user_data) { - if (view->impl->for_each_mapped_surface) { - view->impl->for_each_mapped_surface(view, callback, user_data); + if (view->impl->for_each_surface) { + view->impl->for_each_surface(view, callback, user_data); } } diff --git a/kiwmi/desktop/xdg_shell.c b/kiwmi/desktop/xdg_shell.c index 6439ed0..de52af9 100644 --- a/kiwmi/desktop/xdg_shell.c +++ b/kiwmi/desktop/xdg_shell.c @@ -294,89 +294,12 @@ xdg_shell_view_close(struct kiwmi_view *view) } static void -surface_for_each_mapped_surface( - struct wlr_surface *surface, - int x, - int y, - wlr_surface_iterator_func_t callback, - void *user_data) -{ - struct wlr_subsurface *subsurface; - wl_list_for_each ( - subsurface, &surface->current.subsurfaces_below, current.link) { - if (!subsurface->mapped) { - continue; - } - - surface_for_each_mapped_surface( - subsurface->surface, - x + subsurface->current.x, - y + subsurface->current.y, - callback, - user_data); - } - - callback(surface, x, y, user_data); - - wl_list_for_each ( - subsurface, &surface->current.subsurfaces_above, current.link) { - if (!subsurface->mapped) { - continue; - } - - surface_for_each_mapped_surface( - subsurface->surface, - x + subsurface->current.x, - y + subsurface->current.y, - callback, - user_data); - } -} - -static void -xdg_surface_for_each_mapped_popup_surface( - struct wlr_xdg_surface *surface, - int x, - int y, - wlr_surface_iterator_func_t callback, - void *user_data) -{ - struct wlr_xdg_popup *popup; - wl_list_for_each (popup, &surface->popups, link) { - struct wlr_xdg_surface *popup_surface = popup->base; - if (!popup_surface->configured || !popup_surface->mapped) { - continue; - } - - double popup_sx, popup_sy; - wlr_xdg_popup_get_position(popup, &popup_sx, &popup_sy); - - surface_for_each_mapped_surface( - popup_surface->surface, - x + popup_sx, - y + popup_sy, - callback, - user_data); - xdg_surface_for_each_mapped_popup_surface( - popup_surface, x + popup_sx, y + popup_sy, callback, user_data); - } -} - -static void -xdg_shell_view_for_each_mapped_surface( +xdg_shell_view_for_each_surface( struct kiwmi_view *view, wlr_surface_iterator_func_t callback, void *user_data) { - if (!view->mapped) { - return; - } - - // Have to copy over the wlroots implementation with only small changes - surface_for_each_mapped_surface( - view->xdg_surface->surface, 0, 0, callback, user_data); - xdg_surface_for_each_mapped_popup_surface( - view->xdg_surface, 0, 0, callback, user_data); + wlr_xdg_surface_for_each_surface(view->xdg_surface, callback, user_data); } static pid_t @@ -438,14 +361,14 @@ xdg_shell_view_surface_at( } static const struct kiwmi_view_impl xdg_shell_view_impl = { - .close = xdg_shell_view_close, - .for_each_mapped_surface = xdg_shell_view_for_each_mapped_surface, - .get_pid = xdg_shell_view_get_pid, - .get_string_prop = xdg_shell_view_get_string_prop, - .set_activated = xdg_shell_view_set_activated, - .set_size = xdg_shell_view_set_size, - .set_tiled = xdg_shell_view_set_tiled, - .surface_at = xdg_shell_view_surface_at, + .close = xdg_shell_view_close, + .for_each_surface = xdg_shell_view_for_each_surface, + .get_pid = xdg_shell_view_get_pid, + .get_string_prop = xdg_shell_view_get_string_prop, + .set_activated = xdg_shell_view_set_activated, + .set_size = xdg_shell_view_set_size, + .set_tiled = xdg_shell_view_set_tiled, + .surface_at = xdg_shell_view_surface_at, }; void From c8833972ca7c065cf430948a8a4b19b261da6200 Mon Sep 17 00:00:00 2001 From: tiosgz Date: Thu, 13 Jan 2022 20:35:40 +0000 Subject: [PATCH 3/3] Fix link to wlroots repository It has been quite some time since wlroots migrated to the FDO gitlab instance. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b972d22..47732a3 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ $ kiwmic 'return kiwmi:focused_view():id()' The dependencies required are: -- [wlroots](https://github.com/swaywm/wlroots) +- [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots) - lua or luajit - pixman - meson (build)