From df3ae5e3dd739de2416eac68e31bfb3a15a1bb0a Mon Sep 17 00:00:00 2001 From: Stuart Dilts Date: Sun, 7 Apr 2024 13:02:25 -0600 Subject: [PATCH] Update wlroots to 0.17.2 Release notes: https://gitlab.freedesktop.org/wlroots/wlroots/-/releases/0.17.0 The following things were affected/added: + Update git submodule path to point to new repository + The output mode change event was removed in favor of the general output commit event. Remove the mode handler code instead of adapting to the changes, as there may be better ways to handle it. (https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/3911). + Use the wlr_scene_output_layout helper, which sets various things up that were implicilty done before. https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4318 + Since the backend no longer changes the ouput mode behind our code's back, we handle listen to the `request_state` event to have the previous behavior. https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/2693 + Use the wlr_output_state event to atomically update the output state upon initialization. + Change where the xdg map events are stored: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4043 --- .gitmodules | 2 +- heart/include/hrt/hrt_output.h | 3 +- heart/include/hrt/hrt_server.h | 3 ++ heart/meson.build | 2 +- heart/src/cursor.c | 4 +-- heart/src/keyboard.c | 2 +- heart/src/output.c | 52 +++++++++++++++++++-------------- heart/src/seat.c | 6 ++-- heart/src/server.c | 4 +-- heart/src/xdg_shell.c | 6 ++-- heart/subprojects/wlroots | 2 +- lisp/bindings/hrt-bindings.lisp | 7 +++-- lisp/main.lisp | 3 +- lisp/output.lisp | 4 --- 14 files changed, 53 insertions(+), 47 deletions(-) diff --git a/.gitmodules b/.gitmodules index 27b44cf..390cefb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "heart/wlroots"] path = heart/subprojects/wlroots - url = https://github.com/swaywm/wlroots.git + url = https://gitlab.freedesktop.org/wlroots/wlroots.git [submodule "dependencies/cl-wayland"] path = dependencies/cl-wayland url = https://github.com/sdilts/cl-wayland.git diff --git a/heart/include/hrt/hrt_output.h b/heart/include/hrt/hrt_output.h index 1f18ada..d386265 100644 --- a/heart/include/hrt/hrt_output.h +++ b/heart/include/hrt/hrt_output.h @@ -10,8 +10,8 @@ struct hrt_output { struct wlr_output *wlr_output; struct hrt_server *server; - void (*mode_change_handler)(struct hrt_output *output); + struct wl_listener request_state; struct wl_listener frame; struct wl_listener destroy; struct wl_listener mode; @@ -23,7 +23,6 @@ struct hrt_output { struct hrt_output_callbacks { void (*output_added)(struct hrt_output *output); void (*output_removed)(struct hrt_output *output); - void (*output_mode_changed)(struct hrt_output *output); }; bool hrt_output_init(struct hrt_server *server, const struct hrt_output_callbacks *callbacks); diff --git a/heart/include/hrt/hrt_server.h b/heart/include/hrt/hrt_server.h index feb0117..f1432b7 100644 --- a/heart/include/hrt/hrt_server.h +++ b/heart/include/hrt/hrt_server.h @@ -1,6 +1,7 @@ #ifndef HRT_HRT_SERVER_H #define HRT_HRT_SERVER_H +#include "wlr/backend/session.h" #include #include @@ -17,11 +18,13 @@ struct hrt_server { struct wl_display *wl_display; struct wlr_backend *backend; + struct wlr_session *session; struct wlr_renderer *renderer; struct wlr_compositor *compositor; struct wlr_allocator *allocator; struct wlr_scene *scene; + struct wlr_scene_output_layout *scene_layout; struct wl_listener new_output; struct wlr_output_manager_v1 *output_manager; struct wlr_output_layout *output_layout; diff --git a/heart/meson.build b/heart/meson.build index 25223e4..6ac3157 100644 --- a/heart/meson.build +++ b/heart/meson.build @@ -27,7 +27,7 @@ wayland_protos = dependency('wayland-protocols', version: '>=1.14') xkbcommon = dependency('xkbcommon') xcb = dependency('xcb', required: get_option('xwayland')) -wlroots_version = ['>=0.16.0', '<0.17.0'] +wlroots_version = ['>=0.17.0', '<0.18.0'] wlroots_proj = subproject( 'wlroots', default_options: ['examples=false'], diff --git a/heart/src/cursor.c b/heart/src/cursor.c index 82eb059..58e0f51 100644 --- a/heart/src/cursor.c +++ b/heart/src/cursor.c @@ -6,8 +6,8 @@ #include static void handle_cursor_motion(struct hrt_seat *seat) { - wlr_xcursor_manager_set_cursor_image(seat->xcursor_manager, - seat->cursor_image, seat->cursor); + wlr_cursor_set_xcursor(seat->cursor, seat->xcursor_manager, + seat->cursor_image); } static void seat_motion(struct wl_listener *listener, void *data) { diff --git a/heart/src/keyboard.c b/heart/src/keyboard.c index ddbef12..dfadd57 100644 --- a/heart/src/keyboard.c +++ b/heart/src/keyboard.c @@ -36,7 +36,7 @@ static bool execute_hardcoded_bindings(struct hrt_server *server, if (keysym >= XKB_KEY_XF86Switch_VT_1 && keysym <= XKB_KEY_XF86Switch_VT_12) { if (wlr_backend_is_multi(server->backend)) { - struct wlr_session *session = wlr_backend_get_session(server->backend); + struct wlr_session *session = server->session; if (session) { wlr_log(WLR_DEBUG, "Changing session"); unsigned vt = keysym - XKB_KEY_XF86Switch_VT_1 + 1; diff --git a/heart/src/output.c b/heart/src/output.c index 559e0e8..5eb1162 100644 --- a/heart/src/output.c +++ b/heart/src/output.c @@ -10,12 +10,19 @@ #include +static void handle_request_state(struct wl_listener *listener, void *data) { + wlr_log(WLR_DEBUG, "Request State Handled"); + struct hrt_output* output = wl_container_of(listener, output, request_state); + const struct wlr_output_event_request_state *event = data; + wlr_output_commit_state(output->wlr_output, event->state); +} + static void handle_frame_notify(struct wl_listener *listener, void *data) { struct hrt_output *output = wl_container_of(listener, output, frame); struct wlr_scene *scene = output->server->scene; struct wlr_scene_output *scene_output = wlr_scene_get_scene_output(scene, output->wlr_output); - wlr_scene_output_commit(scene_output); + wlr_scene_output_commit(scene_output, NULL); struct timespec now; clock_gettime(CLOCK_MONOTONIC, &now); @@ -29,21 +36,12 @@ static void handle_output_destroy(struct wl_listener *listener, void *data) { server->output_callback->output_removed(output); wl_list_remove(&output->frame.link); - wl_list_remove(&output->mode.link); // wlr_output_layout removes the output by itself. free(output); } -static void handle_mode_change(struct wl_listener *listener, void *data) { - wlr_log(WLR_DEBUG, "Output mode changed"); - struct hrt_output *output = wl_container_of(listener, output, mode); - if(output->mode_change_handler) { - output->mode_change_handler(output); - } -} - // temp random float generator static float float_rand() { @@ -55,14 +53,11 @@ static struct hrt_output *hrt_output_create(struct hrt_server *server, struct hrt_output *output = calloc(1, sizeof(struct hrt_output)); output->wlr_output = wlr_output; output->server = server; - output->mode_change_handler = server->output_callback->output_mode_changed; - - wlr_output_init_render(wlr_output, server->allocator, server->renderer); output->frame.notify = handle_frame_notify; wl_signal_add(&wlr_output->events.frame, &output->frame); - output->mode.notify = handle_mode_change; - wl_signal_add(&wlr_output->events.mode, &output->mode); + output->request_state.notify = handle_request_state; + wl_signal_add(&wlr_output->events.request_state, &output->request_state); // temp background color: // {0.730473, 0.554736, 0.665036, 1.000000} is really pretty. @@ -83,19 +78,31 @@ static void handle_new_output(struct wl_listener *listener, void *data) { struct wlr_output *wlr_output = data; - struct hrt_output *output = hrt_output_create(server, wlr_output); + wlr_output_init_render(wlr_output, server->allocator, server->renderer); - output->destroy.notify = handle_output_destroy; - wl_signal_add(&wlr_output->events.destroy, &output->destroy); + struct wlr_output_state state; + wlr_output_state_init(&state); + wlr_output_state_set_enabled(&state, true); struct wlr_output_mode *mode = wlr_output_preferred_mode(wlr_output); if (mode != NULL) { - wlr_output_set_mode(wlr_output, mode); - wlr_output_enable(wlr_output, true); - wlr_output_commit(wlr_output); + wlr_output_state_set_mode(&state, mode); + } + + if (!wlr_output_commit_state(wlr_output, &state)) { + // FIXME: Actually do some error handling instead of just logging: + wlr_log(WLR_ERROR, "Output state could not be commited"); } + wlr_output_state_finish(&state); + + struct wlr_output_layout_output* l_output = wlr_output_layout_add_auto(server->output_layout, wlr_output); + struct wlr_scene_output *scene_output = wlr_scene_output_create(server->scene, wlr_output); + wlr_scene_output_layout_add_output(server->scene_layout, l_output, scene_output); - wlr_output_layout_add_auto(server->output_layout, wlr_output); + struct hrt_output *output = hrt_output_create(server, wlr_output); + + output->destroy.notify = handle_output_destroy; + wl_signal_add(&wlr_output->events.destroy, &output->destroy); server->output_callback->output_added(output); } @@ -115,6 +122,7 @@ bool hrt_output_init(struct hrt_server *server, const struct hrt_output_callback server->output_layout = wlr_output_layout_create(); server->scene = wlr_scene_create(); + server->scene_layout = wlr_scene_attach_output_layout(server->scene, server->output_layout); wlr_scene_attach_output_layout(server->scene, server->output_layout); server->output_manager = wlr_output_manager_v1_create(server->wl_display); diff --git a/heart/src/seat.c b/heart/src/seat.c index d0d8272..5fcf4b3 100644 --- a/heart/src/seat.c +++ b/heart/src/seat.c @@ -1,9 +1,9 @@ #include -#include +#include void hrt_seat_set_cursor_img(struct hrt_seat *seat, char *img_name) { seat->cursor_image = img_name; - wlr_xcursor_manager_set_cursor_image(seat->xcursor_manager, - seat->cursor_image, seat->cursor); + wlr_cursor_set_xcursor(seat->cursor, seat->xcursor_manager, + seat->cursor_image); } diff --git a/heart/src/server.c b/heart/src/server.c index 1e75329..78e5e36 100644 --- a/heart/src/server.c +++ b/heart/src/server.c @@ -22,7 +22,7 @@ bool hrt_server_init(struct hrt_server *server, enum wlr_log_importance log_level) { wlr_log_init(log_level, NULL); server->wl_display = wl_display_create(); - server->backend = wlr_backend_autocreate(server->wl_display); + server->backend = wlr_backend_autocreate(server->wl_display, &server->session); if(!server->backend) { return false; @@ -39,7 +39,7 @@ bool hrt_server_init(struct hrt_server *server, return false; } - server->compositor = wlr_compositor_create(server->wl_display, server->renderer); + server->compositor = wlr_compositor_create(server->wl_display, 5, server->renderer); wlr_subcompositor_create(server->wl_display); wlr_data_device_manager_create(server->wl_display); diff --git a/heart/src/xdg_shell.c b/heart/src/xdg_shell.c index 91df4c3..4e8115a 100644 --- a/heart/src/xdg_shell.c +++ b/heart/src/xdg_shell.c @@ -43,9 +43,9 @@ static struct hrt_view *create_view_from_xdg_surface(struct wlr_xdg_surface *xdg view->destroy_handler = destroy_handler; view->map.notify = handle_xdg_toplevel_map; - wl_signal_add(&xdg_surface->events.map, &view->map); + wl_signal_add(&xdg_surface->surface->events.map, &view->map); view->unmap.notify = handle_xdg_toplevel_unmap; - wl_signal_add(&xdg_surface->events.unmap, &view->unmap); + wl_signal_add(&xdg_surface->surface->events.unmap, &view->unmap); view->destroy.notify = handle_xdg_toplevel_destroy; wl_signal_add(&xdg_surface->events.destroy, &view->destroy); @@ -60,7 +60,7 @@ void handle_new_xdg_surface(struct wl_listener *listener, void *data) { if(xdg_surface->role == WLR_XDG_SURFACE_ROLE_POPUP) { // The front end doesn't need to know about popups; wlroots handles it for us. // we do need to set some internal data so that they can be rendered though. - struct wlr_xdg_surface *parent = wlr_xdg_surface_from_wlr_surface(xdg_surface->popup->parent); + struct wlr_xdg_surface *parent = wlr_xdg_surface_try_from_wlr_surface(xdg_surface->popup->parent); struct wlr_scene_tree *parent_tree = parent->data; // The parent view might not have been initizlized properly. In that case, it // isn't being displayed, so we just ignore it: diff --git a/heart/subprojects/wlroots b/heart/subprojects/wlroots index 0a32b5a..6dce6ae 160000 --- a/heart/subprojects/wlroots +++ b/heart/subprojects/wlroots @@ -1 +1 @@ -Subproject commit 0a32b5a74db06a27bee55a47205951bb277a9657 +Subproject commit 6dce6ae2ed92544b9758b194618e21f4c97f1d6b diff --git a/lisp/bindings/hrt-bindings.lisp b/lisp/bindings/hrt-bindings.lisp index 70039c5..0775e7b 100644 --- a/lisp/bindings/hrt-bindings.lisp +++ b/lisp/bindings/hrt-bindings.lisp @@ -105,7 +105,7 @@ See themes section of man xcursor(3) to find where to find valid cursor names." (cffi:defcstruct hrt-output (wlr-output :pointer #| (:struct wlr-output) |# ) (server (:pointer (:struct hrt-server))) - (mode-change-handler :pointer #| function ptr void (struct hrt_output *) |#) + (request-state (:struct wl-listener)) (frame (:struct wl-listener)) (destroy (:struct wl-listener)) (mode (:struct wl-listener)) @@ -113,8 +113,7 @@ See themes section of man xcursor(3) to find where to find valid cursor names." (cffi:defcstruct hrt-output-callbacks (output-added :pointer #| function ptr void (struct hrt_output *) |#) - (output-removed :pointer #| function ptr void (struct hrt_output *) |#) - (output-mode-changed :pointer #| function ptr void (struct hrt_output *) |#)) + (output-removed :pointer #| function ptr void (struct hrt_output *) |#)) (cffi:defcfun ("hrt_output_init" hrt-output-init) :bool (server (:pointer (:struct hrt-server))) @@ -132,10 +131,12 @@ set the width and height of views." (cffi:defcstruct hrt-server (wl-display :pointer #| (:struct wl-display) |# ) (backend :pointer #| (:struct wlr-backend) |# ) + (session :pointer #| (:struct wlr-session) |# ) (renderer :pointer #| (:struct wlr-renderer) |# ) (compositor :pointer #| (:struct wlr-compositor) |# ) (allocator :pointer #| (:struct wlr-allocator) |# ) (scene :pointer #| (:struct wlr-scene) |# ) + (scene-layout :pointer #| (:struct wlr-scene-output-layout) |# ) (new-output (:struct wl-listener)) (output-manager :pointer #| (:struct wlr-output-manager-v1) |# ) (output-layout :pointer #| (:struct wlr-output-layout) |# ) diff --git a/lisp/main.lisp b/lisp/main.lisp index 4547e1c..779cc8a 100644 --- a/lisp/main.lisp +++ b/lisp/main.lisp @@ -44,8 +44,7 @@ (server '(:struct hrt-server))) (init-callback-struct output-callbacks (:struct hrt-output-callbacks) (output-added handle-new-output) - (output-removed handle-output-removed) - (output-mode-changed output-mode-change-callback)) + (output-removed handle-output-removed)) (init-callback-struct seat-callbacks (:struct hrt-seat-callbacks) (button-event cursor-callback) (wheel-event cursor-callback) diff --git a/lisp/output.lisp b/lisp/output.lisp index 4b616b6..4899583 100644 --- a/lisp/output.lisp +++ b/lisp/output.lisp @@ -8,7 +8,3 @@ (log-string :trace "Output removed") (with-accessors ((outputs mahogany-state-outputs)) *compositor-state* (setf outputs (delete output outputs :key #'mahogany-output-hrt-output)))) - -(cffi:defcallback output-mode-change-callback :void ((output (:pointer (:struct hrt-output)))) - (multiple-value-bind (width height) (hrt:output-resolution output) - (log-string :trace "Output mode changed (w: ~S h: ~S)" width height)))