From 349d979f371a14d2152da48f75217d11c61310ab Mon Sep 17 00:00:00 2001 From: Stuart Dilts Date: Sun, 6 Nov 2022 16:33:05 -0700 Subject: [PATCH] Partially rig up xdg-shell Listen to new surface and map / unmap events, but don't do anything with them yet. --- heart/include/hrt/hrt_server.h | 3 ++ heart/include/hrt/hrt_view.h | 10 +++++++ heart/include/xdg_impl.h | 5 ++++ heart/src/meson.build | 1 + heart/src/server.c | 9 ++++++ heart/src/xdg_shell.c | 51 +++++++++++++++++++++++++++++++++ lisp/bindings/hrt-bindings.lisp | 1 - 7 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 heart/include/hrt/hrt_view.h create mode 100644 heart/include/xdg_impl.h create mode 100644 heart/src/xdg_shell.c diff --git a/heart/include/hrt/hrt_server.h b/heart/include/hrt/hrt_server.h index 54259e2..58d4746 100644 --- a/heart/include/hrt/hrt_server.h +++ b/heart/include/hrt/hrt_server.h @@ -29,6 +29,9 @@ struct hrt_server { struct hrt_seat seat; + struct wlr_xdg_shell *xdg_shell; + struct wl_listener new_xdg_surface; + const struct hrt_output_callbacks *output_callback; }; diff --git a/heart/include/hrt/hrt_view.h b/heart/include/hrt/hrt_view.h new file mode 100644 index 0000000..4b5dbf5 --- /dev/null +++ b/heart/include/hrt/hrt_view.h @@ -0,0 +1,10 @@ +#include +#include "hrt/hrt_server.h" + +struct hrt_view { + struct wl_list link; + struct wlr_xdg_toplevel *xdg_toplevel; + struct wl_listener map; + struct wl_listener unmap; + struct wl_listener destroy; +}; diff --git a/heart/include/xdg_impl.h b/heart/include/xdg_impl.h new file mode 100644 index 0000000..454a894 --- /dev/null +++ b/heart/include/xdg_impl.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +void handle_new_xdg_surface(struct wl_listener *listener, void *data); diff --git a/heart/src/meson.build b/heart/src/meson.build index 4cc09ad..eca78b3 100644 --- a/heart/src/meson.build +++ b/heart/src/meson.build @@ -5,4 +5,5 @@ hrt_source_files += files( 'seat.c', 'keyboard.c', 'cursor.c', + 'xdg_shell.c', ) diff --git a/heart/src/server.c b/heart/src/server.c index 1da728b..458a81e 100644 --- a/heart/src/server.c +++ b/heart/src/server.c @@ -1,4 +1,5 @@ #include "wlr/util/log.h" +#include "xdg_impl.h" #include #include #include @@ -8,6 +9,7 @@ #include #include #include +#include #include #include @@ -43,6 +45,13 @@ bool hrt_server_init(struct hrt_server *server, const struct hrt_output_callback wlr_data_control_manager_v1_create(server->wl_display); wlr_gamma_control_manager_v1_create(server->wl_display); + server->output_layout = wlr_output_layout_create(); + + server->xdg_shell = wlr_xdg_shell_create(server->wl_display, 3); + server->new_xdg_surface.notify = handle_new_xdg_surface; + wl_signal_add(&server->xdg_shell->events.new_surface, &server->new_xdg_surface); + + if(!hrt_output_init(server, output_callbacks)) { return false; } diff --git a/heart/src/xdg_shell.c b/heart/src/xdg_shell.c new file mode 100644 index 0000000..eb8ebe7 --- /dev/null +++ b/heart/src/xdg_shell.c @@ -0,0 +1,51 @@ +#include + +#include +#include +#include + +#include "hrt/hrt_input.h" +#include "xdg_impl.h" +#include "hrt/hrt_view.h" + +#include + +static void handle_xdg_toplevel_map(struct wl_listener *listener, void *data) { + wlr_log(WLR_DEBUG, "XDG Toplevel Mapped!"); +} + +static void handle_xdg_toplevel_unmap(struct wl_listener *listener, + void *data) { + wlr_log(WLR_DEBUG, "XDG Toplevel unmapped!"); +} + +static void handle_xdg_toplevel_destroy(struct wl_listener *listener, + void *data) { + wlr_log(WLR_DEBUG, "XDG Toplevel Destroyed!"); + struct hrt_view *view = wl_container_of(listener, view, destroy); + + wl_list_remove(&view->map.link); + wl_list_remove(&view->unmap.link); + wl_list_remove(&view->destroy.link); + + free(view); +} + +void handle_new_xdg_surface(struct wl_listener *listener, void *data) { + wlr_log(WLR_DEBUG, "New XDG Surface recieved"); + struct hrt_server *server = wl_container_of(listener, server, new_xdg_surface); + struct wlr_xdg_surface *xdg_surface = data; + + if(xdg_surface->role == WLR_XDG_SURFACE_ROLE_POPUP) { + return; + } + + struct hrt_view *view = calloc(1, sizeof(struct hrt_view)); + + view->map.notify = handle_xdg_toplevel_map; + wl_signal_add(&xdg_surface->events.map, &view->map); + view->unmap.notify = handle_xdg_toplevel_unmap; + wl_signal_add(&xdg_surface->events.unmap, &view->unmap); + view->destroy.notify = handle_xdg_toplevel_destroy; + wl_signal_add(&xdg_surface->events.destroy, &view->destroy); +} diff --git a/lisp/bindings/hrt-bindings.lisp b/lisp/bindings/hrt-bindings.lisp index 9d39e24..baa884d 100644 --- a/lisp/bindings/hrt-bindings.lisp +++ b/lisp/bindings/hrt-bindings.lisp @@ -97,7 +97,6 @@ See themes section of man xcursor(3) to find where to find valid cursor names." (output-manager-apply (:struct wl-listener)) (output-manager-test (:struct wl-listener)) (seat (:struct hrt-seat)) - (scene :pointer #| (:struct wlr-scene) |# ) (xdg-shell :pointer #| (:struct wlr-xdg-shell) |# ) (new-xdg-surface (:struct wl-listener)) (output-callback (:pointer (:struct hrt-output-callbacks))))