aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsinanmohd <sinan@firemail.cc>2023-07-05 19:26:41 +0530
committersinanmohd <sinan@firemail.cc>2023-07-05 19:26:41 +0530
commitd7fdbc257c002ccac813bf359c310d90eb8bca4b (patch)
tree9ab8a6ce2ffa3baaf344d1db53241530d487ee27
parent9ca48b706a7ad571cf976d8d41d786ff2b01a211 (diff)
parentfbd84aca4a2cbaa4e7daaa9d1a546d2248be8fec (diff)
repo: merge branch 'main' of https://github.com/djpohly/dwl
-rw-r--r--.github/ISSUE_TEMPLATE/bug_report.md5
-rw-r--r--dwl.c191
2 files changed, 91 insertions, 105 deletions
diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
index 6b60803..cd9bd8d 100644
--- a/.github/ISSUE_TEMPLATE/bug_report.md
+++ b/.github/ISSUE_TEMPLATE/bug_report.md
@@ -14,9 +14,4 @@ wlroots version:
<!--
Only report bugs that can be reproduced on the main line
Report patch issues to their respective authors
-If the patch author doesn't respond within a reasonable time, email me:
-
-Leonardo Hernández Hernández <leohdz172@protonmail.com>
-
-but note that I'm NOT making any promises
-->
diff --git a/dwl.c b/dwl.c
index 591c505..cb9fd38 100644
--- a/dwl.c
+++ b/dwl.c
@@ -74,7 +74,7 @@
/* enums */
enum { CurNormal, CurPressed, CurMove, CurResize }; /* cursor */
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
enum { NetWMWindowTypeDialog, NetWMWindowTypeSplash, NetWMWindowTypeToolbar,
NetWMWindowTypeUtility, NetLast }; /* EWMH atoms */
@@ -265,6 +265,7 @@ static void focusmon(const Arg *arg);
static void focusstack(const Arg *arg);
static Client *focustop(Monitor *m);
static void fullscreennotify(struct wl_listener *listener, void *data);
+static int handlesig(int signo, void *data);
static void incnmaster(const Arg *arg);
static void inputdevice(struct wl_listener *listener, void *data);
static int keybinding(uint32_t mods, xkb_keysym_t sym);
@@ -288,7 +289,6 @@ static void pointerfocus(Client *c, struct wlr_surface *surface,
double sx, double sy, uint32_t time);
static void printstatus(void);
static void quit(const Arg *arg);
-static void quitsignal(int signo);
static void rendermon(struct wl_listener *listener, void *data);
static void requeststartdrag(struct wl_listener *listener, void *data);
static void resize(Client *c, struct wlr_box geo, int interact);
@@ -335,9 +335,13 @@ static pid_t child_pid = -1;
static int locked;
static void *exclusive_focus;
static struct wl_display *dpy;
+static struct wl_event_loop *eventloop;
+static struct wl_event_source *sighandler[4];
static struct wlr_backend *backend;
static struct wlr_scene *scene;
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_allocator *alloc;
static struct wlr_compositor *compositor;
@@ -406,7 +410,6 @@ 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 sethints(struct wl_listener *listener, void *data);
-static void sigchld(int unused);
static void xwaylandready(struct wl_listener *listener, void *data);
static struct wl_listener new_xwayland_surface = {.notify = createnotifyx11};
static struct wl_listener xwayland_ready = {.notify = xwaylandready};
@@ -661,6 +664,7 @@ checkidleinhibitor(struct wlr_surface *exclude)
void
cleanup(void)
{
+ int i;
#ifdef XWAYLAND
wlr_xwayland_destroy(xwayland);
#endif
@@ -676,6 +680,8 @@ cleanup(void)
wlr_cursor_destroy(cursor);
wlr_output_layout_destroy(output_layout);
wlr_seat_destroy(seat);
+ for (i = 0; i < LENGTH(sighandler); i++)
+ wl_event_source_remove(sighandler[i]);
wl_display_destroy(dpy);
}
@@ -747,17 +753,16 @@ commitlayersurfacenotify(struct wl_listener *listener, void *data)
LayerSurface *layersurface = wl_container_of(listener, layersurface, surface_commit);
struct wlr_layer_surface_v1 *wlr_layer_surface = layersurface->layer_surface;
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
* its monitor has just been destroyed */
if (!wlr_output || !(layersurface->mon = wlr_output->data))
return;
- if (layers[wlr_layer_surface->current.layer] != layersurface->scene->node.parent) {
- wlr_scene_node_reparent(&layersurface->scene->node,
- layers[wlr_layer_surface->current.layer]);
- wlr_scene_node_reparent(&layersurface->popups->node,
- layers[wlr_layer_surface->current.layer]);
+ if (layer != layersurface->scene->node.parent) {
+ wlr_scene_node_reparent(&layersurface->scene->node, layer);
+ wlr_scene_node_reparent(&layersurface->popups->node, layer);
wl_list_remove(&layersurface->link);
wl_list_insert(&layersurface->mon->layers[wlr_layer_surface->current.layer],
&layersurface->link);
@@ -830,8 +835,7 @@ createkeyboard(struct wlr_keyboard *keyboard)
wlr_seat_set_keyboard(seat, keyboard);
- kb->key_repeat_source = wl_event_loop_add_timer(
- wl_display_get_event_loop(dpy), keyrepeat, kb);
+ kb->key_repeat_source = wl_event_loop_add_timer(eventloop, keyrepeat, kb);
/* And add the keyboard to our list of keyboards */
wl_list_insert(&keyboards, &kb->link);
@@ -843,12 +847,15 @@ createlayersurface(struct wl_listener *listener, void *data)
struct wlr_layer_surface_v1 *wlr_layer_surface = data;
LayerSurface *layersurface;
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)
wlr_layer_surface->output = selmon ? selmon->wlr_output : NULL;
- if (!wlr_layer_surface->output)
+ if (!wlr_layer_surface->output) {
wlr_layer_surface_v1_destroy(wlr_layer_surface);
+ return;
+ }
layersurface = ecalloc(1, sizeof(LayerSurface));
layersurface->type = LayerShell;
@@ -865,11 +872,9 @@ createlayersurface(struct wl_listener *listener, void *data)
layersurface->mon = wlr_layer_surface->output->data;
wlr_layer_surface->data = layersurface;
- layersurface->scene_layer = wlr_scene_layer_surface_v1_create(
- layers[wlr_layer_surface->pending.layer], wlr_layer_surface);
+ layersurface->scene_layer = wlr_scene_layer_surface_v1_create(l, wlr_layer_surface);
layersurface->scene = layersurface->scene_layer->tree;
- layersurface->popups = wlr_layer_surface->surface->data =
- wlr_scene_tree_create(layers[wlr_layer_surface->pending.layer]);
+ layersurface->popups = wlr_layer_surface->surface->data = wlr_scene_tree_create(l);
layersurface->scene->node.data = layersurface;
@@ -1214,7 +1219,9 @@ void
focusclient(Client *c, int lift)
{
struct wlr_surface *old = seat->keyboard_state.focused_surface;
- int i, unused_lx, unused_ly;
+ int i, unused_lx, unused_ly, old_client_type;
+ Client *old_c = NULL;
+ LayerSurface *old_l = NULL;
if (locked)
return;
@@ -1226,6 +1233,12 @@ focusclient(Client *c, int lift)
if (c && client_surface(c) == old)
return;
+ if ((old_client_type = toplevel_from_wlr_surface(old, &old_c, &old_l)) == XDGShell) {
+ struct wlr_xdg_popup *popup, *tmp;
+ wl_list_for_each_safe(popup, tmp, &old_c->surface.xdg->popups, link)
+ wlr_xdg_popup_destroy(popup);
+ }
+
/* Put the new client atop the focus stack and select its monitor */
if (c && !client_is_unmanaged(c)) {
wl_list_remove(&c->flink);
@@ -1246,19 +1259,17 @@ focusclient(Client *c, int lift)
/* If an overlay is focused, don't focus or activate the client,
* but only update its position in fstack to render its border with focuscolor
* and focus it after the overlay is closed. */
- Client *w = NULL;
- LayerSurface *l = NULL;
- int type = toplevel_from_wlr_surface(old, &w, &l);
- if (type == LayerShell && wlr_scene_node_coords(&l->scene->node, &unused_lx, &unused_ly)
- && l->layer_surface->current.layer >= ZWLR_LAYER_SHELL_V1_LAYER_TOP) {
+ if (old_client_type == LayerShell && wlr_scene_node_coords(
+ &old_l->scene->node, &unused_lx, &unused_ly)
+ && old_l->layer_surface->current.layer >= ZWLR_LAYER_SHELL_V1_LAYER_TOP) {
return;
- } else if (w && w == exclusive_focus && client_wants_focus(w)) {
+ } else if (old_c && old_c == exclusive_focus && client_wants_focus(old_c)) {
return;
/* Don't deactivate old client if the new one wants focus, as this causes issues with winecfg
* and probably other clients */
- } else if (w && !client_is_unmanaged(w) && (!c || !client_wants_focus(c))) {
+ } else if (old_c && !client_is_unmanaged(old_c) && (!c || !client_wants_focus(c))) {
for (i = 0; i < 4; i++)
- wlr_scene_rect_set_color(w->border[i], bordercolor);
+ wlr_scene_rect_set_color(old_c->border[i], bordercolor);
client_activate_surface(old, 0);
}
@@ -1381,7 +1392,8 @@ termforwin(Client *w)
}
void
-swallow(Client *c, Client *w) {
+swallow(Client *c, Client *w)
+{
c->bw = w->bw;
c->isfloating = w->isfloating;
c->isurgent = w->isurgent;
@@ -1393,6 +1405,28 @@ swallow(Client *c, Client *w) {
wlr_scene_node_set_enabled(&c->scene->node, 1);
}
+int
+handlesig(int signo, void *data)
+{
+ if (signo == SIGCHLD) {
+#ifdef XWAYLAND
+ siginfo_t in;
+ /* wlroots expects to reap the XWayland process itself, so we
+ * use WNOWAIT to keep the child waitable until we know it's not
+ * XWayland.
+ */
+ 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
+ } else if (signo == SIGINT || signo == SIGTERM) {
+ quit(NULL);
+ }
+ return 0;
+}
+
void
incnmaster(const Arg *arg)
{
@@ -1950,12 +1984,6 @@ quit(const Arg *arg)
}
void
-quitsignal(int signo)
-{
- quit(NULL);
-}
-
-void
rendermon(struct wl_listener *listener, void *data)
{
/* This function is called every time an output is ready to display a frame,
@@ -1969,8 +1997,8 @@ rendermon(struct wl_listener *listener, void *data)
wl_list_for_each(c, &clients, link)
if (c->resize && !c->isfloating && client_is_rendered_on_mon(c, m) && !client_is_stopped(c))
goto skip;
- if (!wlr_scene_output_commit(m->scene_output))
- return;
+ wlr_scene_output_commit(m->scene_output);
+
skip:
/* Let clients know a frame has been rendered */
clock_gettime(CLOCK_MONOTONIC, &now);
@@ -2018,8 +2046,6 @@ run(char *startup_cmd)
{
/* Add a Unix socket to the Wayland display. */
const char *socket = wl_display_add_socket_auto(dpy);
- struct sigaction sa = {.sa_flags = SA_RESTART, .sa_handler = SIG_IGN};
- sigemptyset(&sa.sa_mask);
if (!socket)
die("startup: display_add_socket_auto");
setenv("WAYLAND_DISPLAY", socket, 1);
@@ -2047,8 +2073,6 @@ run(char *startup_cmd)
close(piperw[1]);
close(piperw[0]);
}
- /* If nobody is reading the status output, don't terminate */
- sigaction(SIGPIPE, &sa, NULL);
printstatus();
/* At this point the outputs are initialized, choose initial selmon based on
@@ -2201,26 +2225,14 @@ setsel(struct wl_listener *listener, void *data)
void
setup(void)
{
- struct sigaction sa_term = {.sa_flags = SA_RESTART, .sa_handler = quitsignal};
- struct sigaction sa_sigchld = {
-#ifdef XWAYLAND
- .sa_flags = SA_RESTART,
- .sa_handler = sigchld,
-#else
- .sa_flags = SA_NOCLDSTOP | SA_NOCLDWAIT | SA_RESTART,
- .sa_handler = SIG_IGN,
-#endif
- };
- sigemptyset(&sa_term.sa_mask);
- sigemptyset(&sa_sigchld.sa_mask);
+ int i, sig[] = {SIGCHLD, SIGINT, SIGTERM, SIGPIPE};
+
/* The Wayland display is managed by libwayland. It handles accepting
* clients from the Unix socket, manging Wayland globals, and so on. */
dpy = wl_display_create();
-
- /* Set up signal handlers */
- sigaction(SIGCHLD, &sa_sigchld, NULL);
- sigaction(SIGINT, &sa_term, NULL);
- sigaction(SIGTERM, &sa_term, NULL);
+ eventloop = wl_display_get_event_loop(dpy);
+ for (i = 0; i < LENGTH(sighandler); i++)
+ sighandler[i] = wl_event_loop_add_signal(eventloop, sig[i], handlesig, NULL);
/* The backend is a wlroots feature which abstracts the underlying input and
* output hardware. The autocreate option will choose the most suitable
@@ -2235,15 +2247,8 @@ setup(void)
/* Initialize the scene graph used to lay out windows */
scene = wlr_scene_create();
- layers[LyrBg] = wlr_scene_tree_create(&scene->tree);
- layers[LyrBottom] = 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);
+ for (i = 0; i < NUM_LAYERS; i++)
+ layers[i] = wlr_scene_tree_create(&scene->tree);
/* Create a renderer with the default implementation */
if (!(drw = wlr_renderer_autocreate(backend)))
@@ -2334,6 +2339,7 @@ setup(void)
* images are available at all scale factors on the screen (necessary for
* HiDPI support). Scaled cursors will be loaded with each output. */
cursor_mgr = wlr_xcursor_manager_create(NULL, 24);
+ setenv("XCURSOR_SIZE", "24", 1);
/*
* wlr_cursor *only* displays an image on screen. It does not move around
@@ -2409,11 +2415,13 @@ void
startdrag(struct wl_listener *listener, void *data)
{
struct wlr_drag *drag = data;
+ struct wlr_scene_tree *icon;
if (!drag->icon)
return;
- drag->icon->data = wlr_scene_subsurface_tree_create(layers[LyrDragIcon], drag->icon->surface);
+ drag->icon->data = icon = wlr_scene_subsurface_tree_create(&scene->tree, drag->icon->surface);
+ wlr_scene_node_place_below(&icon->node, &layers[LyrBlock]->node);
motionnotify(0);
wl_signal_add(&drag->icon->events.destroy, &drag_icon_destroy);
}
@@ -2657,9 +2665,12 @@ updatemons(struct wl_listener *listener, void *data)
wl_list_for_each(c, &clients, link)
if (!c->mon && client_is_mapped(c))
setmon(c, selmon, c->tags);
- if (selmon->lock_surface)
+ focusclient(focustop(selmon), 1);
+ if (selmon->lock_surface) {
client_notify_enter(selmon->lock_surface->surface,
wlr_seat_get_keyboard(seat));
+ client_activate_surface(selmon->lock_surface->surface, 1);
+ }
}
wlr_output_manager_v1_set_configuration(output_mgr, config);
@@ -2720,24 +2731,22 @@ xytonode(double x, double y, struct wlr_surface **psurface,
struct wlr_surface *surface = NULL;
Client *c = NULL;
LayerSurface *l = NULL;
- const int *layer;
- int focus_order[] = { LyrBlock, LyrOverlay, LyrTop, LyrFS, LyrFloat, LyrTile, LyrBottom, LyrBg };
-
- 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)
- surface = wlr_scene_surface_from_buffer(
- wlr_scene_buffer_from_node(node))->surface;
- /* Walk the tree to find a node that knows the client */
- for (pnode = node; pnode && !c; pnode = &pnode->parent->node)
- c = pnode->data;
- if (c && c->type == LayerShell) {
- c = NULL;
- l = pnode->data;
- }
+ int layer;
+
+ for (layer = NUM_LAYERS - 1; !surface && layer >= 0; layer--) {
+ if (!(node = wlr_scene_node_at(&layers[layer]->node, x, y, nx, ny)))
+ continue;
+
+ if (node->type == WLR_SCENE_NODE_BUFFER)
+ surface = wlr_scene_surface_from_buffer(
+ wlr_scene_buffer_from_node(node))->surface;
+ /* Walk the tree to find a node that knows the client */
+ for (pnode = node; pnode && !c; pnode = &pnode->parent->node)
+ c = pnode->data;
+ if (c && c->type == LayerShell) {
+ c = NULL;
+ l = pnode->data;
}
- if (surface)
- break;
}
if (psurface) *psurface = surface;
@@ -2850,24 +2859,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
xwaylandready(struct wl_listener *listener, void *data)
{
struct wlr_xcursor *xcursor;