From a6fa3d8849f9af7bfccd3c0eae7bf5197b144a6a Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Thu, 28 May 2026 12:45:30 +0800 Subject: [PATCH] opt: optimize ipc event send --- src/config/parse_config.h | 2 +- src/dispatch/bind_define.h | 16 +++--- src/ext-protocol/dwl-ipc.h | 4 +- src/ipc/ipc.h | 14 ----- src/layout/arrange.h | 2 +- src/mango.c | 114 +++++++++++++++++++++++++++---------- 6 files changed, 97 insertions(+), 55 deletions(-) diff --git a/src/config/parse_config.h b/src/config/parse_config.h index a3cd834a..59364ddc 100644 --- a/src/config/parse_config.h +++ b/src/config/parse_config.h @@ -3844,6 +3844,6 @@ void reset_option(void) { int32_t reload_config(const Arg *arg) { parse_config(); reset_option(); - printstatus(); + printstatus(IPC_WATCH_ARRANGGE); return 1; } diff --git a/src/dispatch/bind_define.h b/src/dispatch/bind_define.h index 73b95a67..137b9881 100644 --- a/src/dispatch/bind_define.h +++ b/src/dispatch/bind_define.h @@ -573,7 +573,7 @@ int32_t setlayout(const Arg *arg) { selmon->pertag->ltidxs[selmon->pertag->curtag] = &layouts[jk]; clear_fullscreen_and_maximized_state(selmon); arrange(selmon, false, false); - printstatus(); + printstatus(IPC_WATCH_ARRANGGE); return 0; } } @@ -587,7 +587,7 @@ int32_t setkeymode(const Arg *arg) { } else { keymode.isdefault = false; } - printstatus(); + printstatus(IPC_WATCH_KEYMODE); return 1; } @@ -1039,7 +1039,7 @@ int32_t switch_keyboard_layout(const Arg *arg) { wlr_seat_keyboard_notify_modifiers(seat, &tkb->modifiers); } - printstatus(); + printstatus(IPC_WATCH_KB_LAYOUT); return 0; } @@ -1083,7 +1083,7 @@ int32_t switch_layout(const Arg *arg) { } clear_fullscreen_and_maximized_state(selmon); arrange(selmon, false, false); - printstatus(); + printstatus(IPC_WATCH_ARRANGGE); return 0; } @@ -1094,7 +1094,7 @@ int32_t switch_layout(const Arg *arg) { jk == LENGTH(layouts) - 1 ? &layouts[0] : &layouts[jk + 1]; clear_fullscreen_and_maximized_state(selmon); arrange(selmon, false, false); - printstatus(); + printstatus(IPC_WATCH_ARRANGGE); return 0; } } @@ -1452,7 +1452,7 @@ int32_t toggletag(const Arg *arg) { focusclient(focustop(selmon), 1); arrange(selmon, false, false); } - printstatus(); + printstatus(IPC_WATCH_ARRANGGE); return 0; } @@ -1478,7 +1478,7 @@ int32_t toggleview(const Arg *arg) { } arrange(selmon, false, false); } - printstatus(); + printstatus(IPC_WATCH_ARRANGGE); return 0; } @@ -1650,7 +1650,7 @@ int32_t comboview(const Arg *arg) { view(&(Arg){.ui = newtags}, false); } - printstatus(); + printstatus(IPC_WATCH_ARRANGGE); return 0; } diff --git a/src/ext-protocol/dwl-ipc.h b/src/ext-protocol/dwl-ipc.h index 1d57a20e..53d96309 100644 --- a/src/ext-protocol/dwl-ipc.h +++ b/src/ext-protocol/dwl-ipc.h @@ -239,7 +239,7 @@ void dwl_ipc_output_set_client_tags(struct wl_client *client, if (selmon == monitor) focusclient(focustop(monitor), 1); arrange(selmon, false, false); - printstatus(); + printstatus(IPC_WATCH_ARRANGGE); } void dwl_ipc_output_set_layout(struct wl_client *client, @@ -258,7 +258,7 @@ void dwl_ipc_output_set_layout(struct wl_client *client, monitor->pertag->ltidxs[monitor->pertag->curtag] = &layouts[index]; clear_fullscreen_and_maximized_state(monitor); arrange(monitor, false, false); - printstatus(); + printstatus(IPC_WATCH_ARRANGGE); } void dwl_ipc_output_set_tags(struct wl_client *client, diff --git a/src/ipc/ipc.h b/src/ipc/ipc.h index 0a36da4a..9e7c8e3f 100644 --- a/src/ipc/ipc.h +++ b/src/ipc/ipc.h @@ -9,20 +9,6 @@ #include #include -enum ipc_watch_type { - IPC_WATCH_NONE, - IPC_WATCH_MONITOR, - IPC_WATCH_CLIENT, - IPC_WATCH_TAGS, - IPC_WATCH_ALL_MONITORS, - IPC_WATCH_ALL_TAGS, - IPC_WATCH_ALL_CLIENTS, - IPC_WATCH_KEYMODE, - IPC_WATCH_KB_LAYOUT, - IPC_WATCH_LAST_OPEN_SURFACE, - IPC_WATCH_FOCUSING_CLIENT -}; - struct ipc_watch_client { struct wl_list link; int fd; diff --git a/src/layout/arrange.h b/src/layout/arrange.h index 3343316e..7223b430 100644 --- a/src/layout/arrange.h +++ b/src/layout/arrange.h @@ -1225,5 +1225,5 @@ arrange(Monitor *m, bool want_animation, bool from_view) { checkidleinhibitor(NULL); } - printstatus(); + printstatus(IPC_WATCH_ARRANGGE); } diff --git a/src/mango.c b/src/mango.c index 1039a566..039dfeb4 100644 --- a/src/mango.c +++ b/src/mango.c @@ -149,6 +149,11 @@ #define BAKED_POINTS_COUNT 256 +#define IPC_WATCH_ARRANGGE \ + IPC_WATCH_MONITOR | IPC_WATCH_CLIENT | IPC_WATCH_TAGS | \ + IPC_WATCH_ALL_MONITORS | IPC_WATCH_ALL_TAGS | IPC_WATCH_ALL_CLIENTS | \ + IPC_WATCH_LAST_OPEN_SURFACE | IPC_WATCH_FOCUSING_CLIENT + /* enums */ enum { TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT }; @@ -194,6 +199,20 @@ enum seat_config_shortcuts_inhibit { SHORTCUTS_INHIBIT_ENABLE, }; +enum ipc_watch_type { + IPC_WATCH_NONE = 0, + IPC_WATCH_MONITOR = 1 << 0, + IPC_WATCH_CLIENT = 1 << 1, + IPC_WATCH_TAGS = 1 << 2, + IPC_WATCH_ALL_MONITORS = 1 << 3, + IPC_WATCH_ALL_TAGS = 1 << 4, + IPC_WATCH_ALL_CLIENTS = 1 << 5, + IPC_WATCH_KEYMODE = 1 << 6, + IPC_WATCH_KB_LAYOUT = 1 << 7, + IPC_WATCH_LAST_OPEN_SURFACE = 1 << 8, + IPC_WATCH_FOCUSING_CLIENT = 1 << 9, +}; + typedef struct Pertag Pertag; typedef struct Monitor Monitor; typedef struct Client Client; @@ -449,6 +468,8 @@ typedef struct { struct wl_listener modifiers; struct wl_listener key; struct wl_listener destroy; + + u_int32_t layout_index; } KeyboardGroup; typedef struct { @@ -712,7 +733,7 @@ static void outputmgrapplyortest(struct wlr_output_configuration_v1 *config, static void outputmgrtest(struct wl_listener *listener, void *data); static void pointerfocus(Client *c, struct wlr_surface *surface, double sx, double sy, uint32_t time); -static void printstatus(void); +static void printstatus(enum ipc_watch_type type); static void quitsignal(int32_t signo); static void powermgrsetmode(struct wl_listener *listener, void *data); static void rendermon(struct wl_listener *listener, void *data); @@ -2627,7 +2648,7 @@ void closemon(Monitor *m) { } if (selmon) { focusclient(focustop(selmon), 1); - printstatus(); + printstatus(IPC_WATCH_ARRANGGE); } } @@ -3322,7 +3343,7 @@ void createmon(struct wl_listener *listener, void *data) { add_workspace_by_tag(i, m); } - printstatus(); + printstatus(IPC_WATCH_ARRANGGE); } void // fix for 0.5 @@ -3819,7 +3840,7 @@ void focusclient(Client *c, int32_t lift) { client_activate_surface(old_keyboard_focus_surface, 0); } } - printstatus(); + printstatus(IPC_WATCH_ARRANGGE); if (!c) { @@ -4200,6 +4221,14 @@ void keypressmod(struct wl_listener *listener, void *data) { wlr_seat_keyboard_notify_modifiers( seat, &group->wlr_group->keyboard.modifiers); } + + xkb_layout_index_t current = xkb_state_serialize_layout( + group->wlr_group->keyboard.xkb_state, XKB_STATE_LAYOUT_EFFECTIVE); + + if (current != group->layout_index) { + group->layout_index = current; + printstatus(IPC_WATCH_KB_LAYOUT); + } } void pending_kill_client(Client *c) { @@ -4466,7 +4495,7 @@ mapnotify(struct wl_listener *listener, void *data) { // make sure the animation is open type c->is_pending_open_animation = true; resize(c, c->geom, 0); - printstatus(); + printstatus(IPC_WATCH_ARRANGGE); } void maximizenotify(struct wl_listener *listener, void *data) { @@ -4887,7 +4916,9 @@ void pointerfocus(Client *c, struct wlr_surface *surface, double sx, double sy, } // 修改printstatus函数,接受掩码参数 -void printstatus(void) { wl_signal_emit(&mango_print_status, NULL); } +void printstatus(enum ipc_watch_type type) { + wl_signal_emit(&mango_print_status, &type); +} // 会话销毁时的回调 void handle_session_destroy(struct wl_listener *listener, void *data) { @@ -5222,7 +5253,7 @@ run(char *startup_cmd) { if (fd_set_nonblock(STDOUT_FILENO) < 0) close(STDOUT_FILENO); - printstatus(); + printstatus(IPC_WATCH_ARRANGGE); /* At this point the outputs are initialized, choose initial selmon * based on cursor position, and set default cursor image */ @@ -5383,7 +5414,7 @@ setfloating(Client *c, int32_t floating) { } setborder_color(c); - printstatus(); + printstatus(IPC_WATCH_ARRANGGE); } void reset_maximizescreen_size(Client *c) { @@ -5709,18 +5740,36 @@ void create_output(struct wlr_backend *backend, void *data) { // 修改信号处理函数,接收掩码参数 void handle_print_status(struct wl_listener *listener, void *data) { - ipc_notify_keymode(); - ipc_notify_kb_layout(); - ipc_notify_focusing_client(); - ipc_notify_all_tags(); - ipc_notify_all_clients(); - ipc_notify_all_monitors(); + enum ipc_watch_type type = *(enum ipc_watch_type *)data; - Client *c = NULL; - wl_list_for_each(c, &clients, link) { - if (c->iskilling) - continue; - ipc_notify_client(c); + if (type & IPC_WATCH_KEYMODE) { + ipc_notify_keymode(); + } + if (type & IPC_WATCH_KB_LAYOUT) { + ipc_notify_kb_layout(); + } + if (type & IPC_WATCH_FOCUSING_CLIENT) { + ipc_notify_focusing_client(); + } + if (type & IPC_WATCH_ALL_TAGS) { + ipc_notify_all_tags(); + } + if (type & IPC_WATCH_ALL_CLIENTS) { + ipc_notify_all_clients(); + } + if (type & + (IPC_WATCH_ALL_MONITORS | IPC_WATCH_KEYMODE | IPC_WATCH_KB_LAYOUT | + IPC_WATCH_FOCUSING_CLIENT | IPC_WATCH_TAGS)) { + ipc_notify_all_monitors(); + } + + if (type & IPC_WATCH_CLIENT) { + Client *c = NULL; + wl_list_for_each(c, &clients, link) { + if (c->iskilling) + continue; + ipc_notify_client(c); + } } Monitor *m = NULL; @@ -5729,9 +5778,16 @@ void handle_print_status(struct wl_listener *listener, void *data) { continue; } - ipc_notify_monitor(m); - ipc_notify_tags(m); - ipc_notify_last_surface_ws_name(m); + if (type & IPC_WATCH_MONITOR) { + ipc_notify_monitor(m); + } + if (type & IPC_WATCH_TAGS) { + ipc_notify_tags(m); + } + + if (type & IPC_WATCH_LAST_OPEN_SURFACE) { + ipc_notify_last_surface_ws_name(m); + } dwl_ext_workspace_printstatus(m); dwl_ipc_output_printstatus(m); @@ -6104,7 +6160,7 @@ void tag_client(const Arg *arg, Client *target_client) { } focusclient(target_client, 1); - printstatus(); + printstatus(IPC_WATCH_ARRANGGE); } // 目标窗口有其他窗口和它同个tag就返回0 @@ -6436,7 +6492,7 @@ void unmapnotify(struct wl_listener *listener, void *data) { c->stack_proportion = 0.0f; wlr_scene_node_destroy(&c->scene->node); - printstatus(); + printstatus(IPC_WATCH_ARRANGGE); motionnotify(0, NULL, 0, 0, 0, 0); } @@ -6593,7 +6649,7 @@ void updatetitle(struct wl_listener *listener, void *data) { }); } if (c == focustop(c->mon)) - printstatus(); + printstatus(IPC_WATCH_ARRANGGE); } void // 17 fix to 0.5 @@ -6613,7 +6669,7 @@ urgent(struct wl_listener *listener, void *data) { c->isurgent = 1; if (client_surface(c)->mapped) setborder_color(c); - printstatus(); + printstatus(IPC_WATCH_ARRANGGE); } } @@ -6672,7 +6728,7 @@ toggleseltags: if (changefocus) focusclient(focustop(m), 1); arrange(m, want_animation, true); - printstatus(); + printstatus(IPC_WATCH_ARRANGGE); } void view(const Arg *arg, bool want_animation) { @@ -6842,7 +6898,7 @@ void activatex11(struct wl_listener *listener, void *data) { arrange(c->mon, false, false); } - printstatus(); + printstatus(IPC_WATCH_ARRANGGE); } void configurex11(struct wl_listener *listener, void *data) { @@ -6931,7 +6987,7 @@ void sethints(struct wl_listener *listener, void *data) { return; c->isurgent = xcb_icccm_wm_hints_get_urgency(c->surface.xwayland->hints); - printstatus(); + printstatus(IPC_WATCH_ARRANGGE); if (c->isurgent && surface && surface->mapped) setborder_color(c);