fix: listen destroy crash when update to wlroots 0.19

This commit is contained in:
DreamMaoMao 2025-03-04 10:46:55 +08:00
parent 7880d44a2a
commit 77113a119c

209
maomao.c
View file

@ -90,11 +90,7 @@
#define ISFULLSCREEN(A) \ #define ISFULLSCREEN(A) \
((A)->isfullscreen || (A)->ismaxmizescreen || \ ((A)->isfullscreen || (A)->ismaxmizescreen || \
(A)->overview_ismaxmizescreenbak || (A)->overview_isfullscreenbak) (A)->overview_ismaxmizescreenbak || (A)->overview_isfullscreenbak)
#define LISTEN_STATIC(E, H) \ #define LISTEN_STATIC(E, H) do { struct wl_listener *_l = ecalloc(1, sizeof(*_l)); _l->notify = (H); wl_signal_add((E), _l); } while (0)
do { \
static struct wl_listener _l = {.notify = (H)}; \
wl_signal_add((E), &_l); \
} while (0)
/* enums */ /* enums */
/* enums */ /* enums */
@ -390,7 +386,8 @@ static void cleanup(void); // 退出清理
static void cleanupkeyboard(struct wl_listener *listener, static void cleanupkeyboard(struct wl_listener *listener,
void *data); // 退出清理 void *data); // 退出清理
static void cleanupmon(struct wl_listener *listener, void *data); // 退出清理 static void cleanupmon(struct wl_listener *listener, void *data); // 退出清理
static void closemon(Monitor *m); // 退出清理 static void closemon(Monitor *m);
static void cleanuplisteners(void);
static void toggle_hotarea(int x_root, int y_root); // 触发热区 static void toggle_hotarea(int x_root, int y_root); // 触发热区
static void commitlayersurfacenotify(struct wl_listener *listener, void *data); static void commitlayersurfacenotify(struct wl_listener *listener, void *data);
static void commitnotify(struct wl_listener *listener, void *data); static void commitnotify(struct wl_listener *listener, void *data);
@ -418,7 +415,6 @@ static void destroylocksurface(struct wl_listener *listener, void *data);
static void destroynotify(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 destroypointerconstraint(struct wl_listener *listener, void *data);
static void destroysessionlock(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 Monitor *dirtomon(enum wlr_direction dir); static Monitor *dirtomon(enum wlr_direction dir);
static void setcursorshape(struct wl_listener *listener, void *data); static void setcursorshape(struct wl_listener *listener, void *data);
static void dwl_ipc_manager_bind(struct wl_client *client, void *data, static void dwl_ipc_manager_bind(struct wl_client *client, void *data,
@ -642,8 +638,34 @@ static struct zdwl_ipc_output_v2_interface dwl_output_implementation = {
.set_tags = dwl_ipc_output_set_tags, .set_tags = dwl_ipc_output_set_tags,
.set_layout = dwl_ipc_output_set_layout, .set_layout = dwl_ipc_output_set_layout,
.set_client_tags = dwl_ipc_output_set_client_tags}; .set_client_tags = dwl_ipc_output_set_client_tags};
static struct wl_listener lock_listener = {.notify = locksession};
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 gpu_reset = {.notify = gpureset};
static struct wl_listener layout_change = {.notify = updatemons};
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_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_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 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_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 new_session_lock = {.notify = locksession};
#ifdef XWAYLAND #ifdef XWAYLAND
static void activatex11(struct wl_listener *listener, void *data); static void activatex11(struct wl_listener *listener, void *data);
@ -654,6 +676,8 @@ static void associatex11(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 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 xwayland_ready = {.notify = xwaylandready};
void free_config(void); void free_config(void);
// 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};
@ -1961,8 +1985,45 @@ setcursorshape(struct wl_listener *listener, void *data) {
wlr_cursor_shape_v1_name(event->shape)); wlr_cursor_shape_v1_name(event->shape));
} }
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(&new_idle_inhibitor.link);
wl_list_remove(&layout_change.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_toplevel.link);
wl_list_remove(&new_xdg_decoration.link);
wl_list_remove(&new_xdg_popup.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(&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_cursor_shape.link);
wl_list_remove(&request_start_drag.link);
wl_list_remove(&start_drag.link);
wl_list_remove(&new_session_lock.link);
#ifdef XWAYLAND
wl_list_remove(&new_xwayland_surface.link);
wl_list_remove(&xwayland_ready.link);
#endif
}
void // 17 void // 17
cleanup(void) { cleanup(void) {
cleanuplisteners();
#ifdef XWAYLAND #ifdef XWAYLAND
wlr_xwayland_destroy(xwayland); wlr_xwayland_destroy(xwayland);
#endif #endif
@ -1971,7 +2032,7 @@ cleanup(void) {
kill(child_pid, SIGTERM); kill(child_pid, SIGTERM);
waitpid(child_pid, NULL, 0); waitpid(child_pid, NULL, 0);
} }
wl_list_remove(&gpu_reset.link);
wlr_backend_destroy(backend); wlr_backend_destroy(backend);
wlr_scene_node_destroy(&scene->tree.node); wlr_scene_node_destroy(&scene->tree.node);
wlr_renderer_destroy(drw); wlr_renderer_destroy(drw);
@ -2200,6 +2261,7 @@ commitpopup(struct wl_listener *listener, void *data)
box.y -= (type == LayerShell ? l->geom.y : c->geom.y); box.y -= (type == LayerShell ? l->geom.y : c->geom.y);
wlr_xdg_popup_unconstrain_from_box(popup, &box); wlr_xdg_popup_unconstrain_from_box(popup, &box);
wl_list_remove(&listener->link); wl_list_remove(&listener->link);
free(listener);
} }
void void
@ -2590,13 +2652,18 @@ destroydragicon(struct wl_listener *listener, void *data) {
/* Focus enter isn't sent during drag, so refocus the focused node. */ /* Focus enter isn't sent during drag, so refocus the focused node. */
focusclient(focustop(selmon), 1); focusclient(focustop(selmon), 1);
motionnotify(0, NULL, 0, 0, 0, 0); motionnotify(0, NULL, 0, 0, 0, 0);
wl_list_remove(&listener->link);
free(listener);
} }
void // 17 void
destroyidleinhibitor(struct wl_listener *listener, void *data) { 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 */ /* `data` is the wlr_surface of the idle inhibitor being destroyed,
checkidleinhibitor(wlr_surface_get_root_surface(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 // 0.5 void // 0.5
@ -2702,12 +2769,6 @@ destroysessionlock(struct wl_listener *listener, void *data) {
motionnotify(0, NULL, 0, 0, 0, 0); motionnotify(0, NULL, 0, 0, 0, 0);
} }
void // 0.5
destroysessionmgr(struct wl_listener *listener, void *data) {
wl_list_remove(&lock_listener.link);
wl_list_remove(&listener->link);
}
void // 17 void // 17
associatex11(struct wl_listener *listener, void *data) { associatex11(struct wl_listener *listener, void *data) {
Client *c = wl_container_of(listener, c, associate); Client *c = wl_container_of(listener, c, associate);
@ -3443,28 +3504,28 @@ void killclient(const Arg *arg) {
} }
} }
void // 0.5 void
locksession(struct wl_listener *listener, void *data) { locksession(struct wl_listener *listener, void *data)
struct wlr_session_lock_v1 *session_lock = data; {
SessionLock *lock; struct wlr_session_lock_v1 *session_lock = data;
wlr_scene_node_set_enabled(&locked_bg->node, 1); SessionLock *lock;
if (cur_lock) { wlr_scene_node_set_enabled(&locked_bg->node, 1);
wlr_session_lock_v1_destroy(session_lock); if (cur_lock) {
return; wlr_session_lock_v1_destroy(session_lock);
} return;
lock = session_lock->data = ecalloc(1, sizeof(*lock)); }
focusclient(NULL, 0); lock = session_lock->data = ecalloc(1, sizeof(*lock));
focusclient(NULL, 0);
lock->scene = wlr_scene_tree_create(layers[LyrBlock]); lock->scene = wlr_scene_tree_create(layers[LyrBlock]);
cur_lock = lock->lock = session_lock; cur_lock = lock->lock = session_lock;
locked = 1; locked = 1;
LISTEN(&session_lock->events.new_surface, &lock->new_surface, LISTEN(&session_lock->events.new_surface, &lock->new_surface, createlocksurface);
createlocksurface); LISTEN(&session_lock->events.destroy, &lock->destroy, destroysessionlock);
LISTEN(&session_lock->events.destroy, &lock->destroy, destroysessionlock); LISTEN(&session_lock->events.unlock, &lock->unlock, unlocksession);
LISTEN(&session_lock->events.unlock, &lock->unlock, unlocksession);
wlr_session_lock_v1_send_locked(session_lock); wlr_session_lock_v1_send_locked(session_lock);
} }
void // 0.5 void // 0.5
@ -4907,7 +4968,7 @@ void setup(void) {
/* Initializes the interface used to implement urgency hints */ /* Initializes the interface used to implement urgency hints */
activation = wlr_xdg_activation_v1_create(dpy); activation = wlr_xdg_activation_v1_create(dpy);
LISTEN_STATIC(&activation->events.request_activate, urgent); wl_signal_add(&activation->events.request_activate, &request_activate);
gamma_control_mgr = wlr_gamma_control_manager_v1_create(dpy); gamma_control_mgr = wlr_gamma_control_manager_v1_create(dpy);
LISTEN_STATIC(&gamma_control_mgr->events.set_gamma, setgamma); LISTEN_STATIC(&gamma_control_mgr->events.set_gamma, setgamma);
@ -4915,13 +4976,13 @@ void setup(void) {
/* Creates an output layout, which a wlroots utility for working with an /* Creates an output layout, which a wlroots utility for working with an
* arrangement of screens in a physical layout. */ * arrangement of screens in a physical layout. */
output_layout = wlr_output_layout_create(dpy); output_layout = wlr_output_layout_create(dpy);
LISTEN_STATIC(&output_layout->events.change, updatemons); wl_signal_add(&output_layout->events.change, &layout_change);
wlr_xdg_output_manager_v1_create(dpy, output_layout); wlr_xdg_output_manager_v1_create(dpy, output_layout);
/* Configure a listener to be notified when new outputs are available on the /* Configure a listener to be notified when new outputs are available on the
* backend. */ * backend. */
wl_list_init(&mons); 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 and the xdg-shell. The xdg-shell is a /* Set up our client lists and the xdg-shell. The xdg-shell is a
* Wayland protocol which is used for application windows. For more * Wayland protocol which is used for application windows. For more
@ -4933,21 +4994,22 @@ void setup(void) {
wl_list_init(&fstack); wl_list_init(&fstack);
wl_list_init(&fadeout_clients); wl_list_init(&fadeout_clients);
idle_notifier = wlr_idle_notifier_v1_create(dpy); 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, &new_idle_inhibitor);
idle_inhibit_mgr = wlr_idle_inhibit_v1_create(dpy);
LISTEN_STATIC(&idle_inhibit_mgr->events.new_inhibitor, createidleinhibitor);
layer_shell = wlr_layer_shell_v1_create(dpy, 3); 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_surface);
xdg_shell = wlr_xdg_shell_create(dpy, 6); xdg_shell = wlr_xdg_shell_create(dpy, 6);
LISTEN_STATIC(&xdg_shell->events.new_toplevel, createnotify); wl_signal_add(&xdg_shell->events.new_toplevel, &new_xdg_toplevel);
LISTEN_STATIC(&xdg_shell->events.new_popup, createpopup); wl_signal_add(&xdg_shell->events.new_popup, &new_xdg_popup);
session_lock_mgr = wlr_session_lock_manager_v1_create(dpy); session_lock_mgr = wlr_session_lock_manager_v1_create(dpy);
wl_signal_add(&session_lock_mgr->events.new_lock, &lock_listener); wl_signal_add(&session_lock_mgr->events.new_lock, &new_session_lock);
LISTEN_STATIC(&session_lock_mgr->events.destroy, destroysessionmgr);
locked_bg = wlr_scene_rect_create(layers[LyrBlock], sgeom.width, sgeom.height, locked_bg = wlr_scene_rect_create(layers[LyrBlock], sgeom.width, sgeom.height,
(float[4]){0.1, 0.1, 0.1, 1.0}); (float[4]){0.1, 0.1, 0.1, 1.0});
wlr_scene_node_set_enabled(&locked_bg->node, 0); wlr_scene_node_set_enabled(&locked_bg->node, 0);
@ -4957,11 +5019,10 @@ void setup(void) {
wlr_server_decoration_manager_create(dpy), wlr_server_decoration_manager_create(dpy),
WLR_SERVER_DECORATION_MANAGER_MODE_SERVER); WLR_SERVER_DECORATION_MANAGER_MODE_SERVER);
xdg_decoration_mgr = wlr_xdg_decoration_manager_v1_create(dpy); xdg_decoration_mgr = wlr_xdg_decoration_manager_v1_create(dpy);
LISTEN_STATIC(&xdg_decoration_mgr->events.new_toplevel_decoration, wl_signal_add(&xdg_decoration_mgr->events.new_toplevel_decoration, &new_xdg_decoration);
createdecoration);
pointer_constraints = wlr_pointer_constraints_v1_create(dpy); pointer_constraints = wlr_pointer_constraints_v1_create(dpy);
LISTEN_STATIC(&pointer_constraints->events.new_constraint, wl_signal_add(&pointer_constraints->events.new_constraint, &new_pointer_constraint);
createpointerconstraint);
relative_pointer_mgr = wlr_relative_pointer_manager_v1_create(dpy); relative_pointer_mgr = wlr_relative_pointer_manager_v1_create(dpy);
@ -4992,15 +5053,15 @@ void setup(void) {
* *
* And more comments are sprinkled throughout the notify functions above. * And more comments are sprinkled throughout the notify functions above.
*/ */
LISTEN_STATIC(&cursor->events.motion, motionrelative); wl_signal_add(&cursor->events.motion, &cursor_motion);
LISTEN_STATIC(&cursor->events.motion_absolute, motionabsolute); wl_signal_add(&cursor->events.motion_absolute, &cursor_motion_absolute);
LISTEN_STATIC(&cursor->events.button, buttonpress); wl_signal_add(&cursor->events.button, &cursor_button);
LISTEN_STATIC(&cursor->events.axis, axisnotify); wl_signal_add(&cursor->events.axis, &cursor_axis);
LISTEN_STATIC(&cursor->events.frame, cursorframe); wl_signal_add(&cursor->events.frame, &cursor_frame);
// 这两句代码会造成obs窗口里的鼠标光标消失,不知道注释有什么影响 // 这两句代码会造成obs窗口里的鼠标光标消失,不知道注释有什么影响
cursor_shape_mgr = wlr_cursor_shape_manager_v1_create(dpy, 1); 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_cursor_shape);
/* /*
* Configures a seat, which is a single "seat" at which a user sits and * Configures a seat, which is a single "seat" at which a user sits and
@ -5009,24 +5070,24 @@ void setup(void) {
* let us know when new input devices are available on the backend. * let us know when new input devices are available on the backend.
*/ */
wl_list_init(&keyboards); wl_list_init(&keyboards);
LISTEN_STATIC(&backend->events.new_input, inputdevice); wl_signal_add(&backend->events.new_input, &new_input_device);
virtual_keyboard_mgr = wlr_virtual_keyboard_manager_v1_create(dpy); virtual_keyboard_mgr = wlr_virtual_keyboard_manager_v1_create(dpy);
LISTEN_STATIC(&virtual_keyboard_mgr->events.new_virtual_keyboard, wl_signal_add(&virtual_keyboard_mgr->events.new_virtual_keyboard,
virtualkeyboard); &new_virtual_keyboard);
virtual_pointer_mgr = wlr_virtual_pointer_manager_v1_create(dpy); virtual_pointer_mgr = wlr_virtual_pointer_manager_v1_create(dpy);
LISTEN_STATIC(&virtual_pointer_mgr->events.new_virtual_pointer, wl_signal_add(&virtual_pointer_mgr->events.new_virtual_pointer,
virtualpointer); &new_virtual_pointer);
seat = wlr_seat_create(dpy, "seat0"); seat = wlr_seat_create(dpy, "seat0");
LISTEN_STATIC(&seat->events.request_set_cursor, setcursor); wl_signal_add(&seat->events.request_set_cursor, &request_cursor);
LISTEN_STATIC(&seat->events.request_set_selection, setsel); wl_signal_add(&seat->events.request_set_selection, &request_set_sel);
LISTEN_STATIC(&seat->events.request_set_primary_selection, setpsel); wl_signal_add(&seat->events.request_set_primary_selection, &request_set_psel);
LISTEN_STATIC(&seat->events.request_start_drag, requeststartdrag); wl_signal_add(&seat->events.request_start_drag, &request_start_drag);
LISTEN_STATIC(&seat->events.start_drag, startdrag); wl_signal_add(&seat->events.start_drag, &start_drag);
output_mgr = wlr_output_manager_v1_create(dpy); output_mgr = wlr_output_manager_v1_create(dpy);
LISTEN_STATIC(&output_mgr->events.apply, outputmgrapply); wl_signal_add(&output_mgr->events.apply, &output_mgr_apply);
LISTEN_STATIC(&output_mgr->events.test, outputmgrtest); wl_signal_add(&output_mgr->events.test, &output_mgr_test);
#ifdef IM #ifdef IM
/* create text_input-, and input_method-protocol relevant globals */ /* create text_input-, and input_method-protocol relevant globals */
@ -5052,8 +5113,8 @@ void setup(void) {
*/ */
xwayland = wlr_xwayland_create(dpy, compositor, 1); xwayland = wlr_xwayland_create(dpy, compositor, 1);
if (xwayland) { if (xwayland) {
LISTEN_STATIC(&xwayland->events.ready, xwaylandready); wl_signal_add(&xwayland->events.ready, &xwayland_ready);
LISTEN_STATIC(&xwayland->events.new_surface, createnotifyx11); wl_signal_add(&xwayland->events.new_surface, &new_xwayland_surface);
setenv("DISPLAY", xwayland->display_name, 1); setenv("DISPLAY", xwayland->display_name, 1);
} else { } else {