aboutsummaryrefslogtreecommitdiffstats
path: root/sway/server.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/server.c')
-rw-r--r--sway/server.c78
1 files changed, 66 insertions, 12 deletions
diff --git a/sway/server.c b/sway/server.c
index cc20e89d..4b48e8e5 100644
--- a/sway/server.c
+++ b/sway/server.c
@@ -1,4 +1,3 @@
1#define _POSIX_C_SOURCE 200809L
2#include <assert.h> 1#include <assert.h>
3#include <stdbool.h> 2#include <stdbool.h>
4#include <stdlib.h> 3#include <stdlib.h>
@@ -8,24 +7,32 @@
8#include <wlr/backend/headless.h> 7#include <wlr/backend/headless.h>
9#include <wlr/backend/multi.h> 8#include <wlr/backend/multi.h>
10#include <wlr/config.h> 9#include <wlr/config.h>
10#include <wlr/render/allocator.h>
11#include <wlr/render/wlr_renderer.h> 11#include <wlr/render/wlr_renderer.h>
12#include <wlr/types/wlr_compositor.h> 12#include <wlr/types/wlr_compositor.h>
13#include <wlr/types/wlr_content_type_v1.h> 13#include <wlr/types/wlr_content_type_v1.h>
14#include <wlr/types/wlr_cursor_shape_v1.h> 14#include <wlr/types/wlr_cursor_shape_v1.h>
15#include <wlr/types/wlr_data_control_v1.h> 15#include <wlr/types/wlr_data_control_v1.h>
16#include <wlr/types/wlr_data_device.h>
16#include <wlr/types/wlr_drm.h> 17#include <wlr/types/wlr_drm.h>
17#include <wlr/types/wlr_export_dmabuf_v1.h> 18#include <wlr/types/wlr_export_dmabuf_v1.h>
19#include <wlr/types/wlr_ext_foreign_toplevel_list_v1.h>
20#include <wlr/types/wlr_foreign_toplevel_management_v1.h>
18#include <wlr/types/wlr_fractional_scale_v1.h> 21#include <wlr/types/wlr_fractional_scale_v1.h>
19#include <wlr/types/wlr_gamma_control_v1.h> 22#include <wlr/types/wlr_gamma_control_v1.h>
20#include <wlr/types/wlr_idle_notify_v1.h> 23#include <wlr/types/wlr_idle_notify_v1.h>
21#include <wlr/types/wlr_layer_shell_v1.h> 24#include <wlr/types/wlr_layer_shell_v1.h>
22#include <wlr/types/wlr_linux_dmabuf_v1.h> 25#include <wlr/types/wlr_linux_dmabuf_v1.h>
26#include <wlr/types/wlr_output_management_v1.h>
27#include <wlr/types/wlr_output_power_management_v1.h>
23#include <wlr/types/wlr_pointer_constraints_v1.h> 28#include <wlr/types/wlr_pointer_constraints_v1.h>
29#include <wlr/types/wlr_presentation_time.h>
24#include <wlr/types/wlr_primary_selection_v1.h> 30#include <wlr/types/wlr_primary_selection_v1.h>
25#include <wlr/types/wlr_relative_pointer_v1.h> 31#include <wlr/types/wlr_relative_pointer_v1.h>
26#include <wlr/types/wlr_screencopy_v1.h> 32#include <wlr/types/wlr_screencopy_v1.h>
27#include <wlr/types/wlr_security_context_v1.h> 33#include <wlr/types/wlr_security_context_v1.h>
28#include <wlr/types/wlr_server_decoration.h> 34#include <wlr/types/wlr_server_decoration.h>
35#include <wlr/types/wlr_session_lock_v1.h>
29#include <wlr/types/wlr_single_pixel_buffer_v1.h> 36#include <wlr/types/wlr_single_pixel_buffer_v1.h>
30#include <wlr/types/wlr_subcompositor.h> 37#include <wlr/types/wlr_subcompositor.h>
31#include <wlr/types/wlr_tablet_v2.h> 38#include <wlr/types/wlr_tablet_v2.h>
@@ -49,7 +56,7 @@
49#include "sway/input/cursor.h" 56#include "sway/input/cursor.h"
50#include "sway/tree/root.h" 57#include "sway/tree/root.h"
51 58
52#if HAVE_XWAYLAND 59#if WLR_HAS_XWAYLAND
53#include <wlr/xwayland/shell.h> 60#include <wlr/xwayland/shell.h>
54#include "sway/xwayland.h" 61#include "sway/xwayland.h"
55#endif 62#endif
@@ -58,8 +65,9 @@
58#include <wlr/types/wlr_drm_lease_v1.h> 65#include <wlr/types/wlr_drm_lease_v1.h>
59#endif 66#endif
60 67
61#define SWAY_XDG_SHELL_VERSION 2 68#define SWAY_XDG_SHELL_VERSION 5
62#define SWAY_LAYER_SHELL_VERSION 4 69#define SWAY_LAYER_SHELL_VERSION 4
70#define SWAY_FOREIGN_TOPLEVEL_LIST_VERSION 1
63 71
64bool allow_unsupported_gpu = false; 72bool allow_unsupported_gpu = false;
65 73
@@ -93,6 +101,7 @@ static bool is_privileged(const struct wl_global *global) {
93 global == server.output_manager_v1->global || 101 global == server.output_manager_v1->global ||
94 global == server.output_power_manager_v1->global || 102 global == server.output_power_manager_v1->global ||
95 global == server.input_method->global || 103 global == server.input_method->global ||
104 global == server.foreign_toplevel_list->global ||
96 global == server.foreign_toplevel_manager->global || 105 global == server.foreign_toplevel_manager->global ||
97 global == server.data_control_manager_v1->global || 106 global == server.data_control_manager_v1->global ||
98 global == server.screencopy_manager_v1->global || 107 global == server.screencopy_manager_v1->global ||
@@ -103,12 +112,13 @@ static bool is_privileged(const struct wl_global *global) {
103 global == server.session_lock.manager->global || 112 global == server.session_lock.manager->global ||
104 global == server.input->keyboard_shortcuts_inhibit->global || 113 global == server.input->keyboard_shortcuts_inhibit->global ||
105 global == server.input->virtual_keyboard->global || 114 global == server.input->virtual_keyboard->global ||
106 global == server.input->virtual_pointer->global; 115 global == server.input->virtual_pointer->global ||
116 global == server.input->transient_seat_manager->global;
107} 117}
108 118
109static bool filter_global(const struct wl_client *client, 119static bool filter_global(const struct wl_client *client,
110 const struct wl_global *global, void *data) { 120 const struct wl_global *global, void *data) {
111#if HAVE_XWAYLAND 121#if WLR_HAS_XWAYLAND
112 struct wlr_xwayland *xwayland = server.xwayland.wlr_xwayland; 122 struct wlr_xwayland *xwayland = server.xwayland.wlr_xwayland;
113 if (xwayland && global == xwayland->shell_v1->global) { 123 if (xwayland && global == xwayland->shell_v1->global) {
114 return xwayland->server != NULL && client == xwayland->server->client; 124 return xwayland->server != NULL && client == xwayland->server->client;
@@ -163,6 +173,45 @@ static void detect_proprietary(struct wlr_backend *backend, void *data) {
163 drmFreeVersion(version); 173 drmFreeVersion(version);
164} 174}
165 175
176static void handle_renderer_lost(struct wl_listener *listener, void *data) {
177 struct sway_server *server = wl_container_of(listener, server, renderer_lost);
178
179 sway_log(SWAY_INFO, "Re-creating renderer after GPU reset");
180
181 struct wlr_renderer *renderer = wlr_renderer_autocreate(server->backend);
182 if (renderer == NULL) {
183 sway_log(SWAY_ERROR, "Unable to create renderer");
184 return;
185 }
186
187 struct wlr_allocator *allocator =
188 wlr_allocator_autocreate(server->backend, renderer);
189 if (allocator == NULL) {
190 sway_log(SWAY_ERROR, "Unable to create allocator");
191 wlr_renderer_destroy(renderer);
192 return;
193 }
194
195 struct wlr_renderer *old_renderer = server->renderer;
196 struct wlr_allocator *old_allocator = server->allocator;
197 server->renderer = renderer;
198 server->allocator = allocator;
199
200 wl_list_remove(&server->renderer_lost.link);
201 wl_signal_add(&server->renderer->events.lost, &server->renderer_lost);
202
203 wlr_compositor_set_renderer(server->compositor, renderer);
204
205 for (int i = 0; i < root->outputs->length; ++i) {
206 struct sway_output *output = root->outputs->items[i];
207 wlr_output_init_render(output->wlr_output,
208 server->allocator, server->renderer);
209 }
210
211 wlr_allocator_destroy(old_allocator);
212 wlr_renderer_destroy(old_renderer);
213}
214
166bool server_init(struct sway_server *server) { 215bool server_init(struct sway_server *server) {
167 sway_log(SWAY_DEBUG, "Initializing Wayland server"); 216 sway_log(SWAY_DEBUG, "Initializing Wayland server");
168 server->wl_display = wl_display_create(); 217 server->wl_display = wl_display_create();
@@ -186,15 +235,17 @@ bool server_init(struct sway_server *server) {
186 return false; 235 return false;
187 } 236 }
188 237
238 server->renderer_lost.notify = handle_renderer_lost;
239 wl_signal_add(&server->renderer->events.lost, &server->renderer_lost);
240
189 wlr_renderer_init_wl_shm(server->renderer, server->wl_display); 241 wlr_renderer_init_wl_shm(server->renderer, server->wl_display);
190 242
191 if (wlr_renderer_get_dmabuf_texture_formats(server->renderer) != NULL) { 243 if (wlr_renderer_get_texture_formats(server->renderer, WLR_BUFFER_CAP_DMABUF) != NULL) {
192 server->linux_dmabuf_v1 = wlr_linux_dmabuf_v1_create_with_renderer( 244 server->linux_dmabuf_v1 = wlr_linux_dmabuf_v1_create_with_renderer(
193 server->wl_display, 4, server->renderer); 245 server->wl_display, 4, server->renderer);
194 } 246 if (debug.legacy_wl_drm) {
195 if (wlr_renderer_get_dmabuf_texture_formats(server->renderer) != NULL && 247 wlr_drm_create(server->wl_display, server->renderer);
196 debug.legacy_wl_drm) { 248 }
197 wlr_drm_create(server->wl_display, server->renderer);
198 } 249 }
199 250
200 server->allocator = wlr_allocator_autocreate(server->backend, 251 server->allocator = wlr_allocator_autocreate(server->backend,
@@ -289,6 +340,8 @@ bool server_init(struct sway_server *server) {
289 &server->output_power_manager_set_mode); 340 &server->output_power_manager_set_mode);
290 server->input_method = wlr_input_method_manager_v2_create(server->wl_display); 341 server->input_method = wlr_input_method_manager_v2_create(server->wl_display);
291 server->text_input = wlr_text_input_manager_v3_create(server->wl_display); 342 server->text_input = wlr_text_input_manager_v3_create(server->wl_display);
343 server->foreign_toplevel_list =
344 wlr_ext_foreign_toplevel_list_v1_create(server->wl_display, SWAY_FOREIGN_TOPLEVEL_LIST_VERSION);
292 server->foreign_toplevel_manager = 345 server->foreign_toplevel_manager =
293 wlr_foreign_toplevel_manager_v1_create(server->wl_display); 346 wlr_foreign_toplevel_manager_v1_create(server->wl_display);
294 347
@@ -384,16 +437,17 @@ bool server_init(struct sway_server *server) {
384 437
385void server_fini(struct sway_server *server) { 438void server_fini(struct sway_server *server) {
386 // TODO: free sway-specific resources 439 // TODO: free sway-specific resources
387#if HAVE_XWAYLAND 440#if WLR_HAS_XWAYLAND
388 wlr_xwayland_destroy(server->xwayland.wlr_xwayland); 441 wlr_xwayland_destroy(server->xwayland.wlr_xwayland);
389#endif 442#endif
390 wl_display_destroy_clients(server->wl_display); 443 wl_display_destroy_clients(server->wl_display);
444 wlr_backend_destroy(server->backend);
391 wl_display_destroy(server->wl_display); 445 wl_display_destroy(server->wl_display);
392 list_free(server->dirty_nodes); 446 list_free(server->dirty_nodes);
393} 447}
394 448
395bool server_start(struct sway_server *server) { 449bool server_start(struct sway_server *server) {
396#if HAVE_XWAYLAND 450#if WLR_HAS_XWAYLAND
397 if (config->xwayland != XWAYLAND_MODE_DISABLED) { 451 if (config->xwayland != XWAYLAND_MODE_DISABLED) {
398 sway_log(SWAY_DEBUG, "Initializing Xwayland (lazy=%d)", 452 sway_log(SWAY_DEBUG, "Initializing Xwayland (lazy=%d)",
399 config->xwayland == XWAYLAND_MODE_LAZY); 453 config->xwayland == XWAYLAND_MODE_LAZY);