Render XDG shell surfaces
This commit is contained in:
parent
7523de7c61
commit
e81e99d16d
|
@ -21,8 +21,11 @@ struct roots_output {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct roots_desktop {
|
struct roots_desktop {
|
||||||
|
struct wl_list views;
|
||||||
|
|
||||||
struct wl_list outputs;
|
struct wl_list outputs;
|
||||||
struct timespec last_frame;
|
struct timespec last_frame;
|
||||||
|
|
||||||
struct roots_server *server;
|
struct roots_server *server;
|
||||||
struct roots_config *config;
|
struct roots_config *config;
|
||||||
|
|
||||||
|
@ -44,7 +47,11 @@ struct roots_desktop *desktop_create(struct roots_server *server,
|
||||||
struct roots_config *config);
|
struct roots_config *config);
|
||||||
void desktop_destroy(struct roots_desktop *desktop);
|
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_add_notify(struct wl_listener *listener, void *data);
|
||||||
void output_remove_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
|
#endif
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
#ifndef _ROOTSTON_VIEW_H
|
#ifndef _ROOTSTON_VIEW_H
|
||||||
#define _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 {
|
struct roots_wl_shell_surface {
|
||||||
// TODO
|
// TODO
|
||||||
|
@ -7,13 +10,14 @@ struct roots_wl_shell_surface {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct roots_xdg_surface_v6 {
|
struct roots_xdg_surface_v6 {
|
||||||
|
struct roots_view *view;
|
||||||
// TODO: Maybe destroy listener should go in roots_view
|
// TODO: Maybe destroy listener should go in roots_view
|
||||||
struct wl_listener destroy_listener;
|
struct wl_listener destroy;
|
||||||
struct wl_listener ping_timeout_listener;
|
struct wl_listener ping_timeout;
|
||||||
struct wl_listener request_minimize_listener;
|
struct wl_listener request_minimize;
|
||||||
struct wl_listener request_move_listener;
|
struct wl_listener request_move;
|
||||||
struct wl_listener request_resize_listener;
|
struct wl_listener request_resize;
|
||||||
struct wl_listener request_show_window_menu_listener;
|
struct wl_listener request_show_window_menu;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum roots_view_type {
|
enum roots_view_type {
|
||||||
|
@ -29,12 +33,13 @@ struct roots_view {
|
||||||
enum roots_view_type type;
|
enum roots_view_type type;
|
||||||
union {
|
union {
|
||||||
struct wlr_shell_surface *wl_shell_surface;
|
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 {
|
union {
|
||||||
struct roots_wl_shell_surface *roots_wl_shell_surface;
|
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;
|
struct wl_list link;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -11,14 +11,9 @@
|
||||||
#include "rootston/desktop.h"
|
#include "rootston/desktop.h"
|
||||||
#include "rootston/server.h"
|
#include "rootston/server.h"
|
||||||
|
|
||||||
static void handle_xdg_shell_v6_surface(struct wl_listener *listener,
|
void view_destroy(struct roots_view *view) {
|
||||||
void *data) {
|
wl_list_remove(&view->link);
|
||||||
struct roots_desktop *desktop =
|
free(view);
|
||||||
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_desktop *desktop_create(struct roots_server *server,
|
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));
|
struct roots_desktop *desktop = calloc(1, sizeof(struct roots_desktop));
|
||||||
wlr_log(L_DEBUG, "Initializing roots desktop");
|
wlr_log(L_DEBUG, "Initializing roots desktop");
|
||||||
|
|
||||||
|
wl_list_init(&desktop->views);
|
||||||
wl_list_init(&desktop->outputs);
|
wl_list_init(&desktop->outputs);
|
||||||
wl_list_init(&desktop->output_add.link);
|
wl_list_init(&desktop->output_add.link);
|
||||||
desktop->output_add.notify = output_add_notify;
|
desktop->output_add.notify = output_add_notify;
|
||||||
|
|
|
@ -6,6 +6,7 @@ executable(
|
||||||
'input.c',
|
'input.c',
|
||||||
'main.c',
|
'main.c',
|
||||||
'output.c',
|
'output.c',
|
||||||
'pointer.c'
|
'pointer.c',
|
||||||
|
'xdg_shell_v6.c'
|
||||||
], dependencies: wlroots
|
], dependencies: wlroots
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,15 +1,43 @@
|
||||||
#define _POSIX_C_SOURCE 199309L
|
#define _POSIX_C_SOURCE 199309L
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <wlr/types/wlr_output_layout.h>
|
#include <wlr/types/wlr_output_layout.h>
|
||||||
#include <wlr/types/wlr_compositor.h>
|
#include <wlr/types/wlr_compositor.h>
|
||||||
#include <wlr/types/wlr_wl_shell.h>
|
#include <wlr/types/wlr_wl_shell.h>
|
||||||
#include <wlr/types/wlr_xdg_shell_v6.h>
|
#include <wlr/types/wlr_xdg_shell_v6.h>
|
||||||
|
#include <wlr/render/matrix.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
#include "rootston/server.h"
|
#include "rootston/server.h"
|
||||||
#include "rootston/desktop.h"
|
#include "rootston/desktop.h"
|
||||||
#include "rootston/config.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) {
|
static void output_frame_notify(struct wl_listener *listener, void *data) {
|
||||||
struct wlr_output *wlr_output = data;
|
struct wlr_output *wlr_output = data;
|
||||||
struct roots_output *output = wl_container_of(listener, output, frame);
|
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_output_make_current(wlr_output);
|
||||||
wlr_renderer_begin(server->renderer, 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_renderer_end(server->renderer);
|
||||||
wlr_output_swap_buffers(wlr_output);
|
wlr_output_swap_buffers(wlr_output);
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
Loading…
Reference in New Issue