diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e82dbf1..31693bf 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,6 +5,9 @@ on: pull_request: branches: [ master ] +env: + WLROOTS_VERSION: 0.19 + jobs: compile: runs-on: ubuntu-latest @@ -23,20 +26,20 @@ jobs: - name: Install dependencies (Alpine) if: "matrix.OS == 'alpine:edge'" - run: apk add build-base xcb-util-wm-dev libseat-dev clang git eudev-dev mesa-dev libdrm-dev libinput-dev libxkbcommon-dev pixman-dev wayland-dev meson wayland-protocols xwayland-dev scdoc-doc hwdata + run: apk add build-base xcb-util-wm-dev libseat-dev clang git eudev-dev mesa-dev libdrm-dev libinput-dev libxkbcommon-dev pixman-dev wayland-dev meson wayland-protocols xwayland-dev scdoc-doc hwdata libdisplay-info-dev - name: Install dependencies (Arch) if: "matrix.OS == 'archlinux:base-devel'" run: | pacman-key --init - pacman -Syu --noconfirm xcb-util-wm seatd git clang meson libinput libdrm mesa libxkbcommon wayland wayland-protocols xorg-server-xwayland scdoc + pacman -Syu --noconfirm xcb-util-wm seatd git clang meson libinput libdrm mesa libxkbcommon wayland wayland-protocols xorg-server-xwayland scdoc libdisplay-info - name: Fetch wlroots as a subproject - run: git clone https://gitlab.freedesktop.org/wlroots/wlroots.git subprojects/wlroots -b 0.18 + run: git clone https://gitlab.freedesktop.org/wlroots/wlroots.git subprojects/wlroots -b $WLROOTS_VERSION - name: Compile Cage (XWayland=${{ matrix.xwayland }}) run: | - meson --fatal-meson-warnings \ + meson --fatal-meson-warnings --wrap-mode=nodownload \ build-${{ matrix.CC }}-${{matrix.xwayland }} \ -Dwlroots:xwayland=${{ matrix.xwayland }} ninja -C build-${{ matrix.CC }}-${{matrix.xwayland }} @@ -50,12 +53,12 @@ jobs: - name: Install dependencies run: | 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 + pacman -Syu --noconfirm xcb-util-wm seatd git clang meson libinput libdrm mesa libxkbcommon wayland wayland-protocols xorg-server-xwayland scdoc hwdata libdisplay-info - name: Fetch wlroots as a subproject - run: git clone https://gitlab.freedesktop.org/wlroots/wlroots.git subprojects/wlroots -b 0.18 + run: git clone https://gitlab.freedesktop.org/wlroots/wlroots.git subprojects/wlroots -b $WLROOTS_VERSION - name: Check for formatting changes run: | - meson build-clang-format -Dwlroots:xwayland=enabled + meson --wrap-mode=nodownload build-clang-format -Dwlroots:xwayland=enabled ninja -C build-clang-format clang-format-check scan-build: @@ -69,10 +72,10 @@ jobs: - name: Install dependencies run: | 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 + pacman -Syu --noconfirm xcb-util-wm seatd git clang meson libinput libdrm mesa libxkbcommon wayland wayland-protocols xorg-server-xwayland scdoc hwdata libdisplay-info - name: Fetch wlroots as a subproject - run: git clone https://gitlab.freedesktop.org/wlroots/wlroots.git subprojects/wlroots -b 0.18 + run: git clone https://gitlab.freedesktop.org/wlroots/wlroots.git subprojects/wlroots -b $WLROOTS_VERSION - name: Run scan-build run: | - meson build-scan-build -Dwlroots:xwayland=enabled + meson --wrap-mode=nodownload build-scan-build -Dwlroots:xwayland=enabled ninja -C build-scan-build scan-build diff --git a/README.md b/README.md index ec6ce78..d285219 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ This README is only relevant for development resources and instructions. For a description of Cage and installation instructions for end-users, please see [its project page](https://www.hjdskes.nl/projects/cage) and [the Wiki](https://github.com/cage-kiosk/cage/wiki/). +See [the man page](./cage.1.scd) for a list of possible environment variables and run options. ## Release signatures diff --git a/cage.1.scd b/cage.1.scd index 0894f5d..ed1f518 100644 --- a/cage.1.scd +++ b/cage.1.scd @@ -6,7 +6,7 @@ cage - a Wayland kiosk compositor # SYNOPSIS -*cage* [-dhmrsv] [--] _application_ [application argument ...] +*cage* [options...] [--] [_application_...] # DESCRIPTION @@ -19,6 +19,9 @@ activities outside the scope of the running application are prevented. *-d* Don't draw client side decorations when possible. +*-D* + Enable debug logging. + *-h* Show the help message. diff --git a/cage.c b/cage.c index 26ab9ef..9b7c510 100644 --- a/cage.c +++ b/cage.c @@ -224,9 +224,10 @@ static void usage(FILE *file, const char *cage) { fprintf(file, - "Usage: %s [OPTIONS] [--] APPLICATION\n" + "Usage: %s [OPTIONS] [--] [APPLICATION...]\n" "\n" " -d\t Don't draw client side decorations, when possible\n" + " -D\t Enable debug logging\n" " -h\t Display this help message\n" " -m extend Extend the display across all connected outputs (default)\n" " -m last Use only the last connected output\n" @@ -241,11 +242,14 @@ static bool parse_args(struct cg_server *server, int argc, char *argv[]) { int c; - while ((c = getopt(argc, argv, "dhm:sv")) != -1) { + while ((c = getopt(argc, argv, "dDhm:sv")) != -1) { switch (c) { case 'd': server->xdg_decoration = true; break; + case 'D': + server->log_level = WLR_DEBUG; + break; case 'h': usage(stdout, argv[0]); return false; @@ -268,31 +272,26 @@ parse_args(struct cg_server *server, int argc, char *argv[]) } } - if (optind >= argc) { - usage(stderr, argv[0]); - return false; - } - return true; } int main(int argc, char *argv[]) { - struct cg_server server = {0}; + struct cg_server server = {.log_level = WLR_INFO}; struct wl_event_source *sigchld_source = NULL; pid_t pid = 0; int ret = 0, app_ret = 0; +#ifdef DEBUG + server.log_level = WLR_DEBUG; +#endif + if (!parse_args(&server, argc, argv)) { return 1; } -#ifdef DEBUG - wlr_log_init(WLR_DEBUG, NULL); -#else - wlr_log_init(WLR_ERROR, NULL); -#endif + wlr_log_init(server.log_level, NULL); /* Wayland requires XDG_RUNTIME_DIR to be set. */ if (!getenv("XDG_RUNTIME_DIR")) { @@ -417,7 +416,7 @@ main(int argc, char *argv[]) wl_signal_add(&server.idle_inhibit_v1->events.new_inhibitor, &server.new_idle_inhibitor_v1); wl_list_init(&server.inhibitors); - struct wlr_xdg_shell *xdg_shell = wlr_xdg_shell_create(server.wl_display, 4); + struct wlr_xdg_shell *xdg_shell = wlr_xdg_shell_create(server.wl_display, 5); if (!xdg_shell) { wlr_log(WLR_ERROR, "Unable to create the XDG shell interface"); ret = 1; @@ -455,7 +454,7 @@ main(int argc, char *argv[]) goto end; } - struct wlr_presentation *presentation = wlr_presentation_create(server.wl_display, server.backend); + struct wlr_presentation *presentation = wlr_presentation_create(server.wl_display, server.backend, 2); if (!presentation) { wlr_log(WLR_ERROR, "Unable to create the presentation interface"); ret = 1; @@ -588,7 +587,7 @@ main(int argc, char *argv[]) } #endif - if (!spawn_primary_client(&server, argv + optind, &pid, &sigchld_source)) { + if (optind < argc && !spawn_primary_client(&server, argv + optind, &pid, &sigchld_source)) { ret = 1; goto end; } @@ -597,13 +596,28 @@ main(int argc, char *argv[]) wl_display_run(server.wl_display); #if CAGE_HAS_XWAYLAND + if (xwayland) { + wl_list_remove(&server.new_xwayland_surface.link); + } wlr_xwayland_destroy(xwayland); wlr_xcursor_manager_destroy(xcursor_manager); #endif wl_display_destroy_clients(server.wl_display); + wl_list_remove(&server.new_virtual_pointer.link); + wl_list_remove(&server.new_virtual_keyboard.link); + wl_list_remove(&server.output_manager_apply.link); + wl_list_remove(&server.output_manager_test.link); + wl_list_remove(&server.xdg_toplevel_decoration.link); + wl_list_remove(&server.new_xdg_toplevel.link); + wl_list_remove(&server.new_xdg_popup.link); + wl_list_remove(&server.new_idle_inhibitor_v1.link); + wl_list_remove(&server.new_output.link); + wl_list_remove(&server.output_layout_change.link); + end: - app_ret = cleanup_primary_client(pid); + if (pid != 0) + app_ret = cleanup_primary_client(pid); if (!ret && server.return_app_code) ret = app_ret; @@ -616,5 +630,8 @@ end: /* This function is not null-safe, but we only ever get here with a proper wl_display. */ wl_display_destroy(server.wl_display); + wlr_scene_node_destroy(&server.scene->tree.node); + wlr_allocator_destroy(server.allocator); + wlr_renderer_destroy(server.renderer); return ret; } diff --git a/meson.build b/meson.build index 7b58cd8..f8ccd76 100644 --- a/meson.build +++ b/meson.build @@ -1,5 +1,5 @@ project('cage', 'c', - version: '0.2.0', + version: '0.2.1', license: 'MIT', meson_version: '>=0.58.1', default_options: [ @@ -35,7 +35,7 @@ if is_freebsd ) endif -wlroots = dependency('wlroots-0.18', fallback: ['wlroots', 'wlroots']) +wlroots = dependency('wlroots-0.19', fallback: ['wlroots', 'wlroots']) wayland_protos = dependency('wayland-protocols', version: '>=1.14') wayland_server = dependency('wayland-server') xkbcommon = dependency('xkbcommon') diff --git a/output.c b/output.c index f1c0419..093836b 100644 --- a/output.c +++ b/output.c @@ -21,13 +21,14 @@ #if WLR_HAS_X11_BACKEND #include #endif +#include #include #include #include -#include #include #include #include +#include #include #include #include @@ -131,31 +132,6 @@ output_disable(struct cg_output *output) output_layout_remove(output); } -static bool -output_apply_config(struct cg_output *output, struct wlr_output_configuration_head_v1 *head, bool test_only) -{ - struct wlr_output_state state = {0}; - wlr_output_head_v1_state_apply(&head->state, &state); - - if (test_only) { - bool ret = wlr_output_test_state(output->wlr_output, &state); - return ret; - } - - /* Apply output configuration */ - if (!wlr_output_commit_state(output->wlr_output, &state)) { - return false; - } - - if (head->state.enabled) { - output_layout_add(output, head->state.x, head->state.y); - } else { - output_layout_remove(output); - } - - return true; -} - static void handle_output_frame(struct wl_listener *listener, void *data) { @@ -356,17 +332,63 @@ output_set_window_title(struct cg_output *output, const char *title) static bool output_config_apply(struct cg_server *server, struct wlr_output_configuration_v1 *config, bool test_only) { - struct wlr_output_configuration_head_v1 *head; + bool ok = false; - wl_list_for_each (head, &config->heads, link) { - struct cg_output *output = head->state.output->data; + size_t states_len; + struct wlr_backend_output_state *states = wlr_output_configuration_v1_build_state(config, &states_len); + if (states == NULL) { + return false; + } - if (!output_apply_config(output, head, test_only)) { - return false; + struct wlr_output_swapchain_manager swapchain_manager; + wlr_output_swapchain_manager_init(&swapchain_manager, server->backend); + + ok = wlr_output_swapchain_manager_prepare(&swapchain_manager, states, states_len); + if (!ok || test_only) { + goto out; + } + + for (size_t i = 0; i < states_len; i++) { + struct wlr_backend_output_state *backend_state = &states[i]; + struct cg_output *output = backend_state->output->data; + + struct wlr_swapchain *swapchain = + wlr_output_swapchain_manager_get_swapchain(&swapchain_manager, backend_state->output); + struct wlr_scene_output_state_options options = { + .swapchain = swapchain, + }; + struct wlr_output_state *state = &backend_state->base; + if (!wlr_scene_output_build_state(output->scene_output, state, &options)) { + ok = false; + goto out; } } - return true; + ok = wlr_backend_commit(server->backend, states, states_len); + if (!ok) { + goto out; + } + + wlr_output_swapchain_manager_apply(&swapchain_manager); + + struct wlr_output_configuration_head_v1 *head; + wl_list_for_each (head, &config->heads, link) { + struct cg_output *output = head->state.output->data; + + if (head->state.enabled) { + output_layout_add(output, head->state.x, head->state.y); + } else { + output_layout_remove(output); + } + } + +out: + wlr_output_swapchain_manager_finish(&swapchain_manager); + for (size_t i = 0; i < states_len; i++) { + wlr_output_state_finish(&states[i].base); + } + free(states); + return ok; } void diff --git a/seat.c b/seat.c index cdf8798..5f659a4 100644 --- a/seat.c +++ b/seat.c @@ -380,6 +380,16 @@ cleanup: free(cg_group); } +static void +keyboard_group_destroy(struct cg_keyboard_group *keyboard_group) +{ + wl_list_remove(&keyboard_group->key.link); + wl_list_remove(&keyboard_group->modifiers.link); + wlr_keyboard_group_destroy(keyboard_group->wlr_group); + wl_list_remove(&keyboard_group->link); + free(keyboard_group); +} + static void handle_new_keyboard(struct cg_seat *seat, struct wlr_keyboard *keyboard, bool virtual) { @@ -893,6 +903,11 @@ seat_destroy(struct cg_seat *seat) wl_list_remove(&seat->request_start_drag.link); wl_list_remove(&seat->start_drag.link); + struct cg_keyboard_group *keyboard_group, *keyboard_group_tmp; + wl_list_for_each_safe (keyboard_group, keyboard_group_tmp, &seat->keyboard_groups, link) { + keyboard_group_destroy(keyboard_group); + } + // Destroying the wlr seat will trigger the destroy handler on our seat, // which will in turn free it. wlr_seat_destroy(seat->seat); @@ -922,7 +937,7 @@ seat_set_focus(struct cg_seat *seat, struct cg_view *view) #if CAGE_HAS_XWAYLAND if (view->type == CAGE_XWAYLAND_VIEW) { struct cg_xwayland_view *xwayland_view = xwayland_view_from_view(view); - if (!wlr_xwayland_or_surface_wants_focus(xwayland_view->xwayland_surface)) { + if (!wlr_xwayland_surface_override_redirect_wants_focus(xwayland_view->xwayland_surface)) { return; } } diff --git a/server.h b/server.h index f7d70d7..00c2a61 100644 --- a/server.h +++ b/server.h @@ -9,6 +9,8 @@ #include #include #include +#include + #if CAGE_HAS_XWAYLAND #include #endif @@ -63,6 +65,7 @@ struct cg_server { bool allow_vt_switch; bool return_app_code; bool terminated; + enum wlr_log_importance log_level; }; void server_terminate(struct cg_server *server); diff --git a/xdg_shell.c b/xdg_shell.c index cae6c90..5493918 100644 --- a/xdg_shell.c +++ b/xdg_shell.c @@ -128,11 +128,10 @@ static void get_geometry(struct cg_view *view, int *width_out, int *height_out) { struct cg_xdg_shell_view *xdg_shell_view = xdg_shell_view_from_view(view); - struct wlr_box geom; + struct wlr_xdg_surface *xdg_surface = xdg_shell_view->xdg_toplevel->base; - wlr_xdg_surface_get_geometry(xdg_shell_view->xdg_toplevel->base, &geom); - *width_out = geom.width; - *height_out = geom.height; + *width_out = xdg_surface->geometry.width; + *height_out = xdg_surface->geometry.height; } static bool @@ -185,7 +184,7 @@ destroy(struct cg_view *view) } static void -handle_xdg_shell_surface_request_fullscreen(struct wl_listener *listener, void *data) +handle_xdg_toplevel_request_fullscreen(struct wl_listener *listener, void *data) { struct cg_xdg_shell_view *xdg_shell_view = wl_container_of(listener, xdg_shell_view, request_fullscreen); @@ -202,7 +201,7 @@ handle_xdg_shell_surface_request_fullscreen(struct wl_listener *listener, void * } static void -handle_xdg_shell_surface_unmap(struct wl_listener *listener, void *data) +handle_xdg_toplevel_unmap(struct wl_listener *listener, void *data) { struct cg_xdg_shell_view *xdg_shell_view = wl_container_of(listener, xdg_shell_view, unmap); struct cg_view *view = &xdg_shell_view->view; @@ -211,7 +210,7 @@ handle_xdg_shell_surface_unmap(struct wl_listener *listener, void *data) } static void -handle_xdg_shell_surface_map(struct wl_listener *listener, void *data) +handle_xdg_toplevel_map(struct wl_listener *listener, void *data) { struct cg_xdg_shell_view *xdg_shell_view = wl_container_of(listener, xdg_shell_view, map); struct cg_view *view = &xdg_shell_view->view; @@ -220,7 +219,7 @@ handle_xdg_shell_surface_map(struct wl_listener *listener, void *data) } static void -handle_xdg_shell_surface_commit(struct wl_listener *listener, void *data) +handle_xdg_toplevel_commit(struct wl_listener *listener, void *data) { struct cg_xdg_shell_view *xdg_shell_view = wl_container_of(listener, xdg_shell_view, commit); @@ -228,13 +227,15 @@ handle_xdg_shell_surface_commit(struct wl_listener *listener, void *data) return; } + wlr_xdg_toplevel_set_wm_capabilities(xdg_shell_view->xdg_toplevel, XDG_TOPLEVEL_WM_CAPABILITIES_FULLSCREEN); + /* When an xdg_surface performs an initial commit, the compositor must * reply with a configure so the client can map the surface. */ view_position(&xdg_shell_view->view); } static void -handle_xdg_shell_surface_destroy(struct wl_listener *listener, void *data) +handle_xdg_toplevel_destroy(struct wl_listener *listener, void *data) { struct cg_xdg_shell_view *xdg_shell_view = wl_container_of(listener, xdg_shell_view, destroy); struct cg_view *view = &xdg_shell_view->view; @@ -274,15 +275,15 @@ handle_new_xdg_toplevel(struct wl_listener *listener, void *data) view_init(&xdg_shell_view->view, server, CAGE_XDG_SHELL_VIEW, &xdg_shell_view_impl); xdg_shell_view->xdg_toplevel = toplevel; - xdg_shell_view->commit.notify = handle_xdg_shell_surface_commit; + xdg_shell_view->commit.notify = handle_xdg_toplevel_commit; wl_signal_add(&toplevel->base->surface->events.commit, &xdg_shell_view->commit); - xdg_shell_view->map.notify = handle_xdg_shell_surface_map; + xdg_shell_view->map.notify = handle_xdg_toplevel_map; wl_signal_add(&toplevel->base->surface->events.map, &xdg_shell_view->map); - xdg_shell_view->unmap.notify = handle_xdg_shell_surface_unmap; + xdg_shell_view->unmap.notify = handle_xdg_toplevel_unmap; wl_signal_add(&toplevel->base->surface->events.unmap, &xdg_shell_view->unmap); - xdg_shell_view->destroy.notify = handle_xdg_shell_surface_destroy; + xdg_shell_view->destroy.notify = handle_xdg_toplevel_destroy; wl_signal_add(&toplevel->events.destroy, &xdg_shell_view->destroy); - xdg_shell_view->request_fullscreen.notify = handle_xdg_shell_surface_request_fullscreen; + xdg_shell_view->request_fullscreen.notify = handle_xdg_toplevel_request_fullscreen; wl_signal_add(&toplevel->events.request_fullscreen, &xdg_shell_view->request_fullscreen); toplevel->base->data = xdg_shell_view; @@ -294,6 +295,7 @@ popup_handle_destroy(struct wl_listener *listener, void *data) struct cg_xdg_popup *popup = wl_container_of(listener, popup, destroy); wl_list_remove(&popup->destroy.link); wl_list_remove(&popup->commit.link); + wl_list_remove(&popup->reposition.link); free(popup); } @@ -307,6 +309,14 @@ popup_handle_commit(struct wl_listener *listener, void *data) } } +static void +popup_handle_reposition(struct wl_listener *listener, void *data) +{ + struct cg_xdg_popup *popup = wl_container_of(listener, popup, reposition); + + popup_unconstrain(popup->xdg_popup); +} + void handle_new_xdg_popup(struct wl_listener *listener, void *data) { @@ -351,6 +361,9 @@ handle_new_xdg_popup(struct wl_listener *listener, void *data) popup->commit.notify = popup_handle_commit; wl_signal_add(&wlr_popup->base->surface->events.commit, &popup->commit); + popup->reposition.notify = popup_handle_reposition; + wl_signal_add(&wlr_popup->events.reposition, &popup->reposition); + struct wlr_scene_tree *popup_scene_tree = wlr_scene_xdg_surface_create(parent_scene_tree, wlr_popup->base); if (popup_scene_tree == NULL) { wlr_log(WLR_ERROR, "Failed to allocate scene-graph node for XDG popup"); diff --git a/xdg_shell.h b/xdg_shell.h index 1fc000a..f819549 100644 --- a/xdg_shell.h +++ b/xdg_shell.h @@ -31,6 +31,7 @@ struct cg_xdg_popup { struct wl_listener destroy; struct wl_listener commit; + struct wl_listener reposition; }; void handle_new_xdg_toplevel(struct wl_listener *listener, void *data); diff --git a/xwayland.c b/xwayland.c index de81408..3df7a08 100644 --- a/xwayland.c +++ b/xwayland.c @@ -92,7 +92,7 @@ maximize(struct cg_view *view, int output_width, int output_height) struct cg_xwayland_view *xwayland_view = xwayland_view_from_view(view); wlr_xwayland_surface_configure(xwayland_view->xwayland_surface, view->lx, view->ly, output_width, output_height); - wlr_xwayland_surface_set_maximized(xwayland_view->xwayland_surface, true); + wlr_xwayland_surface_set_maximized(xwayland_view->xwayland_surface, true, true); } static void