diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 31693bf..e82dbf1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,9 +5,6 @@ on: pull_request: branches: [ master ] -env: - WLROOTS_VERSION: 0.19 - jobs: compile: runs-on: ubuntu-latest @@ -26,20 +23,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 libdisplay-info-dev + 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 - 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 libdisplay-info + 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 $WLROOTS_VERSION + run: git clone https://gitlab.freedesktop.org/wlroots/wlroots.git subprojects/wlroots -b 0.18 - name: Compile Cage (XWayland=${{ matrix.xwayland }}) run: | - meson --fatal-meson-warnings --wrap-mode=nodownload \ + meson --fatal-meson-warnings \ build-${{ matrix.CC }}-${{matrix.xwayland }} \ -Dwlroots:xwayland=${{ matrix.xwayland }} ninja -C build-${{ matrix.CC }}-${{matrix.xwayland }} @@ -53,12 +50,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 libdisplay-info + 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 $WLROOTS_VERSION + run: git clone https://gitlab.freedesktop.org/wlroots/wlroots.git subprojects/wlroots -b 0.18 - name: Check for formatting changes run: | - meson --wrap-mode=nodownload build-clang-format -Dwlroots:xwayland=enabled + meson build-clang-format -Dwlroots:xwayland=enabled ninja -C build-clang-format clang-format-check scan-build: @@ -72,10 +69,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 libdisplay-info + 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 $WLROOTS_VERSION + run: git clone https://gitlab.freedesktop.org/wlroots/wlroots.git subprojects/wlroots -b 0.18 - name: Run scan-build run: | - meson --wrap-mode=nodownload build-scan-build -Dwlroots:xwayland=enabled + meson build-scan-build -Dwlroots:xwayland=enabled ninja -C build-scan-build scan-build diff --git a/README.md b/README.md index d285219..ec6ce78 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,6 @@ 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 ed1f518..0894f5d 100644 --- a/cage.1.scd +++ b/cage.1.scd @@ -6,7 +6,7 @@ cage - a Wayland kiosk compositor # SYNOPSIS -*cage* [options...] [--] [_application_...] +*cage* [-dhmrsv] [--] _application_ [application argument ...] # DESCRIPTION @@ -19,9 +19,6 @@ 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 9b7c510..26ab9ef 100644 --- a/cage.c +++ b/cage.c @@ -224,10 +224,9 @@ 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" @@ -242,14 +241,11 @@ static bool parse_args(struct cg_server *server, int argc, char *argv[]) { int c; - while ((c = getopt(argc, argv, "dDhm:sv")) != -1) { + while ((c = getopt(argc, argv, "dhm: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; @@ -272,26 +268,31 @@ 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 = {.log_level = WLR_INFO}; + struct cg_server server = {0}; 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; } - wlr_log_init(server.log_level, NULL); +#ifdef DEBUG + wlr_log_init(WLR_DEBUG, NULL); +#else + wlr_log_init(WLR_ERROR, NULL); +#endif /* Wayland requires XDG_RUNTIME_DIR to be set. */ if (!getenv("XDG_RUNTIME_DIR")) { @@ -416,7 +417,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, 5); + struct wlr_xdg_shell *xdg_shell = wlr_xdg_shell_create(server.wl_display, 4); if (!xdg_shell) { wlr_log(WLR_ERROR, "Unable to create the XDG shell interface"); ret = 1; @@ -454,7 +455,7 @@ main(int argc, char *argv[]) goto end; } - struct wlr_presentation *presentation = wlr_presentation_create(server.wl_display, server.backend, 2); + struct wlr_presentation *presentation = wlr_presentation_create(server.wl_display, server.backend); if (!presentation) { wlr_log(WLR_ERROR, "Unable to create the presentation interface"); ret = 1; @@ -587,7 +588,7 @@ main(int argc, char *argv[]) } #endif - if (optind < argc && !spawn_primary_client(&server, argv + optind, &pid, &sigchld_source)) { + if (!spawn_primary_client(&server, argv + optind, &pid, &sigchld_source)) { ret = 1; goto end; } @@ -596,28 +597,13 @@ 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: - if (pid != 0) - app_ret = cleanup_primary_client(pid); + app_ret = cleanup_primary_client(pid); if (!ret && server.return_app_code) ret = app_ret; @@ -630,8 +616,5 @@ 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 f8ccd76..7b58cd8 100644 --- a/meson.build +++ b/meson.build @@ -1,5 +1,5 @@ project('cage', 'c', - version: '0.2.1', + version: '0.2.0', license: 'MIT', meson_version: '>=0.58.1', default_options: [ @@ -35,7 +35,7 @@ if is_freebsd ) endif -wlroots = dependency('wlroots-0.19', 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') diff --git a/output.c b/output.c index 093836b..f1c0419 100644 --- a/output.c +++ b/output.c @@ -21,14 +21,13 @@ #if WLR_HAS_X11_BACKEND #include #endif -#include #include #include #include +#include #include #include #include -#include #include #include #include @@ -132,6 +131,31 @@ 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) { @@ -332,63 +356,17 @@ 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) { - bool ok = false; - - size_t states_len; - struct wlr_backend_output_state *states = wlr_output_configuration_v1_build_state(config, &states_len); - if (states == NULL) { - 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; - } - } - - 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); + if (!output_apply_config(output, head, test_only)) { + return false; } } -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; + return true; } void diff --git a/seat.c b/seat.c index 5f659a4..cdf8798 100644 --- a/seat.c +++ b/seat.c @@ -380,16 +380,6 @@ 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) { @@ -903,11 +893,6 @@ 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); @@ -937,7 +922,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_surface_override_redirect_wants_focus(xwayland_view->xwayland_surface)) { + if (!wlr_xwayland_or_surface_wants_focus(xwayland_view->xwayland_surface)) { return; } } diff --git a/server.h b/server.h index 00c2a61..f7d70d7 100644 --- a/server.h +++ b/server.h @@ -9,8 +9,6 @@ #include #include #include -#include - #if CAGE_HAS_XWAYLAND #include #endif @@ -65,7 +63,6 @@ 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 5493918..cae6c90 100644 --- a/xdg_shell.c +++ b/xdg_shell.c @@ -128,10 +128,11 @@ 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_xdg_surface *xdg_surface = xdg_shell_view->xdg_toplevel->base; + struct wlr_box geom; - *width_out = xdg_surface->geometry.width; - *height_out = xdg_surface->geometry.height; + wlr_xdg_surface_get_geometry(xdg_shell_view->xdg_toplevel->base, &geom); + *width_out = geom.width; + *height_out = geom.height; } static bool @@ -184,7 +185,7 @@ destroy(struct cg_view *view) } static void -handle_xdg_toplevel_request_fullscreen(struct wl_listener *listener, void *data) +handle_xdg_shell_surface_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); @@ -201,7 +202,7 @@ handle_xdg_toplevel_request_fullscreen(struct wl_listener *listener, void *data) } static void -handle_xdg_toplevel_unmap(struct wl_listener *listener, void *data) +handle_xdg_shell_surface_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; @@ -210,7 +211,7 @@ handle_xdg_toplevel_unmap(struct wl_listener *listener, void *data) } static void -handle_xdg_toplevel_map(struct wl_listener *listener, void *data) +handle_xdg_shell_surface_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; @@ -219,7 +220,7 @@ handle_xdg_toplevel_map(struct wl_listener *listener, void *data) } static void -handle_xdg_toplevel_commit(struct wl_listener *listener, void *data) +handle_xdg_shell_surface_commit(struct wl_listener *listener, void *data) { struct cg_xdg_shell_view *xdg_shell_view = wl_container_of(listener, xdg_shell_view, commit); @@ -227,15 +228,13 @@ handle_xdg_toplevel_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_toplevel_destroy(struct wl_listener *listener, void *data) +handle_xdg_shell_surface_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; @@ -275,15 +274,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_toplevel_commit; + xdg_shell_view->commit.notify = handle_xdg_shell_surface_commit; wl_signal_add(&toplevel->base->surface->events.commit, &xdg_shell_view->commit); - xdg_shell_view->map.notify = handle_xdg_toplevel_map; + xdg_shell_view->map.notify = handle_xdg_shell_surface_map; wl_signal_add(&toplevel->base->surface->events.map, &xdg_shell_view->map); - xdg_shell_view->unmap.notify = handle_xdg_toplevel_unmap; + xdg_shell_view->unmap.notify = handle_xdg_shell_surface_unmap; wl_signal_add(&toplevel->base->surface->events.unmap, &xdg_shell_view->unmap); - xdg_shell_view->destroy.notify = handle_xdg_toplevel_destroy; + xdg_shell_view->destroy.notify = handle_xdg_shell_surface_destroy; wl_signal_add(&toplevel->events.destroy, &xdg_shell_view->destroy); - xdg_shell_view->request_fullscreen.notify = handle_xdg_toplevel_request_fullscreen; + xdg_shell_view->request_fullscreen.notify = handle_xdg_shell_surface_request_fullscreen; wl_signal_add(&toplevel->events.request_fullscreen, &xdg_shell_view->request_fullscreen); toplevel->base->data = xdg_shell_view; @@ -295,7 +294,6 @@ 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); } @@ -309,14 +307,6 @@ 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) { @@ -361,9 +351,6 @@ 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 f819549..1fc000a 100644 --- a/xdg_shell.h +++ b/xdg_shell.h @@ -31,7 +31,6 @@ 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 3df7a08..de81408 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, true); + wlr_xwayland_surface_set_maximized(xwayland_view->xwayland_surface, true); } static void