| 
									
										
										
										
											2017-06-20 18:27:05 +02:00
										 |  |  | #include <assert.h>
 | 
					
						
							| 
									
										
										
										
											2017-06-19 22:36:40 +02:00
										 |  |  | #include <stdint.h>
 | 
					
						
							| 
									
										
										
										
											2018-02-12 21:29:23 +01:00
										 |  |  | #include <stdio.h>
 | 
					
						
							| 
									
										
										
										
											2017-06-19 22:36:40 +02:00
										 |  |  | #include <stdlib.h>
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							| 
									
										
										
										
											2017-08-14 18:19:42 +02:00
										 |  |  | #include <sys/mman.h>
 | 
					
						
							| 
									
										
										
										
											2018-02-12 21:29:23 +01:00
										 |  |  | #include <sys/types.h>
 | 
					
						
							|  |  |  | #include <unistd.h>
 | 
					
						
							| 
									
										
										
										
											2018-11-11 18:14:48 +13:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-09 23:29:44 +01:00
										 |  |  | #include <drm_fourcc.h>
 | 
					
						
							| 
									
										
										
										
											2017-06-19 22:36:40 +02:00
										 |  |  | #include <wayland-client.h>
 | 
					
						
							| 
									
										
										
										
											2018-11-11 18:14:48 +13:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:27:45 -04:00
										 |  |  | #include <wlr/interfaces/wlr_output.h>
 | 
					
						
							| 
									
										
										
										
											2018-03-20 23:10:42 +01:00
										 |  |  | #include <wlr/render/wlr_renderer.h>
 | 
					
						
							| 
									
										
										
										
											2018-05-01 21:38:04 +01:00
										 |  |  | #include <wlr/types/wlr_matrix.h>
 | 
					
						
							| 
									
										
										
										
											2017-06-21 12:10:07 -04:00
										 |  |  | #include <wlr/util/log.h>
 | 
					
						
							| 
									
										
										
										
											2018-11-11 18:14:48 +13:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-29 00:16:34 +02:00
										 |  |  | #include "backend/backend.h"
 | 
					
						
							| 
									
										
										
										
											2017-06-19 22:36:40 +02:00
										 |  |  | #include "backend/wayland.h"
 | 
					
						
							| 
									
										
										
										
											2021-02-09 23:29:44 +01:00
										 |  |  | #include "render/pixel_format.h"
 | 
					
						
							| 
									
										
										
										
											2020-11-26 11:40:23 +01:00
										 |  |  | #include "render/swapchain.h"
 | 
					
						
							|  |  |  | #include "render/wlr_renderer.h"
 | 
					
						
							| 
									
										
										
										
											2018-02-12 21:29:23 +01:00
										 |  |  | #include "util/signal.h"
 | 
					
						
							| 
									
										
										
										
											2020-11-26 11:40:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-24 15:33:15 +03:00
										 |  |  | #include "linux-dmabuf-unstable-v1-client-protocol.h"
 | 
					
						
							| 
									
										
										
										
											2019-11-16 21:05:46 +01:00
										 |  |  | #include "presentation-time-client-protocol.h"
 | 
					
						
							| 
									
										
										
										
											2019-05-06 19:06:31 +03:00
										 |  |  | #include "xdg-decoration-unstable-v1-client-protocol.h"
 | 
					
						
							| 
									
										
										
										
											2019-01-10 09:17:14 -05:00
										 |  |  | #include "xdg-shell-client-protocol.h"
 | 
					
						
							| 
									
										
										
										
											2017-06-19 22:36:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-17 22:10:34 +02:00
										 |  |  | static struct wlr_wl_output *get_wl_output_from_output( | 
					
						
							|  |  |  | 		struct wlr_output *wlr_output) { | 
					
						
							|  |  |  | 	assert(wlr_output_is_wl(wlr_output)); | 
					
						
							|  |  |  | 	return (struct wlr_wl_output *)wlr_output; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-08-14 18:19:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-26 22:39:23 +01:00
										 |  |  | static void surface_frame_callback(void *data, struct wl_callback *cb, | 
					
						
							|  |  |  | 		uint32_t time) { | 
					
						
							| 
									
										
										
										
											2018-04-29 12:16:31 +01:00
										 |  |  | 	struct wlr_wl_output *output = data; | 
					
						
							| 
									
										
										
										
											2018-01-26 22:39:23 +01:00
										 |  |  | 	assert(output); | 
					
						
							| 
									
										
										
										
											2017-06-26 11:34:22 -04:00
										 |  |  | 	wl_callback_destroy(cb); | 
					
						
							| 
									
										
										
										
											2018-01-18 13:06:57 +01:00
										 |  |  | 	output->frame_callback = NULL; | 
					
						
							| 
									
										
										
										
											2018-01-30 14:45:02 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	wlr_output_send_frame(&output->wlr_output); | 
					
						
							| 
									
										
										
										
											2017-06-26 11:34:22 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-16 21:05:46 +01:00
										 |  |  | static const struct wl_callback_listener frame_listener = { | 
					
						
							| 
									
										
										
										
											2017-06-26 11:34:22 -04:00
										 |  |  | 	.done = surface_frame_callback | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-16 21:05:46 +01:00
										 |  |  | static void presentation_feedback_destroy( | 
					
						
							|  |  |  | 		struct wlr_wl_presentation_feedback *feedback) { | 
					
						
							|  |  |  | 	wl_list_remove(&feedback->link); | 
					
						
							|  |  |  | 	wp_presentation_feedback_destroy(feedback->feedback); | 
					
						
							|  |  |  | 	free(feedback); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void presentation_feedback_handle_sync_output(void *data, | 
					
						
							|  |  |  | 		struct wp_presentation_feedback *feedback, struct wl_output *output) { | 
					
						
							|  |  |  | 	// This space is intentionally left blank
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void presentation_feedback_handle_presented(void *data, | 
					
						
							|  |  |  | 		struct wp_presentation_feedback *wp_feedback, uint32_t tv_sec_hi, | 
					
						
							|  |  |  | 		uint32_t tv_sec_lo, uint32_t tv_nsec, uint32_t refresh_ns, | 
					
						
							|  |  |  | 		uint32_t seq_hi, uint32_t seq_lo, uint32_t flags) { | 
					
						
							|  |  |  | 	struct wlr_wl_presentation_feedback *feedback = data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct timespec t = { | 
					
						
							|  |  |  | 		.tv_sec = ((uint64_t)tv_sec_hi << 32) | tv_sec_lo, | 
					
						
							|  |  |  | 		.tv_nsec = tv_nsec, | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	struct wlr_output_event_present event = { | 
					
						
							|  |  |  | 		.commit_seq = feedback->commit_seq, | 
					
						
							|  |  |  | 		.when = &t, | 
					
						
							|  |  |  | 		.seq = ((uint64_t)seq_hi << 32) | seq_lo, | 
					
						
							|  |  |  | 		.refresh = refresh_ns, | 
					
						
							|  |  |  | 		.flags = flags, | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	wlr_output_send_present(&feedback->output->wlr_output, &event); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	presentation_feedback_destroy(feedback); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void presentation_feedback_handle_discarded(void *data, | 
					
						
							|  |  |  | 		struct wp_presentation_feedback *wp_feedback) { | 
					
						
							|  |  |  | 	struct wlr_wl_presentation_feedback *feedback = data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	wlr_output_send_present(&feedback->output->wlr_output, NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	presentation_feedback_destroy(feedback); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static const struct wp_presentation_feedback_listener | 
					
						
							|  |  |  | 		presentation_feedback_listener = { | 
					
						
							|  |  |  | 	.sync_output = presentation_feedback_handle_sync_output, | 
					
						
							|  |  |  | 	.presented = presentation_feedback_handle_presented, | 
					
						
							|  |  |  | 	.discarded = presentation_feedback_handle_discarded, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-17 22:10:34 +02:00
										 |  |  | static bool output_set_custom_mode(struct wlr_output *wlr_output, | 
					
						
							| 
									
										
										
										
											2017-12-11 12:14:23 +01:00
										 |  |  | 		int32_t width, int32_t height, int32_t refresh) { | 
					
						
							| 
									
										
										
										
											2018-09-17 22:10:34 +02:00
										 |  |  | 	struct wlr_wl_output *output = get_wl_output_from_output(wlr_output); | 
					
						
							| 
									
										
										
										
											2021-04-29 00:16:34 +02:00
										 |  |  | 	struct wlr_allocator *allocator = backend_get_allocator(wlr_output->backend); | 
					
						
							| 
									
										
										
										
											2020-11-26 11:40:23 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (wlr_output->width != width || wlr_output->height != height) { | 
					
						
							| 
									
										
										
										
											2021-04-29 00:16:34 +02:00
										 |  |  | 		struct wlr_swapchain *swapchain = wlr_swapchain_create(allocator, | 
					
						
							|  |  |  | 			width, height, output->backend->format); | 
					
						
							| 
									
										
										
										
											2020-11-26 11:40:23 +01:00
										 |  |  | 		if (swapchain == NULL) { | 
					
						
							|  |  |  | 			return false; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		wlr_swapchain_destroy(output->swapchain); | 
					
						
							|  |  |  | 		output->swapchain = swapchain; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-17 18:02:55 +01:00
										 |  |  | 	wlr_output_update_custom_mode(&output->wlr_output, width, height, 0); | 
					
						
							| 
									
										
										
										
											2017-12-11 12:14:23 +01:00
										 |  |  | 	return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-23 19:26:21 +03:00
										 |  |  | static bool output_attach_render(struct wlr_output *wlr_output, | 
					
						
							| 
									
										
										
										
											2018-01-21 00:06:35 +01:00
										 |  |  | 		int *buffer_age) { | 
					
						
							| 
									
										
										
										
											2020-11-26 11:40:23 +01:00
										 |  |  | 	struct wlr_wl_output *output = get_wl_output_from_output(wlr_output); | 
					
						
							| 
									
										
										
										
											2021-04-29 00:16:34 +02:00
										 |  |  | 	struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend); | 
					
						
							| 
									
										
										
										
											2020-11-26 11:40:23 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	wlr_buffer_unlock(output->back_buffer); | 
					
						
							|  |  |  | 	output->back_buffer = wlr_swapchain_acquire(output->swapchain, buffer_age); | 
					
						
							|  |  |  | 	if (!output->back_buffer) { | 
					
						
							| 
									
										
										
										
											2021-02-18 22:14:19 +01:00
										 |  |  | 		wlr_log(WLR_ERROR, "Failed to acquire swapchain buffer"); | 
					
						
							| 
									
										
										
										
											2020-11-26 11:40:23 +01:00
										 |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-29 00:16:34 +02:00
										 |  |  | 	if (!wlr_renderer_bind_buffer(renderer, output->back_buffer)) { | 
					
						
							| 
									
										
										
										
											2021-02-18 22:14:19 +01:00
										 |  |  | 		wlr_log(WLR_ERROR, "Failed to bind buffer to renderer"); | 
					
						
							| 
									
										
										
										
											2020-11-26 11:40:23 +01:00
										 |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return true; | 
					
						
							| 
									
										
										
										
											2017-06-26 11:34:22 -04:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-06-20 18:27:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-11 18:14:58 +01:00
										 |  |  | void destroy_wl_buffer(struct wlr_wl_buffer *buffer) { | 
					
						
							| 
									
										
										
										
											2020-01-09 15:34:34 +01:00
										 |  |  | 	if (buffer == NULL) { | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-12-11 18:14:58 +01:00
										 |  |  | 	wl_list_remove(&buffer->buffer_destroy.link); | 
					
						
							|  |  |  | 	wl_list_remove(&buffer->link); | 
					
						
							| 
									
										
										
										
											2020-01-09 15:34:34 +01:00
										 |  |  | 	wl_buffer_destroy(buffer->wl_buffer); | 
					
						
							|  |  |  | 	free(buffer); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-09-24 15:33:15 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-09 15:34:34 +01:00
										 |  |  | static void buffer_handle_release(void *data, struct wl_buffer *wl_buffer) { | 
					
						
							|  |  |  | 	struct wlr_wl_buffer *buffer = data; | 
					
						
							| 
									
										
										
										
											2020-12-11 18:14:58 +01:00
										 |  |  | 	buffer->released = true; | 
					
						
							|  |  |  | 	wlr_buffer_unlock(buffer->buffer); // might free buffer
 | 
					
						
							| 
									
										
										
										
											2020-01-09 15:34:34 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static const struct wl_buffer_listener buffer_listener = { | 
					
						
							|  |  |  | 	.release = buffer_handle_release, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-11 18:14:58 +01:00
										 |  |  | static void buffer_handle_buffer_destroy(struct wl_listener *listener, | 
					
						
							|  |  |  | 		void *data) { | 
					
						
							|  |  |  | 	struct wlr_wl_buffer *buffer = | 
					
						
							|  |  |  | 		wl_container_of(listener, buffer, buffer_destroy); | 
					
						
							|  |  |  | 	destroy_wl_buffer(buffer); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-02 14:12:26 +02:00
										 |  |  | static bool test_buffer(struct wlr_wl_backend *wl, | 
					
						
							| 
									
										
										
										
											2020-04-10 14:54:33 +02:00
										 |  |  | 		struct wlr_buffer *wlr_buffer) { | 
					
						
							| 
									
										
										
										
											2021-02-09 23:29:44 +01:00
										 |  |  | 	struct wlr_dmabuf_attributes dmabuf; | 
					
						
							|  |  |  | 	struct wlr_shm_attributes shm; | 
					
						
							|  |  |  | 	if (wlr_buffer_get_dmabuf(wlr_buffer, &dmabuf)) { | 
					
						
							|  |  |  | 		return wlr_drm_format_set_has(&wl->linux_dmabuf_v1_formats, | 
					
						
							|  |  |  | 			dmabuf.format, dmabuf.modifier); | 
					
						
							|  |  |  | 	} else if (wlr_buffer_get_shm(wlr_buffer, &shm)) { | 
					
						
							|  |  |  | 		return wlr_drm_format_set_has(&wl->shm_formats, shm.format, | 
					
						
							|  |  |  | 			DRM_FORMAT_MOD_INVALID); | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2020-04-02 14:12:26 +02:00
										 |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2019-09-24 15:33:15 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-04-02 14:12:26 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-09 23:29:44 +01:00
										 |  |  | static struct wl_buffer *import_dmabuf(struct wlr_wl_backend *wl, | 
					
						
							|  |  |  | 		struct wlr_dmabuf_attributes *dmabuf) { | 
					
						
							|  |  |  | 	uint32_t modifier_hi = dmabuf->modifier >> 32; | 
					
						
							|  |  |  | 	uint32_t modifier_lo = (uint32_t)dmabuf->modifier; | 
					
						
							| 
									
										
										
										
											2019-09-24 15:33:15 +03:00
										 |  |  | 	struct zwp_linux_buffer_params_v1 *params = | 
					
						
							|  |  |  | 		zwp_linux_dmabuf_v1_create_params(wl->zwp_linux_dmabuf_v1); | 
					
						
							| 
									
										
										
										
											2021-02-09 23:29:44 +01:00
										 |  |  | 	for (int i = 0; i < dmabuf->n_planes; i++) { | 
					
						
							|  |  |  | 		zwp_linux_buffer_params_v1_add(params, dmabuf->fd[i], i, | 
					
						
							|  |  |  | 			dmabuf->offset[i], dmabuf->stride[i], modifier_hi, modifier_lo); | 
					
						
							| 
									
										
										
										
											2019-09-24 15:33:15 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	uint32_t flags = 0; | 
					
						
							| 
									
										
										
										
											2021-02-09 23:29:44 +01:00
										 |  |  | 	if (dmabuf->flags & WLR_DMABUF_ATTRIBUTES_FLAGS_Y_INVERT) { | 
					
						
							| 
									
										
										
										
											2019-09-24 15:33:15 +03:00
										 |  |  | 		flags |= ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_Y_INVERT; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-02-09 23:29:44 +01:00
										 |  |  | 	if (dmabuf->flags & WLR_DMABUF_ATTRIBUTES_FLAGS_INTERLACED) { | 
					
						
							| 
									
										
										
										
											2019-09-24 15:33:15 +03:00
										 |  |  | 		flags |= ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_INTERLACED; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-02-09 23:29:44 +01:00
										 |  |  | 	if (dmabuf->flags & WLR_DMABUF_ATTRIBUTES_FLAGS_BOTTOM_FIRST) { | 
					
						
							| 
									
										
										
										
											2019-09-24 15:33:15 +03:00
										 |  |  | 		flags |= ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_BOTTOM_FIRST; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	struct wl_buffer *wl_buffer = zwp_linux_buffer_params_v1_create_immed( | 
					
						
							| 
									
										
										
										
											2021-02-09 23:29:44 +01:00
										 |  |  | 		params, dmabuf->width, dmabuf->height, dmabuf->format, flags); | 
					
						
							| 
									
										
										
										
											2019-09-24 15:33:15 +03:00
										 |  |  | 	// TODO: handle create() errors
 | 
					
						
							| 
									
										
										
										
											2021-02-09 23:29:44 +01:00
										 |  |  | 	return wl_buffer; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct wl_buffer *import_shm(struct wlr_wl_backend *wl, | 
					
						
							|  |  |  | 		struct wlr_shm_attributes *shm) { | 
					
						
							|  |  |  | 	enum wl_shm_format wl_shm_format = convert_drm_format_to_wl_shm(shm->format); | 
					
						
							|  |  |  | 	uint32_t size = shm->stride * shm->height; | 
					
						
							|  |  |  | 	struct wl_shm_pool *pool = wl_shm_create_pool(wl->shm, shm->fd, size); | 
					
						
							|  |  |  | 	if (pool == NULL) { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	struct wl_buffer *wl_buffer = wl_shm_pool_create_buffer(pool, shm->offset, | 
					
						
							|  |  |  | 		shm->width, shm->height, shm->stride, wl_shm_format); | 
					
						
							|  |  |  | 	wl_shm_pool_destroy(pool); | 
					
						
							|  |  |  | 	return wl_buffer; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct wlr_wl_buffer *create_wl_buffer(struct wlr_wl_backend *wl, | 
					
						
							|  |  |  | 		struct wlr_buffer *wlr_buffer) { | 
					
						
							|  |  |  | 	if (!test_buffer(wl, wlr_buffer)) { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct wlr_dmabuf_attributes dmabuf; | 
					
						
							|  |  |  | 	struct wlr_shm_attributes shm; | 
					
						
							|  |  |  | 	struct wl_buffer *wl_buffer; | 
					
						
							|  |  |  | 	if (wlr_buffer_get_dmabuf(wlr_buffer, &dmabuf)) { | 
					
						
							|  |  |  | 		wl_buffer = import_dmabuf(wl, &dmabuf); | 
					
						
							|  |  |  | 	} else if (wlr_buffer_get_shm(wlr_buffer, &shm)) { | 
					
						
							|  |  |  | 		wl_buffer = import_shm(wl, &shm); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (wl_buffer == NULL) { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-09-24 15:33:15 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-09 15:34:34 +01:00
										 |  |  | 	struct wlr_wl_buffer *buffer = calloc(1, sizeof(struct wlr_wl_buffer)); | 
					
						
							|  |  |  | 	if (buffer == NULL) { | 
					
						
							|  |  |  | 		wl_buffer_destroy(wl_buffer); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	buffer->wl_buffer = wl_buffer; | 
					
						
							| 
									
										
										
										
											2020-02-28 13:25:05 +01:00
										 |  |  | 	buffer->buffer = wlr_buffer_lock(wlr_buffer); | 
					
						
							| 
									
										
										
										
											2020-12-11 18:14:58 +01:00
										 |  |  | 	wl_list_insert(&wl->buffers, &buffer->link); | 
					
						
							| 
									
										
										
										
											2019-09-24 15:33:15 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-09 15:34:34 +01:00
										 |  |  | 	wl_buffer_add_listener(wl_buffer, &buffer_listener, buffer); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-11 18:14:58 +01:00
										 |  |  | 	buffer->buffer_destroy.notify = buffer_handle_buffer_destroy; | 
					
						
							|  |  |  | 	wl_signal_add(&wlr_buffer->events.destroy, &buffer->buffer_destroy); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-09 15:34:34 +01:00
										 |  |  | 	return buffer; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-11 18:14:58 +01:00
										 |  |  | static struct wlr_wl_buffer *get_or_create_wl_buffer(struct wlr_wl_backend *wl, | 
					
						
							|  |  |  | 		struct wlr_buffer *wlr_buffer) { | 
					
						
							|  |  |  | 	struct wlr_wl_buffer *buffer; | 
					
						
							|  |  |  | 	wl_list_for_each(buffer, &wl->buffers, link) { | 
					
						
							|  |  |  | 		// We can only re-use a wlr_wl_buffer if the parent compositor has
 | 
					
						
							|  |  |  | 		// released it, because wl_buffer.release is per-wl_buffer, not per
 | 
					
						
							|  |  |  | 		// wl_surface.commit.
 | 
					
						
							|  |  |  | 		if (buffer->buffer == wlr_buffer && buffer->released) { | 
					
						
							|  |  |  | 			buffer->released = false; | 
					
						
							|  |  |  | 			wlr_buffer_lock(buffer->buffer); | 
					
						
							|  |  |  | 			return buffer; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return create_wl_buffer(wl, wlr_buffer); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-02 12:41:19 +02:00
										 |  |  | static bool output_test(struct wlr_output *wlr_output) { | 
					
						
							| 
									
										
										
										
											2020-04-10 15:00:00 +02:00
										 |  |  | 	struct wlr_wl_output *output = | 
					
						
							|  |  |  | 		get_wl_output_from_output(wlr_output); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-02 12:41:19 +02:00
										 |  |  | 	if (wlr_output->pending.committed & WLR_OUTPUT_STATE_ENABLED) { | 
					
						
							|  |  |  | 		wlr_log(WLR_DEBUG, "Cannot disable a Wayland output"); | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (wlr_output->pending.committed & WLR_OUTPUT_STATE_MODE) { | 
					
						
							|  |  |  | 		assert(wlr_output->pending.mode_type == WLR_OUTPUT_STATE_MODE_CUSTOM); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-10 15:00:00 +02:00
										 |  |  | 	if ((wlr_output->pending.committed & WLR_OUTPUT_STATE_BUFFER) && | 
					
						
							|  |  |  | 			wlr_output->pending.buffer_type == WLR_OUTPUT_STATE_BUFFER_SCANOUT && | 
					
						
							|  |  |  | 			!test_buffer(output->backend, wlr_output->pending.buffer)) { | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-02 12:41:19 +02:00
										 |  |  | 	return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-23 19:26:21 +03:00
										 |  |  | static bool output_commit(struct wlr_output *wlr_output) { | 
					
						
							| 
									
										
										
										
											2018-04-29 12:16:31 +01:00
										 |  |  | 	struct wlr_wl_output *output = | 
					
						
							| 
									
										
										
										
											2018-09-17 22:10:34 +02:00
										 |  |  | 		get_wl_output_from_output(wlr_output); | 
					
						
							| 
									
										
										
										
											2021-04-29 00:16:34 +02:00
										 |  |  | 	struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend); | 
					
						
							| 
									
										
										
										
											2018-01-21 00:06:35 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-02 12:41:19 +02:00
										 |  |  | 	if (!output_test(wlr_output)) { | 
					
						
							| 
									
										
										
										
											2018-01-30 14:45:02 +01:00
										 |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-16 19:41:56 +03:00
										 |  |  | 	if (wlr_output->pending.committed & WLR_OUTPUT_STATE_MODE) { | 
					
						
							|  |  |  | 		if (!output_set_custom_mode(wlr_output, | 
					
						
							|  |  |  | 				wlr_output->pending.custom_mode.width, | 
					
						
							|  |  |  | 				wlr_output->pending.custom_mode.height, | 
					
						
							|  |  |  | 				wlr_output->pending.custom_mode.refresh)) { | 
					
						
							|  |  |  | 			return false; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-08-07 08:11:38 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-07-18 21:38:12 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-16 19:41:56 +03:00
										 |  |  | 	if (wlr_output->pending.committed & WLR_OUTPUT_STATE_BUFFER) { | 
					
						
							|  |  |  | 		struct wp_presentation_feedback *wp_feedback = NULL; | 
					
						
							|  |  |  | 		if (output->backend->presentation != NULL) { | 
					
						
							|  |  |  | 			wp_feedback = wp_presentation_feedback(output->backend->presentation, | 
					
						
							|  |  |  | 				output->surface); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-11-16 21:05:46 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-16 19:41:56 +03:00
										 |  |  | 		pixman_region32_t *damage = NULL; | 
					
						
							|  |  |  | 		if (wlr_output->pending.committed & WLR_OUTPUT_STATE_DAMAGE) { | 
					
						
							|  |  |  | 			damage = &wlr_output->pending.damage; | 
					
						
							| 
									
										
										
										
											2019-09-24 15:33:15 +03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-08-16 19:41:56 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-02 20:39:41 +01:00
										 |  |  | 		if (output->frame_callback != NULL) { | 
					
						
							|  |  |  | 			wlr_log(WLR_ERROR, "Skipping buffer swap"); | 
					
						
							|  |  |  | 			return false; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		output->frame_callback = wl_surface_frame(output->surface); | 
					
						
							|  |  |  | 		wl_callback_add_listener(output->frame_callback, &frame_listener, output); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-26 11:40:23 +01:00
										 |  |  | 		struct wlr_buffer *wlr_buffer = NULL; | 
					
						
							| 
									
										
										
										
											2019-08-16 19:41:56 +03:00
										 |  |  | 		switch (wlr_output->pending.buffer_type) { | 
					
						
							|  |  |  | 		case WLR_OUTPUT_STATE_BUFFER_RENDER: | 
					
						
							| 
									
										
										
										
											2020-11-26 11:40:23 +01:00
										 |  |  | 			assert(output->back_buffer != NULL); | 
					
						
							|  |  |  | 			wlr_buffer = output->back_buffer; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-29 00:16:34 +02:00
										 |  |  | 			wlr_renderer_bind_buffer(renderer, NULL); | 
					
						
							| 
									
										
										
										
											2019-08-16 19:41:56 +03:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2020-04-02 14:12:26 +02:00
										 |  |  | 		case WLR_OUTPUT_STATE_BUFFER_SCANOUT:; | 
					
						
							| 
									
										
										
										
											2020-11-26 11:40:23 +01:00
										 |  |  | 			wlr_buffer = wlr_output->pending.buffer; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		struct wlr_wl_buffer *buffer = | 
					
						
							| 
									
										
										
										
											2020-12-11 18:14:58 +01:00
										 |  |  | 			get_or_create_wl_buffer(output->backend, wlr_buffer); | 
					
						
							| 
									
										
										
										
											2020-11-26 11:40:23 +01:00
										 |  |  | 		if (buffer == NULL) { | 
					
						
							|  |  |  | 			return false; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		wl_surface_attach(output->surface, buffer->wl_buffer, 0, 0); | 
					
						
							| 
									
										
										
										
											2020-04-02 14:12:26 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-26 11:40:23 +01:00
										 |  |  | 		if (damage == NULL) { | 
					
						
							|  |  |  | 			wl_surface_damage_buffer(output->surface, | 
					
						
							|  |  |  | 				0, 0, INT32_MAX, INT32_MAX); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			int rects_len; | 
					
						
							|  |  |  | 			pixman_box32_t *rects = | 
					
						
							|  |  |  | 				pixman_region32_rectangles(damage, &rects_len); | 
					
						
							|  |  |  | 			for (int i = 0; i < rects_len; i++) { | 
					
						
							|  |  |  | 				pixman_box32_t *r = &rects[i]; | 
					
						
							|  |  |  | 				wl_surface_damage_buffer(output->surface, r->x1, r->y1, | 
					
						
							|  |  |  | 					r->x2 - r->x1, r->y2 - r->y1); | 
					
						
							| 
									
										
										
										
											2019-09-24 15:33:15 +03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-26 11:40:23 +01:00
										 |  |  | 		wl_surface_commit(output->surface); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		wlr_buffer_unlock(output->back_buffer); | 
					
						
							|  |  |  | 		output->back_buffer = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		wlr_swapchain_set_buffer_submitted(output->swapchain, wlr_buffer); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-16 19:41:56 +03:00
										 |  |  | 		if (wp_feedback != NULL) { | 
					
						
							|  |  |  | 			struct wlr_wl_presentation_feedback *feedback = | 
					
						
							|  |  |  | 				calloc(1, sizeof(*feedback)); | 
					
						
							|  |  |  | 			if (feedback == NULL) { | 
					
						
							|  |  |  | 				wp_presentation_feedback_destroy(wp_feedback); | 
					
						
							|  |  |  | 				return false; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			feedback->output = output; | 
					
						
							|  |  |  | 			feedback->feedback = wp_feedback; | 
					
						
							|  |  |  | 			feedback->commit_seq = output->wlr_output.commit_seq + 1; | 
					
						
							|  |  |  | 			wl_list_insert(&output->presentation_feedbacks, &feedback->link); | 
					
						
							| 
									
										
										
										
											2018-10-01 11:07:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-16 19:41:56 +03:00
										 |  |  | 			wp_presentation_feedback_add_listener(wp_feedback, | 
					
						
							|  |  |  | 				&presentation_feedback_listener, feedback); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			wlr_output_send_present(wlr_output, NULL); | 
					
						
							| 
									
										
										
										
											2019-11-16 21:05:46 +01:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-09-24 15:33:15 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-29 10:06:16 +01:00
										 |  |  | 	wl_display_flush(output->backend->remote_display); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-01 11:07:58 +02:00
										 |  |  | 	return true; | 
					
						
							| 
									
										
										
										
											2017-06-20 18:27:05 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-19 15:49:55 +02:00
										 |  |  | static void output_rollback_render(struct wlr_output *wlr_output) { | 
					
						
							| 
									
										
										
										
											2021-04-29 00:16:34 +02:00
										 |  |  | 	struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend); | 
					
						
							|  |  |  | 	wlr_renderer_bind_buffer(renderer, NULL); | 
					
						
							| 
									
										
										
										
											2020-04-06 11:53:20 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-09 19:58:18 +01:00
										 |  |  | static bool output_set_cursor(struct wlr_output *wlr_output, | 
					
						
							| 
									
										
										
										
											2020-04-10 11:04:21 +02:00
										 |  |  | 		struct wlr_texture *texture, float scale, | 
					
						
							| 
									
										
										
										
											2018-09-17 22:10:34 +02:00
										 |  |  | 		enum wl_output_transform transform, | 
					
						
							|  |  |  | 		int32_t hotspot_x, int32_t hotspot_y, bool update_texture) { | 
					
						
							|  |  |  | 	struct wlr_wl_output *output = get_wl_output_from_output(wlr_output); | 
					
						
							| 
									
										
										
										
											2017-08-14 18:19:42 +02:00
										 |  |  | 	struct wlr_wl_backend *backend = output->backend; | 
					
						
							| 
									
										
										
										
											2021-04-29 00:16:34 +02:00
										 |  |  | 	struct wlr_renderer *renderer = wlr_backend_get_renderer(&backend->backend); | 
					
						
							|  |  |  | 	struct wlr_allocator *allocator = backend_get_allocator(&backend->backend); | 
					
						
							| 
									
										
										
										
											2017-10-08 21:21:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-09 19:58:18 +01:00
										 |  |  | 	struct wlr_box hotspot = { .x = hotspot_x, .y = hotspot_y }; | 
					
						
							| 
									
										
										
										
											2018-12-21 13:56:10 -05:00
										 |  |  | 	wlr_box_transform(&hotspot, &hotspot, | 
					
						
							| 
									
										
										
										
											2018-09-17 22:10:34 +02:00
										 |  |  | 		wlr_output_transform_invert(wlr_output->transform), | 
					
						
							| 
									
										
										
										
											2018-12-21 13:56:10 -05:00
										 |  |  | 		output->cursor.width, output->cursor.height); | 
					
						
							| 
									
										
										
										
											2018-05-09 19:58:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-01 14:25:41 +01:00
										 |  |  | 	// TODO: use output->wlr_output.transform to transform pixels and hotpot
 | 
					
						
							| 
									
										
										
										
											2018-05-09 19:58:18 +01:00
										 |  |  | 	output->cursor.hotspot_x = hotspot.x; | 
					
						
							|  |  |  | 	output->cursor.hotspot_y = hotspot.y; | 
					
						
							| 
									
										
										
										
											2017-10-29 17:43:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-01 21:38:04 +01:00
										 |  |  | 	if (!update_texture) { | 
					
						
							| 
									
										
										
										
											2017-10-12 09:40:51 +02:00
										 |  |  | 		// Update hotspot without changing cursor image
 | 
					
						
							| 
									
										
										
										
											2018-04-25 23:24:58 +01:00
										 |  |  | 		update_wl_output_cursor(output); | 
					
						
							| 
									
										
										
										
											2017-10-12 09:40:51 +02:00
										 |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-10-08 21:21:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-01 21:38:04 +01:00
										 |  |  | 	if (output->cursor.surface == NULL) { | 
					
						
							| 
									
										
										
										
											2017-10-29 17:43:26 +01:00
										 |  |  | 		output->cursor.surface = | 
					
						
							| 
									
										
										
										
											2018-05-01 21:38:04 +01:00
										 |  |  | 			wl_compositor_create_surface(backend->compositor); | 
					
						
							| 
									
										
										
										
											2017-08-14 18:19:42 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-01 21:38:04 +01:00
										 |  |  | 	struct wl_surface *surface = output->cursor.surface; | 
					
						
							| 
									
										
										
										
											2017-08-14 18:19:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-01 21:38:04 +01:00
										 |  |  | 	if (texture != NULL) { | 
					
						
							| 
									
										
										
										
											2020-12-25 12:21:29 +01:00
										 |  |  | 		int width = texture->width * wlr_output->scale / scale; | 
					
						
							|  |  |  | 		int height = texture->height * wlr_output->scale / scale; | 
					
						
							| 
									
										
										
										
											2018-05-09 19:58:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-26 13:18:44 +01:00
										 |  |  | 		if (output->cursor.swapchain == NULL || | 
					
						
							|  |  |  | 				output->cursor.swapchain->width != width || | 
					
						
							|  |  |  | 				output->cursor.swapchain->height != height) { | 
					
						
							|  |  |  | 			wlr_swapchain_destroy(output->cursor.swapchain); | 
					
						
							| 
									
										
										
										
											2021-04-29 00:16:34 +02:00
										 |  |  | 			output->cursor.swapchain = wlr_swapchain_create(allocator, | 
					
						
							|  |  |  | 				width, height, output->backend->format); | 
					
						
							| 
									
										
										
										
											2020-11-26 13:18:44 +01:00
										 |  |  | 			if (output->cursor.swapchain == NULL) { | 
					
						
							|  |  |  | 				return false; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-08-14 18:19:42 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-26 13:18:44 +01:00
										 |  |  | 		struct wlr_buffer *wlr_buffer = | 
					
						
							|  |  |  | 			wlr_swapchain_acquire(output->cursor.swapchain, NULL); | 
					
						
							|  |  |  | 		if (wlr_buffer == NULL) { | 
					
						
							|  |  |  | 			return false; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-08-14 18:19:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-29 00:16:34 +02:00
										 |  |  | 		if (!wlr_renderer_bind_buffer(renderer, wlr_buffer)) { | 
					
						
							| 
									
										
										
										
											2020-11-26 13:18:44 +01:00
										 |  |  | 			return false; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-08-14 18:19:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-09 19:58:18 +01:00
										 |  |  | 		struct wlr_box cursor_box = { | 
					
						
							|  |  |  | 			.width = width, | 
					
						
							|  |  |  | 			.height = height, | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-04 13:22:28 -05:00
										 |  |  | 		float output_matrix[9]; | 
					
						
							|  |  |  | 		wlr_matrix_identity(output_matrix); | 
					
						
							|  |  |  | 		if (wlr_output->transform != WL_OUTPUT_TRANSFORM_NORMAL) { | 
					
						
							| 
									
										
										
										
											2021-03-11 09:49:38 +01:00
										 |  |  | 			struct wlr_box tr_size = { .width = width, .height = height }; | 
					
						
							|  |  |  | 			wlr_box_transform(&tr_size, &tr_size, wlr_output->transform, 0, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-04 13:22:28 -05:00
										 |  |  | 			wlr_matrix_translate(output_matrix, width / 2.0, height / 2.0); | 
					
						
							|  |  |  | 			wlr_matrix_transform(output_matrix, wlr_output->transform); | 
					
						
							| 
									
										
										
										
											2021-03-11 09:49:38 +01:00
										 |  |  | 			wlr_matrix_translate(output_matrix, | 
					
						
							|  |  |  | 				- tr_size.width / 2.0, - tr_size.height / 2.0); | 
					
						
							| 
									
										
										
										
											2021-03-04 13:22:28 -05:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-05-09 19:58:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-01 21:38:04 +01:00
										 |  |  | 		float matrix[9]; | 
					
						
							| 
									
										
										
										
											2021-03-04 13:22:28 -05:00
										 |  |  | 		wlr_matrix_project_box(matrix, &cursor_box, transform, 0, output_matrix); | 
					
						
							| 
									
										
										
										
											2018-05-01 21:38:04 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-29 00:16:34 +02:00
										 |  |  | 		wlr_renderer_begin(renderer, width, height); | 
					
						
							|  |  |  | 		wlr_renderer_clear(renderer, (float[]){ 0.0, 0.0, 0.0, 0.0 }); | 
					
						
							|  |  |  | 		wlr_render_texture_with_matrix(renderer, texture, matrix, 1.0); | 
					
						
							|  |  |  | 		wlr_renderer_end(renderer); | 
					
						
							| 
									
										
										
										
											2018-05-01 21:38:04 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-29 00:16:34 +02:00
										 |  |  | 		wlr_renderer_bind_buffer(renderer, NULL); | 
					
						
							| 
									
										
										
										
											2020-11-26 13:18:44 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		struct wlr_wl_buffer *buffer = | 
					
						
							| 
									
										
										
										
											2021-01-04 12:55:40 +01:00
										 |  |  | 			get_or_create_wl_buffer(output->backend, wlr_buffer); | 
					
						
							| 
									
										
										
										
											2020-11-26 13:18:44 +01:00
										 |  |  | 		if (buffer == NULL) { | 
					
						
							|  |  |  | 			return false; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		wl_surface_attach(surface, buffer->wl_buffer, 0, 0); | 
					
						
							|  |  |  | 		wl_surface_damage_buffer(surface, 0, 0, INT32_MAX, INT32_MAX); | 
					
						
							|  |  |  | 		wl_surface_commit(surface); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		wlr_buffer_unlock(wlr_buffer); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		output->cursor.width = width; | 
					
						
							|  |  |  | 		output->cursor.height = height; | 
					
						
							| 
									
										
										
										
											2018-05-01 21:38:04 +01:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		wl_surface_attach(surface, NULL, 0, 0); | 
					
						
							|  |  |  | 		wl_surface_commit(surface); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-08-14 18:19:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-25 23:24:58 +01:00
										 |  |  | 	update_wl_output_cursor(output); | 
					
						
							| 
									
										
										
										
											2021-01-29 10:06:16 +01:00
										 |  |  | 	wl_display_flush(backend->remote_display); | 
					
						
							| 
									
										
										
										
											2017-08-14 18:19:42 +02:00
										 |  |  | 	return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-25 23:51:00 +01:00
										 |  |  | static void output_destroy(struct wlr_output *wlr_output) { | 
					
						
							| 
									
										
										
										
											2018-09-17 22:10:34 +02:00
										 |  |  | 	struct wlr_wl_output *output = get_wl_output_from_output(wlr_output); | 
					
						
							| 
									
										
										
										
											2018-01-30 19:45:57 +01:00
										 |  |  | 	if (output == NULL) { | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-10-29 17:43:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-13 21:48:59 +01:00
										 |  |  | 	wl_list_remove(&output->link); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-26 13:18:44 +01:00
										 |  |  | 	wlr_swapchain_destroy(output->cursor.swapchain); | 
					
						
							| 
									
										
										
										
											2017-10-29 17:43:26 +01:00
										 |  |  | 	if (output->cursor.surface) { | 
					
						
							|  |  |  | 		wl_surface_destroy(output->cursor.surface); | 
					
						
							| 
									
										
										
										
											2017-08-14 18:19:42 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-12 11:43:36 -04:00
										 |  |  | 	if (output->frame_callback) { | 
					
						
							|  |  |  | 		wl_callback_destroy(output->frame_callback); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-12-13 21:48:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-16 21:05:46 +01:00
										 |  |  | 	struct wlr_wl_presentation_feedback *feedback, *feedback_tmp; | 
					
						
							|  |  |  | 	wl_list_for_each_safe(feedback, feedback_tmp, | 
					
						
							|  |  |  | 			&output->presentation_feedbacks, link) { | 
					
						
							|  |  |  | 		presentation_feedback_destroy(feedback); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-26 11:40:23 +01:00
										 |  |  | 	wlr_buffer_unlock(output->back_buffer); | 
					
						
							|  |  |  | 	wlr_swapchain_destroy(output->swapchain); | 
					
						
							| 
									
										
										
										
											2019-05-06 19:06:31 +03:00
										 |  |  | 	if (output->zxdg_toplevel_decoration_v1) { | 
					
						
							|  |  |  | 		zxdg_toplevel_decoration_v1_destroy(output->zxdg_toplevel_decoration_v1); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-01-10 09:17:14 -05:00
										 |  |  | 	xdg_toplevel_destroy(output->xdg_toplevel); | 
					
						
							|  |  |  | 	xdg_surface_destroy(output->xdg_surface); | 
					
						
							| 
									
										
										
										
											2017-06-19 22:36:40 +02:00
										 |  |  | 	wl_surface_destroy(output->surface); | 
					
						
							| 
									
										
										
										
											2021-01-29 10:06:16 +01:00
										 |  |  | 	wl_display_flush(output->backend->remote_display); | 
					
						
							| 
									
										
										
										
											2017-06-19 22:36:40 +02:00
										 |  |  | 	free(output); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-29 12:16:31 +01:00
										 |  |  | void update_wl_output_cursor(struct wlr_wl_output *output) { | 
					
						
							| 
									
										
										
										
											2020-10-09 22:17:17 +02:00
										 |  |  | 	struct wlr_wl_pointer *pointer = output->cursor.pointer; | 
					
						
							|  |  |  | 	if (pointer) { | 
					
						
							|  |  |  | 		assert(pointer->output == output); | 
					
						
							|  |  |  | 		assert(output->enter_serial); | 
					
						
							| 
									
										
										
										
											2020-10-03 15:06:05 +02:00
										 |  |  | 		wl_pointer_set_cursor(pointer->wl_pointer, output->enter_serial, | 
					
						
							| 
									
										
										
										
											2017-10-29 17:43:26 +01:00
										 |  |  | 			output->cursor.surface, output->cursor.hotspot_x, | 
					
						
							|  |  |  | 			output->cursor.hotspot_y); | 
					
						
							| 
									
										
										
										
											2017-08-14 18:19:42 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-05 16:14:22 +02:00
										 |  |  | static bool output_move_cursor(struct wlr_output *_output, int x, int y) { | 
					
						
							| 
									
										
										
										
											2017-08-14 18:19:42 +02:00
										 |  |  | 	// TODO: only return true if x == current x and y == current y
 | 
					
						
							|  |  |  | 	return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-25 23:51:00 +01:00
										 |  |  | static const struct wlr_output_impl output_impl = { | 
					
						
							|  |  |  | 	.destroy = output_destroy, | 
					
						
							| 
									
										
										
										
											2019-04-23 19:26:21 +03:00
										 |  |  | 	.attach_render = output_attach_render, | 
					
						
							| 
									
										
										
										
											2020-04-02 12:41:19 +02:00
										 |  |  | 	.test = output_test, | 
					
						
							| 
									
										
										
										
											2019-04-23 19:26:21 +03:00
										 |  |  | 	.commit = output_commit, | 
					
						
							| 
									
										
										
										
											2020-06-19 15:49:55 +02:00
										 |  |  | 	.rollback_render = output_rollback_render, | 
					
						
							| 
									
										
										
										
											2018-04-25 23:51:00 +01:00
										 |  |  | 	.set_cursor = output_set_cursor, | 
					
						
							|  |  |  | 	.move_cursor = output_move_cursor, | 
					
						
							| 
									
										
										
										
											2017-06-19 22:36:40 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-19 19:55:18 +01:00
										 |  |  | bool wlr_output_is_wl(struct wlr_output *wlr_output) { | 
					
						
							|  |  |  | 	return wlr_output->impl == &output_impl; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-10 09:17:14 -05:00
										 |  |  | static void xdg_surface_handle_configure(void *data, | 
					
						
							|  |  |  | 		struct xdg_surface *xdg_surface, uint32_t serial) { | 
					
						
							| 
									
										
										
										
											2018-04-29 12:16:31 +01:00
										 |  |  | 	struct wlr_wl_output *output = data; | 
					
						
							| 
									
										
										
										
											2017-08-16 19:19:31 +02:00
										 |  |  | 	assert(output && output->xdg_surface == xdg_surface); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-10 09:17:14 -05:00
										 |  |  | 	xdg_surface_ack_configure(xdg_surface, serial); | 
					
						
							| 
									
										
										
										
											2017-08-16 19:19:31 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// nothing else?
 | 
					
						
							| 
									
										
										
										
											2017-06-20 18:27:05 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 08:57:18 -05:00
										 |  |  | static const struct xdg_surface_listener xdg_surface_listener = { | 
					
						
							| 
									
										
										
										
											2017-08-16 19:19:31 +02:00
										 |  |  | 	.configure = xdg_surface_handle_configure, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-17 22:10:34 +02:00
										 |  |  | static void xdg_toplevel_handle_configure(void *data, | 
					
						
							| 
									
										
										
										
											2019-01-10 09:17:14 -05:00
										 |  |  | 		struct xdg_toplevel *xdg_toplevel, | 
					
						
							| 
									
										
										
										
											2017-08-16 19:19:31 +02:00
										 |  |  | 		int32_t width, int32_t height, struct wl_array *states) { | 
					
						
							| 
									
										
										
										
											2018-04-29 12:16:31 +01:00
										 |  |  | 	struct wlr_wl_output *output = data; | 
					
						
							| 
									
										
										
										
											2017-08-16 19:19:31 +02:00
										 |  |  | 	assert(output && output->xdg_toplevel == xdg_toplevel); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-30 11:08:49 +09:00
										 |  |  | 	if (width == 0 || height == 0) { | 
					
						
							| 
									
										
										
										
											2017-08-17 10:22:54 +02:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-08-16 19:19:31 +02:00
										 |  |  | 	// loop over states for maximized etc?
 | 
					
						
							| 
									
										
										
										
											2019-01-22 14:27:23 -05:00
										 |  |  | 	output_set_custom_mode(&output->wlr_output, width, height, 0); | 
					
						
							| 
									
										
										
										
											2017-06-20 18:27:05 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-17 22:10:34 +02:00
										 |  |  | static void xdg_toplevel_handle_close(void *data, | 
					
						
							| 
									
										
										
										
											2019-01-10 09:17:14 -05:00
										 |  |  | 		struct xdg_toplevel *xdg_toplevel) { | 
					
						
							| 
									
										
										
										
											2018-04-29 12:16:31 +01:00
										 |  |  | 	struct wlr_wl_output *output = data; | 
					
						
							| 
									
										
										
										
											2017-11-01 20:14:52 +01:00
										 |  |  | 	assert(output && output->xdg_toplevel == xdg_toplevel); | 
					
						
							| 
									
										
										
										
											2017-08-16 19:19:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-29 12:12:30 +01:00
										 |  |  | 	wlr_output_destroy(&output->wlr_output); | 
					
						
							| 
									
										
										
										
											2017-06-20 18:27:05 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 08:57:18 -05:00
										 |  |  | static const struct xdg_toplevel_listener xdg_toplevel_listener = { | 
					
						
							| 
									
										
										
										
											2017-08-16 19:19:31 +02:00
										 |  |  | 	.configure = xdg_toplevel_handle_configure, | 
					
						
							|  |  |  | 	.close = xdg_toplevel_handle_close, | 
					
						
							| 
									
										
										
										
											2017-06-20 18:27:05 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-17 22:10:34 +02:00
										 |  |  | struct wlr_output *wlr_wl_output_create(struct wlr_backend *wlr_backend) { | 
					
						
							|  |  |  | 	struct wlr_wl_backend *backend = get_wl_backend_from_backend(wlr_backend); | 
					
						
							| 
									
										
										
										
											2017-09-23 00:29:53 -04:00
										 |  |  | 	if (!backend->started) { | 
					
						
							| 
									
										
										
										
											2017-06-20 18:22:21 -04:00
										 |  |  | 		++backend->requested_outputs; | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-29 12:16:31 +01:00
										 |  |  | 	struct wlr_wl_output *output; | 
					
						
							|  |  |  | 	if (!(output = calloc(sizeof(struct wlr_wl_output), 1))) { | 
					
						
							| 
									
										
										
										
											2018-07-09 22:49:54 +01:00
										 |  |  | 		wlr_log(WLR_ERROR, "Failed to allocate wlr_wl_output"); | 
					
						
							| 
									
										
										
										
											2017-06-19 22:36:40 +02:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-01-04 12:46:15 +01:00
										 |  |  | 	wlr_output_init(&output->wlr_output, &backend->backend, &output_impl, | 
					
						
							|  |  |  | 		backend->local_display); | 
					
						
							| 
									
										
										
										
											2017-08-13 10:51:50 -04:00
										 |  |  | 	struct wlr_output *wlr_output = &output->wlr_output; | 
					
						
							| 
									
										
										
										
											2017-06-19 22:36:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-17 18:02:55 +01:00
										 |  |  | 	wlr_output_update_custom_mode(wlr_output, 1280, 720, 0); | 
					
						
							| 
									
										
										
										
											2017-06-20 15:29:27 -04:00
										 |  |  | 	strncpy(wlr_output->make, "wayland", sizeof(wlr_output->make)); | 
					
						
							|  |  |  | 	strncpy(wlr_output->model, "wayland", sizeof(wlr_output->model)); | 
					
						
							| 
									
										
										
										
											2019-04-08 18:49:25 +00:00
										 |  |  | 	snprintf(wlr_output->name, sizeof(wlr_output->name), "WL-%zd", | 
					
						
							| 
									
										
										
										
											2019-03-15 03:18:06 -04:00
										 |  |  | 		++backend->last_output_num); | 
					
						
							| 
									
										
										
										
											2017-06-19 22:36:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-26 16:09:05 +01:00
										 |  |  | 	char description[128]; | 
					
						
							|  |  |  | 	snprintf(description, sizeof(description), | 
					
						
							|  |  |  | 		"Wayland output %zd", backend->last_output_num); | 
					
						
							|  |  |  | 	wlr_output_set_description(wlr_output, description); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-13 10:51:50 -04:00
										 |  |  | 	output->backend = backend; | 
					
						
							| 
									
										
										
										
											2019-11-16 21:05:46 +01:00
										 |  |  | 	wl_list_init(&output->presentation_feedbacks); | 
					
						
							| 
									
										
										
										
											2017-06-20 18:27:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-13 10:51:50 -04:00
										 |  |  | 	output->surface = wl_compositor_create_surface(backend->compositor); | 
					
						
							| 
									
										
										
										
											2017-08-16 19:33:16 +02:00
										 |  |  | 	if (!output->surface) { | 
					
						
							| 
									
										
										
										
											2018-07-09 22:49:54 +01:00
										 |  |  | 		wlr_log_errno(WLR_ERROR, "Could not create output surface"); | 
					
						
							| 
									
										
										
										
											2017-08-16 19:33:16 +02:00
										 |  |  | 		goto error; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-04-29 13:37:29 +01:00
										 |  |  | 	wl_surface_set_user_data(output->surface, output); | 
					
						
							| 
									
										
										
										
											2017-08-16 19:19:31 +02:00
										 |  |  | 	output->xdg_surface = | 
					
						
							| 
									
										
										
										
											2019-01-10 09:17:14 -05:00
										 |  |  | 		xdg_wm_base_get_xdg_surface(backend->xdg_wm_base, output->surface); | 
					
						
							| 
									
										
										
										
											2017-08-16 19:33:16 +02:00
										 |  |  | 	if (!output->xdg_surface) { | 
					
						
							| 
									
										
										
										
											2018-07-09 22:49:54 +01:00
										 |  |  | 		wlr_log_errno(WLR_ERROR, "Could not get xdg surface"); | 
					
						
							| 
									
										
										
										
											2017-08-16 19:33:16 +02:00
										 |  |  | 		goto error; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-08-16 19:19:31 +02:00
										 |  |  | 	output->xdg_toplevel = | 
					
						
							| 
									
										
										
										
											2019-01-10 09:17:14 -05:00
										 |  |  | 		xdg_surface_get_toplevel(output->xdg_surface); | 
					
						
							| 
									
										
										
										
											2017-08-16 19:33:16 +02:00
										 |  |  | 	if (!output->xdg_toplevel) { | 
					
						
							| 
									
										
										
										
											2018-07-09 22:49:54 +01:00
										 |  |  | 		wlr_log_errno(WLR_ERROR, "Could not get xdg toplevel"); | 
					
						
							| 
									
										
										
										
											2017-08-16 19:33:16 +02:00
										 |  |  | 		goto error; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-08-16 19:19:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-06 19:06:31 +03:00
										 |  |  | 	if (backend->zxdg_decoration_manager_v1) { | 
					
						
							|  |  |  | 		output->zxdg_toplevel_decoration_v1 = | 
					
						
							|  |  |  | 			zxdg_decoration_manager_v1_get_toplevel_decoration( | 
					
						
							|  |  |  | 			backend->zxdg_decoration_manager_v1, output->xdg_toplevel); | 
					
						
							| 
									
										
										
										
											2019-08-09 16:23:10 +02:00
										 |  |  | 		if (!output->zxdg_toplevel_decoration_v1) { | 
					
						
							| 
									
										
										
										
											2019-05-06 19:06:31 +03:00
										 |  |  | 			wlr_log_errno(WLR_ERROR, "Could not get xdg toplevel decoration"); | 
					
						
							|  |  |  | 			goto error; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		zxdg_toplevel_decoration_v1_set_mode(output->zxdg_toplevel_decoration_v1, | 
					
						
							|  |  |  | 			ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 13:48:26 +01:00
										 |  |  | 	wlr_wl_output_set_title(wlr_output, NULL); | 
					
						
							| 
									
										
										
										
											2018-05-15 00:16:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-10 09:17:14 -05:00
										 |  |  | 	xdg_toplevel_set_app_id(output->xdg_toplevel, "wlroots"); | 
					
						
							|  |  |  | 	xdg_surface_add_listener(output->xdg_surface, | 
					
						
							| 
									
										
										
										
											2017-08-16 19:19:31 +02:00
										 |  |  | 			&xdg_surface_listener, output); | 
					
						
							| 
									
										
										
										
											2019-01-10 09:17:14 -05:00
										 |  |  | 	xdg_toplevel_add_listener(output->xdg_toplevel, | 
					
						
							| 
									
										
										
										
											2017-08-16 19:19:31 +02:00
										 |  |  | 			&xdg_toplevel_listener, output); | 
					
						
							| 
									
										
										
										
											2017-08-17 00:52:01 +02:00
										 |  |  | 	wl_surface_commit(output->surface); | 
					
						
							| 
									
										
										
										
											2017-06-20 18:27:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-29 00:16:34 +02:00
										 |  |  | 	struct wlr_allocator *allocator = backend_get_allocator(&backend->backend); | 
					
						
							|  |  |  | 	output->swapchain = wlr_swapchain_create(allocator, | 
					
						
							| 
									
										
										
										
											2020-11-26 11:40:23 +01:00
										 |  |  | 		wlr_output->width, wlr_output->height, output->backend->format); | 
					
						
							|  |  |  | 	if (output->swapchain == NULL) { | 
					
						
							|  |  |  | 		goto error; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-06-19 22:36:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-17 10:22:54 +02:00
										 |  |  | 	wl_display_roundtrip(output->backend->remote_display); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-14 23:33:00 +03:00
										 |  |  | 	wl_list_insert(&backend->outputs, &output->link); | 
					
						
							| 
									
										
										
										
											2018-01-04 12:46:15 +01:00
										 |  |  | 	wlr_output_update_enabled(wlr_output, true); | 
					
						
							| 
									
										
										
										
											2018-04-29 12:16:31 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-12 10:36:43 +01:00
										 |  |  | 	wlr_signal_emit_safe(&backend->backend.events.new_output, wlr_output); | 
					
						
							| 
									
										
										
										
											2018-04-29 12:16:31 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-03 23:06:10 +02:00
										 |  |  | 	struct wlr_wl_seat *seat; | 
					
						
							|  |  |  | 	wl_list_for_each(seat, &backend->seats, link) { | 
					
						
							| 
									
										
										
										
											2020-10-03 17:34:32 +02:00
										 |  |  | 		if (seat->pointer) { | 
					
						
							| 
									
										
										
										
											2020-10-03 22:11:38 +02:00
										 |  |  | 			create_wl_pointer(seat, output); | 
					
						
							| 
									
										
										
										
											2020-10-03 17:34:32 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-04-29 12:16:31 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-26 11:13:52 +01:00
										 |  |  | 	// Start the rendering loop by requesting the compositor to render a frame
 | 
					
						
							|  |  |  | 	wlr_output_schedule_frame(wlr_output); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-19 22:36:40 +02:00
										 |  |  | 	return wlr_output; | 
					
						
							| 
									
										
										
										
											2017-08-16 19:33:16 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | error: | 
					
						
							|  |  |  | 	wlr_output_destroy(&output->wlr_output); | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							| 
									
										
										
										
											2017-06-19 22:36:40 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-01-10 21:53:32 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | void wlr_wl_output_set_title(struct wlr_output *output, const char *title) { | 
					
						
							|  |  |  | 	struct wlr_wl_output *wl_output = get_wl_output_from_output(output); | 
					
						
							| 
									
										
										
										
											2019-01-24 13:48:26 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	char wl_title[32]; | 
					
						
							|  |  |  | 	if (title == NULL) { | 
					
						
							|  |  |  | 		if (snprintf(wl_title, sizeof(wl_title), "wlroots - %s", output->name) <= 0) { | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		title = wl_title; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-10 21:53:32 -05:00
										 |  |  | 	xdg_toplevel_set_title(wl_output->xdg_toplevel, title); | 
					
						
							| 
									
										
										
										
											2021-01-29 10:06:16 +01:00
										 |  |  | 	wl_display_flush(wl_output->backend->remote_display); | 
					
						
							| 
									
										
										
										
											2019-01-10 21:53:32 -05:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-11-12 17:56:57 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | struct wl_surface *wlr_wl_output_get_surface(struct wlr_output *output) { | 
					
						
							|  |  |  | 	struct wlr_wl_output *wl_output = get_wl_output_from_output(output); | 
					
						
							|  |  |  | 	return wl_output->surface; | 
					
						
							|  |  |  | } |