diff options
author | Reza Jelveh <[email protected]> | 2024-04-15 13:39:41 +0800 |
---|---|---|
committer | GitHub <[email protected]> | 2024-04-15 01:39:41 -0400 |
commit | fb86ed6b0588dfdebfb66ce875bc63cfa0a897f6 (patch) | |
tree | 29857a1769107adc58696f08d379f608aa4e29a2 /sway/server.c | |
parent | a5e79676c4bd22fc5902182acf0667907202a465 (diff) |
feat: 1.9 merge (#277)
Co-authored-by: William McKinnon <[email protected]>
Co-authored-by: Erik Reider <[email protected]>
Diffstat (limited to 'sway/server.c')
-rw-r--r-- | sway/server.c | 139 |
1 files changed, 112 insertions, 27 deletions
diff --git a/sway/server.c b/sway/server.c index 262b7788..2b5b8d0f 100644 --- a/sway/server.c +++ b/sway/server.c @@ -1,5 +1,6 @@ #define _POSIX_C_SOURCE 200809L #include <assert.h> +#include <scenefx/render/fx_renderer/fx_renderer.h> #include <stdbool.h> #include <stdlib.h> #include <string.h> @@ -7,17 +8,17 @@ #include <wlr/backend.h> #include <wlr/backend/headless.h> #include <wlr/backend/multi.h> -#include <wlr/backend/session.h> #include <wlr/config.h> #include <wlr/render/gles2.h> #include <wlr/render/wlr_renderer.h> #include <wlr/types/wlr_compositor.h> +#include <wlr/types/wlr_content_type_v1.h> +#include <wlr/types/wlr_cursor_shape_v1.h> #include <wlr/types/wlr_data_control_v1.h> -#include <wlr/types/wlr_drm_lease_v1.h> #include <wlr/types/wlr_drm.h> #include <wlr/types/wlr_export_dmabuf_v1.h> +#include <wlr/types/wlr_fractional_scale_v1.h> #include <wlr/types/wlr_gamma_control_v1.h> -#include <wlr/types/wlr_idle.h> #include <wlr/types/wlr_idle_notify_v1.h> #include <wlr/types/wlr_layer_shell_v1.h> #include <wlr/types/wlr_linux_dmabuf_v1.h> @@ -25,8 +26,9 @@ #include <wlr/types/wlr_primary_selection_v1.h> #include <wlr/types/wlr_relative_pointer_v1.h> #include <wlr/types/wlr_screencopy_v1.h> -#include <wlr/types/wlr_single_pixel_buffer_v1.h> +#include <wlr/types/wlr_security_context_v1.h> #include <wlr/types/wlr_server_decoration.h> +#include <wlr/types/wlr_single_pixel_buffer_v1.h> #include <wlr/types/wlr_subcompositor.h> #include <wlr/types/wlr_tablet_v2.h> #include <wlr/types/wlr_viewporter.h> @@ -41,16 +43,26 @@ #include "list.h" #include "log.h" #include "sway/config.h" -#include "sway/desktop/fx_renderer/fx_renderer.h" #include "sway/desktop/idle_inhibit_v1.h" #include "sway/input/input-manager.h" #include "sway/output.h" #include "sway/server.h" +#include "sway/input/cursor.h" #include "sway/tree/root.h" + #if HAVE_XWAYLAND +#include <wlr/xwayland/shell.h> #include "sway/xwayland.h" #endif +#if WLR_HAS_DRM_BACKEND +#include <wlr/types/wlr_drm_lease_v1.h> +#endif + +#define SWAY_XDG_SHELL_VERSION 2 +#define SWAY_LAYER_SHELL_VERSION 4 + +#if WLR_HAS_DRM_BACKEND static void handle_drm_lease_request(struct wl_listener *listener, void *data) { /* We only offer non-desktop outputs, but in the future we might want to do * more logic here. */ @@ -62,15 +74,67 @@ static void handle_drm_lease_request(struct wl_listener *listener, void *data) { wlr_drm_lease_request_v1_reject(req); } } +#endif + +static bool is_privileged(const struct wl_global *global) { +#if WLR_HAS_DRM_BACKEND + if (server.drm_lease_manager != NULL) { + struct wlr_drm_lease_device_v1 *drm_lease_dev; + wl_list_for_each(drm_lease_dev, &server.drm_lease_manager->devices, link) { + if (drm_lease_dev->global == global) { + return true; + } + } + } +#endif + + return + global == server.output_manager_v1->global || + global == server.output_power_manager_v1->global || + global == server.input_method->global || + global == server.foreign_toplevel_manager->global || + global == server.data_control_manager_v1->global || + global == server.screencopy_manager_v1->global || + global == server.export_dmabuf_manager_v1->global || + global == server.security_context_manager_v1->global || + global == server.gamma_control_manager_v1->global || + global == server.layer_shell->global || + global == server.session_lock.manager->global || + global == server.input->inhibit->global || + global == server.input->keyboard_shortcuts_inhibit->global || + global == server.input->virtual_keyboard->global || + global == server.input->virtual_pointer->global; +} + +static bool filter_global(const struct wl_client *client, + const struct wl_global *global, void *data) { +#if HAVE_XWAYLAND + struct wlr_xwayland *xwayland = server.xwayland.wlr_xwayland; + if (xwayland && global == xwayland->shell_v1->global) { + return xwayland->server != NULL && client == xwayland->server->client; + } +#endif + + // Restrict usage of privileged protocols to unsandboxed clients + // TODO: add a way for users to configure an allow-list + const struct wlr_security_context_v1_state *security_context = + wlr_security_context_manager_v1_lookup_client( + server.security_context_manager_v1, (struct wl_client *)client); + if (is_privileged(global)) { + return security_context == NULL; + } -#define SWAY_XDG_SHELL_VERSION 2 + return true; +} bool server_init(struct sway_server *server) { sway_log(SWAY_DEBUG, "Initializing Wayland server"); server->wl_display = wl_display_create(); server->wl_event_loop = wl_display_get_event_loop(server->wl_display); - server->backend = wlr_backend_autocreate(server->wl_display); + wl_display_set_global_filter(server->wl_display, filter_global, NULL); + + server->backend = wlr_backend_autocreate(server->wl_display, &server->session); if (!server->backend) { sway_log(SWAY_ERROR, "Unable to create backend"); return false; @@ -81,29 +145,29 @@ bool server_init(struct sway_server *server) { return false; } - server->wlr_renderer = wlr_renderer_autocreate(server->backend); - if (!server->wlr_renderer) { - sway_log(SWAY_ERROR, "Failed to create wlr_renderer"); + server->renderer = fx_renderer_create(server->backend); + if (!server->renderer) { + sway_log(SWAY_ERROR, "Failed to create fx_renderer"); return false; } - wlr_renderer_init_wl_shm(server->wlr_renderer, server->wl_display); + wlr_renderer_init_wl_shm(server->renderer, server->wl_display); - if (wlr_renderer_get_dmabuf_texture_formats(server->wlr_renderer) != NULL) { - wlr_drm_create(server->wl_display, server->wlr_renderer); - server->linux_dmabuf_v1 = - wlr_linux_dmabuf_v1_create(server->wl_display, server->wlr_renderer); + if (wlr_renderer_get_dmabuf_texture_formats(server->renderer) != NULL) { + wlr_drm_create(server->wl_display, server->renderer); + server->linux_dmabuf_v1 = wlr_linux_dmabuf_v1_create_with_renderer( + server->wl_display, 4, server->renderer); } server->allocator = wlr_allocator_autocreate(server->backend, - server->wlr_renderer); + server->renderer); if (!server->allocator) { sway_log(SWAY_ERROR, "Failed to create allocator"); return false; } - server->compositor = wlr_compositor_create(server->wl_display, - server->wlr_renderer); + server->compositor = wlr_compositor_create(server->wl_display, 6, + server->renderer); server->compositor_new_surface.notify = handle_compositor_new_surface; wl_signal_add(&server->compositor->events.new_surface, &server->compositor_new_surface); @@ -113,7 +177,11 @@ bool server_init(struct sway_server *server) { server->data_device_manager = wlr_data_device_manager_create(server->wl_display); - wlr_gamma_control_manager_v1_create(server->wl_display); + server->gamma_control_manager_v1 = + wlr_gamma_control_manager_v1_create(server->wl_display); + server->gamma_control_set_gamma.notify = handle_gamma_control_set_gamma; + wl_signal_add(&server->gamma_control_manager_v1->events.set_gamma, + &server->gamma_control_set_gamma); server->new_output.notify = handle_new_output; wl_signal_add(&server->backend->events.new_output, &server->new_output); @@ -123,12 +191,11 @@ bool server_init(struct sway_server *server) { wlr_xdg_output_manager_v1_create(server->wl_display, root->output_layout); - server->idle = wlr_idle_create(server->wl_display); server->idle_notifier_v1 = wlr_idle_notifier_v1_create(server->wl_display); - server->idle_inhibit_manager_v1 = - sway_idle_inhibit_manager_v1_create(server->wl_display, server->idle); + sway_idle_inhibit_manager_v1_init(); - server->layer_shell = wlr_layer_shell_v1_create(server->wl_display); + server->layer_shell = wlr_layer_shell_v1_create(server->wl_display, + SWAY_LAYER_SHELL_VERSION); wl_signal_add(&server->layer_shell->events.new_surface, &server->layer_shell_surface); server->layer_shell_surface.notify = handle_layer_shell_surface; @@ -193,6 +260,7 @@ bool server_init(struct sway_server *server) { sway_session_lock_init(); +#if WLR_HAS_DRM_BACKEND server->drm_lease_manager= wlr_drm_lease_v1_manager_create(server->wl_display, server->backend); if (server->drm_lease_manager) { @@ -203,13 +271,17 @@ bool server_init(struct sway_server *server) { sway_log(SWAY_DEBUG, "Failed to create wlr_drm_lease_device_v1"); sway_log(SWAY_INFO, "VR will not be available"); } +#endif - wlr_export_dmabuf_manager_v1_create(server->wl_display); - wlr_screencopy_manager_v1_create(server->wl_display); - wlr_data_control_manager_v1_create(server->wl_display); - wlr_primary_selection_v1_device_manager_create(server->wl_display); + server->export_dmabuf_manager_v1 = wlr_export_dmabuf_manager_v1_create(server->wl_display); + server->screencopy_manager_v1 = wlr_screencopy_manager_v1_create(server->wl_display); + server->data_control_manager_v1 = wlr_data_control_manager_v1_create(server->wl_display); + server->security_context_manager_v1 = wlr_security_context_manager_v1_create(server->wl_display); wlr_viewporter_create(server->wl_display); wlr_single_pixel_buffer_manager_v1_create(server->wl_display); + server->content_type_manager_v1 = + wlr_content_type_manager_v1_create(server->wl_display, 1); + wlr_fractional_scale_manager_v1_create(server->wl_display, 1); struct wlr_xdg_foreign_registry *foreign_registry = wlr_xdg_foreign_registry_create(server->wl_display); @@ -221,6 +293,15 @@ bool server_init(struct sway_server *server) { xdg_activation_v1_handle_request_activate; wl_signal_add(&server->xdg_activation_v1->events.request_activate, &server->xdg_activation_v1_request_activate); + server->xdg_activation_v1_new_token.notify = + xdg_activation_v1_handle_new_token; + wl_signal_add(&server->xdg_activation_v1->events.new_token, + &server->xdg_activation_v1_new_token); + + struct wlr_cursor_shape_manager_v1 *cursor_shape_manager = + wlr_cursor_shape_manager_v1_create(server->wl_display, 1); + server->request_set_cursor_shape.notify = handle_request_set_cursor_shape; + wl_signal_add(&cursor_shape_manager->events.request_set_shape, &server->request_set_cursor_shape); wl_list_init(&server->pending_launcher_ctxs); @@ -303,6 +384,10 @@ bool server_start(struct sway_server *server) { } #endif + if (config->primary_selection) { + wlr_primary_selection_v1_device_manager_create(server->wl_display); + } + sway_log(SWAY_INFO, "Starting backend on wayland display '%s'", server->socket); if (!wlr_backend_start(server->backend)) { |