aboutsummaryrefslogtreecommitdiffstats
path: root/sway/desktop/output.c
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2017-11-22 21:06:08 -0500
committerLibravatar Drew DeVault <sir@cmpwn.com>2017-11-22 21:06:08 -0500
commit4ca1e77fdbbf559a5bb28d4936afa6ade63985cd (patch)
tree935c9a56d20f591688d196a85cecfc6080727d26 /sway/desktop/output.c
parentAdd workspace to outputs (diff)
downloadsway-4ca1e77fdbbf559a5bb28d4936afa6ade63985cd.tar.gz
sway-4ca1e77fdbbf559a5bb28d4936afa6ade63985cd.tar.zst
sway-4ca1e77fdbbf559a5bb28d4936afa6ade63985cd.zip
Add views to tree and render them
Diffstat (limited to 'sway/desktop/output.c')
-rw-r--r--sway/desktop/output.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/sway/desktop/output.c b/sway/desktop/output.c
index 27579c1b..9e0c18e4 100644
--- a/sway/desktop/output.c
+++ b/sway/desktop/output.c
@@ -3,11 +3,82 @@
3#include <time.h> 3#include <time.h>
4#include <wayland-server.h> 4#include <wayland-server.h>
5#include <wlr/types/wlr_output.h> 5#include <wlr/types/wlr_output.h>
6#include <wlr/types/wlr_surface.h>
6#include <wlr/render.h> 7#include <wlr/render.h>
8#include <wlr/render/matrix.h>
7#include "log.h" 9#include "log.h"
8#include "sway/container.h" 10#include "sway/container.h"
9#include "sway/output.h" 11#include "sway/output.h"
10#include "sway/server.h" 12#include "sway/server.h"
13#include "sway/view.h"
14
15static inline int64_t timespec_to_msec(const struct timespec *a) {
16 return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000;
17}
18
19static void output_frame_view(swayc_t *view, void *data) {
20 struct sway_output *output = data;
21 struct wlr_output *wlr_output = output->wlr_output;
22 struct sway_view *sway_view = view->sway_view;
23 struct wlr_surface *surface = sway_view->surface;
24 if (!wlr_surface_has_buffer(surface)) {
25 return;
26 }
27 // TODO
28 // - Force sway's resolution
29 // - Deal with wlr_output_layout
30 int width = surface->current->width;
31 int height = surface->current->height;
32 int render_width = width * wlr_output->scale;
33 int render_height = height * wlr_output->scale;
34 double ox = view->x, oy = view->y;
35 // TODO
36 //wlr_output_layout_output_coords(desktop->layout, wlr_output, &ox, &oy);
37 ox *= wlr_output->scale;
38 oy *= wlr_output->scale;
39 // TODO
40 //if (wlr_output_layout_intersects(desktop->layout, wlr_output,
41 // lx, ly, lx + render_width, ly + render_height)) {
42 // return;
43 //}
44
45 // TODO
46 double rotation = 0;
47 float matrix[16];
48
49 float translate_origin[16];
50 wlr_matrix_translate(&translate_origin,
51 (int)ox + render_width / 2, (int)oy + render_height / 2, 0);
52
53 float rotate[16];
54 wlr_matrix_rotate(&rotate, rotation);
55
56 float translate_center[16];
57 wlr_matrix_translate(&translate_center, -render_width / 2,
58 -render_height / 2, 0);
59
60 float scale[16];
61 wlr_matrix_scale(&scale, render_width, render_height, 1);
62
63 float transform[16];
64 wlr_matrix_mul(&translate_origin, &rotate, &transform);
65 wlr_matrix_mul(&transform, &translate_center, &transform);
66 wlr_matrix_mul(&transform, &scale, &transform);
67 wlr_matrix_mul(&wlr_output->transform_matrix, &transform, &matrix);
68
69 wlr_render_with_matrix(output->server->renderer, surface->texture, &matrix);
70
71 // TODO: move into wlroots
72 struct timespec now;
73 clock_gettime(CLOCK_MONOTONIC, &now);
74
75 struct wlr_frame_callback *cb, *cnext;
76 wl_list_for_each_safe(cb, cnext,
77 &surface->current->frame_callback_list, link) {
78 wl_callback_send_done(cb->resource, timespec_to_msec(&now));
79 wl_resource_destroy(cb->resource);
80 }
81}
11 82
12static void output_frame_notify(struct wl_listener *listener, void *data) { 83static void output_frame_notify(struct wl_listener *listener, void *data) {
13 struct sway_output *soutput = wl_container_of( 84 struct sway_output *soutput = wl_container_of(
@@ -21,6 +92,9 @@ static void output_frame_notify(struct wl_listener *listener, void *data) {
21 wlr_output_make_current(wlr_output); 92 wlr_output_make_current(wlr_output);
22 wlr_renderer_begin(server->renderer, wlr_output); 93 wlr_renderer_begin(server->renderer, wlr_output);
23 94
95 swayc_descendants_of_type(
96 &root_container, C_VIEW, output_frame_view, soutput);
97
24 wlr_renderer_end(server->renderer); 98 wlr_renderer_end(server->renderer);
25 wlr_output_swap_buffers(wlr_output); 99 wlr_output_swap_buffers(wlr_output);
26 100