From 6f34a6d3a6f6604af2c4c257343a31064983651f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Hern=C3=A1ndez=20Hern=C3=A1ndez?= Date: Sat, 10 Aug 2024 11:25:41 -0600 Subject: [PATCH 1/8] use wlr_xwayland_surface_has_window_type() (wlroots!4553) References: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4553 --- client.h | 13 ++++++------- dwl.c | 34 ---------------------------------- 2 files changed, 6 insertions(+), 41 deletions(-) diff --git a/client.h b/client.h index 389b4f0..f1e2ab5 100644 --- a/client.h +++ b/client.h @@ -213,16 +213,15 @@ client_is_float_type(Client *c) if (client_is_x11(c)) { struct wlr_xwayland_surface *surface = c->surface.xwayland; xcb_size_hints_t *size_hints = surface->size_hints; - size_t i; if (surface->modal) return 1; - for (i = 0; i < surface->window_type_len; i++) - if (surface->window_type[i] == netatom[NetWMWindowTypeDialog] - || surface->window_type[i] == netatom[NetWMWindowTypeSplash] - || surface->window_type[i] == netatom[NetWMWindowTypeToolbar] - || surface->window_type[i] == netatom[NetWMWindowTypeUtility]) - return 1; + if (wlr_xwayland_surface_has_window_type(surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_DIALOG) + || wlr_xwayland_surface_has_window_type(surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_SPLASH) + || wlr_xwayland_surface_has_window_type(surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_TOOLBAR) + || wlr_xwayland_surface_has_window_type(surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_UTILITY)) { + return 1; + } return size_hints && size_hints->min_width > 0 && size_hints->min_height > 0 && (size_hints->max_width == size_hints->min_width diff --git a/dwl.c b/dwl.c index 0eba3e9..05e1975 100644 --- a/dwl.c +++ b/dwl.c @@ -85,10 +85,6 @@ enum { CurNormal, CurPressed, CurMove, CurResize }; /* cursor */ enum { XDGShell, LayerShell, X11 }; /* client types */ enum { LyrBg, LyrBottom, LyrTile, LyrFloat, LyrTop, LyrFS, LyrOverlay, LyrBlock, NUM_LAYERS }; /* scene layers */ -#ifdef XWAYLAND -enum { NetWMWindowTypeDialog, NetWMWindowTypeSplash, NetWMWindowTypeToolbar, - NetWMWindowTypeUtility, NetLast }; /* EWMH atoms */ -#endif typedef union { int i; @@ -417,11 +413,9 @@ static void associatex11(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 dissociatex11(struct wl_listener *listener, void *data); -static xcb_atom_t getatom(xcb_connection_t *xc, const char *name); static void sethints(struct wl_listener *listener, void *data); static void xwaylandready(struct wl_listener *listener, void *data); static struct wlr_xwayland *xwayland; -static xcb_atom_t netatom[NetLast]; #endif /* configuration, allows nested code to access above variables */ @@ -3091,19 +3085,6 @@ dissociatex11(struct wl_listener *listener, void *data) wl_list_remove(&c->unmap.link); } -xcb_atom_t -getatom(xcb_connection_t *xc, const char *name) -{ - xcb_atom_t atom = 0; - xcb_intern_atom_reply_t *reply; - xcb_intern_atom_cookie_t cookie = xcb_intern_atom(xc, 0, strlen(name), name); - if ((reply = xcb_intern_atom_reply(xc, cookie, NULL))) - atom = reply->atom; - free(reply); - - return atom; -} - void sethints(struct wl_listener *listener, void *data) { @@ -3123,19 +3104,6 @@ void xwaylandready(struct wl_listener *listener, void *data) { struct wlr_xcursor *xcursor; - xcb_connection_t *xc = xcb_connect(xwayland->display_name, NULL); - int err = xcb_connection_has_error(xc); - if (err) { - fprintf(stderr, "xcb_connect to X server failed with code %d\n. Continuing with degraded functionality.\n", err); - return; - } - - /* Collect atoms we are interested in. If getatom returns 0, we will - * not detect that window type. */ - netatom[NetWMWindowTypeDialog] = getatom(xc, "_NET_WM_WINDOW_TYPE_DIALOG"); - netatom[NetWMWindowTypeSplash] = getatom(xc, "_NET_WM_WINDOW_TYPE_SPLASH"); - netatom[NetWMWindowTypeToolbar] = getatom(xc, "_NET_WM_WINDOW_TYPE_TOOLBAR"); - netatom[NetWMWindowTypeUtility] = getatom(xc, "_NET_WM_WINDOW_TYPE_UTILITY"); /* assign the one and only seat */ wlr_xwayland_set_seat(xwayland, seat); @@ -3146,8 +3114,6 @@ xwaylandready(struct wl_listener *listener, void *data) xcursor->images[0]->buffer, xcursor->images[0]->width * 4, xcursor->images[0]->width, xcursor->images[0]->height, xcursor->images[0]->hotspot_x, xcursor->images[0]->hotspot_y); - - xcb_disconnect(xc); } #endif From 26504f9a6f93e5b14819d5ed84dd27d3fbb41f3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Hern=C3=A1ndez=20Hern=C3=A1ndez?= Date: Thu, 26 Dec 2024 20:18:51 -0600 Subject: [PATCH 2/8] do not call waitid(2) in the signal handler when Xwayland is enabled waitid(2) is not a async-signal-safe function acording to signal-safety(7) We can stop doing this because wlroots!4926 allows compositors to install signal handlers for SIGCHLD. References: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4926 --- dwl.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/dwl.c b/dwl.c index 05e1975..ea66483 100644 --- a/dwl.c +++ b/dwl.c @@ -1486,22 +1486,10 @@ gpureset(struct wl_listener *listener, void *data) void handlesig(int signo) { - 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 + if (signo == SIGCHLD) while (waitpid(-1, NULL, WNOHANG) > 0); -#endif - } else if (signo == SIGINT || signo == SIGTERM) { + else if (signo == SIGINT || signo == SIGTERM) quit(NULL); - } } void From 0925fe956aeddb983875f0fd892e9049e2d8cb76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Hern=C3=A1ndez=20Hern=C3=A1ndez?= Date: Thu, 16 Jan 2025 19:02:02 -0600 Subject: [PATCH 3/8] unlink some destroy listeners Recently wlroots was updated to assert that signals do not have listeners attached on destroy. This is just a preliminar work to fix dwl. At the moment dwl will trigger the assertions at exit. References: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4918 --- dwl.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dwl.c b/dwl.c index ea66483..d9d9f95 100644 --- a/dwl.c +++ b/dwl.c @@ -1176,6 +1176,7 @@ destroydragicon(struct wl_listener *listener, void *data) /* Focus enter isn't sent during drag, so refocus the focused node. */ focusclient(focustop(selmon), 1); motionnotify(0, NULL, 0, 0, 0, 0); + wl_list_remove(&listener->link); } void @@ -1184,6 +1185,7 @@ destroyidleinhibitor(struct wl_listener *listener, void *data) /* `data` is the wlr_surface of the idle inhibitor being destroyed, * at this point the idle inhibitor is still in the list of the manager */ checkidleinhibitor(wlr_surface_get_root_surface(data)); + wl_list_remove(&listener->link); } void From 4e7e2999d42fdb6d4796d88e355138fa6ae61252 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Hern=C3=A1ndez=20Hern=C3=A1ndez?= Date: Sun, 19 Jan 2025 13:43:51 -0600 Subject: [PATCH 4/8] Partially revert "Line saver: LISTEN_STATIC macro" This reverts commit 33bcd2e4ca892bb0b558660c99ed63a3dfdd9011. We keep LISTEN_STATIC for three instances where we use it. We use simple listeners for the rest of signals. This is the continuation of 0925fe956aeddb983875f0fd892e9049e2d8cb76 --- dwl.c | 108 ++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 72 insertions(+), 36 deletions(-) diff --git a/dwl.c b/dwl.c index d9d9f95..cfe7772 100644 --- a/dwl.c +++ b/dwl.c @@ -394,7 +394,6 @@ static struct wlr_scene_rect *root_bg; static struct wlr_session_lock_manager_v1 *session_lock_mgr; static struct wlr_scene_rect *locked_bg; static struct wlr_session_lock_v1 *cur_lock; -static struct wl_listener lock_listener = {.notify = locksession}; static struct wlr_seat *seat; static KeyboardGroup *kb_group; @@ -407,6 +406,37 @@ static struct wlr_box sgeom; static struct wl_list mons; static Monitor *selmon; +/* global event handlers */ +static struct wl_listener cursor_axis = {.notify = axisnotify}; +static struct wl_listener cursor_button = {.notify = buttonpress}; +static struct wl_listener cursor_frame = {.notify = cursorframe}; +static struct wl_listener cursor_motion = {.notify = motionrelative}; +static struct wl_listener cursor_motion_absolute = {.notify = motionabsolute}; +static struct wl_listener gpu_reset = {.notify = gpureset}; +static struct wl_listener idle_inhibitor_create = {.notify = createidleinhibitor}; +static struct wl_listener layout_change = {.notify = updatemons}; +static struct wl_listener new_input = {.notify = inputdevice}; +static struct wl_listener new_virtual_keyboard = {.notify = virtualkeyboard}; +static struct wl_listener new_virtual_pointer = {.notify = virtualpointer}; +static struct wl_listener new_pointer_constraint = {.notify = createpointerconstraint}; +static struct wl_listener new_output = {.notify = createmon}; +static struct wl_listener new_xdg_surface = {.notify = createnotify}; +static struct wl_listener new_xdg_popup = {.notify = createpopup}; +static struct wl_listener new_xdg_decoration = {.notify = createdecoration}; +static struct wl_listener new_layer_shell_surface = {.notify = createlayersurface}; +static struct wl_listener output_mgr_apply = {.notify = outputmgrapply}; +static struct wl_listener output_mgr_test = {.notify = outputmgrtest}; +static struct wl_listener output_power_mgr_set_mode = {.notify = powermgrsetmode}; +static struct wl_listener request_activate = {.notify = urgent}; +static struct wl_listener request_cursor = {.notify = setcursor}; +static struct wl_listener request_set_psel = {.notify = setpsel}; +static struct wl_listener request_set_sel = {.notify = setsel}; +static struct wl_listener request_set_shape = {.notify = setcursorshape}; +static struct wl_listener request_start_drag = {.notify = requeststartdrag}; +static struct wl_listener start_drag = {.notify = startdrag}; +static struct wl_listener session_lock_create_lock = {.notify = locksession}; +static struct wl_listener session_lock_mgr_destroy = {.notify = destroysessionmgr}; + #ifdef XWAYLAND static void activatex11(struct wl_listener *listener, void *data); static void associatex11(struct wl_listener *listener, void *data); @@ -415,6 +445,8 @@ static void createnotifyx11(struct wl_listener *listener, void *data); static void dissociatex11(struct wl_listener *listener, void *data); static void sethints(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 xwayland_ready = {.notify = xwaylandready}; static struct wlr_xwayland *xwayland; #endif @@ -1296,8 +1328,8 @@ destroysessionlock(struct wl_listener *listener, void *data) void destroysessionmgr(struct wl_listener *listener, void *data) { - wl_list_remove(&lock_listener.link); - wl_list_remove(&listener->link); + wl_list_remove(&session_lock_create_lock.link); + wl_list_remove(&session_lock_mgr_destroy.link); } void @@ -1473,7 +1505,8 @@ gpureset(struct wl_listener *listener, void *data) if (!(alloc = wlr_allocator_autocreate(backend, drw))) die("couldn't recreate allocator"); - LISTEN_STATIC(&drw->events.lost, gpureset); + wl_list_remove(&gpu_reset.link); + wl_signal_add(&drw->events.lost, &gpu_reset); wlr_compositor_set_renderer(compositor, drw); @@ -2406,7 +2439,7 @@ setup(void) * supports for shared memory, this configures that for clients. */ if (!(drw = wlr_renderer_autocreate(backend))) die("couldn't create renderer"); - LISTEN_STATIC(&drw->events.lost, gpureset); + wl_signal_add(&drw->events.lost, &gpu_reset); /* Create shm, drm and linux_dmabuf interfaces by ourselves. * The simplest way is call: @@ -2453,23 +2486,24 @@ setup(void) /* Initializes the interface used to implement urgency hints */ activation = wlr_xdg_activation_v1_create(dpy); - LISTEN_STATIC(&activation->events.request_activate, urgent); + wl_signal_add(&activation->events.request_activate, &request_activate); wlr_scene_set_gamma_control_manager_v1(scene, wlr_gamma_control_manager_v1_create(dpy)); power_mgr = wlr_output_power_manager_v1_create(dpy); - LISTEN_STATIC(&power_mgr->events.set_mode, powermgrsetmode); + wl_signal_add(&power_mgr->events.set_mode, &output_power_mgr_set_mode); /* Creates an output layout, which a wlroots utility for working with an * arrangement of screens in a physical layout. */ output_layout = wlr_output_layout_create(dpy); - LISTEN_STATIC(&output_layout->events.change, updatemons); - wlr_xdg_output_manager_v1_create(dpy, output_layout); + wl_signal_add(&output_layout->events.change, &layout_change); + + wlr_xdg_output_manager_v1_create(dpy, output_layout); /* Configure a listener to be notified when new outputs are available on the * backend. */ wl_list_init(&mons); - LISTEN_STATIC(&backend->events.new_output, createmon); + wl_signal_add(&backend->events.new_output, &new_output); /* Set up our client lists, the xdg-shell and the layer-shell. The xdg-shell is a * Wayland protocol which is used for application windows. For more @@ -2481,20 +2515,20 @@ setup(void) wl_list_init(&fstack); xdg_shell = wlr_xdg_shell_create(dpy, 6); - LISTEN_STATIC(&xdg_shell->events.new_toplevel, createnotify); - LISTEN_STATIC(&xdg_shell->events.new_popup, createpopup); + wl_signal_add(&xdg_shell->events.new_toplevel, &new_xdg_surface); + wl_signal_add(&xdg_shell->events.new_popup, &new_xdg_popup); layer_shell = wlr_layer_shell_v1_create(dpy, 3); - LISTEN_STATIC(&layer_shell->events.new_surface, createlayersurface); + wl_signal_add(&layer_shell->events.new_surface, &new_layer_shell_surface); idle_notifier = wlr_idle_notifier_v1_create(dpy); idle_inhibit_mgr = wlr_idle_inhibit_v1_create(dpy); - LISTEN_STATIC(&idle_inhibit_mgr->events.new_inhibitor, createidleinhibitor); + wl_signal_add(&idle_inhibit_mgr->events.new_inhibitor, &idle_inhibitor_create); session_lock_mgr = wlr_session_lock_manager_v1_create(dpy); - wl_signal_add(&session_lock_mgr->events.new_lock, &lock_listener); - LISTEN_STATIC(&session_lock_mgr->events.destroy, destroysessionmgr); + wl_signal_add(&session_lock_mgr->events.new_lock, &session_lock_create_lock); + wl_signal_add(&session_lock_mgr->events.destroy, &session_lock_mgr_destroy); locked_bg = wlr_scene_rect_create(layers[LyrBlock], sgeom.width, sgeom.height, (float [4]){0.1f, 0.1f, 0.1f, 1.0f}); wlr_scene_node_set_enabled(&locked_bg->node, 0); @@ -2504,10 +2538,10 @@ setup(void) wlr_server_decoration_manager_create(dpy), WLR_SERVER_DECORATION_MANAGER_MODE_SERVER); xdg_decoration_mgr = wlr_xdg_decoration_manager_v1_create(dpy); - LISTEN_STATIC(&xdg_decoration_mgr->events.new_toplevel_decoration, createdecoration); + wl_signal_add(&xdg_decoration_mgr->events.new_toplevel_decoration, &new_xdg_decoration); pointer_constraints = wlr_pointer_constraints_v1_create(dpy); - LISTEN_STATIC(&pointer_constraints->events.new_constraint, createpointerconstraint); + wl_signal_add(&pointer_constraints->events.new_constraint, &new_pointer_constraint); relative_pointer_mgr = wlr_relative_pointer_manager_v1_create(dpy); @@ -2535,14 +2569,14 @@ setup(void) * * And more comments are sprinkled throughout the notify functions above. */ - LISTEN_STATIC(&cursor->events.motion, motionrelative); - LISTEN_STATIC(&cursor->events.motion_absolute, motionabsolute); - LISTEN_STATIC(&cursor->events.button, buttonpress); - LISTEN_STATIC(&cursor->events.axis, axisnotify); - LISTEN_STATIC(&cursor->events.frame, cursorframe); + wl_signal_add(&cursor->events.motion, &cursor_motion); + wl_signal_add(&cursor->events.motion_absolute, &cursor_motion_absolute); + wl_signal_add(&cursor->events.button, &cursor_button); + wl_signal_add(&cursor->events.axis, &cursor_axis); + wl_signal_add(&cursor->events.frame, &cursor_frame); cursor_shape_mgr = wlr_cursor_shape_manager_v1_create(dpy, 1); - LISTEN_STATIC(&cursor_shape_mgr->events.request_set_shape, setcursorshape); + wl_signal_add(&cursor_shape_mgr->events.request_set_shape, &request_set_shape); /* * Configures a seat, which is a single "seat" at which a user sits and @@ -2550,25 +2584,27 @@ setup(void) * pointer, touch, and drawing tablet device. We also rig up a listener to * let us know when new input devices are available on the backend. */ - LISTEN_STATIC(&backend->events.new_input, inputdevice); + wl_signal_add(&backend->events.new_input, &new_input); virtual_keyboard_mgr = wlr_virtual_keyboard_manager_v1_create(dpy); - LISTEN_STATIC(&virtual_keyboard_mgr->events.new_virtual_keyboard, virtualkeyboard); + wl_signal_add(&virtual_keyboard_mgr->events.new_virtual_keyboard, + &new_virtual_keyboard); virtual_pointer_mgr = wlr_virtual_pointer_manager_v1_create(dpy); - LISTEN_STATIC(&virtual_pointer_mgr->events.new_virtual_pointer, virtualpointer); + wl_signal_add(&virtual_pointer_mgr->events.new_virtual_pointer, + &new_virtual_pointer); seat = wlr_seat_create(dpy, "seat0"); - LISTEN_STATIC(&seat->events.request_set_cursor, setcursor); - LISTEN_STATIC(&seat->events.request_set_selection, setsel); - LISTEN_STATIC(&seat->events.request_set_primary_selection, setpsel); - LISTEN_STATIC(&seat->events.request_start_drag, requeststartdrag); - LISTEN_STATIC(&seat->events.start_drag, startdrag); + wl_signal_add(&seat->events.request_set_cursor, &request_cursor); + wl_signal_add(&seat->events.request_set_selection, &request_set_sel); + wl_signal_add(&seat->events.request_set_primary_selection, &request_set_psel); + wl_signal_add(&seat->events.request_start_drag, &request_start_drag); + wl_signal_add(&seat->events.start_drag, &start_drag); kb_group = createkeyboardgroup(); wl_list_init(&kb_group->destroy.link); output_mgr = wlr_output_manager_v1_create(dpy); - LISTEN_STATIC(&output_mgr->events.apply, outputmgrapply); - LISTEN_STATIC(&output_mgr->events.test, outputmgrtest); + wl_signal_add(&output_mgr->events.apply, &output_mgr_apply); + wl_signal_add(&output_mgr->events.test, &output_mgr_test); /* Make sure XWayland clients don't connect to the parent X server, * e.g when running in the x11 backend or the wayland backend and the @@ -2580,8 +2616,8 @@ setup(void) * It will be started when the first X client is started. */ if ((xwayland = wlr_xwayland_create(dpy, compositor, 1))) { - LISTEN_STATIC(&xwayland->events.ready, xwaylandready); - LISTEN_STATIC(&xwayland->events.new_surface, createnotifyx11); + wl_signal_add(&xwayland->events.ready, &xwayland_ready); + wl_signal_add(&xwayland->events.new_surface, &new_xwayland_surface); setenv("DISPLAY", xwayland->display_name, 1); } else { From 9a9f67db1c9a1b05d4edbaa310d78a76f3831b54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Hern=C3=A1ndez=20Hern=C3=A1ndez?= Date: Sun, 19 Jan 2025 14:04:03 -0600 Subject: [PATCH 5/8] unlink global listeners on destroy Continuation of 0925fe956aeddb983875f0fd892e9049e2d8cb76 --- dwl.c | 49 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/dwl.c b/dwl.c index cfe7772..f7ae6fb 100644 --- a/dwl.c +++ b/dwl.c @@ -252,6 +252,7 @@ static void chvt(const Arg *arg); static void checkidleinhibitor(struct wlr_surface *exclude); static void cleanup(void); static void cleanupmon(struct wl_listener *listener, void *data); +static void cleanuplisteners(void); static void closemon(Monitor *m); static void commitlayersurfacenotify(struct wl_listener *listener, void *data); static void commitnotify(struct wl_listener *listener, void *data); @@ -279,7 +280,6 @@ static void destroylocksurface(struct wl_listener *listener, void *data); static void destroynotify(struct wl_listener *listener, void *data); static void destroypointerconstraint(struct wl_listener *listener, void *data); static void destroysessionlock(struct wl_listener *listener, void *data); -static void destroysessionmgr(struct wl_listener *listener, void *data); static void destroykeyboardgroup(struct wl_listener *listener, void *data); static Monitor *dirtomon(enum wlr_direction dir); static void focusclient(Client *c, int lift); @@ -435,7 +435,6 @@ static struct wl_listener request_set_shape = {.notify = setcursorshape}; static struct wl_listener request_start_drag = {.notify = requeststartdrag}; static struct wl_listener start_drag = {.notify = startdrag}; static struct wl_listener session_lock_create_lock = {.notify = locksession}; -static struct wl_listener session_lock_mgr_destroy = {.notify = destroysessionmgr}; #ifdef XWAYLAND static void activatex11(struct wl_listener *listener, void *data); @@ -696,6 +695,7 @@ checkidleinhibitor(struct wlr_surface *exclude) void cleanup(void) { + cleanuplisteners(); #ifdef XWAYLAND wlr_xwayland_destroy(xwayland); xwayland = NULL; @@ -745,6 +745,43 @@ cleanupmon(struct wl_listener *listener, void *data) free(m); } +void +cleanuplisteners(void) +{ + wl_list_remove(&cursor_axis.link); + wl_list_remove(&cursor_button.link); + wl_list_remove(&cursor_frame.link); + wl_list_remove(&cursor_motion.link); + wl_list_remove(&cursor_motion_absolute.link); + wl_list_remove(&gpu_reset.link); + wl_list_remove(&idle_inhibitor_create.link); + wl_list_remove(&layout_change.link); + wl_list_remove(&new_input.link); + wl_list_remove(&new_virtual_keyboard.link); + wl_list_remove(&new_virtual_pointer.link); + wl_list_remove(&new_pointer_constraint.link); + wl_list_remove(&new_output.link); + wl_list_remove(&new_xdg_surface.link); + wl_list_remove(&new_xdg_decoration.link); + wl_list_remove(&new_xdg_popup.link); + wl_list_remove(&new_layer_shell_surface.link); + wl_list_remove(&output_mgr_apply.link); + wl_list_remove(&output_mgr_test.link); + wl_list_remove(&output_power_mgr_set_mode.link); + wl_list_remove(&request_activate.link); + wl_list_remove(&request_cursor.link); + wl_list_remove(&request_set_psel.link); + wl_list_remove(&request_set_sel.link); + wl_list_remove(&request_set_shape.link); + wl_list_remove(&request_start_drag.link); + wl_list_remove(&start_drag.link); + wl_list_remove(&session_lock_create_lock.link); +#ifdef XWAYLAND + wl_list_remove(&new_xwayland_surface.link); + wl_list_remove(&xwayland_ready.link); +#endif +} + void closemon(Monitor *m) { @@ -1325,13 +1362,6 @@ destroysessionlock(struct wl_listener *listener, void *data) destroylock(lock, 0); } -void -destroysessionmgr(struct wl_listener *listener, void *data) -{ - wl_list_remove(&session_lock_create_lock.link); - wl_list_remove(&session_lock_mgr_destroy.link); -} - void destroykeyboardgroup(struct wl_listener *listener, void *data) { @@ -2528,7 +2558,6 @@ setup(void) session_lock_mgr = wlr_session_lock_manager_v1_create(dpy); wl_signal_add(&session_lock_mgr->events.new_lock, &session_lock_create_lock); - wl_signal_add(&session_lock_mgr->events.destroy, &session_lock_mgr_destroy); locked_bg = wlr_scene_rect_create(layers[LyrBlock], sgeom.width, sgeom.height, (float [4]){0.1f, 0.1f, 0.1f, 1.0f}); wlr_scene_node_set_enabled(&locked_bg->node, 0); From da13a9568312ccfdb1c5e527abf773d7512f3f14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Hern=C3=A1ndez=20Hern=C3=A1ndez?= Date: Sun, 19 Jan 2025 14:05:54 -0600 Subject: [PATCH 6/8] destroy keyboard group after unlinking listeners Last commit addressing the issue mentioned in 0925fe956aeddb983875f0fd892e9049e2d8cb76 --- dwl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dwl.c b/dwl.c index f7ae6fb..1ff1167 100644 --- a/dwl.c +++ b/dwl.c @@ -1367,10 +1367,10 @@ destroykeyboardgroup(struct wl_listener *listener, void *data) { KeyboardGroup *group = wl_container_of(listener, group, destroy); wl_event_source_remove(group->key_repeat_source); - wlr_keyboard_group_destroy(group->wlr_group); wl_list_remove(&group->key.link); wl_list_remove(&group->modifiers.link); wl_list_remove(&group->destroy.link); + wlr_keyboard_group_destroy(group->wlr_group); free(group); } From d1c2f434983562bd7d2ace15ab0c05155be603bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Hern=C3=A1ndez=20Hern=C3=A1ndez?= Date: Sun, 19 Jan 2025 17:24:01 -0600 Subject: [PATCH 7/8] rename some listeners To keep consistency with the rest of listeners --- dwl.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/dwl.c b/dwl.c index 1ff1167..ad21e1b 100644 --- a/dwl.c +++ b/dwl.c @@ -413,17 +413,17 @@ static struct wl_listener cursor_frame = {.notify = cursorframe}; static struct wl_listener cursor_motion = {.notify = motionrelative}; static struct wl_listener cursor_motion_absolute = {.notify = motionabsolute}; static struct wl_listener gpu_reset = {.notify = gpureset}; -static struct wl_listener idle_inhibitor_create = {.notify = createidleinhibitor}; static struct wl_listener layout_change = {.notify = updatemons}; -static struct wl_listener new_input = {.notify = inputdevice}; +static struct wl_listener new_idle_inhibitor = {.notify = createidleinhibitor}; +static struct wl_listener new_input_device = {.notify = inputdevice}; static struct wl_listener new_virtual_keyboard = {.notify = virtualkeyboard}; static struct wl_listener new_virtual_pointer = {.notify = virtualpointer}; static struct wl_listener new_pointer_constraint = {.notify = createpointerconstraint}; static struct wl_listener new_output = {.notify = createmon}; -static struct wl_listener new_xdg_surface = {.notify = createnotify}; +static struct wl_listener new_xdg_toplevel = {.notify = createnotify}; static struct wl_listener new_xdg_popup = {.notify = createpopup}; static struct wl_listener new_xdg_decoration = {.notify = createdecoration}; -static struct wl_listener new_layer_shell_surface = {.notify = createlayersurface}; +static struct wl_listener new_layer_surface = {.notify = createlayersurface}; static struct wl_listener output_mgr_apply = {.notify = outputmgrapply}; static struct wl_listener output_mgr_test = {.notify = outputmgrtest}; static struct wl_listener output_power_mgr_set_mode = {.notify = powermgrsetmode}; @@ -431,10 +431,10 @@ static struct wl_listener request_activate = {.notify = urgent}; static struct wl_listener request_cursor = {.notify = setcursor}; static struct wl_listener request_set_psel = {.notify = setpsel}; static struct wl_listener request_set_sel = {.notify = setsel}; -static struct wl_listener request_set_shape = {.notify = setcursorshape}; +static struct wl_listener request_set_cursor_shape = {.notify = setcursorshape}; static struct wl_listener request_start_drag = {.notify = requeststartdrag}; static struct wl_listener start_drag = {.notify = startdrag}; -static struct wl_listener session_lock_create_lock = {.notify = locksession}; +static struct wl_listener new_session_lock = {.notify = locksession}; #ifdef XWAYLAND static void activatex11(struct wl_listener *listener, void *data); @@ -754,17 +754,17 @@ cleanuplisteners(void) wl_list_remove(&cursor_motion.link); wl_list_remove(&cursor_motion_absolute.link); wl_list_remove(&gpu_reset.link); - wl_list_remove(&idle_inhibitor_create.link); + wl_list_remove(&new_idle_inhibitor.link); wl_list_remove(&layout_change.link); - wl_list_remove(&new_input.link); + wl_list_remove(&new_input_device.link); wl_list_remove(&new_virtual_keyboard.link); wl_list_remove(&new_virtual_pointer.link); wl_list_remove(&new_pointer_constraint.link); wl_list_remove(&new_output.link); - wl_list_remove(&new_xdg_surface.link); + wl_list_remove(&new_xdg_toplevel.link); wl_list_remove(&new_xdg_decoration.link); wl_list_remove(&new_xdg_popup.link); - wl_list_remove(&new_layer_shell_surface.link); + wl_list_remove(&new_layer_surface.link); wl_list_remove(&output_mgr_apply.link); wl_list_remove(&output_mgr_test.link); wl_list_remove(&output_power_mgr_set_mode.link); @@ -772,10 +772,10 @@ cleanuplisteners(void) wl_list_remove(&request_cursor.link); wl_list_remove(&request_set_psel.link); wl_list_remove(&request_set_sel.link); - wl_list_remove(&request_set_shape.link); + wl_list_remove(&request_set_cursor_shape.link); wl_list_remove(&request_start_drag.link); wl_list_remove(&start_drag.link); - wl_list_remove(&session_lock_create_lock.link); + wl_list_remove(&new_session_lock.link); #ifdef XWAYLAND wl_list_remove(&new_xwayland_surface.link); wl_list_remove(&xwayland_ready.link); @@ -2545,19 +2545,19 @@ setup(void) wl_list_init(&fstack); xdg_shell = wlr_xdg_shell_create(dpy, 6); - wl_signal_add(&xdg_shell->events.new_toplevel, &new_xdg_surface); + wl_signal_add(&xdg_shell->events.new_toplevel, &new_xdg_toplevel); wl_signal_add(&xdg_shell->events.new_popup, &new_xdg_popup); layer_shell = wlr_layer_shell_v1_create(dpy, 3); - wl_signal_add(&layer_shell->events.new_surface, &new_layer_shell_surface); + wl_signal_add(&layer_shell->events.new_surface, &new_layer_surface); idle_notifier = wlr_idle_notifier_v1_create(dpy); idle_inhibit_mgr = wlr_idle_inhibit_v1_create(dpy); - wl_signal_add(&idle_inhibit_mgr->events.new_inhibitor, &idle_inhibitor_create); + wl_signal_add(&idle_inhibit_mgr->events.new_inhibitor, &new_idle_inhibitor); session_lock_mgr = wlr_session_lock_manager_v1_create(dpy); - wl_signal_add(&session_lock_mgr->events.new_lock, &session_lock_create_lock); + wl_signal_add(&session_lock_mgr->events.new_lock, &new_session_lock); locked_bg = wlr_scene_rect_create(layers[LyrBlock], sgeom.width, sgeom.height, (float [4]){0.1f, 0.1f, 0.1f, 1.0f}); wlr_scene_node_set_enabled(&locked_bg->node, 0); @@ -2605,7 +2605,7 @@ setup(void) wl_signal_add(&cursor->events.frame, &cursor_frame); cursor_shape_mgr = wlr_cursor_shape_manager_v1_create(dpy, 1); - wl_signal_add(&cursor_shape_mgr->events.request_set_shape, &request_set_shape); + wl_signal_add(&cursor_shape_mgr->events.request_set_shape, &request_set_cursor_shape); /* * Configures a seat, which is a single "seat" at which a user sits and @@ -2613,7 +2613,7 @@ setup(void) * pointer, touch, and drawing tablet device. We also rig up a listener to * let us know when new input devices are available on the backend. */ - wl_signal_add(&backend->events.new_input, &new_input); + wl_signal_add(&backend->events.new_input, &new_input_device); virtual_keyboard_mgr = wlr_virtual_keyboard_manager_v1_create(dpy); wl_signal_add(&virtual_keyboard_mgr->events.new_virtual_keyboard, &new_virtual_keyboard); From aa69ed81b558f74e470e69cdcd442f9048ee624c Mon Sep 17 00:00:00 2001 From: korei999 Date: Sun, 2 Feb 2025 01:38:47 +0200 Subject: [PATCH 8/8] allocate with LISTEN_STATIC Fixes: https://codeberg.org/dwl/dwl/issues/723 Supersedes: https://codeberg.org/dwl/dwl/pulls/724 --- dwl.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dwl.c b/dwl.c index ad21e1b..ec4ca86 100644 --- a/dwl.c +++ b/dwl.c @@ -79,7 +79,7 @@ #define END(A) ((A) + LENGTH(A)) #define TAGMASK ((1u << TAGCOUNT) - 1) #define LISTEN(E, L, H) wl_signal_add((E), ((L)->notify = (H), (L))) -#define LISTEN_STATIC(E, H) do { static struct wl_listener _l = {.notify = (H)}; wl_signal_add((E), &_l); } while (0) +#define LISTEN_STATIC(E, H) do { struct wl_listener *_l = ecalloc(1, sizeof(*_l)); _l->notify = (H); wl_signal_add((E), _l); } while (0) /* enums */ enum { CurNormal, CurPressed, CurMove, CurResize }; /* cursor */ @@ -906,6 +906,7 @@ commitpopup(struct wl_listener *listener, void *data) box.y -= (type == LayerShell ? l->scene->node.y : c->geom.y); wlr_xdg_popup_unconstrain_from_box(popup, &box); wl_list_remove(&listener->link); + free(listener); } void @@ -1246,6 +1247,7 @@ destroydragicon(struct wl_listener *listener, void *data) focusclient(focustop(selmon), 1); motionnotify(0, NULL, 0, 0, 0, 0); wl_list_remove(&listener->link); + free(listener); } void @@ -1255,6 +1257,7 @@ destroyidleinhibitor(struct wl_listener *listener, void *data) * at this point the idle inhibitor is still in the list of the manager */ checkidleinhibitor(wlr_surface_get_root_surface(data)); wl_list_remove(&listener->link); + free(listener); } void