diff options
-rw-r--r-- | include/rootston/desktop.h | 7 | ||||
-rw-r--r-- | include/rootston/view.h | 21 | ||||
-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 |
6 files changed, 118 insertions, 18 deletions
diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index 3d31059c..8fb55219 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -21,8 +21,11 @@ struct roots_output { }; struct roots_desktop { + struct wl_list views; + struct wl_list outputs; struct timespec last_frame; + struct roots_server *server; struct roots_config *config; @@ -44,7 +47,11 @@ struct roots_desktop *desktop_create(struct roots_server *server, struct roots_config *config); void desktop_destroy(struct roots_desktop *desktop); +void view_destroy(struct roots_view *view); + void output_add_notify(struct wl_listener *listener, void *data); void output_remove_notify(struct wl_listener *listener, void *data); +void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data); + #endif diff --git a/include/rootston/view.h b/include/rootston/view.h index d33e6bfb..9535094b 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -1,5 +1,8 @@ #ifndef _ROOTSTON_VIEW_H #define _ROOTSTON_VIEW_H +#include <stdbool.h> +#include <wlr/types/wlr_xdg_shell_v6.h> +#include <wlr/types/wlr_surface.h> struct roots_wl_shell_surface { // TODO @@ -7,13 +10,14 @@ struct roots_wl_shell_surface { }; struct roots_xdg_surface_v6 { + struct roots_view *view; // TODO: Maybe destroy listener should go in roots_view - struct wl_listener destroy_listener; - struct wl_listener ping_timeout_listener; - struct wl_listener request_minimize_listener; - struct wl_listener request_move_listener; - struct wl_listener request_resize_listener; - struct wl_listener request_show_window_menu_listener; + struct wl_listener destroy; + struct wl_listener ping_timeout; + struct wl_listener request_minimize; + struct wl_listener request_move; + struct wl_listener request_resize; + struct wl_listener request_show_window_menu; }; enum roots_view_type { @@ -29,12 +33,13 @@ struct roots_view { enum roots_view_type type; union { struct wlr_shell_surface *wl_shell_surface; - struct xdg_shell_v6_surface *xdg_shell_v6_surface; + struct wlr_xdg_surface_v6 *xdg_surface_v6; }; union { struct roots_wl_shell_surface *roots_wl_shell_surface; - struct xdg_shell_v6_surface *roots_xdg_surface_v6; + struct roots_xdg_surface_v6 *roots_xdg_surface_v6; }; + struct wlr_surface *wlr_surface; struct wl_list link; }; 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); +} |