Merge remote-tracking branch 'upstream/main' into wlroots-next

This commit is contained in:
Leonardo Hernández Hernández 2023-06-29 13:11:55 -06:00
commit 9dd3f230c0
No known key found for this signature in database
GPG key ID: E538897EE11B9624
2 changed files with 66 additions and 75 deletions

117
dwl.c
View file

@ -74,7 +74,7 @@
/* enums */ /* enums */
enum { CurNormal, CurPressed, CurMove, CurResize }; /* cursor */ enum { CurNormal, CurPressed, CurMove, CurResize }; /* cursor */
enum { XDGShell, LayerShell, X11Managed, X11Unmanaged }; /* client types */ enum { XDGShell, LayerShell, X11Managed, X11Unmanaged }; /* client types */
enum { LyrBg, LyrBottom, LyrTop, LyrOverlay, LyrTile, LyrFloat, LyrFS, LyrDragIcon, LyrBlock, NUM_LAYERS }; /* scene layers */ enum { LyrBg, LyrBottom, LyrTile, LyrFloat, LyrFS, LyrTop, LyrOverlay, LyrBlock, NUM_LAYERS }; /* scene layers */
#ifdef XWAYLAND #ifdef XWAYLAND
enum { NetWMWindowTypeDialog, NetWMWindowTypeSplash, NetWMWindowTypeToolbar, enum { NetWMWindowTypeDialog, NetWMWindowTypeSplash, NetWMWindowTypeToolbar,
NetWMWindowTypeUtility, NetLast }; /* EWMH atoms */ NetWMWindowTypeUtility, NetLast }; /* EWMH atoms */
@ -302,6 +302,7 @@ static void setmon(Client *c, Monitor *m, uint32_t newtags);
static void setpsel(struct wl_listener *listener, void *data); static void setpsel(struct wl_listener *listener, void *data);
static void setsel(struct wl_listener *listener, void *data); static void setsel(struct wl_listener *listener, void *data);
static void setup(void); static void setup(void);
static void sigchld(int unused);
static void spawn(const Arg *arg); static void spawn(const Arg *arg);
static void startdrag(struct wl_listener *listener, void *data); static void startdrag(struct wl_listener *listener, void *data);
static void tag(const Arg *arg); static void tag(const Arg *arg);
@ -333,6 +334,8 @@ static struct wl_display *dpy;
static struct wlr_backend *backend; static struct wlr_backend *backend;
static struct wlr_scene *scene; static struct wlr_scene *scene;
static struct wlr_scene_tree *layers[NUM_LAYERS]; static struct wlr_scene_tree *layers[NUM_LAYERS];
/* Map from ZWLR_LAYER_SHELL_* constants to Lyr* enum */
static const int layermap[] = { LyrBg, LyrBottom, LyrTop, LyrOverlay };
static struct wlr_renderer *drw; static struct wlr_renderer *drw;
static struct wlr_allocator *alloc; static struct wlr_allocator *alloc;
static struct wlr_compositor *compositor; static struct wlr_compositor *compositor;
@ -404,7 +407,6 @@ static void createnotifyx11(struct wl_listener *listener, void *data);
static void dissociatex11(struct wl_listener *listener, void *data); static void dissociatex11(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 sethints(struct wl_listener *listener, void *data); static void sethints(struct wl_listener *listener, void *data);
static void sigchld(int unused);
static void xwaylandready(struct wl_listener *listener, void *data); static void xwaylandready(struct wl_listener *listener, void *data);
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};
@ -740,17 +742,16 @@ commitlayersurfacenotify(struct wl_listener *listener, void *data)
LayerSurface *layersurface = wl_container_of(listener, layersurface, surface_commit); LayerSurface *layersurface = wl_container_of(listener, layersurface, surface_commit);
struct wlr_layer_surface_v1 *wlr_layer_surface = layersurface->layer_surface; struct wlr_layer_surface_v1 *wlr_layer_surface = layersurface->layer_surface;
struct wlr_output *wlr_output = wlr_layer_surface->output; struct wlr_output *wlr_output = wlr_layer_surface->output;
struct wlr_scene_tree *layer = layers[layermap[wlr_layer_surface->current.layer]];
/* For some reason this layersurface have no monitor, this can be because /* For some reason this layersurface have no monitor, this can be because
* its monitor has just been destroyed */ * its monitor has just been destroyed */
if (!wlr_output || !(layersurface->mon = wlr_output->data)) if (!wlr_output || !(layersurface->mon = wlr_output->data))
return; return;
if (layers[wlr_layer_surface->current.layer] != layersurface->scene->node.parent) { if (layer != layersurface->scene->node.parent) {
wlr_scene_node_reparent(&layersurface->scene->node, wlr_scene_node_reparent(&layersurface->scene->node, layer);
layers[wlr_layer_surface->current.layer]); wlr_scene_node_reparent(&layersurface->popups->node, layer);
wlr_scene_node_reparent(&layersurface->popups->node,
layers[wlr_layer_surface->current.layer]);
wl_list_remove(&layersurface->link); wl_list_remove(&layersurface->link);
wl_list_insert(&layersurface->mon->layers[wlr_layer_surface->current.layer], wl_list_insert(&layersurface->mon->layers[wlr_layer_surface->current.layer],
&layersurface->link); &layersurface->link);
@ -836,6 +837,7 @@ createlayersurface(struct wl_listener *listener, void *data)
struct wlr_layer_surface_v1 *wlr_layer_surface = data; struct wlr_layer_surface_v1 *wlr_layer_surface = data;
LayerSurface *layersurface; LayerSurface *layersurface;
struct wlr_layer_surface_v1_state old_state; struct wlr_layer_surface_v1_state old_state;
struct wlr_scene_tree *l = layers[layermap[wlr_layer_surface->pending.layer]];
if (!wlr_layer_surface->output) if (!wlr_layer_surface->output)
wlr_layer_surface->output = selmon ? selmon->wlr_output : NULL; wlr_layer_surface->output = selmon ? selmon->wlr_output : NULL;
@ -860,11 +862,9 @@ createlayersurface(struct wl_listener *listener, void *data)
layersurface->mon = wlr_layer_surface->output->data; layersurface->mon = wlr_layer_surface->output->data;
wlr_layer_surface->data = layersurface; wlr_layer_surface->data = layersurface;
layersurface->scene_layer = wlr_scene_layer_surface_v1_create( layersurface->scene_layer = wlr_scene_layer_surface_v1_create(l, wlr_layer_surface);
layers[wlr_layer_surface->pending.layer], wlr_layer_surface);
layersurface->scene = layersurface->scene_layer->tree; layersurface->scene = layersurface->scene_layer->tree;
layersurface->popups = wlr_layer_surface->surface->data = layersurface->popups = wlr_layer_surface->surface->data = wlr_scene_tree_create(l);
wlr_scene_tree_create(layers[wlr_layer_surface->pending.layer]);
layersurface->scene->node.data = layersurface; layersurface->scene->node.data = layersurface;
@ -2157,27 +2157,21 @@ setsel(struct wl_listener *listener, void *data)
void void
setup(void) setup(void)
{ {
struct sigaction sa_term = {.sa_flags = SA_RESTART, .sa_handler = quitsignal}; int layer;
struct sigaction sa_sigchld = {
#ifdef XWAYLAND /* Set up signal handlers */
.sa_flags = SA_RESTART, struct sigaction sa = {.sa_flags = SA_RESTART, .sa_handler = sigchld};
.sa_handler = sigchld, sigemptyset(&sa.sa_mask);
#else sigaction(SIGCHLD, &sa, NULL);
.sa_flags = SA_NOCLDSTOP | SA_NOCLDWAIT | SA_RESTART,
.sa_handler = SIG_IGN, sa.sa_handler = quitsignal;
#endif sigaction(SIGINT, &sa, NULL);
}; sigaction(SIGTERM, &sa, NULL);
sigemptyset(&sa_term.sa_mask);
sigemptyset(&sa_sigchld.sa_mask);
/* The Wayland display is managed by libwayland. It handles accepting /* The Wayland display is managed by libwayland. It handles accepting
* clients from the Unix socket, manging Wayland globals, and so on. */ * clients from the Unix socket, manging Wayland globals, and so on. */
dpy = wl_display_create(); dpy = wl_display_create();
/* Set up signal handlers */
sigaction(SIGCHLD, &sa_sigchld, NULL);
sigaction(SIGINT, &sa_term, NULL);
sigaction(SIGTERM, &sa_term, NULL);
/* The backend is a wlroots feature which abstracts the underlying input and /* The backend is a wlroots feature which abstracts the underlying input and
* output hardware. The autocreate option will choose the most suitable * output hardware. The autocreate option will choose the most suitable
* backend based on the current environment, such as opening an X11 window * backend based on the current environment, such as opening an X11 window
@ -2191,15 +2185,8 @@ setup(void)
/* Initialize the scene graph used to lay out windows */ /* Initialize the scene graph used to lay out windows */
scene = wlr_scene_create(); scene = wlr_scene_create();
layers[LyrBg] = wlr_scene_tree_create(&scene->tree); for (layer = 0; layer < NUM_LAYERS; layer++)
layers[LyrBottom] = wlr_scene_tree_create(&scene->tree); layers[layer] = wlr_scene_tree_create(&scene->tree);
layers[LyrTile] = wlr_scene_tree_create(&scene->tree);
layers[LyrFloat] = wlr_scene_tree_create(&scene->tree);
layers[LyrFS] = wlr_scene_tree_create(&scene->tree);
layers[LyrTop] = wlr_scene_tree_create(&scene->tree);
layers[LyrOverlay] = wlr_scene_tree_create(&scene->tree);
layers[LyrDragIcon] = wlr_scene_tree_create(&scene->tree);
layers[LyrBlock] = wlr_scene_tree_create(&scene->tree);
/* Create a renderer with the default implementation */ /* Create a renderer with the default implementation */
if (!(drw = wlr_renderer_autocreate(backend))) if (!(drw = wlr_renderer_autocreate(backend)))
@ -2364,6 +2351,28 @@ setup(void)
#endif #endif
} }
void
sigchld(int unused)
{
#ifdef XWAYLAND
siginfo_t in;
/* We should be able to remove this function in favor of a simple
* struct sigaction sa = {.sa_handler = SIG_IGN};
* sigaction(SIGCHLD, &sa, NULL);
* but the Xwayland implementation in wlroots currently prevents us from
* setting our own disposition for SIGCHLD.
*/
/* WNOWAIT leaves the child in a waitable state, in case this is the
* XWayland process
*/
while (!waitid(P_ALL, 0, &in, WEXITED|WNOHANG|WNOWAIT) && in.si_pid
&& (!xwayland || in.si_pid != xwayland->server->pid))
waitpid(in.si_pid, NULL, 0);
#else
while (waitpid(-1, NULL, WNOHANG) > 0);
#endif
}
void void
spawn(const Arg *arg) spawn(const Arg *arg)
{ {
@ -2379,11 +2388,13 @@ void
startdrag(struct wl_listener *listener, void *data) startdrag(struct wl_listener *listener, void *data)
{ {
struct wlr_drag *drag = data; struct wlr_drag *drag = data;
struct wlr_scene_tree *icon;
if (!drag->icon) if (!drag->icon)
return; return;
drag->icon->data = wlr_scene_drag_icon_create(layers[LyrDragIcon], drag->icon); drag->icon->data = icon = wlr_scene_drag_icon_create(&scene->tree, drag->icon);
wlr_scene_node_place_below(&icon->node, &layers[LyrBlock]->node);
motionnotify(0); motionnotify(0);
wl_signal_add(&drag->icon->events.destroy, &drag_icon_destroy); wl_signal_add(&drag->icon->events.destroy, &drag_icon_destroy);
} }
@ -2680,11 +2691,12 @@ xytonode(double x, double y, struct wlr_surface **psurface,
struct wlr_surface *surface = NULL; struct wlr_surface *surface = NULL;
Client *c = NULL; Client *c = NULL;
LayerSurface *l = NULL; LayerSurface *l = NULL;
const int *layer; int layer;
int focus_order[] = { LyrBlock, LyrOverlay, LyrTop, LyrFS, LyrFloat, LyrTile, LyrBottom, LyrBg };
for (layer = NUM_LAYERS - 1; !surface && layer >= 0; layer--) {
if (!(node = wlr_scene_node_at(&layers[layer]->node, x, y, nx, ny)))
continue;
for (layer = focus_order; layer < END(focus_order); layer++) {
if ((node = wlr_scene_node_at(&layers[*layer]->node, x, y, nx, ny))) {
if (node->type == WLR_SCENE_NODE_BUFFER) if (node->type == WLR_SCENE_NODE_BUFFER)
surface = wlr_scene_surface_try_from_buffer( surface = wlr_scene_surface_try_from_buffer(
wlr_scene_buffer_from_node(node))->surface; wlr_scene_buffer_from_node(node))->surface;
@ -2696,9 +2708,6 @@ xytonode(double x, double y, struct wlr_surface **psurface,
l = pnode->data; l = pnode->data;
} }
} }
if (surface)
break;
}
if (psurface) *psurface = surface; if (psurface) *psurface = surface;
if (pc) *pc = c; if (pc) *pc = c;
@ -2828,24 +2837,6 @@ sethints(struct wl_listener *listener, void *data)
} }
} }
void
sigchld(int unused)
{
siginfo_t in;
/* We should be able to remove this function in favor of a simple
* struct sigaction sa = {.sa_handler = SIG_IGN};
* sigaction(SIGCHLD, &sa, NULL);
* but the Xwayland implementation in wlroots currently prevents us from
* setting our own disposition for SIGCHLD.
*/
/* WNOWAIT leaves the child in a waitable state, in case this is the
* XWayland process
*/
while (!waitid(P_ALL, 0, &in, WEXITED|WNOHANG|WNOWAIT) && in.si_pid
&& (!xwayland || in.si_pid != xwayland->server->pid))
waitpid(in.si_pid, NULL, 0);
}
void void
xwaylandready(struct wl_listener *listener, void *data) xwaylandready(struct wl_listener *listener, void *data)
{ {