Skip to content

Commit

Permalink
hrt: Update wlroots to 0.18.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sdilts committed Oct 19, 2024
1 parent a76b0d5 commit b58853d
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 38 deletions.
6 changes: 5 additions & 1 deletion heart/include/hrt/hrt_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "wlr/backend/session.h"
#include <stdbool.h>

#include <wayland-server-core.h>
#include <wayland-server.h>
#include <wlr/backend.h>
#include <wlr/types/wlr_compositor.h>
Expand All @@ -18,6 +19,7 @@
struct hrt_server {
struct wl_display *wl_display;
struct wlr_backend *backend;
struct wl_listener backend_destroy;
struct wlr_session *session;
struct wlr_renderer *renderer;
struct wlr_compositor *compositor;
Expand All @@ -35,7 +37,9 @@ struct hrt_server {
struct hrt_seat seat;

struct wlr_xdg_shell *xdg_shell;
struct wl_listener new_xdg_surface;
struct wl_listener new_xdg_toplevel;
struct wl_listener new_xdg_popup;


const struct hrt_output_callbacks *output_callback;
const struct hrt_view_callbacks *view_callbacks;
Expand Down
1 change: 1 addition & 0 deletions heart/include/hrt/hrt_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct hrt_view {
// internal state:
struct wl_listener map;
struct wl_listener unmap;
struct wl_listener commit;
struct wl_listener destroy;
view_destroy_handler destroy_handler;
};
Expand Down
10 changes: 9 additions & 1 deletion heart/include/xdg_impl.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#pragma once

#include <wayland-server-core.h>
#include <wayland-server.h>
#include "hrt/hrt_server.h"

void handle_new_xdg_surface(struct wl_listener *listener, void *data);
struct hrt_xdg_popup {
struct wlr_xdg_popup *xdg_popup;
struct wl_listener commit;
struct wl_listener destroy;
};

bool hrt_xdg_shell_init(struct hrt_server *server);
2 changes: 1 addition & 1 deletion heart/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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.17.0', '<0.18.0']
wlroots_version = ['>=0.18.0', '<0.19.0']
wlroots_proj = subproject(
'wlroots',
default_options: ['examples=false'],
Expand Down
7 changes: 4 additions & 3 deletions heart/src/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ bool hrt_output_init(struct hrt_server *server, const struct hrt_output_callback
server->new_output.notify = handle_new_output;
wl_signal_add(&server->backend->events.new_output, &server->new_output);

server->output_layout = wlr_output_layout_create();
server->output_layout = wlr_output_layout_create(server->wl_display);
server->scene = wlr_scene_create();
server->scene_layout = wlr_scene_attach_output_layout(server->scene, server->output_layout);

Expand All @@ -155,6 +155,7 @@ bool hrt_output_init(struct hrt_server *server, const struct hrt_output_callback
}

void hrt_output_destroy(struct hrt_server *server) {
wlr_scene_node_destroy(&server->scene->tree.node);
wlr_output_layout_destroy(server->output_layout);
wlr_scene_node_destroy(&server->scene->tree.node);
// The output layout gets destroyed when the display does:
// wlr_output_layout_destroy(server->output_layout);
}
21 changes: 16 additions & 5 deletions heart/src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "xdg_impl.h"
#include <stdlib.h>
#include <wayland-server-core.h>
#include <wayland-util.h>
#include <wlr/types/wlr_export_dmabuf_v1.h>
#include <wlr/types/wlr_screencopy_v1.h>
#include <wlr/types/wlr_data_control_v1.h>
Expand All @@ -15,14 +16,24 @@
#include <hrt/hrt_output.h>
#include <hrt/hrt_input.h>

static void handle_backend_destroyed(struct wl_listener *listener, void *data) {
struct hrt_server *server =
wl_container_of(listener, server, backend_destroy);
wl_display_terminate(server->wl_display);
}

bool hrt_server_init(struct hrt_server *server,
const struct hrt_output_callbacks *output_callbacks,
const struct hrt_seat_callbacks *seat_callbacks,
const struct hrt_view_callbacks *view_callbacks,
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->session);
server->backend = wlr_backend_autocreate(
wl_display_get_event_loop(server->wl_display), &server->session);

server->backend_destroy.notify = &handle_backend_destroyed;
wl_signal_add(&server->backend->events.destroy, &server->backend_destroy);

if(!server->backend) {
return false;
Expand All @@ -48,13 +59,13 @@ bool hrt_server_init(struct hrt_server *server,
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->output_layout = wlr_output_layout_create(server->wl_display);

server->view_callbacks = view_callbacks;

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_xdg_shell_init(server)) {
return false;
}


if(!hrt_output_init(server, output_callbacks)) {
Expand Down
100 changes: 76 additions & 24 deletions heart/src/xdg_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <wlr/types/wlr_xdg_shell.h>


static void handle_xdg_toplevel_map(struct wl_listener *listener, void *data) {
wlr_log(WLR_DEBUG, "XDG Toplevel Mapped!");
}
Expand All @@ -30,15 +31,25 @@ static void handle_xdg_toplevel_destroy(struct wl_listener *listener,
wl_list_remove(&view->map.link);
wl_list_remove(&view->unmap.link);
wl_list_remove(&view->destroy.link);
wl_list_remove(&view->commit.link);

free(view);
}

static struct hrt_view *create_view_from_xdg_surface(struct wlr_xdg_surface *xdg_surface, view_destroy_handler destroy_handler) {
// This method can only deal with toplevel xdg_surfaces:
assert(xdg_surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL);
static void handle_xdg_toplevel_commit(struct wl_listener *listener,
void *data) {
struct hrt_view *view = wl_container_of(listener, view, commit);
if (view->xdg_toplevel->base->initial_commit) {
// TODO: we probably want to explicitly pick the size here:
wlr_xdg_toplevel_set_size(view->xdg_toplevel, 0,0);
}
}

static struct hrt_view *create_view_from_xdg_surface(struct wlr_xdg_toplevel *xdg_toplevel, view_destroy_handler destroy_handler) {
struct hrt_view *view = calloc(1, sizeof(struct hrt_view));
view->xdg_toplevel = xdg_surface->toplevel;
view->xdg_toplevel = xdg_toplevel;
struct wlr_xdg_surface *xdg_surface = xdg_toplevel->base;
// TODO: Maybe remove view->xdg_surface? We can get to it via the toplevel.
view->xdg_surface = xdg_surface;
view->destroy_handler = destroy_handler;

Expand All @@ -48,38 +59,79 @@ static struct hrt_view *create_view_from_xdg_surface(struct wlr_xdg_surface *xdg
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);
view->commit.notify = handle_xdg_toplevel_commit;
wl_signal_add(&xdg_toplevel->base->surface->events.commit, &view->commit);
// TODO: We need to listen to the commit event so we can send the configure message on first commit

return 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) {
// 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_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:
if (parent_tree) {
xdg_surface->data = wlr_scene_xdg_surface_create(parent_tree, xdg_surface);
} else {
wlr_log(WLR_ERROR, "Encountered XDG Popup without properly configured parent");
}
return;
static void handle_xdg_popup_commit(struct wl_listener *listener, void *data) {
struct hrt_xdg_popup *popup = wl_container_of(listener, popup, commit);
if (popup->xdg_popup->base->initial_commit) {
wlr_xdg_surface_schedule_configure(popup->xdg_popup->base);
}
}

static void handle_xdg_popup_destroy(struct wl_listener *listener, void *data) {
struct hrt_xdg_popup *popup = wl_container_of(listener, popup, destroy);

wl_list_remove(&popup->destroy.link);
wl_list_remove(&popup->commit.link);

// Initialization occurs in two steps so the consumer can place the view where it needs to go;
free(popup);
}

static void handle_new_xdg_popup(struct wl_listener *listener, void *data) {
wlr_log(WLR_DEBUG, "New xdg popup received");
struct hrt_server *server = wl_container_of(listener, server, new_xdg_popup);
struct wlr_xdg_popup *xdg_popup = data;

// 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_try_from_wlr_surface(xdg_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:
if (parent_tree) {
xdg_popup->base->data = wlr_scene_xdg_surface_create(parent_tree, xdg_popup->base);
struct hrt_xdg_popup *popup = calloc(1, sizeof(*popup));
popup->commit.notify = handle_xdg_popup_commit;
wl_signal_add(&xdg_popup->base->surface->events.commit,
&popup->commit);

popup->destroy.notify = handle_xdg_popup_destroy;
wl_signal_add(&xdg_popup->events.destroy, &popup->destroy);

} else {
wlr_log(WLR_ERROR, "Encountered XDG Popup without properly configured parent");
}
}

static void handle_new_xdg_toplevel(struct wl_listener *listener, void * data) {
wlr_log(WLR_DEBUG, "New XDG Popup received");
struct hrt_server *server =
wl_container_of(listener, server, new_xdg_toplevel);
struct wlr_xdg_toplevel *toplevel = data;
// Initialization occurs in two steps so the consumer can place the view where it needs to go;
// in order to create a scene tree node, it must have a parent.
// We don't have it until the callback.
struct hrt_view *view = create_view_from_xdg_surface(xdg_surface,
struct hrt_view *view = create_view_from_xdg_surface(toplevel,
server->view_callbacks->view_destroyed);
// At some point, we will want the front end to call this, as it should decide what node
// of the scene graph the view gets added to:
// hrt_view_init(view, &server->scene->tree);

server->view_callbacks->new_view(view);
}

bool hrt_xdg_shell_init(struct hrt_server *server) {
server->xdg_shell = wlr_xdg_shell_create(server->wl_display, 3);
server->new_xdg_popup.notify = handle_new_xdg_popup;
wl_signal_add(&server->xdg_shell->events.new_popup, &server->new_xdg_popup);

server->new_xdg_toplevel.notify = handle_new_xdg_toplevel;
wl_signal_add(&server->xdg_shell->events.new_toplevel, &server->new_xdg_toplevel);
return true;
}
2 changes: 1 addition & 1 deletion heart/subprojects/wlroots
Submodule wlroots updated from a2d2c3 to 5bc390
5 changes: 4 additions & 1 deletion lisp/bindings/hrt-bindings.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
(scene-tree :pointer #| (:struct wlr-scene-tree) |# )
(map (:struct wl-listener))
(unmap (:struct wl-listener))
(commit (:struct wl-listener))
(destroy (:struct wl-listener))
(destroy-handler view-destroy-handler))

Expand Down Expand Up @@ -159,6 +160,7 @@ set the width and height of views."
(cffi:defcstruct hrt-server
(wl-display :pointer #| (:struct wl-display) |# )
(backend :pointer #| (:struct wlr-backend) |# )
(backend-destroy (:struct wl-listener))
(session :pointer #| (:struct wlr-session) |# )
(renderer :pointer #| (:struct wlr-renderer) |# )
(compositor :pointer #| (:struct wlr-compositor) |# )
Expand All @@ -173,7 +175,8 @@ set the width and height of views."
(output-manager-destroy (:struct wl-listener))
(seat (:struct hrt-seat))
(xdg-shell :pointer #| (:struct wlr-xdg-shell) |# )
(new-xdg-surface (:struct wl-listener))
(new-xdg-toplevel (:struct wl-listener))
(new-xdg-popup (:struct wl-listener))
(output-callback (:pointer (:struct hrt-output-callbacks)))
(view-callbacks (:pointer (:struct hrt-view-callbacks))))

Expand Down
2 changes: 1 addition & 1 deletion lisp/bindings/hrt-libs.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
(:unix "libheart.so"))

(cffi:define-foreign-library libwlroots
(:unix "libwlroots.so"))
(:unix "libwlroots-0.18.so"))

(defun load-foreign-libraries ()
(cffi:use-foreign-library libwlroots)
Expand Down

0 comments on commit b58853d

Please sign in to comment.