From 929d3d9569086963c7597dc1fcd38d59896278bc Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sun, 5 Sep 2021 15:55:36 -0500 Subject: [PATCH 01/25] use type enum to distinguish Client from LayerSurface --- dwl.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dwl.c b/dwl.c index c4ca60f..08f7e32 100644 --- a/dwl.c +++ b/dwl.c @@ -65,10 +65,10 @@ /* enums */ enum { CurNormal, CurMove, CurResize }; /* cursor */ +enum { XDGShell, LayerShell, X11Managed, X11Unmanaged }; /* client types */ #ifdef XWAYLAND enum { NetWMWindowTypeDialog, NetWMWindowTypeSplash, NetWMWindowTypeToolbar, NetWMWindowTypeUtility, NetLast }; /* EWMH atoms */ -enum { XDGShell, X11Managed, X11Unmanaged }; /* client types */ #endif typedef union { @@ -87,6 +87,8 @@ typedef struct { typedef struct Monitor Monitor; typedef struct { + /* Must be first */ + unsigned int type; /* XDGShell or X11* */ struct wl_list link; struct wl_list flink; struct wl_list slink; @@ -103,7 +105,6 @@ typedef struct { struct wlr_box geom; /* layout-relative, includes border */ Monitor *mon; #ifdef XWAYLAND - unsigned int type; struct wl_listener activate; struct wl_listener configure; #endif @@ -140,6 +141,8 @@ typedef struct { } Keyboard; typedef struct { + /* Must be first */ + unsigned int type; /* LayerShell */ struct wlr_layer_surface_v1 *layer_surface; struct wl_list link; @@ -917,6 +920,7 @@ createlayersurface(struct wl_listener *listener, void *data) } layersurface = calloc(1, sizeof(LayerSurface)); + layersurface->type = LayerShell; LISTEN(&wlr_layer_surface->surface->events.commit, &layersurface->surface_commit, commitlayersurfacenotify); LISTEN(&wlr_layer_surface->events.destroy, &layersurface->destroy, From 1b38801eef319a9f8b618bf29564104af6b0a39d Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sun, 5 Sep 2021 16:07:28 -0500 Subject: [PATCH 02/25] use scene-graph API for Client/LayerSurface --- dwl.c | 422 ++++++++++++++++------------------------------------------ 1 file changed, 115 insertions(+), 307 deletions(-) diff --git a/dwl.c b/dwl.c index 08f7e32..2f4bb4c 100644 --- a/dwl.c +++ b/dwl.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -60,12 +61,12 @@ #define LENGTH(X) (sizeof X / sizeof X[0]) #define END(A) ((A) + LENGTH(A)) #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))) /* enums */ enum { CurNormal, CurMove, CurResize }; /* cursor */ enum { XDGShell, LayerShell, X11Managed, X11Unmanaged }; /* client types */ +enum { LyrBg, LyrBottom, LyrTop, LyrOverlay, LyrTile, LyrFloat, NUM_LAYERS }; /* scene layers */ #ifdef XWAYLAND enum { NetWMWindowTypeDialog, NetWMWindowTypeSplash, NetWMWindowTypeToolbar, NetWMWindowTypeUtility, NetLast }; /* EWMH atoms */ @@ -89,9 +90,11 @@ typedef struct Monitor Monitor; typedef struct { /* Must be first */ 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 flink; - struct wl_list slink; union { struct wlr_xdg_surface *xdg; struct wlr_xwayland_surface *xwayland; @@ -143,8 +146,9 @@ typedef struct { typedef struct { /* Must be first */ unsigned int type; /* LayerShell */ - struct wlr_layer_surface_v1 *layer_surface; + struct wlr_scene_node *scene; struct wl_list link; + struct wlr_layer_surface_v1 *layer_surface; struct wl_listener destroy; struct wl_listener map; @@ -203,14 +207,6 @@ typedef struct { int monitor; } 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 */ static void applybounds(Client *c, struct wlr_box *bbox); 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 quit(const Arg *arg); 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 resize(Client *c, int x, int y, int w, int h, int interact); static void run(char *startup_cmd); -static void scalebox(struct wlr_box *box, float scale); static Client *selclient(void); static void setcursor(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 view(const Arg *arg); static void virtualkeyboard(struct wl_listener *listener, void *data); -static Client *xytoclient(double x, double y); -static struct wlr_surface *xytolayersurface(struct wl_list *layer_surfaces, - double x, double y, double *sx, double *sy); +static struct wlr_scene_node *xytonode(double x, double y, struct wlr_surface **psurface, + Client **pc, LayerSurface **pl, double *nx, double *ny); static Monitor *xytomon(double x, double y); static void zoom(const Arg *arg); @@ -309,6 +300,8 @@ static void zoom(const Arg *arg); static const char broken[] = "broken"; static struct wl_display *dpy; 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_compositor *compositor; @@ -316,7 +309,6 @@ static struct wlr_xdg_shell *xdg_shell; static struct wlr_xdg_activation_v1 *activation; static struct wl_list clients; /* tiling order */ static struct wl_list fstack; /* focus order */ -static struct wl_list stack; /* stacking z-order */ static struct wl_list independents; static struct wlr_idle *idle; 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 createnotifyx11(struct wl_listener *listener, void *data); 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 Client *xytoindependent(double x, double y); static struct wl_listener new_xwayland_surface = {.notify = createnotifyx11}; static struct wl_listener xwayland_ready = {.notify = xwaylandready}; static struct wlr_xwayland *xwayland; @@ -483,12 +473,17 @@ applyrules(Client *c) mon = m; } } + wlr_scene_node_reparent(c->scene, layers[c->isfloating ? LyrFloat : LyrTile]); setmon(c, mon, newtags); } void 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) m->lt[m->sellt]->arrange(m); /* 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, state->margin.top, state->margin.right, 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); } } @@ -650,7 +646,8 @@ buttonpress(struct wl_listener *listener, void *data) switch (event->state) { case WLR_BUTTON_PRESSED:; /* 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); 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; Monitor *m; + wlr_scene_node_reparent(layersurface->scene, + layers[wlr_layer_surface->current.layer]); + if (!wlr_output) return; @@ -932,8 +932,13 @@ createlayersurface(struct wl_listener *listener, void *data) layersurface->layer_surface = wlr_layer_surface; wlr_layer_surface->data = layersurface; - 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], &layersurface->link); @@ -1075,8 +1080,9 @@ focusclient(Client *c, int lift) /* Raise client in stacking order if requested */ if (c && lift) { - wl_list_remove(&c->slink); - wl_list_insert(&stack, &c->slink); + /* This isn't easy to do via the current API */ + 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) @@ -1303,27 +1309,40 @@ mapnotify(struct wl_listener *listener, void *data) { /* Called when the surface is mapped, or ready to display on-screen. */ 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)) { + /* Floating, no border */ + wlr_scene_node_reparent(c->scene, layers[LyrFloat]); + c->bw = 0; + /* Insert this independent into independents lists. */ wl_list_insert(&independents, &c->link); return; } - /* Insert this client into client lists. */ - wl_list_insert(&clients, &c->link); - wl_list_insert(&fstack, &c->flink); - wl_list_insert(&stack, &c->slink); - + /* Initialize client geometry with room for border */ + client_set_tiled(c, WLR_EDGE_TOP | WLR_EDGE_BOTTOM | WLR_EDGE_LEFT | WLR_EDGE_RIGHT); client_get_geometry(c, &c->geom); c->geom.width += 2 * c->bw; c->geom.height += 2 * c->bw; - /* Tell the client not to try anything fancy */ - client_set_tiled(c, WLR_EDGE_TOP | WLR_EDGE_BOTTOM | WLR_EDGE_LEFT | WLR_EDGE_RIGHT); + /* Insert this client into client lists. */ + wl_list_insert(&clients, &c->link); + wl_list_insert(&fstack, &c->flink); /* Set initial monitor, tags, floating status, and focus */ applyrules(c); + resize(c, c->geom.x, c->geom.y, c->geom.width, c->geom.height, 0); } void @@ -1356,8 +1375,8 @@ void motionnotify(uint32_t time) { double sx = 0, sy = 0; - struct wlr_surface *surface = NULL; Client *c = NULL; + struct wlr_surface *surface = NULL; // time is 0 in internal calls meant to restore pointer focus. if (time) { @@ -1381,32 +1400,8 @@ motionnotify(uint32_t time) return; } - if ((surface = xytolayersurface(&selmon->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY], - cursor->x, cursor->y, &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); + /* Find the client under the pointer and send the event along. */ + xytonode(cursor->x, cursor->y, &surface, &c, NULL, &sx, &sy); /* 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 @@ -1437,7 +1432,10 @@ motionrelative(struct wl_listener *listener, void *data) void 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; /* Float the window and tell motionnotify to grab it */ @@ -1604,140 +1602,11 @@ quitsignal(int signo) 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 rendermon(struct wl_listener *listener, void *data) { Client *c; - int render = 1; + int skip = 0; /* This function is called every time an output is ready to display a frame, * generally at the output's refresh rate (e.g. 60Hz). */ @@ -1746,13 +1615,9 @@ rendermon(struct wl_listener *listener, void *data) struct timespec now; clock_gettime(CLOCK_MONOTONIC, &now); - /* Do not render if any XDG clients have an outstanding resize. */ - wl_list_for_each(c, &stack, slink) { - if (c->resize) { - wlr_surface_send_frame_done(client_surface(c), &now); - render = 0; - } - } + /* Skip rendering if any XDG clients have an outstanding resize. */ + wl_list_for_each(c, &clients, link) + skip = skip || c->resize; /* HACK: This loop is the simplest way to handle ephemeral pageflip * 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)) return; - if (render) { + if (!skip) { /* 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_clear(drw, rootcolor); - renderlayer(&m->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND], &now); - renderlayer(&m->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM], &now); - renderclients(m, &now); -#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); + /* Render the scene at (-mx, -my) to get this monitor's view. + * wlroots will not render windows falling outside the box. */ + wlr_scene_render_output(scene, m->wlr_output, -m->m.x, -m->m.y, NULL); /* Conclude rendering and swap the buffers, showing the final frame * on-screen. */ wlr_renderer_end(drw); } - } 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 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; c->geom.x = x; c->geom.y = y; c->geom.width = w; c->geom.height = h; 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 */ c->resize = client_set_size(c, c->geom.width - 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 * selclient(void) { @@ -1911,6 +1763,7 @@ void setfloating(Client *c, int floating) { c->isfloating = floating; + wlr_scene_node_reparent(c->scene, layers[c->isfloating ? LyrFloat : LyrTile]); arrange(c->mon); } @@ -1957,7 +1810,7 @@ setmon(Client *c, Monitor *m, unsigned int newtags) } if (m) { /* 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); c->tags = newtags ? newtags : m->tagset[m->seltags]; /* assign tags of target monitor */ arrange(m); @@ -2010,6 +1863,15 @@ setup(void) if (!(backend = wlr_backend_autocreate(dpy))) 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. * The renderer is responsible for defining the various pixel formats it * supports for shared memory, this configures that for clients. */ @@ -2054,7 +1916,6 @@ setup(void) */ wl_list_init(&clients); wl_list_init(&fstack); - wl_list_init(&stack); wl_list_init(&independents); idle = wlr_idle_create(dpy); @@ -2302,7 +2163,7 @@ unmapnotify(struct wl_listener *listener, void *data) setmon(c, NULL, 0); wl_list_remove(&c->flink); - wl_list_remove(&c->slink); + wlr_scene_node_destroy(c->scene); } void @@ -2386,37 +2247,31 @@ virtualkeyboard(struct wl_listener *listener, void *data) createkeyboard(device); } -Client * -xytoclient(double x, double y) +struct wlr_scene_node * +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 - * borders. This relies on stack being ordered from top to bottom. */ - Client *c; - wl_list_for_each(c, &stack, slink) - if (VISIBLEON(c, c->mon) && wlr_box_contains_point(&c->geom, x, y)) - return c; - return NULL; -} - -struct wlr_surface * -xytolayersurface(struct wl_list *layer_surfaces, double x, double y, - double *sx, double *sy) -{ - 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; + struct wlr_scene_node *node, *pnode; + struct wlr_surface *surface = NULL; + Client *c = NULL; + LayerSurface *l = NULL; + if ((node = wlr_scene_node_at(&scene->node, x, y, nx, ny))) { + 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; + } } - return NULL; + + if (psurface) *psurface = surface; + if (pc) *pc = c; + if (pl) *pl = l; + return node; } Monitor * @@ -2520,31 +2375,6 @@ getatom(xcb_connection_t *xc, const char *name) 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 xwaylandready(struct wl_listener *listener, void *data) { @@ -2575,28 +2405,6 @@ xwaylandready(struct wl_listener *listener, void *data) 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 int From be6f573b4ef723a3985489b0ac0eb035d7c34420 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sun, 5 Sep 2021 16:09:26 -0500 Subject: [PATCH 03/25] use scene to keep track of LayerSurfaces' layers --- dwl.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/dwl.c b/dwl.c index 2f4bb4c..de4e573 100644 --- a/dwl.c +++ b/dwl.c @@ -156,7 +156,6 @@ typedef struct { struct wl_listener surface_commit; struct wlr_box geo; - enum zwlr_layer_shell_v1_layer layer; } LayerSurface; typedef struct { @@ -764,16 +763,14 @@ commitlayersurfacenotify(struct wl_listener *listener, void *data) if (!wlr_output) return; - m = wlr_output->data; - arrangelayers(m); - if (layersurface->layer != wlr_layer_surface->current.layer) { + if (layers[wlr_layer_surface->current.layer] != layersurface->scene) { wl_list_remove(&layersurface->link); wl_list_insert(&m->layers[wlr_layer_surface->current.layer], &layersurface->link); - layersurface->layer = wlr_layer_surface->current.layer; } + arrangelayers(m); } void From 0146a9954b2735a08b326abd69492ac3803ec709 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sun, 5 Sep 2021 22:35:07 -0500 Subject: [PATCH 04/25] use scene_output for damage-tracked rendering --- dwl.c | 53 ++++++++++------------------------------------------- 1 file changed, 10 insertions(+), 43 deletions(-) diff --git a/dwl.c b/dwl.c index de4e573..2b37533 100644 --- a/dwl.c +++ b/dwl.c @@ -174,6 +174,7 @@ typedef struct { struct Monitor { struct wl_list link; struct wlr_output *wlr_output; + struct wlr_scene_output *scene_output; struct wl_listener frame; struct wl_listener destroy; struct wlr_box m; /* monitor area, layout-relative */ @@ -862,20 +863,8 @@ createmon(struct wl_listener *listener, void *data) * display, which Wayland clients can see to find out information about the * output (such as DPI, scale factor, manufacturer, etc). */ - wlr_output_layout_add(output_layout, wlr_output, r->x, r->y); - sgeom = *wlr_output_layout_get_box(output_layout, NULL); - - /* When adding monitors, the geometries of all monitors must be updated */ - wl_list_for_each(m, &mons, link) { - /* The first monitor in the list is the most recently added */ - Client *c; - wl_list_for_each(c, &clients, link) { - if (c->isfloating) - resize(c, c->geom.x + m->w.width, c->geom.y, - c->geom.width, c->geom.height, 0); - } - return; - } + m->scene_output = wlr_scene_output_create(scene, wlr_output); + wlr_output_layout_add_auto(output_layout, wlr_output); } void @@ -1602,44 +1591,21 @@ quitsignal(int signo) void rendermon(struct wl_listener *listener, void *data) { - Client *c; - int skip = 0; - /* This function is called every time an output is ready to display a frame, * generally at the output's refresh rate (e.g. 60Hz). */ Monitor *m = wl_container_of(listener, m, frame); - + Client *c; + int skip = 0; struct timespec now; - clock_gettime(CLOCK_MONOTONIC, &now); - /* Skip rendering if any XDG clients have an outstanding resize. */ + /* Render if no XDG clients have an outstanding resize. */ wl_list_for_each(c, &clients, link) skip = skip || c->resize; - - /* HACK: This loop is the simplest way to handle ephemeral pageflip - * failures but probably not the best. Revisit if damage tracking is - * added. */ - do { - /* wlr_output_attach_render makes the OpenGL context current. */ - if (!wlr_output_attach_render(m->wlr_output, NULL)) - return; - - if (!skip) { - /* 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_clear(drw, rootcolor); - - /* Render the scene at (-mx, -my) to get this monitor's view. - * wlroots will not render windows falling outside the box. */ - wlr_scene_render_output(scene, m->wlr_output, -m->m.x, -m->m.y, NULL); - - /* Conclude rendering and swap the buffers, showing the final frame - * on-screen. */ - wlr_renderer_end(drw); - } - } while (!wlr_output_commit(m->wlr_output)); + if (!skip && !wlr_scene_output_commit(m->scene_output)) + return; /* Let clients know a frame has been rendered */ + clock_gettime(CLOCK_MONOTONIC, &now); wl_list_for_each(c, &clients, link) wlr_surface_send_frame_done(client_surface(c), &now); } @@ -2186,6 +2152,7 @@ updatemons(struct wl_listener *listener, void *data) /* Get the effective monitor geometry to use for surfaces */ m->m = m->w = *wlr_output_layout_get_box(output_layout, m->wlr_output); + wlr_scene_output_set_position(m->scene_output, m->m.x, m->m.y); /* Calculate the effective monitor geometry to use for clients */ arrangelayers(m); /* Don't move clients to the left output when plugging monitors */ From c8bf457c0f12955f89abf88e929a97d96d6f46de Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Tue, 21 Sep 2021 10:42:43 -0500 Subject: [PATCH 05/25] fixup: follow name change on surface_tree_create --- dwl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dwl.c b/dwl.c index 2b37533..a15bbd8 100644 --- a/dwl.c +++ b/dwl.c @@ -920,7 +920,7 @@ createlayersurface(struct wl_listener *listener, void *data) wlr_layer_surface->data = layersurface; m = wlr_layer_surface->output->data; - layersurface->scene = wlr_scene_surface_tree_create( + layersurface->scene = wlr_scene_subsurface_tree_create( layers[wlr_layer_surface->client_pending.layer], wlr_layer_surface->surface); layersurface->scene->data = layersurface; @@ -1299,7 +1299,7 @@ mapnotify(struct wl_listener *listener, void *data) /* 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 = wlr_scene_subsurface_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); From 7de6920bd781d77b2d8d5abb847258c6153638c7 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Tue, 21 Sep 2021 14:42:36 -0500 Subject: [PATCH 06/25] send frame_done to all visible surfaces --- dwl.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/dwl.c b/dwl.c index a15bbd8..9e811ca 100644 --- a/dwl.c +++ b/dwl.c @@ -261,6 +261,7 @@ static void pointerfocus(Client *c, struct wlr_surface *surface, static void printstatus(void); static void quit(const Arg *arg); static void quitsignal(int signo); +static void rendered(struct wlr_surface *surface, int sx, int sy, 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 run(char *startup_cmd); @@ -1588,6 +1589,13 @@ quitsignal(int signo) quit(NULL); } +void +rendered(struct wlr_surface *surface, int sx, int sy, void *data) +{ + struct timespec *now = data; + wlr_surface_send_frame_done(surface, now); +} + void rendermon(struct wl_listener *listener, void *data) { @@ -1607,7 +1615,8 @@ rendermon(struct wl_listener *listener, void *data) /* Let clients know a frame has been rendered */ clock_gettime(CLOCK_MONOTONIC, &now); wl_list_for_each(c, &clients, link) - wlr_surface_send_frame_done(client_surface(c), &now); + if (VISIBLEON(c, c->mon)) + client_for_each_surface(c, rendered, &now); } void From df332de9d22f0680a362cd9408a96df58a1d04bc Mon Sep 17 00:00:00 2001 From: Leonardo Hernandez Hernandez Date: Fri, 24 Sep 2021 16:07:06 -0500 Subject: [PATCH 07/25] send frame_done also to all layer surfaces this fixes an issue when bemenu don't update his surface when typing --- dwl.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/dwl.c b/dwl.c index 9e811ca..50ac1b1 100644 --- a/dwl.c +++ b/dwl.c @@ -1603,7 +1603,8 @@ rendermon(struct wl_listener *listener, void *data) * generally at the output's refresh rate (e.g. 60Hz). */ Monitor *m = wl_container_of(listener, m, frame); Client *c; - int skip = 0; + LayerSurface *layer; + int i, skip = 0; struct timespec now; /* Render if no XDG clients have an outstanding resize. */ @@ -1617,6 +1618,11 @@ rendermon(struct wl_listener *listener, void *data) wl_list_for_each(c, &clients, link) if (VISIBLEON(c, c->mon)) client_for_each_surface(c, rendered, &now); + + for (i = 0; i < LENGTH(m->layers); i++) + wl_list_for_each(layer, &m->layers[i], link) + wlr_layer_surface_v1_for_each_surface(layer->layer_surface, rendered, &now); + } void From 2c9423d1b7a387d63b07b96ecbda725f1e16002b Mon Sep 17 00:00:00 2001 From: Leonardo Hernandez Hernandez Date: Sun, 3 Oct 2021 22:08:00 -0500 Subject: [PATCH 08/25] `wlr_xdg_surface.configure_serial` has been moved into `wlr_xdg_surface_state` as seen in swaywm/wlroots@0e34208 --- dwl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dwl.c b/dwl.c index 4a58770..868d57b 100644 --- a/dwl.c +++ b/dwl.c @@ -779,7 +779,7 @@ commitnotify(struct wl_listener *listener, void *data) Client *c = wl_container_of(listener, c, commit); /* mark a pending resize as completed */ - if (c->resize && c->resize <= c->surface.xdg->configure_serial) + if (c->resize && c->resize <= c->surface.xdg->current.configure_serial) c->resize = 0; } From 894f2a3152481f7c53baad14dabc1511b70c7bd7 Mon Sep 17 00:00:00 2001 From: Leonardo Hernandez Hernandez Date: Sun, 31 Oct 2021 15:32:49 -0600 Subject: [PATCH 09/25] change border color according to focus state --- dwl.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/dwl.c b/dwl.c index 58a1bd9..a2054b5 100644 --- a/dwl.c +++ b/dwl.c @@ -1064,6 +1064,8 @@ focusclient(Client *c, int lift) { struct wlr_surface *old = seat->keyboard_state.focused_surface; struct wlr_keyboard *kb; + Client *w; + int i; /* Raise client in stacking order if requested */ if (c && lift) { @@ -1081,6 +1083,9 @@ focusclient(Client *c, int lift) wl_list_insert(&fstack, &c->flink); selmon = c->mon; c->isurgent = 0; + + for (i = 0; i < 4; i++) + wlr_scene_rect_set_color(c->border[i], focuscolor); } /* Deactivate old client if focus is changing */ @@ -1100,6 +1105,16 @@ focusclient(Client *c, int lift) )) return; } else { +#ifdef XWAYLAND + if (wlr_surface_is_xwayland_surface(old)) + w = wlr_xwayland_surface_from_wlr_surface(old)->data; + else +#endif + w = wlr_xdg_surface_from_wlr_surface(old)->data; + + for (i = 0; i < 4; i++) + wlr_scene_rect_set_color(w->border[i], bordercolor); + client_activate_surface(old, 0); } } @@ -1305,6 +1320,7 @@ mapnotify(struct wl_listener *listener, void *data) for (i = 0; i < 4; i++) { c->border[i] = wlr_scene_rect_create(c->scene, 0, 0, bordercolor); c->border[i]->node.data = c; + wlr_scene_rect_set_color(c->border[i], bordercolor); } if (client_is_unmanaged(c)) { From 2b2f72d7c287fe3255dfa8f7db13f81c6a534a57 Mon Sep 17 00:00:00 2001 From: Leonardo Hernandez Hernandez Date: Fri, 24 Sep 2021 16:07:06 -0500 Subject: [PATCH 10/25] use wlr_scene_output_send_frame_done() --- dwl.c | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/dwl.c b/dwl.c index 301256b..5dd566a 100644 --- a/dwl.c +++ b/dwl.c @@ -262,7 +262,6 @@ static void pointerfocus(Client *c, struct wlr_surface *surface, static void printstatus(void); static void quit(const Arg *arg); static void quitsignal(int signo); -static void rendered(struct wlr_surface *surface, int sx, int sy, 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 run(char *startup_cmd); @@ -1605,13 +1604,6 @@ quitsignal(int signo) quit(NULL); } -void -rendered(struct wlr_surface *surface, int sx, int sy, void *data) -{ - struct timespec *now = data; - wlr_surface_send_frame_done(surface, now); -} - void rendermon(struct wl_listener *listener, void *data) { @@ -1631,14 +1623,7 @@ rendermon(struct wl_listener *listener, void *data) /* Let clients know a frame has been rendered */ clock_gettime(CLOCK_MONOTONIC, &now); - wl_list_for_each(c, &clients, link) - if (VISIBLEON(c, c->mon)) - client_for_each_surface(c, rendered, &now); - - for (i = 0; i < LENGTH(m->layers); i++) - wl_list_for_each(layer, &m->layers[i], link) - wlr_layer_surface_v1_for_each_surface(layer->layer_surface, rendered, &now); - + wlr_scene_output_send_frame_done(m->scene_output, &now); } void From b97d9e1ce102fe0aa2331b480827b523164c7d42 Mon Sep 17 00:00:00 2001 From: Leonardo Hernandez Hernandez Date: Sun, 31 Oct 2021 17:05:40 -0600 Subject: [PATCH 11/25] use wlr_scene_node_raise_to_top() --- dwl.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/dwl.c b/dwl.c index 5dd566a..4e90d17 100644 --- a/dwl.c +++ b/dwl.c @@ -1067,11 +1067,8 @@ focusclient(Client *c, int lift) int i; /* Raise client in stacking order if requested */ - if (c && lift) { - /* This isn't easy to do via the current API */ - wl_list_remove(&c->scene->state.link); - wl_list_insert(c->scene->parent->state.children.prev, &c->scene->state.link); - } + if (c && lift) + wlr_scene_node_raise_to_top(c->scene); if (c && client_surface(c) == old) return; From 4465dcb6da1fb91177fc26b4513d14c48eb56d5e Mon Sep 17 00:00:00 2001 From: Leonardo Hernandez Hernandez Date: Tue, 15 Feb 2022 17:38:56 -0600 Subject: [PATCH 12/25] fix left border 'y' position also add comment about border ordering --- dwl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dwl.c b/dwl.c index 4e90d17..d2f910c 100644 --- a/dwl.c +++ b/dwl.c @@ -92,7 +92,7 @@ typedef struct { /* Must be first */ unsigned int type; /* XDGShell or X11* */ struct wlr_scene_node *scene; - struct wlr_scene_rect *border[4]; + struct wlr_scene_rect *border[4]; /* top, bottom, left, right */ struct wlr_scene_node *scene_surface; struct wl_list link; struct wl_list flink; @@ -1641,6 +1641,7 @@ resize(Client *c, int x, int y, int w, int h, int interact) 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[2]->node, 0, 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 */ From 1087bc5db98faf12e02e57433ed52cbc9845e98b Mon Sep 17 00:00:00 2001 From: Leonardo Hernandez Hernandez Date: Fri, 29 Oct 2021 18:38:24 -0500 Subject: [PATCH 13/25] use wlr_scene_xdg_surface_create() for xdg_popups --- dwl.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/dwl.c b/dwl.c index d2f910c..8deee97 100644 --- a/dwl.c +++ b/dwl.c @@ -875,7 +875,11 @@ createnotify(struct wl_listener *listener, void *data) struct wlr_xdg_surface *xdg_surface = data; Client *c; - if (xdg_surface->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) + if (xdg_surface->role == WLR_XDG_SURFACE_ROLE_POPUP) { + xdg_surface->surface->data = wlr_scene_xdg_surface_create( + xdg_surface->popup->parent->data, xdg_surface); + return; + } else if (xdg_surface->role == WLR_XDG_SURFACE_ROLE_NONE) return; /* Allocate a Client for this surface */ @@ -1311,7 +1315,8 @@ mapnotify(struct wl_listener *listener, void *data) /* Create scene tree for this client and its border */ c->scene = &wlr_scene_tree_create(layers[LyrTile])->node; - c->scene_surface = wlr_scene_subsurface_tree_create(c->scene, client_surface(c)); + c->scene_surface = client_surface(c)->data = + wlr_scene_subsurface_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); From b92c0ff57fbf9cc9ffb2a33e689acc08b8745f1d Mon Sep 17 00:00:00 2001 From: Leonardo Hernandez Hernandez Date: Tue, 1 Feb 2022 01:16:56 -0600 Subject: [PATCH 14/25] add support for layer_shell popups --- dwl.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/dwl.c b/dwl.c index 8deee97..0d8a1b1 100644 --- a/dwl.c +++ b/dwl.c @@ -871,7 +871,10 @@ void createnotify(struct wl_listener *listener, void *data) { /* This event is raised when wlr_xdg_shell receives a new xdg surface from a - * client, either a toplevel (application window) or popup. */ + * client, either a toplevel (application window) or popup, + * or when wlr_layer_shell receives a new popup from a layer. + * If you want to do something tricky with popups you should check if + * its parent is wlr_xdg_shell or wlr_layer_shell */ struct wlr_xdg_surface *xdg_surface = data; Client *c; @@ -924,8 +927,8 @@ createlayersurface(struct wl_listener *listener, void *data) wlr_layer_surface->data = layersurface; m = wlr_layer_surface->output->data; - layersurface->scene = wlr_scene_subsurface_tree_create( - layers[wlr_layer_surface->pending.layer], + layersurface->scene = wlr_layer_surface->surface->data = + wlr_scene_subsurface_tree_create(layers[wlr_layer_surface->pending.layer], wlr_layer_surface->surface); layersurface->scene->data = layersurface; From 863eedd05e8d292ccef2530d9b4b8b5475b8cbef Mon Sep 17 00:00:00 2001 From: Leonardo Hernandez Hernandez Date: Mon, 31 Jan 2022 14:02:59 -0600 Subject: [PATCH 15/25] set correct position for unmanaged clients - don't allow to move/resize with them - don't focus unmanaged clients on buttonpress() --- dwl.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dwl.c b/dwl.c index 0d8a1b1..7f8d3f4 100644 --- a/dwl.c +++ b/dwl.c @@ -645,7 +645,8 @@ buttonpress(struct wl_listener *listener, void *data) case WLR_BUTTON_PRESSED:; /* Change focus if the button was _pressed_ over a client */ xytonode(cursor->x, cursor->y, NULL, &c, NULL, NULL, NULL); - if (c) + /* Don't focus unmanaged clients */ + if (c && !client_is_unmanaged(c)) focusclient(c, 1); keyboard = wlr_seat_get_keyboard(seat); @@ -1328,9 +1329,12 @@ mapnotify(struct wl_listener *listener, void *data) } if (client_is_unmanaged(c)) { + client_get_geometry(c, &c->geom); /* Floating, no border */ wlr_scene_node_reparent(c->scene, layers[LyrFloat]); c->bw = 0; + wlr_scene_node_set_position(c->scene, c->geom.x + borderpx, + c->geom.y + borderpx); /* Insert this independent into independents lists. */ wl_list_insert(&independents, &c->link); @@ -1442,7 +1446,7 @@ moveresize(const Arg *arg) if (cursor_mode != CurNormal) return; xytonode(cursor->x, cursor->y, NULL, &grabc, NULL, NULL, NULL); - if (!grabc) + if (!grabc || client_is_unmanaged(grabc)) return; /* Float the window and tell motionnotify to grab it */ From f1c92b05fb124d6865d4dfb0c121b3dbf7fd5407 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Hern=C3=A1ndez=20Hern=C3=A1ndez?= Date: Fri, 18 Mar 2022 00:49:47 -0600 Subject: [PATCH 16/25] get old client by surface's node --- dwl.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/dwl.c b/dwl.c index 347178b..4df0e95 100644 --- a/dwl.c +++ b/dwl.c @@ -1076,7 +1076,6 @@ focusclient(Client *c, int lift) { struct wlr_surface *old = seat->keyboard_state.focused_surface; struct wlr_keyboard *kb; - Client *w; int i; /* Raise client in stacking order if requested */ @@ -1114,15 +1113,11 @@ focusclient(Client *c, int lift) )) return; } else { -#ifdef XWAYLAND - if (wlr_surface_is_xwayland_surface(old)) - w = wlr_xwayland_surface_from_wlr_surface(old)->data; - else -#endif - w = wlr_xdg_surface_from_wlr_surface(old)->data; - - for (i = 0; i < 4; i++) - wlr_scene_rect_set_color(w->border[i], bordercolor); + Client *w; + struct wlr_scene_node *node = old->data; + if ((w = node->data)) + for (i = 0; i < 4; i++) + wlr_scene_rect_set_color(w->border[i], bordercolor); client_activate_surface(old, 0); } From 1b22ef16161fe832e14aa29678e09eb7df56e395 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Hern=C3=A1ndez=20Hern=C3=A1ndez?= Date: Fri, 18 Mar 2022 00:52:21 -0600 Subject: [PATCH 17/25] use xdg_shell helper for xwayland continue using wlr_scene_subsurface_create() --- dwl.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dwl.c b/dwl.c index 4df0e95..464554c 100644 --- a/dwl.c +++ b/dwl.c @@ -1319,8 +1319,9 @@ mapnotify(struct wl_listener *listener, void *data) /* Create scene tree for this client and its border */ c->scene = &wlr_scene_tree_create(layers[LyrTile])->node; - c->scene_surface = client_surface(c)->data = - wlr_scene_subsurface_tree_create(c->scene, client_surface(c)); + c->scene_surface = client_surface(c)->data = c->type == XDGShell + ? wlr_scene_xdg_surface_create(c->scene, c->surface.xdg) + : wlr_scene_subsurface_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); From 0815626d4c4db3aa05ed256975476d6a31be2125 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Hern=C3=A1ndez=20Hern=C3=A1ndez?= Date: Fri, 18 Mar 2022 00:59:52 -0600 Subject: [PATCH 18/25] pointerfocus: only use provided surface if a client is given focus it --- dwl.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/dwl.c b/dwl.c index 464554c..392cec1 100644 --- a/dwl.c +++ b/dwl.c @@ -1540,9 +1540,8 @@ pointerfocus(Client *c, struct wlr_surface *surface, double sx, double sy, struct timespec now; int internal_call = !time; - /* Use top level surface if nothing more specific given */ - if (c && !surface) - surface = client_surface(c); + if (sloppyfocus && !internal_call && c && !client_is_unmanaged(c)) + focusclient(c, 0); /* If surface is NULL, clear pointer focus */ if (!surface) { @@ -1555,21 +1554,12 @@ pointerfocus(Client *c, struct wlr_surface *surface, double sx, double sy, time = now.tv_sec * 1000 + now.tv_nsec / 1000000; } - /* If surface is already focused, only notify of motion */ - if (surface == seat->pointer_state.focused_surface) { - wlr_seat_pointer_notify_motion(seat, time, sx, sy); - return; - } - - /* Otherwise, let the client know that the mouse cursor has entered one - * of its surfaces, and make keyboard focus follow if desired. */ + /* Let the client know that the mouse cursor has entered one + * of its surfaces, and make keyboard focus follow if desired. + * wlroots makes this a no-op if surface is already focused */ wlr_seat_pointer_notify_enter(seat, surface, sx, sy); + wlr_seat_pointer_notify_motion(seat, time, sx, sy); - if (!c || client_is_unmanaged(c)) - return; - - if (sloppyfocus && !internal_call) - focusclient(c, 0); } void From 254f799fde51faf71ce3ec5e7af75826f4263d81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Hern=C3=A1ndez=20Hern=C3=A1ndez?= Date: Fri, 18 Mar 2022 01:02:50 -0600 Subject: [PATCH 19/25] do not create borders for unmanaged clients --- dwl.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/dwl.c b/dwl.c index 392cec1..8f6e816 100644 --- a/dwl.c +++ b/dwl.c @@ -1323,17 +1323,11 @@ mapnotify(struct wl_listener *listener, void *data) ? wlr_scene_xdg_surface_create(c->scene, c->surface.xdg) : wlr_scene_subsurface_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; - wlr_scene_rect_set_color(c->border[i], bordercolor); - } if (client_is_unmanaged(c)) { client_get_geometry(c, &c->geom); - /* Floating, no border */ + /* Floating */ wlr_scene_node_reparent(c->scene, layers[LyrFloat]); - c->bw = 0; wlr_scene_node_set_position(c->scene, c->geom.x + borderpx, c->geom.y + borderpx); @@ -1342,6 +1336,13 @@ mapnotify(struct wl_listener *listener, void *data) return; } + for (i = 0; i < 4; i++) { + c->border[i] = wlr_scene_rect_create(c->scene, 0, 0, bordercolor); + c->border[i]->node.data = c; + wlr_scene_rect_set_color(c->border[i], bordercolor); + wlr_scene_node_lower_to_bottom(&c->border[i]->node); + } + /* Initialize client geometry with room for border */ client_set_tiled(c, WLR_EDGE_TOP | WLR_EDGE_BOTTOM | WLR_EDGE_LEFT | WLR_EDGE_RIGHT); client_get_geometry(c, &c->geom); From 467123dc99db4a537f1043e081cc4a6db136417b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Hern=C3=A1ndez=20Hern=C3=A1ndez?= Date: Fri, 18 Mar 2022 01:03:33 -0600 Subject: [PATCH 20/25] make sure to destroy wlr_scene_node of unmanaged clients --- dwl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dwl.c b/dwl.c index 8f6e816..c63dbe4 100644 --- a/dwl.c +++ b/dwl.c @@ -2139,8 +2139,10 @@ unmapnotify(struct wl_listener *listener, void *data) grabc = NULL; } wl_list_remove(&c->link); - if (client_is_unmanaged(c)) + if (client_is_unmanaged(c)) { + wlr_scene_node_destroy(c->scene); return; + } setmon(c, NULL, 0); wl_list_remove(&c->flink); From 475c13414479d1013c83309fcc4bb8a8707aa721 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Hern=C3=A1ndez=20Hern=C3=A1ndez?= Date: Fri, 18 Mar 2022 01:25:53 -0600 Subject: [PATCH 21/25] do not allow set client size less than its min size --- client.h | 20 ++++++++++++++++++++ dwl.c | 6 ++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/client.h b/client.h index 191dcc5..c59b7a9 100644 --- a/client.h +++ b/client.h @@ -179,3 +179,23 @@ client_surface_at(Client *c, double cx, double cy, double *sx, double *sy) #endif return wlr_xdg_surface_surface_at(c->surface.xdg, cx, cy, sx, sy); } + +static inline void +client_min_size(Client *c, int *width, int *height) +{ + struct wlr_xdg_toplevel *toplevel; + struct wlr_xdg_toplevel_state *state; +#ifdef XWAYLAND + if (client_is_x11(c)) { + struct wlr_xwayland_surface_size_hints *size_hints; + size_hints = c->surface.xwayland->size_hints; + *width = size_hints->min_width; + *height = size_hints->min_height; + return; + } +#endif + toplevel = c->surface.xdg->toplevel; + state = &toplevel->current; + *width = state->min_width; + *height = state->min_height; +} diff --git a/dwl.c b/dwl.c index c63dbe4..d2f0718 100644 --- a/dwl.c +++ b/dwl.c @@ -1636,11 +1636,13 @@ rendermon(struct wl_listener *listener, void *data) void resize(Client *c, int x, int y, int w, int h, int interact) { + int min_width = 0, min_height = 0; struct wlr_box *bbox = interact ? &sgeom : &c->mon->w; + client_min_size(c, &min_width, &min_height); c->geom.x = x; c->geom.y = y; - c->geom.width = w; - c->geom.height = h; + c->geom.width = MAX(min_width + 2 * c->bw, w); + c->geom.height = MAX(min_height + 2 * c->bw, h); applybounds(c, bbox); /* Update scene-graph, including borders */ From e4bf83e26d4eccfcab3d54c6ebdbcc53a90346cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Hern=C3=A1ndez=20Hern=C3=A1ndez?= Date: Fri, 18 Mar 2022 01:43:30 -0600 Subject: [PATCH 22/25] update README.md --- README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1389803..d094599 100644 --- a/README.md +++ b/README.md @@ -19,15 +19,14 @@ dwl is not meant to provide every feature under the sun. Instead, like dwm, it s - Various Wayland protocols - XWayland support as provided by wlroots (can be enabled in `config.mk`) - Zero flickering - Wayland users naturally expect that "every frame is perfect" +- Layer shell popups (used by Waybar) +- Damage tracking provided by scenegraph API Features under consideration (possibly as patches) are: - Protocols made trivial by wlroots -- Implement the input-inhibitor protocol to support screen lockers -- Implement the idle-inhibit protocol which lets applications such as mpv disable idle monitoring -- Layer shell popups (used by Waybar) -- Basic yes/no damage tracking to avoid needless redraws -- More in-depth damage region tracking ([which may improve power usage](https://mozillagfx.wordpress.com/2019/10/22/dramatically-reduced-power-usage-in-firefox-70-on-macos-with-core-animation/)) +- Implement the input-inhibitor protocol to support screen lockers (see https://github.com/djpohly/dwl/pull/132) +- Implement the idle-inhibit protocol which lets applications such as mpv disable idle monitoring (see https://github.com/djpohly/dwl/pull/133) - Implement the text-input and input-method protocols to support IME once ibus implements input-method v2 (see https://github.com/ibus/ibus/pull/2256 and https://github.com/djpohly/dwl/pull/12) Feature *non-goals* for the main codebase include: From e645ea8301f3d6edf14cfb36c4d663bf721d3200 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Hern=C3=A1ndez=20Hern=C3=A1ndez?= Date: Fri, 18 Mar 2022 10:40:40 -0600 Subject: [PATCH 23/25] attach presentation to scene --- dwl.c | 1 + 1 file changed, 1 insertion(+) diff --git a/dwl.c b/dwl.c index bb3ff9a..7f4da78 100644 --- a/dwl.c +++ b/dwl.c @@ -1986,6 +1986,7 @@ setup(void) wl_signal_add(&output_mgr->events.test, &output_mgr_test); presentation = wlr_presentation_create(dpy, backend); + wlr_scene_set_presentation(scene, presentation); #ifdef XWAYLAND /* From 19c14b058c9188b7010ffd62bcb1276417e9ed67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Hern=C3=A1ndez=20Hern=C3=A1ndez?= Date: Fri, 18 Mar 2022 11:04:34 -0600 Subject: [PATCH 24/25] remove unneeded variables --- dwl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dwl.c b/dwl.c index 7f4da78..2d95286 100644 --- a/dwl.c +++ b/dwl.c @@ -1625,8 +1625,7 @@ rendermon(struct wl_listener *listener, void *data) * generally at the output's refresh rate (e.g. 60Hz). */ Monitor *m = wl_container_of(listener, m, frame); Client *c; - LayerSurface *layer; - int i, skip = 0; + int skip = 0; struct timespec now; /* Render if no XDG clients have an outstanding resize. */ From dd463b25c7de4ea802038997a93ea749297b8c2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Hern=C3=A1ndez=20Hern=C3=A1ndez?= Date: Sun, 20 Mar 2022 12:32:44 -0600 Subject: [PATCH 25/25] remove independents list --- dwl.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/dwl.c b/dwl.c index 2d95286..01f51ad 100644 --- a/dwl.c +++ b/dwl.c @@ -302,7 +302,6 @@ static struct wlr_xdg_shell *xdg_shell; static struct wlr_xdg_activation_v1 *activation; static struct wl_list clients; /* tiling order */ static struct wl_list fstack; /* focus order */ -static struct wl_list independents; static struct wlr_idle *idle; static struct wlr_layer_shell_v1 *layer_shell; static struct wlr_output_manager_v1 *output_mgr; @@ -1337,9 +1336,6 @@ mapnotify(struct wl_listener *listener, void *data) wlr_scene_node_reparent(c->scene, layers[LyrFloat]); wlr_scene_node_set_position(c->scene, c->geom.x + borderpx, c->geom.y + borderpx); - - /* Insert this independent into independents lists. */ - wl_list_insert(&independents, &c->link); return; } @@ -1917,7 +1913,6 @@ setup(void) */ wl_list_init(&clients); wl_list_init(&fstack); - wl_list_init(&independents); idle = wlr_idle_create(dpy); @@ -2147,12 +2142,13 @@ unmapnotify(struct wl_listener *listener, void *data) cursor_mode = CurNormal; grabc = NULL; } - wl_list_remove(&c->link); + if (client_is_unmanaged(c)) { wlr_scene_node_destroy(c->scene); return; } + wl_list_remove(&c->link); setmon(c, NULL, 0); wl_list_remove(&c->flink); wlr_scene_node_destroy(c->scene);