diff options
author | Drew DeVault <sir@cmpwn.com> | 2017-11-22 21:06:08 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2017-11-22 21:06:08 -0500 |
commit | 4ca1e77fdbbf559a5bb28d4936afa6ade63985cd (patch) | |
tree | 935c9a56d20f591688d196a85cecfc6080727d26 | |
parent | Add workspace to outputs (diff) | |
download | sway-4ca1e77fdbbf559a5bb28d4936afa6ade63985cd.tar.gz sway-4ca1e77fdbbf559a5bb28d4936afa6ade63985cd.tar.zst sway-4ca1e77fdbbf559a5bb28d4936afa6ade63985cd.zip |
Add views to tree and render them
-rw-r--r-- | include/sway/container.h | 4 | ||||
-rw-r--r-- | include/sway/server.h | 2 | ||||
-rw-r--r-- | include/sway/view.h | 2 | ||||
-rw-r--r-- | sway/desktop/output.c | 74 | ||||
-rw-r--r-- | sway/desktop/xdg_shell_v6.c | 11 | ||||
-rw-r--r-- | sway/server.c | 4 | ||||
-rw-r--r-- | sway/tree/container.c | 39 |
7 files changed, 136 insertions, 0 deletions
diff --git a/include/sway/container.h b/include/sway/container.h index 2a96165f..96e4db69 100644 --- a/include/sway/container.h +++ b/include/sway/container.h | |||
@@ -125,7 +125,11 @@ struct sway_container { | |||
125 | list_t *marks; | 125 | list_t *marks; |
126 | }; | 126 | }; |
127 | 127 | ||
128 | void swayc_descendants_of_type(swayc_t *root, enum swayc_types type, | ||
129 | void (*func)(swayc_t *item, void *data), void *data); | ||
130 | |||
128 | swayc_t *new_output(struct sway_output *sway_output); | 131 | swayc_t *new_output(struct sway_output *sway_output); |
129 | swayc_t *new_workspace(swayc_t *output, const char *name); | 132 | swayc_t *new_workspace(swayc_t *output, const char *name); |
133 | swayc_t *new_view(swayc_t *sibling, struct sway_view *sway_view); | ||
130 | 134 | ||
131 | #endif | 135 | #endif |
diff --git a/include/sway/server.h b/include/sway/server.h index 60f35190..b0684d15 100644 --- a/include/sway/server.h +++ b/include/sway/server.h | |||
@@ -4,6 +4,7 @@ | |||
4 | #include <wayland-server.h> | 4 | #include <wayland-server.h> |
5 | #include <wlr/backend.h> | 5 | #include <wlr/backend.h> |
6 | #include <wlr/backend/session.h> | 6 | #include <wlr/backend/session.h> |
7 | #include <wlr/types/wlr_compositor.h> | ||
7 | #include <wlr/types/wlr_data_device.h> | 8 | #include <wlr/types/wlr_data_device.h> |
8 | #include <wlr/types/wlr_xdg_shell_v6.h> | 9 | #include <wlr/types/wlr_xdg_shell_v6.h> |
9 | #include <wlr/render.h> | 10 | #include <wlr/render.h> |
@@ -18,6 +19,7 @@ struct sway_server { | |||
18 | struct wlr_backend *backend; | 19 | struct wlr_backend *backend; |
19 | struct wlr_renderer *renderer; | 20 | struct wlr_renderer *renderer; |
20 | 21 | ||
22 | struct wlr_compositor *compositor; | ||
21 | struct wlr_data_device_manager *data_device_manager; | 23 | struct wlr_data_device_manager *data_device_manager; |
22 | 24 | ||
23 | struct sway_input *input; | 25 | struct sway_input *input; |
diff --git a/include/sway/view.h b/include/sway/view.h index 979b20a8..2675a6f5 100644 --- a/include/sway/view.h +++ b/include/sway/view.h | |||
@@ -1,6 +1,7 @@ | |||
1 | #ifndef _SWAY_VIEW_H | 1 | #ifndef _SWAY_VIEW_H |
2 | #define _SWAY_VIEW_H | 2 | #define _SWAY_VIEW_H |
3 | #include <wayland-server.h> | 3 | #include <wayland-server.h> |
4 | #include <wlr/types/wlr_surface.h> | ||
4 | #include <wlr/types/wlr_xdg_shell_v6.h> | 5 | #include <wlr/types/wlr_xdg_shell_v6.h> |
5 | 6 | ||
6 | struct sway_container; | 7 | struct sway_container; |
@@ -38,6 +39,7 @@ struct sway_view { | |||
38 | struct wl_listener destroy; | 39 | struct wl_listener destroy; |
39 | enum sway_view_type type; | 40 | enum sway_view_type type; |
40 | struct sway_container *swayc; | 41 | struct sway_container *swayc; |
42 | struct wlr_surface *surface; | ||
41 | 43 | ||
42 | union { | 44 | union { |
43 | struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6; | 45 | struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6; |
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 | |||
15 | static inline int64_t timespec_to_msec(const struct timespec *a) { | ||
16 | return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000; | ||
17 | } | ||
18 | |||
19 | static 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 | ||
12 | static void output_frame_notify(struct wl_listener *listener, void *data) { | 83 | static 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 | ||
diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index b3dbcfbe..e2a61ebf 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c | |||
@@ -2,6 +2,7 @@ | |||
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | #include <wayland-server.h> | 3 | #include <wayland-server.h> |
4 | #include <wlr/types/wlr_xdg_shell_v6.h> | 4 | #include <wlr/types/wlr_xdg_shell_v6.h> |
5 | #include "sway/container.h" | ||
5 | #include "sway/server.h" | 6 | #include "sway/server.h" |
6 | #include "sway/view.h" | 7 | #include "sway/view.h" |
7 | #include "log.h" | 8 | #include "log.h" |
@@ -47,6 +48,9 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { | |||
47 | } | 48 | } |
48 | sway_view->type = SWAY_XDG_SHELL_V6_VIEW; | 49 | sway_view->type = SWAY_XDG_SHELL_V6_VIEW; |
49 | sway_view->iface.get_prop = get_prop; | 50 | sway_view->iface.get_prop = get_prop; |
51 | sway_view->wlr_xdg_surface_v6 = xdg_surface; | ||
52 | sway_view->sway_xdg_surface_v6 = sway_surface; | ||
53 | sway_view->surface = xdg_surface->surface; | ||
50 | sway_surface->view = sway_view; | 54 | sway_surface->view = sway_view; |
51 | 55 | ||
52 | // TODO: | 56 | // TODO: |
@@ -56,4 +60,11 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { | |||
56 | // - Look up pid and open on appropriate workspace | 60 | // - Look up pid and open on appropriate workspace |
57 | // - Set new view to maximized so it behaves nicely | 61 | // - Set new view to maximized so it behaves nicely |
58 | // - Criteria | 62 | // - Criteria |
63 | |||
64 | // TODO: actual focus semantics | ||
65 | swayc_t *parent = root_container.children->items[0]; | ||
66 | parent = parent->children->items[0]; // workspace | ||
67 | |||
68 | swayc_t *cont = new_view(parent, sway_view); | ||
69 | sway_view->swayc = cont; | ||
59 | } | 70 | } |
diff --git a/sway/server.c b/sway/server.c index f78bcef1..6e66bc3c 100644 --- a/sway/server.c +++ b/sway/server.c | |||
@@ -6,6 +6,7 @@ | |||
6 | #include <wlr/backend/session.h> | 6 | #include <wlr/backend/session.h> |
7 | #include <wlr/render.h> | 7 | #include <wlr/render.h> |
8 | #include <wlr/render/gles2.h> | 8 | #include <wlr/render/gles2.h> |
9 | #include <wlr/types/wlr_compositor.h> | ||
9 | // TODO WLR: make Xwayland optional | 10 | // TODO WLR: make Xwayland optional |
10 | #include <wlr/xwayland.h> | 11 | #include <wlr/xwayland.h> |
11 | #include "sway/server.h" | 12 | #include "sway/server.h" |
@@ -21,6 +22,9 @@ bool server_init(struct sway_server *server) { | |||
21 | server->renderer = wlr_gles2_renderer_create(server->backend); | 22 | server->renderer = wlr_gles2_renderer_create(server->backend); |
22 | wl_display_init_shm(server->wl_display); | 23 | wl_display_init_shm(server->wl_display); |
23 | 24 | ||
25 | server->compositor = wlr_compositor_create( | ||
26 | server->wl_display, server->renderer); | ||
27 | |||
24 | server->data_device_manager = | 28 | server->data_device_manager = |
25 | wlr_data_device_manager_create(server->wl_display); | 29 | wlr_data_device_manager_create(server->wl_display); |
26 | 30 | ||
diff --git a/sway/tree/container.c b/sway/tree/container.c index ac79356a..d3931612 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -5,9 +5,23 @@ | |||
5 | #include "sway/container.h" | 5 | #include "sway/container.h" |
6 | #include "sway/layout.h" | 6 | #include "sway/layout.h" |
7 | #include "sway/output.h" | 7 | #include "sway/output.h" |
8 | #include "sway/view.h" | ||
8 | #include "sway/workspace.h" | 9 | #include "sway/workspace.h" |
9 | #include "log.h" | 10 | #include "log.h" |
10 | 11 | ||
12 | void swayc_descendants_of_type(swayc_t *root, enum swayc_types type, | ||
13 | void (*func)(swayc_t *item, void *data), void *data) { | ||
14 | for (int i = 0; i < root->children->length; ++i) { | ||
15 | swayc_t *item = root->children->items[i]; | ||
16 | if (item->type == type) { | ||
17 | func(item, data); | ||
18 | } | ||
19 | if (item->children && item->children->length) { | ||
20 | swayc_descendants_of_type(item, type, func, data); | ||
21 | } | ||
22 | } | ||
23 | } | ||
24 | |||
11 | static swayc_t *new_swayc(enum swayc_types type) { | 25 | static swayc_t *new_swayc(enum swayc_types type) { |
12 | // next id starts at 1 because 0 is assigned to root_container in layout.c | 26 | // next id starts at 1 because 0 is assigned to root_container in layout.c |
13 | static size_t next_id = 1; | 27 | static size_t next_id = 1; |
@@ -69,3 +83,28 @@ swayc_t *new_workspace(swayc_t *output, const char *name) { | |||
69 | sort_workspaces(output); | 83 | sort_workspaces(output); |
70 | return workspace; | 84 | return workspace; |
71 | } | 85 | } |
86 | |||
87 | swayc_t *new_view(swayc_t *sibling, struct sway_view *sway_view) { | ||
88 | if (!sway_assert(sibling, "new_view called with NULL sibling/parent")) { | ||
89 | return NULL; | ||
90 | } | ||
91 | const char *title = sway_view->iface.get_prop(sway_view, VIEW_PROP_TITLE); | ||
92 | swayc_t *swayc = new_swayc(C_VIEW); | ||
93 | sway_log(L_DEBUG, "Adding new view %p:%s to container %p %d", | ||
94 | swayc, title, sibling, sibling ? sibling->type : 0); | ||
95 | // Setup values | ||
96 | swayc->sway_view = sway_view; | ||
97 | swayc->name = title ? strdup(title) : NULL; | ||
98 | swayc->width = 0; | ||
99 | swayc->height = 0; | ||
100 | |||
101 | if (sibling->type == C_WORKSPACE) { | ||
102 | // Case of focused workspace, just create as child of it | ||
103 | add_child(sibling, swayc); | ||
104 | } else { | ||
105 | // Regular case, create as sibling of current container | ||
106 | // TODO WLR | ||
107 | //add_sibling(sibling, swayc); | ||
108 | } | ||
109 | return swayc; | ||
110 | } | ||