From 075d4979b6750e46b034573a662f1846c37faedb Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Tue, 2 Dec 2025 16:19:31 +0800 Subject: [PATCH] opt: use signal to handle printstauts --- src/mango.c | 56 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/src/mango.c b/src/mango.c index c80eed1..62656db 100644 --- a/src/mango.c +++ b/src/mango.c @@ -204,6 +204,9 @@ typedef struct { unsigned int ui; unsigned int ui2; } Arg; +struct mango_print_status_manager { + struct wl_signal print_status; +}; typedef struct { unsigned int mod; @@ -515,6 +518,7 @@ static void arrangelayer(Monitor *m, struct wl_list *list, struct wlr_box *usable_area, int exclusive); static void arrangelayers(Monitor *m); static char *get_autostart_path(char *, unsigned int); // 自启动命令执行 +static void handle_print_status(struct wl_listener *listener, void *data); static void axisnotify(struct wl_listener *listener, void *data); // 滚轮事件处理 static void buttonpress(struct wl_listener *listener, @@ -777,6 +781,7 @@ static struct wlr_virtual_pointer_manager_v1 *virtual_pointer_mgr; static struct wlr_output_power_manager_v1 *power_mgr; static struct wlr_pointer_gestures_v1 *pointer_gestures; static struct wlr_drm_lease_v1_manager *drm_lease_manager; +struct mango_print_status_manager *print_status_manager; static struct wlr_cursor *cursor; static struct wlr_xcursor_manager *cursor_mgr; @@ -852,6 +857,8 @@ struct Pertag { *ltidxs[LENGTH(tags) + 1]; /* matrix of tags and layouts indexes */ }; +static struct wl_listener print_status_listener = {.notify = + handle_print_status}; static struct wl_listener cursor_axis = {.notify = axisnotify}; static struct wl_listener cursor_button = {.notify = buttonpress}; static struct wl_listener cursor_frame = {.notify = cursorframe}; @@ -2004,6 +2011,7 @@ void setcursorshape(struct wl_listener *listener, void *data) { } void cleanuplisteners(void) { + wl_list_remove(&print_status_listener.link); wl_list_remove(&cursor_axis.link); wl_list_remove(&cursor_button.link); wl_list_remove(&cursor_frame.link); @@ -4135,19 +4143,8 @@ void pointerfocus(Client *c, struct wlr_surface *surface, double sx, double sy, wlr_seat_pointer_notify_motion(seat, time, sx, sy); } -void // 17 -printstatus(void) { - Monitor *m = NULL; - wl_list_for_each(m, &mons, link) { - if (!m->wlr_output->enabled) { - continue; - } - // Update workspace active states - dwl_ext_workspace_printstatus(m); - - // Update IPC output status - dwl_ipc_output_printstatus(m); - } +void printstatus(void) { + wl_signal_emit(&print_status_manager->print_status, NULL); } void powermgrsetmode(struct wl_listener *listener, void *data) { @@ -4871,6 +4868,35 @@ void create_output(struct wlr_backend *backend, void *data) { #endif } +// 创建函数 +struct mango_print_status_manager *mango_print_status_manager_create() { + struct mango_print_status_manager *manager = calloc(1, sizeof(*manager)); + if (!manager) + return NULL; + + // 初始化 print_status 信号,不是 event_signal + wl_signal_init(&manager->print_status); + + return manager; +} + +void handle_print_status(struct wl_listener *listener, void *data) { + struct mango_print_status_manager *manager = + wl_container_of(listener, manager, print_status); + // struct wlr_print_status *status = data; + Monitor *m = NULL; + wl_list_for_each(m, &mons, link) { + if (!m->wlr_output->enabled) { + continue; + } + // Update workspace active states + dwl_ext_workspace_printstatus(m); + + // Update IPC output status + dwl_ipc_output_printstatus(m); + } +} + void setup(void) { setenv("XCURSOR_SIZE", "24", 1); @@ -4966,6 +4992,10 @@ void setup(void) { wlr_alpha_modifier_v1_create(dpy); wlr_ext_data_control_manager_v1_create(dpy, 1); + // 在 setup 函数中 + print_status_manager = mango_print_status_manager_create(); + wl_signal_add(&print_status_manager->print_status, &print_status_listener); + /* Initializes the interface used to implement urgency hints */ activation = wlr_xdg_activation_v1_create(dpy); wl_signal_add(&activation->events.request_activate, &request_activate);