diff options
author | Drew DeVault <sir@cmpwn.com> | 2017-09-23 11:13:18 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2017-09-23 11:13:18 -0400 |
commit | e81e99d16d31765b51fcca31d5ffffd5087febfa (patch) | |
tree | 53f9e4a86fd053467858ce0a24c41d3eb29b0b6f /rootston | |
parent | 7523de7c61b9eac310b10bf6711c75af2cd9b2f4 (diff) |
Render XDG shell surfaces
Diffstat (limited to 'rootston')
-rw-r--r-- | rootston/desktop.c | 12 | ||||
-rw-r--r-- | rootston/meson.build | 3 | ||||
-rw-r--r-- | rootston/output.c | 42 | ||||
-rw-r--r-- | rootston/xdg_shell_v6.c | 51 |
4 files changed, 98 insertions, 10 deletions
diff --git a/rootston/desktop.c b/rootston/desktop.c index 86d128ef..fc341a23 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -11,14 +11,9 @@ #include "rootston/desktop.h" #include "rootston/server.h" -static void handle_xdg_shell_v6_surface(struct wl_listener *listener, - void *data) { - struct roots_desktop *desktop = - wl_container_of(listener, desktop, xdg_shell_v6_surface); - struct wlr_xdg_surface_v6 *surface = data; - wlr_log(L_DEBUG, "new xdg surface: title=%s, app_id=%s", - surface->title, surface->app_id); - wlr_xdg_surface_v6_ping(surface); +void view_destroy(struct roots_view *view) { + wl_list_remove(&view->link); + free(view); } struct roots_desktop *desktop_create(struct roots_server *server, @@ -26,6 +21,7 @@ struct roots_desktop *desktop_create(struct roots_server *server, struct roots_desktop *desktop = calloc(1, sizeof(struct roots_desktop)); wlr_log(L_DEBUG, "Initializing roots desktop"); + wl_list_init(&desktop->views); wl_list_init(&desktop->outputs); wl_list_init(&desktop->output_add.link); desktop->output_add.notify = output_add_notify; diff --git a/rootston/meson.build b/rootston/meson.build index 6fc4452f..03ca837a 100644 --- a/rootston/meson.build +++ b/rootston/meson.build @@ -6,6 +6,7 @@ executable( 'input.c', 'main.c', 'output.c', - 'pointer.c' + 'pointer.c', + 'xdg_shell_v6.c' ], dependencies: wlroots ) diff --git a/rootston/output.c b/rootston/output.c index 39586e0e..481832cf 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -1,15 +1,43 @@ #define _POSIX_C_SOURCE 199309L #include <time.h> #include <stdlib.h> +#include <stdbool.h> #include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_compositor.h> #include <wlr/types/wlr_wl_shell.h> #include <wlr/types/wlr_xdg_shell_v6.h> +#include <wlr/render/matrix.h> #include <wlr/util/log.h> #include "rootston/server.h" #include "rootston/desktop.h" #include "rootston/config.h" +static inline int64_t timespec_to_msec(const struct timespec *a) { + return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000; +} + +static void render_view(struct roots_desktop *desktop, + struct wlr_output *wlr_output, struct timespec *when, + struct roots_view *view, double ox, double oy) { + struct wlr_surface *surface = view->wlr_surface; + float matrix[16]; + float transform[16]; + wlr_surface_flush_damage(surface); + if (surface->texture->valid) { + wlr_matrix_translate(&transform, ox, oy, 0); + wlr_surface_get_matrix(surface, &matrix, + &wlr_output->transform_matrix, &transform); + wlr_render_with_matrix(desktop->server->renderer, + surface->texture, &matrix); + + struct wlr_frame_callback *cb, *cnext; + wl_list_for_each_safe(cb, cnext, &surface->frame_callback_list, link) { + wl_callback_send_done(cb->resource, timespec_to_msec(when)); + wl_resource_destroy(cb->resource); + } + } +} + static void output_frame_notify(struct wl_listener *listener, void *data) { struct wlr_output *wlr_output = data; struct roots_output *output = wl_container_of(listener, output, frame); @@ -22,7 +50,19 @@ static void output_frame_notify(struct wl_listener *listener, void *data) { wlr_output_make_current(wlr_output); wlr_renderer_begin(server->renderer, wlr_output); - // TODO: render views + struct roots_view *view; + wl_list_for_each(view, &desktop->views, link) { + int width = view->wlr_surface->current.buffer_width; + int height = view->wlr_surface->current.buffer_height; + + if (wlr_output_layout_intersects(desktop->layout, wlr_output, + view->x, view->y, view->x + width, view->y + height)) { + double ox = view->x, oy = view->y; + wlr_output_layout_output_coords( + desktop->layout, wlr_output, &ox, &oy); + render_view(desktop, wlr_output, &now, view, ox, oy); + } + } wlr_renderer_end(server->renderer); wlr_output_swap_buffers(wlr_output); diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c new file mode 100644 index 00000000..6c2bff55 --- /dev/null +++ b/rootston/xdg_shell_v6.c @@ -0,0 +1,51 @@ +#include <stdlib.h> +#include <wayland-server.h> +#include <wlr/types/wlr_xdg_shell_v6.h> +#include <wlr/types/wlr_surface.h> +#include <wlr/util/log.h> +#include "rootston/desktop.h" +#include "rootston/server.h" + +static void handle_destroy(struct wl_listener *listener, void *data) { + struct roots_xdg_surface_v6 *roots_xdg_surface = + wl_container_of(listener, roots_xdg_surface, destroy); + wl_list_remove(&roots_xdg_surface->destroy.link); + wl_list_remove(&roots_xdg_surface->ping_timeout.link); + wl_list_remove(&roots_xdg_surface->request_move.link); + wl_list_remove(&roots_xdg_surface->request_resize.link); + wl_list_remove(&roots_xdg_surface->request_show_window_menu.link); + wl_list_remove(&roots_xdg_surface->request_minimize.link); + view_destroy(roots_xdg_surface->view); + free(roots_xdg_surface); +} + +void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { + struct roots_desktop *desktop = + wl_container_of(listener, desktop, xdg_shell_v6_surface); + + struct wlr_xdg_surface_v6 *surface = data; + wlr_log(L_DEBUG, "new xdg surface: title=%s, app_id=%s", + surface->title, surface->app_id); + wlr_xdg_surface_v6_ping(surface); + + struct roots_xdg_surface_v6 *roots_surface = + calloc(1, sizeof(struct roots_xdg_surface_v6)); + // TODO: all of the trimmings + wl_list_init(&roots_surface->destroy.link); + roots_surface->destroy.notify = handle_destroy; + wl_signal_add(&surface->events.destroy, &roots_surface->destroy); + wl_list_init(&roots_surface->ping_timeout.link); + wl_list_init(&roots_surface->request_minimize.link); + wl_list_init(&roots_surface->request_move.link); + wl_list_init(&roots_surface->request_resize.link); + wl_list_init(&roots_surface->request_show_window_menu.link); + + struct roots_view *view = calloc(1, sizeof(struct roots_view)); + view->type = ROOTS_XDG_SHELL_V6_VIEW; + view->x = view->y = 200; + view->xdg_surface_v6 = surface; + view->roots_xdg_surface_v6 = roots_surface; + view->wlr_surface = surface->surface; + roots_surface->view = view; + wl_list_insert(&desktop->views, &view->link); +} |