Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for wlroots v0.18 #313

Merged
merged 11 commits into from
Sep 7, 2024
11 changes: 7 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@ jobs:
pacman -Syu --noconfirm xcb-util-wm seatd git clang meson libinput libdrm mesa libxkbcommon wayland wayland-protocols xorg-server-xwayland scdoc

- name: Fetch wlroots as a subproject
run: git clone https://gitlab.freedesktop.org/wlroots/wlroots.git subprojects/wlroots -b 0.17
run: git clone https://gitlab.freedesktop.org/wlroots/wlroots.git subprojects/wlroots -b 0.18

# TODO: drop explicit c_std when this is released:
# https://gitlab.freedesktop.org/wayland/wayland/-/merge_requests/401
- name: Compile Cage (XWayland=${{ matrix.xwayland }})
run: |
meson --fatal-meson-warnings \
build-${{ matrix.CC }}-${{matrix.xwayland }} \
-Dwlroots:xwayland=${{ matrix.xwayland }}
-Dwlroots:xwayland=${{ matrix.xwayland }} \
-Dwlroots:c_std=c11
ninja -C build-${{ matrix.CC }}-${{matrix.xwayland }}

format:
Expand All @@ -52,7 +55,7 @@ jobs:
pacman-key --init
pacman -Syu --noconfirm xcb-util-wm seatd git clang meson libinput libdrm mesa libxkbcommon wayland wayland-protocols xorg-server-xwayland scdoc hwdata
- name: Fetch wlroots as a subproject
run: git clone https://gitlab.freedesktop.org/wlroots/wlroots.git subprojects/wlroots -b 0.17
run: git clone https://gitlab.freedesktop.org/wlroots/wlroots.git subprojects/wlroots -b 0.18
- name: Check for formatting changes
run: |
meson build-clang-format -Dwlroots:xwayland=enabled
Expand All @@ -71,7 +74,7 @@ jobs:
pacman-key --init
pacman -Syu --noconfirm xcb-util-wm seatd git clang meson libinput libdrm mesa libxkbcommon wayland wayland-protocols xorg-server-xwayland scdoc hwdata
- name: Fetch wlroots as a subproject
run: git clone https://gitlab.freedesktop.org/wlroots/wlroots.git subprojects/wlroots -b 0.17
run: git clone https://gitlab.freedesktop.org/wlroots/wlroots.git subprojects/wlroots -b 0.18
- name: Run scan-build
run: |
meson build-scan-build -Dwlroots:xwayland=enabled
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ All releases are published on [GitHub](https://github.com/cage-kiosk/cage/releas

You can build Cage with the [meson](https://mesonbuild.com/) build system. It
requires wayland, wlroots, and xkbcommon to be installed. Optionally, install
scdoc for manual pages. Cage is currently based on branch 0.17 of wlroots.
scdoc for manual pages. Cage is currently based on branch 0.18 of wlroots.

Simply execute the following steps to build Cage:

Expand Down
45 changes: 32 additions & 13 deletions cage.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,24 @@
#include "xwayland.h"
#endif

void
server_terminate(struct cg_server *server)
{
// Workaround for https://gitlab.freedesktop.org/wayland/wayland/-/merge_requests/421
if (server->terminated) {
return;
}

wl_display_terminate(server->wl_display);
}

static void
handle_display_destroy(struct wl_listener *listener, void *data)
{
struct cg_server *server = wl_container_of(listener, server, display_destroy);
server->terminated = true;
}

static int
sigchld_handler(int fd, uint32_t mask, void *data)
{
Expand All @@ -76,7 +94,7 @@ sigchld_handler(int fd, uint32_t mask, void *data)
}

server->return_app_code = true;
wl_display_terminate(server->wl_display);
server_terminate(server);
return 0;
}

Expand Down Expand Up @@ -189,13 +207,13 @@ drop_permissions(void)
static int
handle_signal(int signal, void *data)
{
struct wl_display *display = data;
struct cg_server *server = data;

switch (signal) {
case SIGINT:
/* Fallthrough */
case SIGTERM:
wl_display_terminate(display);
server_terminate(server);
return 0;
default:
return 0;
Expand Down Expand Up @@ -288,13 +306,14 @@ main(int argc, char *argv[])
return 1;
}

server.display_destroy.notify = handle_display_destroy;
wl_display_add_destroy_listener(server.wl_display, &server.display_destroy);

struct wl_event_loop *event_loop = wl_display_get_event_loop(server.wl_display);
struct wl_event_source *sigint_source =
wl_event_loop_add_signal(event_loop, SIGINT, handle_signal, server.wl_display);
struct wl_event_source *sigterm_source =
wl_event_loop_add_signal(event_loop, SIGTERM, handle_signal, server.wl_display);
struct wl_event_source *sigint_source = wl_event_loop_add_signal(event_loop, SIGINT, handle_signal, &server);
struct wl_event_source *sigterm_source = wl_event_loop_add_signal(event_loop, SIGTERM, handle_signal, &server);

server.backend = wlr_backend_autocreate(server.wl_display, &server.session);
server.backend = wlr_backend_autocreate(event_loop, &server.session);
if (!server.backend) {
wlr_log(WLR_ERROR, "Unable to create the wlroots backend");
ret = 1;
Expand Down Expand Up @@ -325,7 +344,7 @@ main(int argc, char *argv[])
wl_list_init(&server.views);
wl_list_init(&server.outputs);

server.output_layout = wlr_output_layout_create();
server.output_layout = wlr_output_layout_create(server.wl_display);
emersion marked this conversation as resolved.
Show resolved Hide resolved
if (!server.output_layout) {
wlr_log(WLR_ERROR, "Unable to create output layout");
ret = 1;
Expand Down Expand Up @@ -404,8 +423,10 @@ main(int argc, char *argv[])
ret = 1;
goto end;
}
server.new_xdg_shell_surface.notify = handle_xdg_shell_surface_new;
wl_signal_add(&xdg_shell->events.new_surface, &server.new_xdg_shell_surface);
server.new_xdg_toplevel.notify = handle_new_xdg_toplevel;
wl_signal_add(&xdg_shell->events.new_toplevel, &server.new_xdg_toplevel);
server.new_xdg_popup.notify = handle_new_xdg_popup;
wl_signal_add(&xdg_shell->events.new_popup, &server.new_xdg_popup);

struct wlr_xdg_decoration_manager_v1 *xdg_decoration_manager =
wlr_xdg_decoration_manager_v1_create(server.wl_display);
Expand Down Expand Up @@ -440,7 +461,6 @@ main(int argc, char *argv[])
ret = 1;
goto end;
}
wlr_scene_set_presentation(server.scene, presentation);

if (!wlr_export_dmabuf_manager_v1_create(server.wl_display)) {
wlr_log(WLR_ERROR, "Unable to create the export DMABUF manager");
Expand Down Expand Up @@ -596,6 +616,5 @@ main(int argc, char *argv[])
/* This function is not null-safe, but we only ever get here
with a proper wl_display. */
wl_display_destroy(server.wl_display);
wlr_output_layout_destroy(server.output_layout);
return ret;
}
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ if is_freebsd
)
endif

wlroots = dependency('wlroots', version: '>= 0.17.0', fallback: ['wlroots', 'wlroots'])
wlroots = dependency('wlroots-0.18', fallback: ['wlroots', 'wlroots'])
wayland_protos = dependency('wayland-protocols', version: '>=1.14')
wayland_server = dependency('wayland-server')
xkbcommon = dependency('xkbcommon')
Expand Down
2 changes: 1 addition & 1 deletion output.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ output_destroy(struct cg_output *output)
free(output);

if (wl_list_empty(&server->outputs) && was_nested_output) {
wl_display_terminate(server->wl_display);
server_terminate(server);
} else if (server->output_mode == CAGE_MULTI_OUTPUT_MODE_LAST && !wl_list_empty(&server->outputs)) {
struct cg_output *prev = wl_container_of(server->outputs.next, prev, link);
output_enable(prev);
Expand Down
6 changes: 3 additions & 3 deletions seat.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ handle_keybinding(struct cg_server *server, xkb_keysym_t sym)
{
#ifdef DEBUG
if (sym == XKB_KEY_Escape) {
wl_display_terminate(server->wl_display);
server_terminate(server);
return true;
}
#endif
Expand Down Expand Up @@ -441,7 +441,7 @@ handle_new_input(struct wl_listener *listener, void *data)
case WLR_INPUT_DEVICE_SWITCH:
wlr_log(WLR_DEBUG, "Switch input is not implemented");
return;
case WLR_INPUT_DEVICE_TABLET_TOOL:
case WLR_INPUT_DEVICE_TABLET:
case WLR_INPUT_DEVICE_TABLET_PAD:
wlr_log(WLR_DEBUG, "Tablet input is not implemented");
return;
Expand Down Expand Up @@ -591,7 +591,7 @@ handle_cursor_axis(struct wl_listener *listener, void *data)
struct wlr_pointer_axis_event *event = data;

wlr_seat_pointer_notify_axis(seat->seat, event->time_msec, event->orientation, event->delta,
event->delta_discrete, event->source);
event->delta_discrete, event->source, event->relative_direction);
wlr_idle_notifier_v1_notify_activity(seat->server->idle, seat->seat);
}

Expand Down
7 changes: 6 additions & 1 deletion server.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct cg_server {
struct wlr_renderer *renderer;
struct wlr_allocator *allocator;
struct wlr_session *session;
struct wl_listener display_destroy;

struct cg_seat *seat;
struct wlr_idle_notifier_v1 *idle;
Expand All @@ -44,7 +45,8 @@ struct cg_server {
struct wl_listener output_layout_change;

struct wl_listener xdg_toplevel_decoration;
struct wl_listener new_xdg_shell_surface;
struct wl_listener new_xdg_toplevel;
struct wl_listener new_xdg_popup;

struct wl_listener new_virtual_keyboard;
struct wl_listener new_virtual_pointer;
Expand All @@ -60,6 +62,9 @@ struct cg_server {
bool xdg_decoration;
bool allow_vt_switch;
bool return_app_code;
bool terminated;
};

void server_terminate(struct cg_server *server);

#endif
8 changes: 6 additions & 2 deletions view.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ view_maximize(struct cg_view *view, struct wlr_box *layout_box)
view->lx = layout_box->x;
view->ly = layout_box->y;

wlr_scene_node_set_position(&view->scene_tree->node, view->lx, view->ly);
if (view->scene_tree) {
wlr_scene_node_set_position(&view->scene_tree->node, view->lx, view->ly);
}

view->impl->maximize(view, layout_box->width, layout_box->height);
}
Expand All @@ -81,7 +83,9 @@ view_center(struct cg_view *view, struct wlr_box *layout_box)
view->lx = (layout_box->width - width) / 2;
view->ly = (layout_box->height - height) / 2;

wlr_scene_node_set_position(&view->scene_tree->node, view->lx, view->ly);
if (view->scene_tree) {
wlr_scene_node_set_position(&view->scene_tree->node, view->lx, view->ly);
}
}

void
Expand Down
Loading
Loading