2018-03-30 00:47:57 -04:00
|
|
|
#include <assert.h>
|
2017-10-22 10:37:30 -04:00
|
|
|
#include <stdbool.h>
|
2018-03-30 00:47:57 -04:00
|
|
|
#include <stdlib.h>
|
2020-09-15 10:53:35 -04:00
|
|
|
#include <string.h>
|
2019-07-27 23:02:56 +03:00
|
|
|
#include <wayland-server-core.h>
|
2017-10-22 10:37:30 -04:00
|
|
|
#include <wlr/backend.h>
|
2020-04-14 15:04:56 +02:00
|
|
|
#include <wlr/backend/headless.h>
|
|
|
|
|
#include <wlr/backend/multi.h>
|
2021-01-25 19:24:21 -08:00
|
|
|
#include <wlr/config.h>
|
2024-02-15 12:01:24 +01:00
|
|
|
#include <wlr/render/allocator.h>
|
2018-03-19 23:31:18 +01:00
|
|
|
#include <wlr/render/wlr_renderer.h>
|
2024-09-29 16:57:52 +02:00
|
|
|
#include <wlr/types/wlr_alpha_modifier_v1.h>
|
2025-01-26 14:36:54 +01:00
|
|
|
#include <wlr/types/wlr_color_management_v1.h>
|
2025-11-13 21:21:09 +05:30
|
|
|
#include <wlr/types/wlr_color_representation_v1.h>
|
2017-11-22 21:06:08 -05:00
|
|
|
#include <wlr/types/wlr_compositor.h>
|
2022-10-04 09:46:47 +02:00
|
|
|
#include <wlr/types/wlr_content_type_v1.h>
|
2023-05-05 16:34:35 +02:00
|
|
|
#include <wlr/types/wlr_cursor_shape_v1.h>
|
2019-01-07 18:39:33 +01:00
|
|
|
#include <wlr/types/wlr_data_control_v1.h>
|
2025-03-09 02:08:43 +05:30
|
|
|
#include <wlr/types/wlr_ext_data_control_v1.h>
|
2024-02-15 12:01:24 +01:00
|
|
|
#include <wlr/types/wlr_data_device.h>
|
2018-07-01 22:55:25 +01:00
|
|
|
#include <wlr/types/wlr_export_dmabuf_v1.h>
|
2024-02-15 12:01:24 +01:00
|
|
|
#include <wlr/types/wlr_ext_foreign_toplevel_list_v1.h>
|
2025-07-25 04:30:42 +01:00
|
|
|
#include <wlr/types/wlr_fixes.h>
|
2024-05-15 15:54:40 -05:00
|
|
|
#include <wlr/types/wlr_fifo_v1.h>
|
2024-02-15 12:01:24 +01:00
|
|
|
#include <wlr/types/wlr_foreign_toplevel_management_v1.h>
|
2024-02-12 21:13:35 +01:00
|
|
|
#include <wlr/types/wlr_ext_image_capture_source_v1.h>
|
|
|
|
|
#include <wlr/types/wlr_ext_image_copy_capture_v1.h>
|
2023-02-10 18:07:26 +01:00
|
|
|
#include <wlr/types/wlr_fractional_scale_v1.h>
|
2019-01-26 00:45:06 +01:00
|
|
|
#include <wlr/types/wlr_gamma_control_v1.h>
|
2022-10-04 11:44:05 +02:00
|
|
|
#include <wlr/types/wlr_idle_notify_v1.h>
|
2018-09-14 19:21:44 +02:00
|
|
|
#include <wlr/types/wlr_layer_shell_v1.h>
|
2021-06-07 18:58:20 +02:00
|
|
|
#include <wlr/types/wlr_linux_dmabuf_v1.h>
|
2024-05-10 16:11:38 +02:00
|
|
|
#include <wlr/types/wlr_linux_drm_syncobj_v1.h>
|
2024-02-15 12:01:24 +01:00
|
|
|
#include <wlr/types/wlr_output_management_v1.h>
|
|
|
|
|
#include <wlr/types/wlr_output_power_management_v1.h>
|
2019-01-26 00:45:06 +01:00
|
|
|
#include <wlr/types/wlr_pointer_constraints_v1.h>
|
2024-02-15 12:01:24 +01:00
|
|
|
#include <wlr/types/wlr_presentation_time.h>
|
2019-02-20 11:16:05 +01:00
|
|
|
#include <wlr/types/wlr_primary_selection_v1.h>
|
|
|
|
|
#include <wlr/types/wlr_relative_pointer_v1.h>
|
2018-07-01 22:55:25 +01:00
|
|
|
#include <wlr/types/wlr_screencopy_v1.h>
|
2023-06-22 17:06:10 +02:00
|
|
|
#include <wlr/types/wlr_security_context_v1.h>
|
2018-04-07 13:21:07 -04:00
|
|
|
#include <wlr/types/wlr_server_decoration.h>
|
2024-02-15 12:01:24 +01:00
|
|
|
#include <wlr/types/wlr_session_lock_v1.h>
|
2023-06-22 17:06:10 +02:00
|
|
|
#include <wlr/types/wlr_single_pixel_buffer_v1.h>
|
2022-01-13 11:15:39 +01:00
|
|
|
#include <wlr/types/wlr_subcompositor.h>
|
2019-09-17 21:46:29 -07:00
|
|
|
#include <wlr/types/wlr_tablet_v2.h>
|
2020-04-27 16:41:54 +02:00
|
|
|
#include <wlr/types/wlr_viewporter.h>
|
2018-03-31 00:13:26 -04:00
|
|
|
#include <wlr/types/wlr_xcursor_manager.h>
|
2021-03-23 11:31:18 +01:00
|
|
|
#include <wlr/types/wlr_xdg_activation_v1.h>
|
2018-09-24 20:54:57 +10:00
|
|
|
#include <wlr/types/wlr_xdg_decoration_v1.h>
|
2021-01-25 19:24:21 -08:00
|
|
|
#include <wlr/types/wlr_xdg_foreign_registry.h>
|
|
|
|
|
#include <wlr/types/wlr_xdg_foreign_v1.h>
|
|
|
|
|
#include <wlr/types/wlr_xdg_foreign_v2.h>
|
2018-09-14 20:55:05 -04:00
|
|
|
#include <wlr/types/wlr_xdg_output_v1.h>
|
2025-07-10 16:44:48 +02:00
|
|
|
#include <wlr/types/wlr_xdg_toplevel_tag_v1.h>
|
2023-12-12 15:25:10 +01:00
|
|
|
#include <xf86drm.h>
|
2018-11-23 12:07:46 +01:00
|
|
|
#include "config.h"
|
2018-06-23 16:24:11 +10:00
|
|
|
#include "list.h"
|
2019-01-20 13:51:12 -05:00
|
|
|
#include "log.h"
|
2018-01-30 20:01:49 -05:00
|
|
|
#include "sway/config.h"
|
2018-07-02 09:26:57 +09:00
|
|
|
#include "sway/desktop/idle_inhibit_v1.h"
|
2017-12-08 08:07:47 -05:00
|
|
|
#include "sway/input/input-manager.h"
|
2019-01-17 20:16:23 +10:00
|
|
|
#include "sway/output.h"
|
2018-04-05 14:01:14 -04:00
|
|
|
#include "sway/server.h"
|
2023-05-05 16:34:35 +02:00
|
|
|
#include "sway/input/cursor.h"
|
2018-08-26 12:05:16 +10:00
|
|
|
#include "sway/tree/root.h"
|
2026-03-12 01:09:47 +01:00
|
|
|
#include "sway/tree/workspace.h"
|
2022-11-26 20:15:52 +01:00
|
|
|
|
2024-05-18 14:02:14 +02:00
|
|
|
#if WLR_HAS_XWAYLAND
|
2023-06-22 16:26:00 +02:00
|
|
|
#include <wlr/xwayland/shell.h>
|
2018-06-18 22:49:28 +01:00
|
|
|
#include "sway/xwayland.h"
|
2018-07-24 22:16:06 +02:00
|
|
|
#endif
|
2018-01-30 20:01:49 -05:00
|
|
|
|
2022-11-26 20:15:52 +01:00
|
|
|
#if WLR_HAS_DRM_BACKEND
|
|
|
|
|
#include <wlr/types/wlr_drm_lease_v1.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-02-27 15:10:09 +01:00
|
|
|
#define SWAY_XDG_SHELL_VERSION 5
|
2026-02-24 11:55:04 +01:00
|
|
|
#define SWAY_LAYER_SHELL_VERSION 5
|
2024-02-11 12:20:15 +01:00
|
|
|
#define SWAY_FOREIGN_TOPLEVEL_LIST_VERSION 1
|
2024-10-15 23:07:46 +05:30
|
|
|
#define SWAY_PRESENTATION_VERSION 2
|
2022-11-14 09:59:58 -05:00
|
|
|
|
2026-02-03 10:26:50 +00:00
|
|
|
bool unsupported_gpu_detected = false;
|
2023-12-12 15:25:10 +01:00
|
|
|
|
2022-11-26 20:15:52 +01:00
|
|
|
#if WLR_HAS_DRM_BACKEND
|
2019-06-27 13:55:34 -04:00
|
|
|
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. */
|
|
|
|
|
|
|
|
|
|
struct wlr_drm_lease_request_v1 *req = data;
|
|
|
|
|
struct wlr_drm_lease_v1 *lease = wlr_drm_lease_request_v1_grant(req);
|
|
|
|
|
if (!lease) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to grant lease request");
|
|
|
|
|
wlr_drm_lease_request_v1_reject(req);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-26 20:15:52 +01:00
|
|
|
#endif
|
2019-06-27 13:55:34 -04:00
|
|
|
|
2023-06-22 17:06:10 +02:00
|
|
|
static bool is_privileged(const struct wl_global *global) {
|
2024-01-04 15:01:26 +01:00
|
|
|
#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
|
|
|
|
|
|
2023-06-22 17:06:10 +02:00
|
|
|
return
|
|
|
|
|
global == server.output_manager_v1->global ||
|
|
|
|
|
global == server.output_power_manager_v1->global ||
|
|
|
|
|
global == server.input_method->global ||
|
2024-02-11 12:20:15 +01:00
|
|
|
global == server.foreign_toplevel_list->global ||
|
2023-06-22 17:06:10 +02:00
|
|
|
global == server.foreign_toplevel_manager->global ||
|
2025-03-09 02:08:43 +05:30
|
|
|
global == server.wlr_data_control_manager_v1->global ||
|
|
|
|
|
global == server.ext_data_control_manager_v1->global ||
|
2023-06-22 17:06:10 +02:00
|
|
|
global == server.screencopy_manager_v1->global ||
|
2024-02-12 21:13:35 +01:00
|
|
|
global == server.ext_image_copy_capture_manager_v1->global ||
|
2023-06-22 17:06:10 +02:00
|
|
|
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->keyboard_shortcuts_inhibit->global ||
|
|
|
|
|
global == server.input->virtual_keyboard->global ||
|
2020-02-08 18:17:42 +00:00
|
|
|
global == server.input->virtual_pointer->global ||
|
2024-05-24 23:49:32 +02:00
|
|
|
global == server.input->transient_seat_manager->global ||
|
|
|
|
|
global == server.xdg_output_manager_v1->global;
|
2023-06-22 17:06:10 +02:00
|
|
|
}
|
|
|
|
|
|
2023-06-22 16:26:00 +02:00
|
|
|
static bool filter_global(const struct wl_client *client,
|
|
|
|
|
const struct wl_global *global, void *data) {
|
2024-05-18 14:02:14 +02:00
|
|
|
#if WLR_HAS_XWAYLAND
|
2023-06-22 16:26:00 +02:00
|
|
|
struct wlr_xwayland *xwayland = server.xwayland.wlr_xwayland;
|
2023-09-09 17:02:55 -04:00
|
|
|
if (xwayland && global == xwayland->shell_v1->global) {
|
2023-06-22 16:26:00 +02:00
|
|
|
return xwayland->server != NULL && client == xwayland->server->client;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-06-22 17:06:10 +02:00
|
|
|
// 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;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 16:26:00 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-12 15:25:10 +01:00
|
|
|
static void detect_proprietary(struct wlr_backend *backend, void *data) {
|
|
|
|
|
int drm_fd = wlr_backend_get_drm_fd(backend);
|
|
|
|
|
if (drm_fd < 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
drmVersion *version = drmGetVersion(drm_fd);
|
|
|
|
|
if (version == NULL) {
|
|
|
|
|
sway_log(SWAY_ERROR, "drmGetVersion() failed");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (strcmp(version->name, "nvidia-drm") == 0) {
|
2026-02-03 10:26:50 +00:00
|
|
|
unsupported_gpu_detected = true;
|
2023-12-12 15:36:23 +01:00
|
|
|
sway_log(SWAY_ERROR, "!!! Proprietary Nvidia drivers are in use !!!");
|
2023-12-12 15:25:10 +01:00
|
|
|
}
|
|
|
|
|
|
2023-12-12 15:36:23 +01:00
|
|
|
if (strcmp(version->name, "evdi") == 0) {
|
2026-02-03 10:26:50 +00:00
|
|
|
unsupported_gpu_detected = true;
|
2023-12-12 15:36:23 +01:00
|
|
|
sway_log(SWAY_ERROR, "!!! Proprietary DisplayLink drivers are in use !!!");
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-12 15:25:10 +01:00
|
|
|
drmFreeVersion(version);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-21 18:35:36 +01:00
|
|
|
static void do_renderer_recreate(void *data) {
|
|
|
|
|
struct sway_server *server = data;
|
|
|
|
|
server->recreating_renderer = NULL;
|
2024-03-14 13:54:08 +01:00
|
|
|
|
|
|
|
|
sway_log(SWAY_INFO, "Re-creating renderer after GPU reset");
|
|
|
|
|
struct wlr_renderer *renderer = wlr_renderer_autocreate(server->backend);
|
|
|
|
|
if (renderer == NULL) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Unable to create renderer");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct wlr_allocator *allocator =
|
|
|
|
|
wlr_allocator_autocreate(server->backend, renderer);
|
|
|
|
|
if (allocator == NULL) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Unable to create allocator");
|
|
|
|
|
wlr_renderer_destroy(renderer);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct wlr_renderer *old_renderer = server->renderer;
|
|
|
|
|
struct wlr_allocator *old_allocator = server->allocator;
|
|
|
|
|
server->renderer = renderer;
|
|
|
|
|
server->allocator = allocator;
|
|
|
|
|
|
|
|
|
|
wl_list_remove(&server->renderer_lost.link);
|
|
|
|
|
wl_signal_add(&server->renderer->events.lost, &server->renderer_lost);
|
|
|
|
|
|
|
|
|
|
wlr_compositor_set_renderer(server->compositor, renderer);
|
|
|
|
|
|
2024-10-02 15:55:17 +02:00
|
|
|
struct sway_output *output;
|
|
|
|
|
wl_list_for_each(output, &root->all_outputs, link) {
|
2024-03-14 13:54:08 +01:00
|
|
|
wlr_output_init_render(output->wlr_output,
|
|
|
|
|
server->allocator, server->renderer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wlr_allocator_destroy(old_allocator);
|
|
|
|
|
wlr_renderer_destroy(old_renderer);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-21 18:35:36 +01:00
|
|
|
static void handle_renderer_lost(struct wl_listener *listener, void *data) {
|
|
|
|
|
struct sway_server *server = wl_container_of(listener, server, renderer_lost);
|
|
|
|
|
|
|
|
|
|
if (server->recreating_renderer != NULL) {
|
|
|
|
|
sway_log(SWAY_DEBUG, "Re-creation of renderer already scheduled");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sway_log(SWAY_INFO, "Scheduling re-creation of renderer after GPU reset");
|
|
|
|
|
server->recreating_renderer = wl_event_loop_add_idle(server->wl_event_loop, do_renderer_recreate, server);
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-25 19:38:05 +02:00
|
|
|
static void handle_new_foreign_toplevel_capture_request(struct wl_listener *listener, void *data) {
|
|
|
|
|
struct wlr_ext_foreign_toplevel_image_capture_source_manager_v1_request *request = data;
|
|
|
|
|
struct sway_view *view = request->toplevel_handle->data;
|
|
|
|
|
|
|
|
|
|
if (view->image_capture_source == NULL) {
|
|
|
|
|
view->image_capture_source = wlr_ext_image_capture_source_v1_create_with_scene_node(
|
|
|
|
|
&view->image_capture_scene->tree.node, server.wl_event_loop, server.allocator, server.renderer);
|
|
|
|
|
if (view->image_capture_source == NULL) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wlr_ext_foreign_toplevel_image_capture_source_manager_v1_request_accept(request, view->image_capture_source);
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-13 00:39:24 +02:00
|
|
|
bool server_init(struct sway_server *server) {
|
2019-01-20 13:51:12 -05:00
|
|
|
sway_log(SWAY_DEBUG, "Initializing Wayland server");
|
2022-06-01 20:01:19 +02:00
|
|
|
server->wl_display = wl_display_create();
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!server->wl_display) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create wl_display");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-06-01 20:01:19 +02:00
|
|
|
server->wl_event_loop = wl_display_get_event_loop(server->wl_display);
|
|
|
|
|
|
2023-06-22 16:26:00 +02:00
|
|
|
wl_display_set_global_filter(server->wl_display, filter_global, NULL);
|
2025-01-11 16:36:07 +01:00
|
|
|
wl_display_set_default_max_buffer_size(server->wl_display, 1024 * 1024);
|
2023-06-22 16:26:00 +02:00
|
|
|
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!wlr_fixes_create(server->wl_display, 1)) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create wp_fixes global");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-11-23 13:08:53 +01:00
|
|
|
root = root_create(server->wl_display);
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!root) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create root");
|
|
|
|
|
wl_display_destroy(server->wl_display);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-11-23 13:08:53 +01:00
|
|
|
|
2024-01-25 18:10:50 +03:00
|
|
|
server->backend = wlr_backend_autocreate(server->wl_event_loop, &server->session);
|
2022-06-01 20:01:19 +02:00
|
|
|
if (!server->backend) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Unable to create backend");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-06-13 00:39:24 +02:00
|
|
|
|
2023-12-12 15:25:10 +01:00
|
|
|
wlr_multi_for_each_backend(server->backend, detect_proprietary, NULL);
|
|
|
|
|
|
2021-11-15 13:32:52 -05:00
|
|
|
server->renderer = wlr_renderer_autocreate(server->backend);
|
|
|
|
|
if (!server->renderer) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create renderer");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-03-30 00:47:57 -04:00
|
|
|
|
2024-03-14 13:54:08 +01:00
|
|
|
server->renderer_lost.notify = handle_renderer_lost;
|
|
|
|
|
wl_signal_add(&server->renderer->events.lost, &server->renderer_lost);
|
|
|
|
|
|
2021-06-07 18:58:20 +02:00
|
|
|
wlr_renderer_init_wl_shm(server->renderer, server->wl_display);
|
|
|
|
|
|
2026-04-09 02:09:59 +02:00
|
|
|
if (wlr_renderer_get_drm_fd(server->renderer) >= 0 &&
|
|
|
|
|
wlr_renderer_get_texture_formats(server->renderer, WLR_BUFFER_CAP_DMABUF) != NULL) {
|
2022-11-30 17:14:07 +01:00
|
|
|
server->linux_dmabuf_v1 = wlr_linux_dmabuf_v1_create_with_renderer(
|
2026-02-24 11:40:00 +01:00
|
|
|
server->wl_display, 5, server->renderer);
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!server->linux_dmabuf_v1) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create linux-dmabuf v1");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2024-01-20 10:57:01 +01:00
|
|
|
}
|
2024-05-10 16:11:38 +02:00
|
|
|
if (wlr_renderer_get_drm_fd(server->renderer) >= 0 &&
|
2024-10-10 16:32:59 +02:00
|
|
|
server->renderer->features.timeline &&
|
|
|
|
|
server->backend->features.timeline) {
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!wlr_linux_drm_syncobj_manager_v1_create(server->wl_display, 1,
|
|
|
|
|
wlr_renderer_get_drm_fd(server->renderer))) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create linux-drm-syncobj v1");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2024-05-10 16:11:38 +02:00
|
|
|
}
|
2017-10-22 10:37:30 -04:00
|
|
|
|
2021-11-15 13:32:52 -05:00
|
|
|
server->allocator = wlr_allocator_autocreate(server->backend,
|
|
|
|
|
server->renderer);
|
|
|
|
|
if (!server->allocator) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create allocator");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-08 15:28:20 +01:00
|
|
|
server->compositor = wlr_compositor_create(server->wl_display, 6,
|
2021-11-15 13:32:52 -05:00
|
|
|
server->renderer);
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!server->compositor) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create compositor");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-10-09 16:06:30 +03:00
|
|
|
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!wlr_subcompositor_create(server->wl_display)) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create subcompositor");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-01-13 11:15:39 +01:00
|
|
|
|
2017-10-22 10:37:30 -04:00
|
|
|
server->data_device_manager =
|
|
|
|
|
wlr_data_device_manager_create(server->wl_display);
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!server->data_device_manager) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create data device manager");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-03-29 18:07:03 -04:00
|
|
|
|
2023-03-06 17:17:05 +01:00
|
|
|
server->gamma_control_manager_v1 =
|
|
|
|
|
wlr_gamma_control_manager_v1_create(server->wl_display);
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!server->gamma_control_manager_v1) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create gamma control manager");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2024-08-14 13:42:53 -04:00
|
|
|
wlr_scene_set_gamma_control_manager_v1(root->root_scene,
|
|
|
|
|
server->gamma_control_manager_v1);
|
2017-10-22 10:37:30 -04:00
|
|
|
|
2018-02-14 14:51:51 -05:00
|
|
|
server->new_output.notify = handle_new_output;
|
|
|
|
|
wl_signal_add(&server->backend->events.new_output, &server->new_output);
|
2017-11-11 14:41:18 -05:00
|
|
|
|
2024-05-24 23:49:32 +02:00
|
|
|
server->xdg_output_manager_v1 =
|
|
|
|
|
wlr_xdg_output_manager_v1_create(server->wl_display, root->output_layout);
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!server->xdg_output_manager_v1) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create XDG output manager");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-04-05 14:01:14 -04:00
|
|
|
|
2022-10-04 11:44:05 +02:00
|
|
|
server->idle_notifier_v1 = wlr_idle_notifier_v1_create(server->wl_display);
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!server->idle_notifier_v1) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create idle notifier");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!sway_idle_inhibit_manager_v1_init()) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to init idle inhibit manager");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-06-27 18:16:49 +09:00
|
|
|
|
2022-11-14 09:59:58 -05:00
|
|
|
server->layer_shell = wlr_layer_shell_v1_create(server->wl_display,
|
|
|
|
|
SWAY_LAYER_SHELL_VERSION);
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!server->layer_shell) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create layer shell");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-03-28 15:47:22 -04:00
|
|
|
wl_signal_add(&server->layer_shell->events.new_surface,
|
|
|
|
|
&server->layer_shell_surface);
|
|
|
|
|
server->layer_shell_surface.notify = handle_layer_shell_surface;
|
|
|
|
|
|
2022-05-16 13:53:36 +02:00
|
|
|
server->xdg_shell = wlr_xdg_shell_create(server->wl_display,
|
|
|
|
|
SWAY_XDG_SHELL_VERSION);
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!server->xdg_shell) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create XDG shell");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-07-11 15:09:14 +03:00
|
|
|
wl_signal_add(&server->xdg_shell->events.new_toplevel,
|
|
|
|
|
&server->xdg_shell_toplevel);
|
|
|
|
|
server->xdg_shell_toplevel.notify = handle_xdg_shell_toplevel;
|
2018-03-31 09:21:15 -04:00
|
|
|
|
2019-09-17 21:46:29 -07:00
|
|
|
server->tablet_v2 = wlr_tablet_v2_create(server->wl_display);
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!server->tablet_v2) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create tablet manager");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-09-17 21:46:29 -07:00
|
|
|
|
2018-07-13 21:53:56 +01:00
|
|
|
server->server_decoration_manager =
|
2018-04-07 13:21:07 -04:00
|
|
|
wlr_server_decoration_manager_create(server->wl_display);
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!server->server_decoration_manager) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create server decoration manager");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-04-07 13:21:07 -04:00
|
|
|
wlr_server_decoration_manager_set_default_mode(
|
2018-07-13 21:53:56 +01:00
|
|
|
server->server_decoration_manager,
|
|
|
|
|
WLR_SERVER_DECORATION_MANAGER_MODE_SERVER);
|
|
|
|
|
wl_signal_add(&server->server_decoration_manager->events.new_decoration,
|
|
|
|
|
&server->server_decoration);
|
|
|
|
|
server->server_decoration.notify = handle_server_decoration;
|
2018-07-29 18:31:10 +01:00
|
|
|
wl_list_init(&server->decorations);
|
2018-04-07 13:21:07 -04:00
|
|
|
|
2018-09-24 20:54:57 +10:00
|
|
|
server->xdg_decoration_manager =
|
|
|
|
|
wlr_xdg_decoration_manager_v1_create(server->wl_display);
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!server->xdg_decoration_manager) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create XDG decoration manager");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-09-24 20:54:57 +10:00
|
|
|
wl_signal_add(
|
|
|
|
|
&server->xdg_decoration_manager->events.new_toplevel_decoration,
|
|
|
|
|
&server->xdg_decoration);
|
|
|
|
|
server->xdg_decoration.notify = handle_xdg_decoration;
|
|
|
|
|
wl_list_init(&server->xdg_decorations);
|
|
|
|
|
|
2019-01-29 20:52:59 +01:00
|
|
|
server->relative_pointer_manager =
|
|
|
|
|
wlr_relative_pointer_manager_v1_create(server->wl_display);
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!server->relative_pointer_manager) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create relative pointer manager");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-01-29 20:52:59 +01:00
|
|
|
|
2019-01-26 00:45:06 +01:00
|
|
|
server->pointer_constraints =
|
|
|
|
|
wlr_pointer_constraints_v1_create(server->wl_display);
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!server->pointer_constraints) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create pointer constraints");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-01-26 00:45:06 +01:00
|
|
|
server->pointer_constraint.notify = handle_pointer_constraint;
|
|
|
|
|
wl_signal_add(&server->pointer_constraints->events.new_constraint,
|
|
|
|
|
&server->pointer_constraint);
|
|
|
|
|
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!wlr_presentation_create(server->wl_display, server->backend, SWAY_PRESENTATION_VERSION)) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create presentation");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!wlr_alpha_modifier_v1_create(server->wl_display)) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create alpha modifier");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-10-23 23:38:57 +02:00
|
|
|
|
2019-05-20 23:47:05 +02:00
|
|
|
server->output_manager_v1 =
|
|
|
|
|
wlr_output_manager_v1_create(server->wl_display);
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!server->output_manager_v1) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create output manager");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-05-20 23:47:05 +02:00
|
|
|
server->output_manager_apply.notify = handle_output_manager_apply;
|
|
|
|
|
wl_signal_add(&server->output_manager_v1->events.apply,
|
|
|
|
|
&server->output_manager_apply);
|
|
|
|
|
server->output_manager_test.notify = handle_output_manager_test;
|
|
|
|
|
wl_signal_add(&server->output_manager_v1->events.test,
|
|
|
|
|
&server->output_manager_test);
|
|
|
|
|
|
2020-01-27 18:39:29 +01:00
|
|
|
server->output_power_manager_v1 =
|
|
|
|
|
wlr_output_power_manager_v1_create(server->wl_display);
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!server->output_power_manager_v1) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create output power manager");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-01-27 18:39:29 +01:00
|
|
|
server->output_power_manager_set_mode.notify =
|
|
|
|
|
handle_output_power_manager_set_mode;
|
|
|
|
|
wl_signal_add(&server->output_power_manager_v1->events.set_mode,
|
|
|
|
|
&server->output_power_manager_set_mode);
|
2019-10-18 18:57:17 +08:00
|
|
|
server->input_method = wlr_input_method_manager_v2_create(server->wl_display);
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!server->input_method) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create input method manager");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-10-18 18:57:17 +08:00
|
|
|
server->text_input = wlr_text_input_manager_v3_create(server->wl_display);
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!server->text_input) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create text input manager");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2024-02-11 12:20:15 +01:00
|
|
|
server->foreign_toplevel_list =
|
|
|
|
|
wlr_ext_foreign_toplevel_list_v1_create(server->wl_display, SWAY_FOREIGN_TOPLEVEL_LIST_VERSION);
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!server->foreign_toplevel_list) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create foreign toplevel list");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-08-20 18:30:09 +09:00
|
|
|
server->foreign_toplevel_manager =
|
|
|
|
|
wlr_foreign_toplevel_manager_v1_create(server->wl_display);
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!server->foreign_toplevel_manager) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create foreign toplevel manager");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-01-27 18:39:29 +01:00
|
|
|
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!sway_session_lock_init()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!sway_ext_workspace_init()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-03-08 21:14:26 -05:00
|
|
|
|
2022-11-26 20:15:52 +01:00
|
|
|
#if WLR_HAS_DRM_BACKEND
|
2019-06-27 13:55:34 -04:00
|
|
|
server->drm_lease_manager=
|
|
|
|
|
wlr_drm_lease_v1_manager_create(server->wl_display, server->backend);
|
|
|
|
|
if (server->drm_lease_manager) {
|
|
|
|
|
server->drm_lease_request.notify = handle_drm_lease_request;
|
|
|
|
|
wl_signal_add(&server->drm_lease_manager->events.request,
|
|
|
|
|
&server->drm_lease_request);
|
|
|
|
|
} else {
|
|
|
|
|
sway_log(SWAY_DEBUG, "Failed to create wlr_drm_lease_device_v1");
|
|
|
|
|
sway_log(SWAY_INFO, "VR will not be available");
|
|
|
|
|
}
|
2022-11-26 20:15:52 +01:00
|
|
|
#endif
|
2019-06-27 13:55:34 -04:00
|
|
|
|
2023-06-22 17:06:10 +02:00
|
|
|
server->export_dmabuf_manager_v1 = wlr_export_dmabuf_manager_v1_create(server->wl_display);
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!server->export_dmabuf_manager_v1) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create export dmabuf manager");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-06-22 17:06:10 +02:00
|
|
|
server->screencopy_manager_v1 = wlr_screencopy_manager_v1_create(server->wl_display);
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!server->screencopy_manager_v1) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create screencopy manager");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2024-02-12 21:13:35 +01:00
|
|
|
server->ext_image_copy_capture_manager_v1 = wlr_ext_image_copy_capture_manager_v1_create(server->wl_display, 1);
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!server->ext_image_copy_capture_manager_v1) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create ext image copy capture manager");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!wlr_ext_output_image_capture_source_manager_v1_create(server->wl_display, 1)) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create ext output image capture source manager");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2025-03-09 02:08:43 +05:30
|
|
|
server->wlr_data_control_manager_v1 = wlr_data_control_manager_v1_create(server->wl_display);
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!server->wlr_data_control_manager_v1) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create data control manager");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2025-03-09 02:08:43 +05:30
|
|
|
server->ext_data_control_manager_v1 = wlr_ext_data_control_manager_v1_create(server->wl_display, 1);
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!server->ext_data_control_manager_v1) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create ext data control manager");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-06-22 17:06:10 +02:00
|
|
|
server->security_context_manager_v1 = wlr_security_context_manager_v1_create(server->wl_display);
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!server->security_context_manager_v1) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create security context manager");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!wlr_viewporter_create(server->wl_display)) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create viewporter");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!wlr_single_pixel_buffer_manager_v1_create(server->wl_display)) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create single pixel buffer manager");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-10-04 09:46:47 +02:00
|
|
|
server->content_type_manager_v1 =
|
|
|
|
|
wlr_content_type_manager_v1_create(server->wl_display, 1);
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!server->content_type_manager_v1) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create content type manager");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!wlr_fractional_scale_manager_v1_create(server->wl_display, 1)) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create fractional scale manager");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2024-08-07 15:26:49 +03:00
|
|
|
|
2025-05-25 19:38:05 +02:00
|
|
|
server->ext_foreign_toplevel_image_capture_source_manager_v1 =
|
|
|
|
|
wlr_ext_foreign_toplevel_image_capture_source_manager_v1_create(server->wl_display, 1);
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!server->ext_foreign_toplevel_image_capture_source_manager_v1) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create ext foreign toplevel image capture source manager");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2025-05-25 19:38:05 +02:00
|
|
|
server->new_foreign_toplevel_capture_request.notify = handle_new_foreign_toplevel_capture_request;
|
|
|
|
|
wl_signal_add(&server->ext_foreign_toplevel_image_capture_source_manager_v1->events.new_request,
|
|
|
|
|
&server->new_foreign_toplevel_capture_request);
|
|
|
|
|
|
2024-08-07 15:26:49 +03:00
|
|
|
server->tearing_control_v1 =
|
2024-08-05 02:13:49 +02:00
|
|
|
wlr_tearing_control_manager_v1_create(server->wl_display, 1);
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!server->tearing_control_v1) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create tearing control manager");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2024-08-05 02:13:49 +02:00
|
|
|
server->tearing_control_new_object.notify = handle_new_tearing_hint;
|
|
|
|
|
wl_signal_add(&server->tearing_control_v1->events.new_object,
|
|
|
|
|
&server->tearing_control_new_object);
|
|
|
|
|
wl_list_init(&server->tearing_controllers);
|
2017-12-03 14:21:26 -05:00
|
|
|
|
2021-01-25 19:24:21 -08:00
|
|
|
struct wlr_xdg_foreign_registry *foreign_registry =
|
|
|
|
|
wlr_xdg_foreign_registry_create(server->wl_display);
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!foreign_registry) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create XDG foreign registry");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!wlr_xdg_foreign_v1_create(server->wl_display, foreign_registry)) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create XDG foreign v1");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!wlr_xdg_foreign_v2_create(server->wl_display, foreign_registry)) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create XDG foreign v2");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-01-25 19:24:21 -08:00
|
|
|
|
2021-03-23 11:31:18 +01:00
|
|
|
server->xdg_activation_v1 = wlr_xdg_activation_v1_create(server->wl_display);
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!server->xdg_activation_v1) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create XDG activation");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-03-23 11:31:18 +01:00
|
|
|
server->xdg_activation_v1_request_activate.notify =
|
|
|
|
|
xdg_activation_v1_handle_request_activate;
|
|
|
|
|
wl_signal_add(&server->xdg_activation_v1->events.request_activate,
|
|
|
|
|
&server->xdg_activation_v1_request_activate);
|
2022-11-30 11:54:50 -07:00
|
|
|
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);
|
2023-05-05 16:34:35 +02:00
|
|
|
|
2025-07-10 16:44:48 +02:00
|
|
|
struct wlr_xdg_toplevel_tag_manager_v1 *xdg_toplevel_tag_manager_v1 =
|
|
|
|
|
wlr_xdg_toplevel_tag_manager_v1_create(server->wl_display, 1);
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!xdg_toplevel_tag_manager_v1) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create XDG toplevel tag manager");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2025-07-10 16:44:48 +02:00
|
|
|
server->xdg_toplevel_tag_manager_v1_set_tag.notify =
|
|
|
|
|
xdg_toplevel_tag_manager_v1_handle_set_tag;
|
|
|
|
|
wl_signal_add(&xdg_toplevel_tag_manager_v1->events.set_tag,
|
|
|
|
|
&server->xdg_toplevel_tag_manager_v1_set_tag);
|
|
|
|
|
|
2023-05-05 16:34:35 +02:00
|
|
|
struct wlr_cursor_shape_manager_v1 *cursor_shape_manager =
|
2026-02-24 11:34:01 +01:00
|
|
|
wlr_cursor_shape_manager_v1_create(server->wl_display, 2);
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!cursor_shape_manager) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create cursor shape manager");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-05-05 16:34:35 +02:00
|
|
|
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);
|
2021-03-23 11:31:18 +01:00
|
|
|
|
2025-01-26 14:36:54 +01:00
|
|
|
if (server->renderer->features.input_color_transform) {
|
|
|
|
|
const enum wp_color_manager_v1_render_intent render_intents[] = {
|
|
|
|
|
WP_COLOR_MANAGER_V1_RENDER_INTENT_PERCEPTUAL,
|
|
|
|
|
};
|
2025-10-04 11:54:31 +02:00
|
|
|
size_t transfer_functions_len = 0;
|
|
|
|
|
enum wp_color_manager_v1_transfer_function *transfer_functions =
|
|
|
|
|
wlr_color_manager_v1_transfer_function_list_from_renderer(server->renderer, &transfer_functions_len);
|
|
|
|
|
size_t primaries_len = 0;
|
|
|
|
|
enum wp_color_manager_v1_primaries *primaries =
|
|
|
|
|
wlr_color_manager_v1_primaries_list_from_renderer(server->renderer, &primaries_len);
|
2025-09-21 06:44:24 +05:30
|
|
|
struct wlr_color_manager_v1 *cm = wlr_color_manager_v1_create(
|
2026-01-29 04:44:02 +05:30
|
|
|
server->wl_display, 2, &(struct wlr_color_manager_v1_options){
|
2025-01-26 14:36:54 +01:00
|
|
|
.features = {
|
|
|
|
|
.parametric = true,
|
|
|
|
|
.set_mastering_display_primaries = true,
|
|
|
|
|
},
|
|
|
|
|
.render_intents = render_intents,
|
|
|
|
|
.render_intents_len = sizeof(render_intents) / sizeof(render_intents[0]),
|
|
|
|
|
.transfer_functions = transfer_functions,
|
2025-10-04 11:54:31 +02:00
|
|
|
.transfer_functions_len = transfer_functions_len,
|
2025-01-26 14:36:54 +01:00
|
|
|
.primaries = primaries,
|
2025-10-04 11:54:31 +02:00
|
|
|
.primaries_len = primaries_len,
|
2025-01-26 14:36:54 +01:00
|
|
|
});
|
2025-10-04 11:54:31 +02:00
|
|
|
free(transfer_functions);
|
|
|
|
|
free(primaries);
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!cm) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create color manager");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2025-09-21 06:44:24 +05:30
|
|
|
wlr_scene_set_color_manager_v1(root->root_scene, cm);
|
2025-01-26 14:36:54 +01:00
|
|
|
}
|
|
|
|
|
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!wlr_color_representation_manager_v1_create_with_renderer(
|
|
|
|
|
server->wl_display, 1, server->renderer)) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create color representation manager");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2025-11-13 21:21:09 +05:30
|
|
|
|
2022-11-16 15:50:34 -07:00
|
|
|
wl_list_init(&server->pending_launcher_ctxs);
|
|
|
|
|
|
2024-05-15 15:54:40 -05:00
|
|
|
server->fifo_manager_v1 = wlr_fifo_manager_v1_create(server->wl_display, 1);
|
|
|
|
|
wlr_scene_set_fifo_manager_v1(root->root_scene, server->fifo_manager_v1);
|
|
|
|
|
|
2020-09-15 10:53:35 -04:00
|
|
|
// Avoid using "wayland-0" as display socket
|
|
|
|
|
char name_candidate[16];
|
Avoid format-truncation warning
The existing code gives this error when compiled with GCC 12:
../sway/server.c: In function ‘server_init’:
../sway/server.c:217:75: error: ‘%d’ directive output may be truncated writing between 1 and 11 bytes into a region of size 8 [-Werror=format-truncation=]
217 | snprintf(name_candidate, sizeof(name_candidate), "wayland-%d", i);
| ^~
../sway/server.c:217:66: note: directive argument in the range [-2147483647, 32]
217 | snprintf(name_candidate, sizeof(name_candidate), "wayland-%d", i);
| ^~~~~~~~~~~~
../sway/server.c:217:17: note: ‘snprintf’ output between 10 and 20 bytes into a destination of size 16
217 | snprintf(name_candidate, sizeof(name_candidate), "wayland-%d", i);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Because i is never negative, this is a false positive, but it is easy to
change i to unsigned to silence the error.
2022-04-09 12:03:52 -04:00
|
|
|
for (unsigned int i = 1; i <= 32; ++i) {
|
|
|
|
|
snprintf(name_candidate, sizeof(name_candidate), "wayland-%u", i);
|
2020-09-15 10:53:35 -04:00
|
|
|
if (wl_display_add_socket(server->wl_display, name_candidate) >= 0) {
|
|
|
|
|
server->socket = strdup(name_candidate);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-31 14:32:28 -07:00
|
|
|
if (!server->socket) {
|
2019-01-20 13:51:12 -05:00
|
|
|
sway_log(SWAY_ERROR, "Unable to open wayland socket");
|
2017-10-22 10:37:30 -04:00
|
|
|
wlr_backend_destroy(server->backend);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2017-12-06 08:28:46 -05:00
|
|
|
|
2024-01-25 18:10:50 +03:00
|
|
|
server->headless_backend = wlr_headless_backend_create(server->wl_event_loop);
|
2020-12-08 16:15:03 +01:00
|
|
|
if (!server->headless_backend) {
|
2021-11-25 16:20:54 +01:00
|
|
|
sway_log(SWAY_ERROR, "Failed to create secondary headless backend");
|
|
|
|
|
wlr_backend_destroy(server->backend);
|
|
|
|
|
return false;
|
2020-12-08 16:15:03 +01:00
|
|
|
} else {
|
|
|
|
|
wlr_multi_backend_add(server->backend, server->headless_backend);
|
|
|
|
|
}
|
2020-04-14 15:04:56 +02:00
|
|
|
|
2021-10-04 10:04:46 -04:00
|
|
|
struct wlr_output *wlr_output =
|
|
|
|
|
wlr_headless_add_output(server->headless_backend, 800, 600);
|
2021-12-09 15:55:58 +01:00
|
|
|
wlr_output_set_name(wlr_output, "FALLBACK");
|
2021-10-04 10:04:46 -04:00
|
|
|
root->fallback_output = output_create(wlr_output);
|
|
|
|
|
|
2018-08-18 16:58:50 +10:00
|
|
|
// This may have been set already via -Dtxn-timeout
|
|
|
|
|
if (!server->txn_timeout_ms) {
|
|
|
|
|
server->txn_timeout_ms = 200;
|
2018-06-25 09:09:43 +10:00
|
|
|
}
|
2018-08-18 16:58:50 +10:00
|
|
|
|
Implement type safe arguments and demote sway_container
This commit changes the meaning of sway_container so that it only refers
to layout containers and view containers. Workspaces, outputs and the
root are no longer known as containers. Instead, root, outputs,
workspaces and containers are all a type of node, and containers come in
two types: layout containers and view containers.
In addition to the above, this implements type safe variables. This
means we use specific types such as sway_output and sway_workspace
instead of generic containers or nodes. However, it's worth noting that
in a few places places (eg. seat focus and transactions) referring to
them in a generic way is unavoidable which is why we still use nodes in
some places.
If you want a TL;DR, look at node.h, as well as the struct definitions
for root, output, workspace and container. Note that sway_output now
contains a workspaces list, and workspaces now contain a tiling and
floating list, and containers now contain a pointer back to the
workspace.
There are now functions for seat_get_focused_workspace and
seat_get_focused_container. The latter will return NULL if a workspace
itself is focused. Most other seat functions like seat_get_focus and
seat_set_focus now accept and return nodes.
In the config->handler_context struct, current_container has been
replaced with three pointers: node, container and workspace. node is the
same as what current_container was, while workspace is the workspace
that the node resides on and container is the actual container, which
may be NULL if a workspace itself is focused.
The global root_container variable has been replaced with one simply
called root, which is a pointer to the sway_root instance.
The way outputs are created, enabled, disabled and destroyed has
changed. Previously we'd wrap the sway_output in a container when it is
enabled, but as we don't have containers any more it needs a different
approach. The output_create and output_destroy functions previously
created/destroyed the container, but now they create/destroy the
sway_output. There is a new function output_disable to disable an output
without destroying it.
Containers have a new view property. If this is populated then the
container is a view container, otherwise it's a layout container. Like
before, this property is immutable for the life of the container.
Containers have both a `sway_container *parent` and
`sway_workspace *workspace`. As we use specific types now, parent cannot
point to a workspace so it'll be NULL for containers which are direct
children of the workspace. The workspace property is set for all
containers, except those which are hidden in the scratchpad as they have
no workspace.
In some cases we need to refer to workspaces in a container-like way.
For example, workspaces have layout and children, but when using
specific types this makes it difficult. Likewise, it's difficult for a
container to get its parent's layout when the parent could be another
container or a workspace. To make it easier, some helper functions have
been created: container_parent_layout and container_get_siblings.
container_remove_child has been renamed to container_detach and
container_replace_child has been renamed to container_replace.
`container_handle_fullscreen_reparent(con, old_parent)` has had the
old_parent removed. We now unfullscreen the workspace when detaching the
container, so this function is simplified and only needs one argument
now.
container_notify_subtree_changed has been renamed to
container_update_representation. This is more descriptive of its
purpose. I also wanted to be able to call it with whatever container was
changed rather than the container's parent, which makes bubbling up to
the workspace easier.
There are now state structs per node thing. ie. sway_output_state,
sway_workspace_state and sway_container_state.
The focus, move and layout commands have been completely refactored to
work with the specific types. I considered making these a separate PR,
but I'd be backporting my changes only to replace them again, and it's
easier just to test everything at once.
2018-08-30 21:00:10 +10:00
|
|
|
server->dirty_nodes = create_list();
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!server->dirty_nodes) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create dirty nodes list");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-06-27 19:07:48 +10:00
|
|
|
|
2018-10-18 21:20:00 +10:00
|
|
|
server->input = input_manager_create(server);
|
2026-04-09 02:09:59 +02:00
|
|
|
if (!server->input) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to create input manager");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-10-18 21:20:00 +10:00
|
|
|
input_manager_get_default_seat(); // create seat0
|
|
|
|
|
|
2017-10-22 10:37:30 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void server_fini(struct sway_server *server) {
|
2025-02-18 01:51:49 +01:00
|
|
|
// remove listeners
|
|
|
|
|
wl_list_remove(&server->renderer_lost.link);
|
|
|
|
|
wl_list_remove(&server->new_output.link);
|
|
|
|
|
wl_list_remove(&server->layer_shell_surface.link);
|
|
|
|
|
wl_list_remove(&server->xdg_shell_toplevel.link);
|
|
|
|
|
wl_list_remove(&server->server_decoration.link);
|
|
|
|
|
wl_list_remove(&server->xdg_decoration.link);
|
|
|
|
|
wl_list_remove(&server->pointer_constraint.link);
|
|
|
|
|
wl_list_remove(&server->output_manager_apply.link);
|
|
|
|
|
wl_list_remove(&server->output_manager_test.link);
|
|
|
|
|
wl_list_remove(&server->output_power_manager_set_mode.link);
|
|
|
|
|
#if WLR_HAS_DRM_BACKEND
|
2025-04-14 08:57:40 +02:00
|
|
|
if (server->drm_lease_manager) {
|
|
|
|
|
wl_list_remove(&server->drm_lease_request.link);
|
|
|
|
|
}
|
2025-02-18 01:51:49 +01:00
|
|
|
#endif
|
|
|
|
|
wl_list_remove(&server->tearing_control_new_object.link);
|
|
|
|
|
wl_list_remove(&server->xdg_activation_v1_request_activate.link);
|
|
|
|
|
wl_list_remove(&server->xdg_activation_v1_new_token.link);
|
2025-07-10 16:44:48 +02:00
|
|
|
wl_list_remove(&server->xdg_toplevel_tag_manager_v1_set_tag.link);
|
2025-02-18 01:51:49 +01:00
|
|
|
wl_list_remove(&server->request_set_cursor_shape.link);
|
2025-05-25 19:38:05 +02:00
|
|
|
wl_list_remove(&server->new_foreign_toplevel_capture_request.link);
|
2026-03-12 01:09:47 +01:00
|
|
|
wl_list_remove(&server->workspace_manager_v1_commit.link);
|
2025-02-18 01:52:25 +01:00
|
|
|
input_manager_finish(server->input);
|
2025-02-18 01:51:49 +01:00
|
|
|
|
2018-04-17 23:15:11 +01:00
|
|
|
// TODO: free sway-specific resources
|
2024-05-18 14:02:14 +02:00
|
|
|
#if WLR_HAS_XWAYLAND
|
2025-04-14 09:29:45 +02:00
|
|
|
if (server->xwayland.wlr_xwayland != NULL) {
|
|
|
|
|
wl_list_remove(&server->xwayland_surface.link);
|
|
|
|
|
wl_list_remove(&server->xwayland_ready.link);
|
|
|
|
|
wlr_xwayland_destroy(server->xwayland.wlr_xwayland);
|
|
|
|
|
}
|
2018-08-30 10:05:04 +02:00
|
|
|
#endif
|
|
|
|
|
wl_display_destroy_clients(server->wl_display);
|
2024-03-04 13:51:27 +01:00
|
|
|
wlr_backend_destroy(server->backend);
|
2018-04-17 23:15:11 +01:00
|
|
|
wl_display_destroy(server->wl_display);
|
Implement type safe arguments and demote sway_container
This commit changes the meaning of sway_container so that it only refers
to layout containers and view containers. Workspaces, outputs and the
root are no longer known as containers. Instead, root, outputs,
workspaces and containers are all a type of node, and containers come in
two types: layout containers and view containers.
In addition to the above, this implements type safe variables. This
means we use specific types such as sway_output and sway_workspace
instead of generic containers or nodes. However, it's worth noting that
in a few places places (eg. seat focus and transactions) referring to
them in a generic way is unavoidable which is why we still use nodes in
some places.
If you want a TL;DR, look at node.h, as well as the struct definitions
for root, output, workspace and container. Note that sway_output now
contains a workspaces list, and workspaces now contain a tiling and
floating list, and containers now contain a pointer back to the
workspace.
There are now functions for seat_get_focused_workspace and
seat_get_focused_container. The latter will return NULL if a workspace
itself is focused. Most other seat functions like seat_get_focus and
seat_set_focus now accept and return nodes.
In the config->handler_context struct, current_container has been
replaced with three pointers: node, container and workspace. node is the
same as what current_container was, while workspace is the workspace
that the node resides on and container is the actual container, which
may be NULL if a workspace itself is focused.
The global root_container variable has been replaced with one simply
called root, which is a pointer to the sway_root instance.
The way outputs are created, enabled, disabled and destroyed has
changed. Previously we'd wrap the sway_output in a container when it is
enabled, but as we don't have containers any more it needs a different
approach. The output_create and output_destroy functions previously
created/destroyed the container, but now they create/destroy the
sway_output. There is a new function output_disable to disable an output
without destroying it.
Containers have a new view property. If this is populated then the
container is a view container, otherwise it's a layout container. Like
before, this property is immutable for the life of the container.
Containers have both a `sway_container *parent` and
`sway_workspace *workspace`. As we use specific types now, parent cannot
point to a workspace so it'll be NULL for containers which are direct
children of the workspace. The workspace property is set for all
containers, except those which are hidden in the scratchpad as they have
no workspace.
In some cases we need to refer to workspaces in a container-like way.
For example, workspaces have layout and children, but when using
specific types this makes it difficult. Likewise, it's difficult for a
container to get its parent's layout when the parent could be another
container or a workspace. To make it easier, some helper functions have
been created: container_parent_layout and container_get_siblings.
container_remove_child has been renamed to container_detach and
container_replace_child has been renamed to container_replace.
`container_handle_fullscreen_reparent(con, old_parent)` has had the
old_parent removed. We now unfullscreen the workspace when detaching the
container, so this function is simplified and only needs one argument
now.
container_notify_subtree_changed has been renamed to
container_update_representation. This is more descriptive of its
purpose. I also wanted to be able to call it with whatever container was
changed rather than the container's parent, which makes bubbling up to
the workspace easier.
There are now state structs per node thing. ie. sway_output_state,
sway_workspace_state and sway_container_state.
The focus, move and layout commands have been completely refactored to
work with the specific types. I considered making these a separate PR,
but I'd be backporting my changes only to replace them again, and it's
easier just to test everything at once.
2018-08-30 21:00:10 +10:00
|
|
|
list_free(server->dirty_nodes);
|
2025-06-05 13:46:06 +08:00
|
|
|
free(server->socket);
|
2017-10-22 10:37:30 -04:00
|
|
|
}
|
2017-11-11 11:58:43 -05:00
|
|
|
|
2018-11-17 12:29:59 +01:00
|
|
|
bool server_start(struct sway_server *server) {
|
2024-05-18 14:02:14 +02:00
|
|
|
#if WLR_HAS_XWAYLAND
|
2019-08-15 03:00:14 -04:00
|
|
|
if (config->xwayland != XWAYLAND_MODE_DISABLED) {
|
|
|
|
|
sway_log(SWAY_DEBUG, "Initializing Xwayland (lazy=%d)",
|
|
|
|
|
config->xwayland == XWAYLAND_MODE_LAZY);
|
2018-11-17 12:29:59 +01:00
|
|
|
server->xwayland.wlr_xwayland =
|
2019-08-15 03:00:14 -04:00
|
|
|
wlr_xwayland_create(server->wl_display, server->compositor,
|
|
|
|
|
config->xwayland == XWAYLAND_MODE_LAZY);
|
2020-05-27 12:48:07 -04:00
|
|
|
if (!server->xwayland.wlr_xwayland) {
|
|
|
|
|
sway_log(SWAY_ERROR, "Failed to start Xwayland");
|
2020-07-02 13:50:24 +02:00
|
|
|
unsetenv("DISPLAY");
|
2020-05-27 12:48:07 -04:00
|
|
|
} else {
|
|
|
|
|
wl_signal_add(&server->xwayland.wlr_xwayland->events.new_surface,
|
|
|
|
|
&server->xwayland_surface);
|
|
|
|
|
server->xwayland_surface.notify = handle_xwayland_surface;
|
|
|
|
|
wl_signal_add(&server->xwayland.wlr_xwayland->events.ready,
|
|
|
|
|
&server->xwayland_ready);
|
|
|
|
|
server->xwayland_ready.notify = handle_xwayland_ready;
|
2018-11-17 12:29:59 +01:00
|
|
|
|
2020-05-27 12:48:07 -04:00
|
|
|
setenv("DISPLAY", server->xwayland.wlr_xwayland->display_name, true);
|
2019-03-04 20:51:48 +01:00
|
|
|
|
2020-05-27 12:48:07 -04:00
|
|
|
/* xcursor configured by the default seat */
|
|
|
|
|
}
|
2018-11-17 12:29:59 +01:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-03-16 22:22:41 +00:00
|
|
|
if (config->primary_selection) {
|
|
|
|
|
wlr_primary_selection_v1_device_manager_create(server->wl_display);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-20 13:51:12 -05:00
|
|
|
sway_log(SWAY_INFO, "Starting backend on wayland display '%s'",
|
2017-11-11 11:58:43 -05:00
|
|
|
server->socket);
|
2017-12-31 14:32:28 -07:00
|
|
|
if (!wlr_backend_start(server->backend)) {
|
2019-01-20 13:51:12 -05:00
|
|
|
sway_log(SWAY_ERROR, "Failed to start backend");
|
2017-11-11 11:58:43 -05:00
|
|
|
wlr_backend_destroy(server->backend);
|
2018-07-19 01:39:58 -04:00
|
|
|
return false;
|
2017-11-11 11:58:43 -05:00
|
|
|
}
|
2021-10-04 10:04:46 -04:00
|
|
|
|
2018-07-19 01:39:58 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void server_run(struct sway_server *server) {
|
2019-01-20 13:51:12 -05:00
|
|
|
sway_log(SWAY_INFO, "Running compositor on wayland display '%s'",
|
2018-07-19 01:39:58 -04:00
|
|
|
server->socket);
|
2017-11-11 11:58:43 -05:00
|
|
|
wl_display_run(server->wl_display);
|
|
|
|
|
}
|