use scene-graph API for Client/LayerSurface

This commit is contained in:
Devin J. Pohly 2021-09-05 16:07:28 -05:00
parent 929d3d9569
commit 1b38801eef

422
dwl.c
View File

@ -33,6 +33,7 @@
#include <wlr/types/wlr_primary_selection.h> #include <wlr/types/wlr_primary_selection.h>
#include <wlr/types/wlr_primary_selection_v1.h> #include <wlr/types/wlr_primary_selection_v1.h>
#include <wlr/types/wlr_screencopy_v1.h> #include <wlr/types/wlr_screencopy_v1.h>
#include <wlr/types/wlr_scene.h>
#include <wlr/types/wlr_server_decoration.h> #include <wlr/types/wlr_server_decoration.h>
#include <wlr/types/wlr_seat.h> #include <wlr/types/wlr_seat.h>
#include <wlr/types/wlr_viewporter.h> #include <wlr/types/wlr_viewporter.h>
@ -60,12 +61,12 @@
#define LENGTH(X) (sizeof X / sizeof X[0]) #define LENGTH(X) (sizeof X / sizeof X[0])
#define END(A) ((A) + LENGTH(A)) #define END(A) ((A) + LENGTH(A))
#define TAGMASK ((1 << LENGTH(tags)) - 1) #define TAGMASK ((1 << LENGTH(tags)) - 1)
#define ROUND(X) ((int)((X)+0.5))
#define LISTEN(E, L, H) wl_signal_add((E), ((L)->notify = (H), (L))) #define LISTEN(E, L, H) wl_signal_add((E), ((L)->notify = (H), (L)))
/* enums */ /* enums */
enum { CurNormal, CurMove, CurResize }; /* cursor */ enum { CurNormal, CurMove, CurResize }; /* cursor */
enum { XDGShell, LayerShell, X11Managed, X11Unmanaged }; /* client types */ enum { XDGShell, LayerShell, X11Managed, X11Unmanaged }; /* client types */
enum { LyrBg, LyrBottom, LyrTop, LyrOverlay, LyrTile, LyrFloat, NUM_LAYERS }; /* scene layers */
#ifdef XWAYLAND #ifdef XWAYLAND
enum { NetWMWindowTypeDialog, NetWMWindowTypeSplash, NetWMWindowTypeToolbar, enum { NetWMWindowTypeDialog, NetWMWindowTypeSplash, NetWMWindowTypeToolbar,
NetWMWindowTypeUtility, NetLast }; /* EWMH atoms */ NetWMWindowTypeUtility, NetLast }; /* EWMH atoms */
@ -89,9 +90,11 @@ typedef struct Monitor Monitor;
typedef struct { typedef struct {
/* Must be first */ /* Must be first */
unsigned int type; /* XDGShell or X11* */ unsigned int type; /* XDGShell or X11* */
struct wlr_scene_node *scene;
struct wlr_scene_rect *border[4];
struct wlr_scene_node *scene_surface;
struct wl_list link; struct wl_list link;
struct wl_list flink; struct wl_list flink;
struct wl_list slink;
union { union {
struct wlr_xdg_surface *xdg; struct wlr_xdg_surface *xdg;
struct wlr_xwayland_surface *xwayland; struct wlr_xwayland_surface *xwayland;
@ -143,8 +146,9 @@ typedef struct {
typedef struct { typedef struct {
/* Must be first */ /* Must be first */
unsigned int type; /* LayerShell */ unsigned int type; /* LayerShell */
struct wlr_layer_surface_v1 *layer_surface; struct wlr_scene_node *scene;
struct wl_list link; struct wl_list link;
struct wlr_layer_surface_v1 *layer_surface;
struct wl_listener destroy; struct wl_listener destroy;
struct wl_listener map; struct wl_listener map;
@ -203,14 +207,6 @@ typedef struct {
int monitor; int monitor;
} Rule; } Rule;
/* Used to move all of the data necessary to render a surface from the top-level
* frame handler to the per-surface render function. */
struct render_data {
struct wlr_output *output;
struct timespec *when;
int x, y; /* layout-relative */
};
/* function declarations */ /* function declarations */
static void applybounds(Client *c, struct wlr_box *bbox); static void applybounds(Client *c, struct wlr_box *bbox);
static void applyexclusive(struct wlr_box *usable_area, uint32_t anchor, static void applyexclusive(struct wlr_box *usable_area, uint32_t anchor,
@ -265,13 +261,9 @@ static void pointerfocus(Client *c, struct wlr_surface *surface,
static void printstatus(void); static void printstatus(void);
static void quit(const Arg *arg); static void quit(const Arg *arg);
static void quitsignal(int signo); static void quitsignal(int signo);
static void render(struct wlr_surface *surface, int sx, int sy, void *data);
static void renderclients(Monitor *m, struct timespec *now);
static void renderlayer(struct wl_list *layer_surfaces, struct timespec *now);
static void rendermon(struct wl_listener *listener, void *data); static void rendermon(struct wl_listener *listener, void *data);
static void resize(Client *c, int x, int y, int w, int h, int interact); static void resize(Client *c, int x, int y, int w, int h, int interact);
static void run(char *startup_cmd); static void run(char *startup_cmd);
static void scalebox(struct wlr_box *box, float scale);
static Client *selclient(void); static Client *selclient(void);
static void setcursor(struct wl_listener *listener, void *data); static void setcursor(struct wl_listener *listener, void *data);
static void setpsel(struct wl_listener *listener, void *data); static void setpsel(struct wl_listener *listener, void *data);
@ -299,9 +291,8 @@ static void updatetitle(struct wl_listener *listener, void *data);
static void urgent(struct wl_listener *listener, void *data); static void urgent(struct wl_listener *listener, void *data);
static void view(const Arg *arg); static void view(const Arg *arg);
static void virtualkeyboard(struct wl_listener *listener, void *data); static void virtualkeyboard(struct wl_listener *listener, void *data);
static Client *xytoclient(double x, double y); static struct wlr_scene_node *xytonode(double x, double y, struct wlr_surface **psurface,
static struct wlr_surface *xytolayersurface(struct wl_list *layer_surfaces, Client **pc, LayerSurface **pl, double *nx, double *ny);
double x, double y, double *sx, double *sy);
static Monitor *xytomon(double x, double y); static Monitor *xytomon(double x, double y);
static void zoom(const Arg *arg); static void zoom(const Arg *arg);
@ -309,6 +300,8 @@ static void zoom(const Arg *arg);
static const char broken[] = "broken"; static const char broken[] = "broken";
static struct wl_display *dpy; static struct wl_display *dpy;
static struct wlr_backend *backend; static struct wlr_backend *backend;
static struct wlr_scene *scene;
static struct wlr_scene_node *layers[NUM_LAYERS];
static struct wlr_renderer *drw; static struct wlr_renderer *drw;
static struct wlr_compositor *compositor; static struct wlr_compositor *compositor;
@ -316,7 +309,6 @@ static struct wlr_xdg_shell *xdg_shell;
static struct wlr_xdg_activation_v1 *activation; static struct wlr_xdg_activation_v1 *activation;
static struct wl_list clients; /* tiling order */ static struct wl_list clients; /* tiling order */
static struct wl_list fstack; /* focus order */ static struct wl_list fstack; /* focus order */
static struct wl_list stack; /* stacking z-order */
static struct wl_list independents; static struct wl_list independents;
static struct wlr_idle *idle; static struct wlr_idle *idle;
static struct wlr_layer_shell_v1 *layer_shell; static struct wlr_layer_shell_v1 *layer_shell;
@ -366,9 +358,7 @@ static void activatex11(struct wl_listener *listener, void *data);
static void configurex11(struct wl_listener *listener, void *data); static void configurex11(struct wl_listener *listener, void *data);
static void createnotifyx11(struct wl_listener *listener, void *data); static void createnotifyx11(struct wl_listener *listener, void *data);
static Atom getatom(xcb_connection_t *xc, const char *name); static Atom getatom(xcb_connection_t *xc, const char *name);
static void renderindependents(struct wlr_output *output, struct timespec *now);
static void xwaylandready(struct wl_listener *listener, void *data); static void xwaylandready(struct wl_listener *listener, void *data);
static Client *xytoindependent(double x, double y);
static struct wl_listener new_xwayland_surface = {.notify = createnotifyx11}; static struct wl_listener new_xwayland_surface = {.notify = createnotifyx11};
static struct wl_listener xwayland_ready = {.notify = xwaylandready}; static struct wl_listener xwayland_ready = {.notify = xwaylandready};
static struct wlr_xwayland *xwayland; static struct wlr_xwayland *xwayland;
@ -483,12 +473,17 @@ applyrules(Client *c)
mon = m; mon = m;
} }
} }
wlr_scene_node_reparent(c->scene, layers[c->isfloating ? LyrFloat : LyrTile]);
setmon(c, mon, newtags); setmon(c, mon, newtags);
} }
void void
arrange(Monitor *m) arrange(Monitor *m)
{ {
Client *c;
wl_list_for_each(c, &clients, link)
wlr_scene_node_set_enabled(c->scene, VISIBLEON(c, c->mon));
if (m->lt[m->sellt]->arrange) if (m->lt[m->sellt]->arrange)
m->lt[m->sellt]->arrange(m); m->lt[m->sellt]->arrange(m);
/* TODO recheck pointer focus here... or in resize()? */ /* TODO recheck pointer focus here... or in resize()? */
@ -567,6 +562,7 @@ arrangelayer(Monitor *m, struct wl_list *list, struct wlr_box *usable_area, int
applyexclusive(usable_area, state->anchor, state->exclusive_zone, applyexclusive(usable_area, state->anchor, state->exclusive_zone,
state->margin.top, state->margin.right, state->margin.top, state->margin.right,
state->margin.bottom, state->margin.left); state->margin.bottom, state->margin.left);
wlr_scene_node_set_position(layersurface->scene, box.x, box.y);
wlr_layer_surface_v1_configure(wlr_layer_surface, box.width, box.height); wlr_layer_surface_v1_configure(wlr_layer_surface, box.width, box.height);
} }
} }
@ -650,7 +646,8 @@ buttonpress(struct wl_listener *listener, void *data)
switch (event->state) { switch (event->state) {
case WLR_BUTTON_PRESSED:; case WLR_BUTTON_PRESSED:;
/* Change focus if the button was _pressed_ over a client */ /* Change focus if the button was _pressed_ over a client */
if ((c = xytoclient(cursor->x, cursor->y))) xytonode(cursor->x, cursor->y, NULL, &c, NULL, NULL, NULL);
if (c)
focusclient(c, 1); focusclient(c, 1);
keyboard = wlr_seat_get_keyboard(seat); keyboard = wlr_seat_get_keyboard(seat);
@ -762,6 +759,9 @@ commitlayersurfacenotify(struct wl_listener *listener, void *data)
struct wlr_output *wlr_output = wlr_layer_surface->output; struct wlr_output *wlr_output = wlr_layer_surface->output;
Monitor *m; Monitor *m;
wlr_scene_node_reparent(layersurface->scene,
layers[wlr_layer_surface->current.layer]);
if (!wlr_output) if (!wlr_output)
return; return;
@ -932,8 +932,13 @@ createlayersurface(struct wl_listener *listener, void *data)
layersurface->layer_surface = wlr_layer_surface; layersurface->layer_surface = wlr_layer_surface;
wlr_layer_surface->data = layersurface; wlr_layer_surface->data = layersurface;
m = wlr_layer_surface->output->data; m = wlr_layer_surface->output->data;
layersurface->scene = wlr_scene_surface_tree_create(
layers[wlr_layer_surface->client_pending.layer],
wlr_layer_surface->surface);
layersurface->scene->data = layersurface;
wl_list_insert(&m->layers[wlr_layer_surface->client_pending.layer], wl_list_insert(&m->layers[wlr_layer_surface->client_pending.layer],
&layersurface->link); &layersurface->link);
@ -1075,8 +1080,9 @@ focusclient(Client *c, int lift)
/* Raise client in stacking order if requested */ /* Raise client in stacking order if requested */
if (c && lift) { if (c && lift) {
wl_list_remove(&c->slink); /* This isn't easy to do via the current API */
wl_list_insert(&stack, &c->slink); wl_list_remove(&c->scene->state.link);
wl_list_insert(c->scene->parent->state.children.prev, &c->scene->state.link);
} }
if (c && client_surface(c) == old) if (c && client_surface(c) == old)
@ -1303,27 +1309,40 @@ mapnotify(struct wl_listener *listener, void *data)
{ {
/* Called when the surface is mapped, or ready to display on-screen. */ /* Called when the surface is mapped, or ready to display on-screen. */
Client *c = wl_container_of(listener, c, map); Client *c = wl_container_of(listener, c, map);
int i;
/* Create scene tree for this client and its border */
c->scene = &wlr_scene_tree_create(layers[LyrTile])->node;
c->scene_surface = wlr_scene_surface_tree_create(c->scene, client_surface(c));
c->scene_surface->data = c;
for (i = 0; i < 4; i++) {
c->border[i] = wlr_scene_rect_create(c->scene, 0, 0, bordercolor);
c->border[i]->node.data = c;
}
if (client_is_unmanaged(c)) { if (client_is_unmanaged(c)) {
/* Floating, no border */
wlr_scene_node_reparent(c->scene, layers[LyrFloat]);
c->bw = 0;
/* Insert this independent into independents lists. */ /* Insert this independent into independents lists. */
wl_list_insert(&independents, &c->link); wl_list_insert(&independents, &c->link);
return; return;
} }
/* Insert this client into client lists. */ /* Initialize client geometry with room for border */
wl_list_insert(&clients, &c->link); client_set_tiled(c, WLR_EDGE_TOP | WLR_EDGE_BOTTOM | WLR_EDGE_LEFT | WLR_EDGE_RIGHT);
wl_list_insert(&fstack, &c->flink);
wl_list_insert(&stack, &c->slink);
client_get_geometry(c, &c->geom); client_get_geometry(c, &c->geom);
c->geom.width += 2 * c->bw; c->geom.width += 2 * c->bw;
c->geom.height += 2 * c->bw; c->geom.height += 2 * c->bw;
/* Tell the client not to try anything fancy */ /* Insert this client into client lists. */
client_set_tiled(c, WLR_EDGE_TOP | WLR_EDGE_BOTTOM | WLR_EDGE_LEFT | WLR_EDGE_RIGHT); wl_list_insert(&clients, &c->link);
wl_list_insert(&fstack, &c->flink);
/* Set initial monitor, tags, floating status, and focus */ /* Set initial monitor, tags, floating status, and focus */
applyrules(c); applyrules(c);
resize(c, c->geom.x, c->geom.y, c->geom.width, c->geom.height, 0);
} }
void void
@ -1356,8 +1375,8 @@ void
motionnotify(uint32_t time) motionnotify(uint32_t time)
{ {
double sx = 0, sy = 0; double sx = 0, sy = 0;
struct wlr_surface *surface = NULL;
Client *c = NULL; Client *c = NULL;
struct wlr_surface *surface = NULL;
// time is 0 in internal calls meant to restore pointer focus. // time is 0 in internal calls meant to restore pointer focus.
if (time) { if (time) {
@ -1381,32 +1400,8 @@ motionnotify(uint32_t time)
return; return;
} }
if ((surface = xytolayersurface(&selmon->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY], /* Find the client under the pointer and send the event along. */
cursor->x, cursor->y, &sx, &sy))) xytonode(cursor->x, cursor->y, &surface, &c, NULL, &sx, &sy);
;
else if ((surface = xytolayersurface(&selmon->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP],
cursor->x, cursor->y, &sx, &sy)))
;
#ifdef XWAYLAND
/* Find an independent under the pointer and send the event along. */
else if ((c = xytoindependent(cursor->x, cursor->y))) {
surface = wlr_surface_surface_at(c->surface.xwayland->surface,
cursor->x - c->surface.xwayland->x - c->bw,
cursor->y - c->surface.xwayland->y - c->bw, &sx, &sy);
/* Otherwise, find the client under the pointer and send the event along. */
}
#endif
else if ((c = xytoclient(cursor->x, cursor->y))) {
surface = client_surface_at(c, cursor->x - c->geom.x - c->bw,
cursor->y - c->geom.y - c->bw, &sx, &sy);
}
else if ((surface = xytolayersurface(&selmon->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM],
cursor->x, cursor->y, &sx, &sy)))
;
else
surface = xytolayersurface(&selmon->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND],
cursor->x, cursor->y, &sx, &sy);
/* If there's no client surface under the cursor, set the cursor image to a /* If there's no client surface under the cursor, set the cursor image to a
* default. This is what makes the cursor image appear when you move it * default. This is what makes the cursor image appear when you move it
@ -1437,7 +1432,10 @@ motionrelative(struct wl_listener *listener, void *data)
void void
moveresize(const Arg *arg) moveresize(const Arg *arg)
{ {
if (cursor_mode != CurNormal || !(grabc = xytoclient(cursor->x, cursor->y))) if (cursor_mode != CurNormal)
return;
xytonode(cursor->x, cursor->y, NULL, &grabc, NULL, NULL, NULL);
if (!grabc)
return; return;
/* Float the window and tell motionnotify to grab it */ /* Float the window and tell motionnotify to grab it */
@ -1604,140 +1602,11 @@ quitsignal(int signo)
quit(NULL); quit(NULL);
} }
void
render(struct wlr_surface *surface, int sx, int sy, void *data)
{
/* This function is called for every surface that needs to be rendered. */
struct render_data *rdata = data;
struct wlr_output *output = rdata->output;
double ox = 0, oy = 0;
struct wlr_box obox;
float matrix[9];
enum wl_output_transform transform;
/* We first obtain a wlr_texture, which is a GPU resource. wlroots
* automatically handles negotiating these with the client. The underlying
* resource could be an opaque handle passed from the client, or the client
* could have sent a pixel buffer which we copied to the GPU, or a few other
* means. You don't have to worry about this, wlroots takes care of it. */
struct wlr_texture *texture = wlr_surface_get_texture(surface);
if (!texture)
return;
/* The client has a position in layout coordinates. If you have two displays,
* one next to the other, both 1080p, a client on the rightmost display might
* have layout coordinates of 2000,100. We need to translate that to
* output-local coordinates, or (2000 - 1920). */
wlr_output_layout_output_coords(output_layout, output, &ox, &oy);
/* We also have to apply the scale factor for HiDPI outputs. This is only
* part of the puzzle, dwl does not fully support HiDPI. */
obox.x = ox + rdata->x + sx;
obox.y = oy + rdata->y + sy;
obox.width = surface->current.width;
obox.height = surface->current.height;
scalebox(&obox, output->scale);
/*
* Those familiar with OpenGL are also familiar with the role of matrices
* in graphics programming. We need to prepare a matrix to render the
* client with. wlr_matrix_project_box is a helper which takes a box with
* a desired x, y coordinates, width and height, and an output geometry,
* then prepares an orthographic projection and multiplies the necessary
* transforms to produce a model-view-projection matrix.
*
* Naturally you can do this any way you like, for example to make a 3D
* compositor.
*/
transform = wlr_output_transform_invert(surface->current.transform);
wlr_matrix_project_box(matrix, &obox, transform, 0,
output->transform_matrix);
/* This takes our matrix, the texture, and an alpha, and performs the actual
* rendering on the GPU. */
wlr_render_texture_with_matrix(drw, texture, matrix, 1);
/* This lets the client know that we've displayed that frame and it can
* prepare another one now if it likes. */
wlr_surface_send_frame_done(surface, rdata->when);
wlr_presentation_surface_sampled_on_output(presentation, surface, output);
}
void
renderclients(Monitor *m, struct timespec *now)
{
Client *c, *sel = selclient();
const float *color;
double ox, oy;
int i, w, h;
struct render_data rdata;
struct wlr_box *borders;
struct wlr_surface *surface;
/* Each subsequent window we render is rendered on top of the last. Because
* our stacking list is ordered front-to-back, we iterate over it backwards. */
wl_list_for_each_reverse(c, &stack, slink) {
/* Only render visible clients which show on this monitor */
if (!VISIBLEON(c, c->mon) || !wlr_output_layout_intersects(
output_layout, m->wlr_output, &c->geom))
continue;
surface = client_surface(c);
ox = c->geom.x, oy = c->geom.y;
wlr_output_layout_output_coords(output_layout, m->wlr_output,
&ox, &oy);
if (c->bw) {
w = surface->current.width;
h = surface->current.height;
borders = (struct wlr_box[4]) {
{ox, oy, w + 2 * c->bw, c->bw}, /* top */
{ox, oy + c->bw, c->bw, h}, /* left */
{ox + c->bw + w, oy + c->bw, c->bw, h}, /* right */
{ox, oy + c->bw + h, w + 2 * c->bw, c->bw}, /* bottom */
};
/* Draw window borders */
color = (c == sel) ? focuscolor : bordercolor;
for (i = 0; i < 4; i++) {
scalebox(&borders[i], m->wlr_output->scale);
wlr_render_rect(drw, &borders[i], color,
m->wlr_output->transform_matrix);
}
}
/* This calls our render function for each surface among the
* xdg_surface's toplevel and popups. */
rdata.output = m->wlr_output;
rdata.when = now;
rdata.x = c->geom.x + c->bw;
rdata.y = c->geom.y + c->bw;
client_for_each_surface(c, render, &rdata);
}
}
void
renderlayer(struct wl_list *layer_surfaces, struct timespec *now)
{
LayerSurface *layersurface;
wl_list_for_each(layersurface, layer_surfaces, link) {
struct render_data rdata = {
.output = layersurface->layer_surface->output,
.when = now,
.x = layersurface->geo.x,
.y = layersurface->geo.y,
};
wlr_surface_for_each_surface(layersurface->layer_surface->surface,
render, &rdata);
}
}
void void
rendermon(struct wl_listener *listener, void *data) rendermon(struct wl_listener *listener, void *data)
{ {
Client *c; Client *c;
int render = 1; int skip = 0;
/* This function is called every time an output is ready to display a frame, /* This function is called every time an output is ready to display a frame,
* generally at the output's refresh rate (e.g. 60Hz). */ * generally at the output's refresh rate (e.g. 60Hz). */
@ -1746,13 +1615,9 @@ rendermon(struct wl_listener *listener, void *data)
struct timespec now; struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now); clock_gettime(CLOCK_MONOTONIC, &now);
/* Do not render if any XDG clients have an outstanding resize. */ /* Skip rendering if any XDG clients have an outstanding resize. */
wl_list_for_each(c, &stack, slink) { wl_list_for_each(c, &clients, link)
if (c->resize) { skip = skip || c->resize;
wlr_surface_send_frame_done(client_surface(c), &now);
render = 0;
}
}
/* HACK: This loop is the simplest way to handle ephemeral pageflip /* HACK: This loop is the simplest way to handle ephemeral pageflip
* failures but probably not the best. Revisit if damage tracking is * failures but probably not the best. Revisit if damage tracking is
@ -1762,50 +1627,46 @@ rendermon(struct wl_listener *listener, void *data)
if (!wlr_output_attach_render(m->wlr_output, NULL)) if (!wlr_output_attach_render(m->wlr_output, NULL))
return; return;
if (render) { if (!skip) {
/* Begin the renderer (calls glViewport and some other GL sanity checks) */ /* Begin the renderer (calls glViewport and some other GL sanity checks) */
wlr_renderer_begin(drw, m->wlr_output->width, m->wlr_output->height); wlr_renderer_begin(drw, m->wlr_output->width, m->wlr_output->height);
wlr_renderer_clear(drw, rootcolor); wlr_renderer_clear(drw, rootcolor);
renderlayer(&m->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND], &now); /* Render the scene at (-mx, -my) to get this monitor's view.
renderlayer(&m->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM], &now); * wlroots will not render windows falling outside the box. */
renderclients(m, &now); wlr_scene_render_output(scene, m->wlr_output, -m->m.x, -m->m.y, NULL);
#ifdef XWAYLAND
renderindependents(m->wlr_output, &now);
#endif
renderlayer(&m->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP], &now);
renderlayer(&m->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY], &now);
/* Hardware cursors are rendered by the GPU on a separate plane, and can be
* moved around without re-rendering what's beneath them - which is more
* efficient. However, not all hardware supports hardware cursors. For this
* reason, wlroots provides a software fallback, which we ask it to render
* here. wlr_cursor handles configuring hardware vs software cursors for you,
* and this function is a no-op when hardware cursors are in use. */
wlr_output_render_software_cursors(m->wlr_output, NULL);
/* Conclude rendering and swap the buffers, showing the final frame /* Conclude rendering and swap the buffers, showing the final frame
* on-screen. */ * on-screen. */
wlr_renderer_end(drw); wlr_renderer_end(drw);
} }
} while (!wlr_output_commit(m->wlr_output)); } while (!wlr_output_commit(m->wlr_output));
/* Let clients know a frame has been rendered */
wl_list_for_each(c, &clients, link)
wlr_surface_send_frame_done(client_surface(c), &now);
} }
void void
resize(Client *c, int x, int y, int w, int h, int interact) resize(Client *c, int x, int y, int w, int h, int interact)
{ {
/*
* Note that I took some shortcuts here. In a more fleshed-out
* compositor, you'd wait for the client to prepare a buffer at
* the new size, then commit any movement that was prepared.
*/
struct wlr_box *bbox = interact ? &sgeom : &c->mon->w; struct wlr_box *bbox = interact ? &sgeom : &c->mon->w;
c->geom.x = x; c->geom.x = x;
c->geom.y = y; c->geom.y = y;
c->geom.width = w; c->geom.width = w;
c->geom.height = h; c->geom.height = h;
applybounds(c, bbox); applybounds(c, bbox);
/* Update scene-graph, including borders */
wlr_scene_node_set_position(c->scene, c->geom.x, c->geom.y);
wlr_scene_node_set_position(c->scene_surface, c->bw, c->bw);
wlr_scene_rect_set_size(c->border[0], c->geom.width, c->bw);
wlr_scene_rect_set_size(c->border[1], c->geom.width, c->bw);
wlr_scene_rect_set_size(c->border[2], c->bw, c->geom.height - 2 * c->bw);
wlr_scene_rect_set_size(c->border[3], c->bw, c->geom.height - 2 * c->bw);
wlr_scene_node_set_position(&c->border[1]->node, 0, c->geom.height - c->bw);
wlr_scene_node_set_position(&c->border[3]->node, c->geom.width - c->bw, c->bw);
/* wlroots makes this a no-op if size hasn't changed */ /* wlroots makes this a no-op if size hasn't changed */
c->resize = client_set_size(c, c->geom.width - 2 * c->bw, c->resize = client_set_size(c, c->geom.width - 2 * c->bw,
c->geom.height - 2 * c->bw); c->geom.height - 2 * c->bw);
@ -1870,15 +1731,6 @@ run(char *startup_cmd)
} }
} }
void
scalebox(struct wlr_box *box, float scale)
{
box->width = ROUND((box->x + box->width) * scale) - ROUND(box->x * scale);
box->height = ROUND((box->y + box->height) * scale) - ROUND(box->y * scale);
box->x = ROUND(box->x * scale);
box->y = ROUND(box->y * scale);
}
Client * Client *
selclient(void) selclient(void)
{ {
@ -1911,6 +1763,7 @@ void
setfloating(Client *c, int floating) setfloating(Client *c, int floating)
{ {
c->isfloating = floating; c->isfloating = floating;
wlr_scene_node_reparent(c->scene, layers[c->isfloating ? LyrFloat : LyrTile]);
arrange(c->mon); arrange(c->mon);
} }
@ -1957,7 +1810,7 @@ setmon(Client *c, Monitor *m, unsigned int newtags)
} }
if (m) { if (m) {
/* Make sure window actually overlaps with the monitor */ /* Make sure window actually overlaps with the monitor */
applybounds(c, &m->m); resize(c, c->geom.x, c->geom.y, c->geom.width, c->geom.height, 0);
wlr_surface_send_enter(client_surface(c), m->wlr_output); wlr_surface_send_enter(client_surface(c), m->wlr_output);
c->tags = newtags ? newtags : m->tagset[m->seltags]; /* assign tags of target monitor */ c->tags = newtags ? newtags : m->tagset[m->seltags]; /* assign tags of target monitor */
arrange(m); arrange(m);
@ -2010,6 +1863,15 @@ setup(void)
if (!(backend = wlr_backend_autocreate(dpy))) if (!(backend = wlr_backend_autocreate(dpy)))
BARF("couldn't create backend"); BARF("couldn't create backend");
/* Initialize the scene graph used to lay out windows */
scene = wlr_scene_create();
layers[LyrBg] = &wlr_scene_tree_create(&scene->node)->node;
layers[LyrBottom] = &wlr_scene_tree_create(&scene->node)->node;
layers[LyrTile] = &wlr_scene_tree_create(&scene->node)->node;
layers[LyrFloat] = &wlr_scene_tree_create(&scene->node)->node;
layers[LyrTop] = &wlr_scene_tree_create(&scene->node)->node;
layers[LyrOverlay] = &wlr_scene_tree_create(&scene->node)->node;
/* If we don't provide a renderer, autocreate makes a GLES2 renderer for us. /* If we don't provide a renderer, autocreate makes a GLES2 renderer for us.
* The renderer is responsible for defining the various pixel formats it * The renderer is responsible for defining the various pixel formats it
* supports for shared memory, this configures that for clients. */ * supports for shared memory, this configures that for clients. */
@ -2054,7 +1916,6 @@ setup(void)
*/ */
wl_list_init(&clients); wl_list_init(&clients);
wl_list_init(&fstack); wl_list_init(&fstack);
wl_list_init(&stack);
wl_list_init(&independents); wl_list_init(&independents);
idle = wlr_idle_create(dpy); idle = wlr_idle_create(dpy);
@ -2302,7 +2163,7 @@ unmapnotify(struct wl_listener *listener, void *data)
setmon(c, NULL, 0); setmon(c, NULL, 0);
wl_list_remove(&c->flink); wl_list_remove(&c->flink);
wl_list_remove(&c->slink); wlr_scene_node_destroy(c->scene);
} }
void void
@ -2386,37 +2247,31 @@ virtualkeyboard(struct wl_listener *listener, void *data)
createkeyboard(device); createkeyboard(device);
} }
Client * struct wlr_scene_node *
xytoclient(double x, double y) xytonode(double x, double y, struct wlr_surface **psurface,
Client **pc, LayerSurface **pl, double *nx, double *ny)
{ {
/* Find the topmost visible client (if any) at point (x, y), including struct wlr_scene_node *node, *pnode;
* borders. This relies on stack being ordered from top to bottom. */ struct wlr_surface *surface = NULL;
Client *c; Client *c = NULL;
wl_list_for_each(c, &stack, slink) LayerSurface *l = NULL;
if (VISIBLEON(c, c->mon) && wlr_box_contains_point(&c->geom, x, y))
return c; if ((node = wlr_scene_node_at(&scene->node, x, y, nx, ny))) {
return NULL; if (node->type == WLR_SCENE_NODE_SURFACE)
surface = wlr_scene_surface_from_node(node)->surface;
/* Walk the tree to find a node that knows the client */
for (pnode = node; pnode && !c; pnode = pnode->parent)
c = pnode->data;
if (c && c->type == LayerShell) {
c = NULL;
l = pnode->data;
}
} }
struct wlr_surface * if (psurface) *psurface = surface;
xytolayersurface(struct wl_list *layer_surfaces, double x, double y, if (pc) *pc = c;
double *sx, double *sy) if (pl) *pl = l;
{ return node;
LayerSurface *layersurface;
wl_list_for_each_reverse(layersurface, layer_surfaces, link) {
struct wlr_surface *sub;
if (!layersurface->layer_surface->mapped)
continue;
sub = wlr_layer_surface_v1_surface_at(
layersurface->layer_surface,
x - layersurface->geo.x,
y - layersurface->geo.y,
sx, sy);
if (sub)
return sub;
}
return NULL;
} }
Monitor * Monitor *
@ -2520,31 +2375,6 @@ getatom(xcb_connection_t *xc, const char *name)
return atom; return atom;
} }
void
renderindependents(struct wlr_output *output, struct timespec *now)
{
Client *c;
struct render_data rdata;
struct wlr_box geom;
wl_list_for_each_reverse(c, &independents, link) {
geom.x = c->surface.xwayland->x;
geom.y = c->surface.xwayland->y;
geom.width = c->surface.xwayland->width;
geom.height = c->surface.xwayland->height;
/* Only render visible clients which show on this output */
if (!wlr_output_layout_intersects(output_layout, output, &geom))
continue;
rdata.output = output;
rdata.when = now;
rdata.x = c->surface.xwayland->x;
rdata.y = c->surface.xwayland->y;
wlr_surface_for_each_surface(c->surface.xwayland->surface, render, &rdata);
}
}
void void
xwaylandready(struct wl_listener *listener, void *data) xwaylandready(struct wl_listener *listener, void *data)
{ {
@ -2575,28 +2405,6 @@ xwaylandready(struct wl_listener *listener, void *data)
xcb_disconnect(xc); xcb_disconnect(xc);
} }
Client *
xytoindependent(double x, double y)
{
/* Find the topmost visible independent at point (x, y).
* For independents, the most recently created can be used as the "top".
* We rely on the X11 convention of unmapping unmanaged when the "owning"
* client loses focus, which ensures that unmanaged are only visible on
* the current tag. */
Client *c;
wl_list_for_each_reverse(c, &independents, link) {
struct wlr_box geom = {
.x = c->surface.xwayland->x,
.y = c->surface.xwayland->y,
.width = c->surface.xwayland->width,
.height = c->surface.xwayland->height,
};
if (wlr_box_contains_point(&geom, x, y))
return c;
}
return NULL;
}
#endif #endif
int int