Skip to content

Commit

Permalink
Update wlroots to 0.17.2
Browse files Browse the repository at this point in the history
Release notes:
https://gitlab.freedesktop.org/wlroots/wlroots/-/releases/0.17.0

The following things were affected/added:
+ 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
  • Loading branch information
sdilts committed Apr 7, 2024
1 parent 7c4cee7 commit 4251762
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 46 deletions.
3 changes: 1 addition & 2 deletions heart/include/hrt/hrt_output.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions heart/include/hrt/hrt_server.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef HRT_HRT_SERVER_H
#define HRT_HRT_SERVER_H

#include "wlr/backend/session.h"
#include <stdbool.h>

#include <wayland-server.h>
Expand All @@ -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;
Expand Down
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.16.0', '<0.17.0']
wlroots_version = ['>=0.17.0', '<0.18.0']
wlroots_proj = subproject(
'wlroots',
default_options: ['examples=false'],
Expand Down
4 changes: 2 additions & 2 deletions heart/src/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include <hrt/hrt_input.h>

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) {
Expand Down
2 changes: 1 addition & 1 deletion heart/src/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
52 changes: 30 additions & 22 deletions heart/src/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,19 @@

#include <hrt/hrt_output.h>

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);
Expand All @@ -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()
{
Expand All @@ -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.
Expand All @@ -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);
}
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions heart/src/seat.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include <hrt/hrt_input.h>

#include <wlr/types/wlr_xcursor_manager.h>
#include <wlr/types/wlr_cursor.h>

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);
}
4 changes: 2 additions & 2 deletions heart/src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions heart/src/xdg_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion heart/subprojects/wlroots
Submodule wlroots updated 339 files
7 changes: 4 additions & 3 deletions lisp/bindings/hrt-bindings.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,15 @@ 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))
(color :float :count 4))

(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)))
Expand All @@ -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) |# )
Expand Down
3 changes: 1 addition & 2 deletions lisp/main.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions lisp/output.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

0 comments on commit 4251762

Please sign in to comment.