decorate xwayland views

This commit is contained in:
Tony Crisci 2018-01-16 07:50:40 -05:00
parent dc701b72fc
commit 3751a17321
5 changed files with 47 additions and 1 deletions

View file

@ -61,6 +61,10 @@ struct roots_view {
double x, y; double x, y;
float rotation; float rotation;
bool decorated;
int border_width;
int titlebar_height;
bool maximized; bool maximized;
struct roots_output *fullscreen_output; struct roots_output *fullscreen_output;
struct { struct {
@ -113,6 +117,7 @@ struct roots_view {
}; };
void view_get_box(const struct roots_view *view, struct wlr_box *box); void view_get_box(const struct roots_view *view, struct wlr_box *box);
void view_get_deco_box(const struct roots_view *view, struct wlr_box *box);
void view_activate(struct roots_view *view, bool active); void view_activate(struct roots_view *view, bool active);
void view_move(struct roots_view *view, double x, double y); void view_move(struct roots_view *view, double x, double y);
void view_resize(struct roots_view *view, uint32_t width, uint32_t height); void view_resize(struct roots_view *view, uint32_t width, uint32_t height);

View file

@ -177,7 +177,7 @@ static bool wlr_gles2_render_texture(struct wlr_renderer *_renderer,
static void wlr_gles2_render_quad(struct wlr_renderer *renderer, static void wlr_gles2_render_quad(struct wlr_renderer *renderer,
const float (*color)[4], const float (*matrix)[16]) { const float (*color)[4], const float (*matrix)[16]) {
GL_CALL(glUseProgram(shaders.quad)); GL_CALL(glUseProgram(shaders.quad));
GL_CALL(glUniformMatrix4fv(0, 1, GL_TRUE, *matrix)); GL_CALL(glUniformMatrix4fv(0, 1, GL_FALSE, *matrix));
GL_CALL(glUniform4f(1, (*color)[0], (*color)[1], (*color)[2], (*color)[3])); GL_CALL(glUniform4f(1, (*color)[0], (*color)[1], (*color)[2], (*color)[3]));
draw_quad(); draw_quad();
} }

View file

@ -31,6 +31,18 @@ void view_get_box(const struct roots_view *view, struct wlr_box *box) {
} }
} }
void view_get_deco_box(const struct roots_view *view, struct wlr_box *box) {
view_get_box(view, box);
if (!view->decorated) {
return;
}
box->x -= view->border_width;
box->y -= (view->border_width + view->titlebar_height);
box->width += view->border_width * 2;
box->height += (view->border_width * 2 + view->titlebar_height);
}
static void view_update_output(const struct roots_view *view, static void view_update_output(const struct roots_view *view,
const struct wlr_box *before) { const struct wlr_box *before) {
struct roots_desktop *desktop = view->desktop; struct roots_desktop *desktop = view->desktop;

View file

@ -144,8 +144,32 @@ static void render_xwayland_children(struct wlr_xwayland_surface *surface,
} }
} }
static void render_decorations(struct roots_view *view,
struct roots_desktop *desktop, struct wlr_output *output) {
if (!view->decorated) {
return;
}
struct wlr_box deco_box;
view_get_deco_box(view, &deco_box);
double ox = deco_box.x;
double oy = deco_box.y;
wlr_output_layout_output_coords(desktop->layout, output, &ox, &oy);
ox *= output->scale;
oy *= output->scale;
float matrix[16];
wlr_output_get_box_matrix(output, ox, oy, deco_box.width,
deco_box.height, WL_OUTPUT_TRANSFORM_NORMAL, view->rotation,
&matrix);
float color[4] = { 0.2, 0.2, 0.2, 1 };
wlr_render_colored_quad(desktop->server->renderer, &color, &matrix);
}
static void render_view(struct roots_view *view, struct roots_desktop *desktop, static void render_view(struct roots_view *view, struct roots_desktop *desktop,
struct wlr_output *wlr_output, struct timespec *when) { struct wlr_output *wlr_output, struct timespec *when) {
render_decorations(view, desktop, wlr_output);
switch (view->type) { switch (view->type) {
case ROOTS_XDG_SHELL_V6_VIEW: case ROOTS_XDG_SHELL_V6_VIEW:
render_surface(view->wlr_surface, desktop, wlr_output, when, render_surface(view->wlr_surface, desktop, wlr_output, when,

View file

@ -296,6 +296,7 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
view->type = ROOTS_XWAYLAND_VIEW; view->type = ROOTS_XWAYLAND_VIEW;
view->x = (double)surface->x; view->x = (double)surface->x;
view->y = (double)surface->y; view->y = (double)surface->y;
view->xwayland_surface = surface; view->xwayland_surface = surface;
view->roots_xwayland_surface = roots_surface; view->roots_xwayland_surface = roots_surface;
view->wlr_surface = surface->surface; view->wlr_surface = surface->surface;
@ -311,6 +312,10 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
wl_list_insert(&desktop->views, &view->link); wl_list_insert(&desktop->views, &view->link);
if (!surface->override_redirect) { if (!surface->override_redirect) {
view->decorated = true;
view->border_width = 4;
view->titlebar_height = 12;
view_setup(view); view_setup(view);
} }
} }