From 9196e2a50be7c1de84da08ef50fba8c440f1c6b2 Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Tue, 2 Dec 2025 16:46:11 +0800 Subject: [PATCH] opt: use event mask to decide whether print ipc message --- src/config/parse_config.h | 2 +- src/dispatch/bind_define.h | 16 +-- src/ext-protocol/dwl-ipc.h | 208 +++++++++++++++++++++++++------------ src/mango.c | 75 +++++++++---- 4 files changed, 205 insertions(+), 96 deletions(-) diff --git a/src/config/parse_config.h b/src/config/parse_config.h index 7196270..afc9acb 100644 --- a/src/config/parse_config.h +++ b/src/config/parse_config.h @@ -3255,6 +3255,6 @@ void reset_option(void) { int reload_config(const Arg *arg) { parse_config(); reset_option(); - printstatus(); + printstatus(PRINT_ALL); return 0; } diff --git a/src/dispatch/bind_define.h b/src/dispatch/bind_define.h index a141830..a782d4f 100644 --- a/src/dispatch/bind_define.h +++ b/src/dispatch/bind_define.h @@ -503,7 +503,7 @@ int setlayout(const Arg *arg) { selmon->pertag->ltidxs[selmon->pertag->curtag] = &layouts[jk]; clear_fullscreen_and_maximized_state(selmon); arrange(selmon, false); - printstatus(); + printstatus(PRINT_ALL); return 0; } } @@ -517,7 +517,7 @@ int setkeymode(const Arg *arg) { } else { keymode.isdefault = false; } - printstatus(); + printstatus(PRINT_KEYMODE); return 1; } @@ -866,7 +866,7 @@ int switch_keyboard_layout(const Arg *arg) { wlr_seat_keyboard_notify_modifiers(seat, &tkb->modifiers); } - printstatus(); + printstatus(PRINT_KB_LAYOUT); return 0; } @@ -907,7 +907,7 @@ int switch_layout(const Arg *arg) { } clear_fullscreen_and_maximized_state(selmon); arrange(selmon, false); - printstatus(); + printstatus(PRINT_ALL); return 0; } @@ -918,7 +918,7 @@ int switch_layout(const Arg *arg) { jk == LENGTH(layouts) - 1 ? &layouts[0] : &layouts[jk + 1]; clear_fullscreen_and_maximized_state(selmon); arrange(selmon, false); - printstatus(); + printstatus(PRINT_ALL); return 0; } } @@ -1260,7 +1260,7 @@ int toggletag(const Arg *arg) { focusclient(focustop(selmon), 1); arrange(selmon, false); } - printstatus(); + printstatus(PRINT_ALL); return 0; } @@ -1278,7 +1278,7 @@ int toggleview(const Arg *arg) { focusclient(focustop(selmon), 1); arrange(selmon, false); } - printstatus(); + printstatus(PRINT_ALL); return 0; } @@ -1398,7 +1398,7 @@ int comboview(const Arg *arg) { view(&(Arg){.ui = newtags}, false); } - printstatus(); + printstatus(PRINT_ALL); return 0; } diff --git a/src/ext-protocol/dwl-ipc.h b/src/ext-protocol/dwl-ipc.h index 15b2376..1d861b9 100644 --- a/src/ext-protocol/dwl-ipc.h +++ b/src/ext-protocol/dwl-ipc.h @@ -10,8 +10,9 @@ static void dwl_ipc_manager_get_output(struct wl_client *client, static void dwl_ipc_manager_release(struct wl_client *client, struct wl_resource *resource); static void dwl_ipc_output_destroy(struct wl_resource *resource); -static void dwl_ipc_output_printstatus(Monitor *monitor); -static void dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output); +static void dwl_ipc_output_printstatus(Monitor *monitor, uint32_t event_mask); +static void dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output, + uint32_t event_mask); static void dwl_ipc_output_set_client_tags(struct wl_client *client, struct wl_resource *resource, unsigned int and_tags, @@ -87,7 +88,7 @@ void dwl_ipc_manager_get_output(struct wl_client *client, wl_resource_set_implementation(output_resource, &dwl_output_implementation, ipc_output, dwl_ipc_output_destroy); wl_list_insert(&monitor->dwl_ipc_outputs, &ipc_output->link); - dwl_ipc_output_printstatus_to(ipc_output); + dwl_ipc_output_printstatus_to(ipc_output, PRINT_ALL); } void dwl_ipc_manager_release(struct wl_client *client, @@ -101,13 +102,16 @@ static void dwl_ipc_output_destroy(struct wl_resource *resource) { free(ipc_output); } -void dwl_ipc_output_printstatus(Monitor *monitor) { +// 修改IPC输出函数,接受掩码参数 +void dwl_ipc_output_printstatus(Monitor *monitor, uint32_t event_mask) { DwlIpcOutput *ipc_output; wl_list_for_each(ipc_output, &monitor->dwl_ipc_outputs, link) - dwl_ipc_output_printstatus_to(ipc_output); + dwl_ipc_output_printstatus_to(ipc_output, event_mask); } -void dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output) { +// 修改主IPC输出函数,根据掩码发送相应事件 +void dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output, + uint32_t event_mask) { Monitor *monitor = ipc_output->mon; Client *c = NULL, *focused = NULL; struct wlr_keyboard *keyboard; @@ -115,103 +119,175 @@ void dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output) { int tagmask, state, numclients, focused_client, tag; const char *title, *appid, *symbol; char kb_layout[32]; - focused = focustop(monitor); - zdwl_ipc_output_v2_send_active(ipc_output->resource, monitor == selmon); - for (tag = 0; tag < LENGTH(tags); tag++) { - numclients = state = focused_client = 0; - tagmask = 1 << tag; - if ((tagmask & monitor->tagset[monitor->seltags]) != 0) - state |= ZDWL_IPC_OUTPUT_V2_TAG_STATE_ACTIVE; - wl_list_for_each(c, &clients, link) { - if (c->mon != monitor) - continue; - if (!(c->tags & tagmask)) - continue; - if (c == focused) - focused_client = 1; - if (c->isurgent) - state |= ZDWL_IPC_OUTPUT_V2_TAG_STATE_URGENT; - numclients++; + // 只在需要时才获取这些数据 + if (event_mask & (PRINT_ACTIVE | PRINT_TAG | PRINT_TITLE | PRINT_APPID | + PRINT_FULLSCREEN | PRINT_FLOATING | PRINT_X | PRINT_Y | + PRINT_WIDTH | PRINT_HEIGHT)) { + focused = focustop(monitor); + } + + // 发送活动状态 + if (event_mask & PRINT_ACTIVE) { + zdwl_ipc_output_v2_send_active(ipc_output->resource, monitor == selmon); + } + + // 发送标签状态 + if (event_mask & PRINT_TAG) { + for (tag = 0; tag < LENGTH(tags); tag++) { + numclients = state = focused_client = 0; + tagmask = 1 << tag; + if ((tagmask & monitor->tagset[monitor->seltags]) != 0) + state |= ZDWL_IPC_OUTPUT_V2_TAG_STATE_ACTIVE; + + if (focused) { + wl_list_for_each(c, &clients, link) { + if (c->mon != monitor) + continue; + if (!(c->tags & tagmask)) + continue; + if (c == focused) + focused_client = 1; + if (c->isurgent) + state |= ZDWL_IPC_OUTPUT_V2_TAG_STATE_URGENT; + numclients++; + } + } + zdwl_ipc_output_v2_send_tag(ipc_output->resource, tag, state, + numclients, focused_client); } - zdwl_ipc_output_v2_send_tag(ipc_output->resource, tag, state, - numclients, focused_client); } - title = focused ? client_get_title(focused) : ""; - appid = focused ? client_get_appid(focused) : ""; - - if (monitor->isoverview) { - symbol = overviewlayout.symbol; - } else { - symbol = monitor->pertag->ltidxs[monitor->pertag->curtag]->symbol; + // 只在需要时才获取标题和应用ID + if (event_mask & (PRINT_TITLE | PRINT_APPID)) { + title = focused ? client_get_title(focused) : ""; + appid = focused ? client_get_appid(focused) : ""; } - keyboard = &kb_group->wlr_group->keyboard; - current = xkb_state_serialize_layout(keyboard->xkb_state, - XKB_STATE_LAYOUT_EFFECTIVE); - get_layout_abbr(kb_layout, - xkb_keymap_layout_get_name(keyboard->keymap, current)); + // 获取布局符号 + if (event_mask & PRINT_LAYOUT_SYMBOL) { + if (monitor->isoverview) { + symbol = overviewlayout.symbol; + } else { + symbol = monitor->pertag->ltidxs[monitor->pertag->curtag]->symbol; + } + } - zdwl_ipc_output_v2_send_layout( - ipc_output->resource, - monitor->pertag->ltidxs[monitor->pertag->curtag] - layouts); - zdwl_ipc_output_v2_send_title(ipc_output->resource, title ? title : broken); - zdwl_ipc_output_v2_send_appid(ipc_output->resource, appid ? appid : broken); - zdwl_ipc_output_v2_send_layout_symbol(ipc_output->resource, symbol); - if (wl_resource_get_version(ipc_output->resource) >= - ZDWL_IPC_OUTPUT_V2_FULLSCREEN_SINCE_VERSION) { + // 发送布局索引 + if (event_mask & PRINT_LAYOUT) { + zdwl_ipc_output_v2_send_layout( + ipc_output->resource, + monitor->pertag->ltidxs[monitor->pertag->curtag] - layouts); + } + + // 发送标题 + if (event_mask & PRINT_TITLE) { + zdwl_ipc_output_v2_send_title(ipc_output->resource, + title ? title : broken); + } + + // 发送应用ID + if (event_mask & PRINT_APPID) { + zdwl_ipc_output_v2_send_appid(ipc_output->resource, + appid ? appid : broken); + } + + // 发送布局符号 + if (event_mask & PRINT_LAYOUT_SYMBOL) { + zdwl_ipc_output_v2_send_layout_symbol(ipc_output->resource, symbol); + } + + // 发送全屏状态 + if ((event_mask & PRINT_FULLSCREEN) && + wl_resource_get_version(ipc_output->resource) >= + ZDWL_IPC_OUTPUT_V2_FULLSCREEN_SINCE_VERSION) { zdwl_ipc_output_v2_send_fullscreen(ipc_output->resource, focused ? focused->isfullscreen : 0); } - if (wl_resource_get_version(ipc_output->resource) >= - ZDWL_IPC_OUTPUT_V2_FLOATING_SINCE_VERSION) { + + // 发送浮动状态 + if ((event_mask & PRINT_FLOATING) && + wl_resource_get_version(ipc_output->resource) >= + ZDWL_IPC_OUTPUT_V2_FLOATING_SINCE_VERSION) { zdwl_ipc_output_v2_send_floating(ipc_output->resource, focused ? focused->isfloating : 0); } - if (wl_resource_get_version(ipc_output->resource) >= - ZDWL_IPC_OUTPUT_V2_X_SINCE_VERSION) { + + // 发送X坐标 + if ((event_mask & PRINT_X) && + wl_resource_get_version(ipc_output->resource) >= + ZDWL_IPC_OUTPUT_V2_X_SINCE_VERSION) { zdwl_ipc_output_v2_send_x(ipc_output->resource, focused ? focused->geom.x : 0); } - if (wl_resource_get_version(ipc_output->resource) >= - ZDWL_IPC_OUTPUT_V2_Y_SINCE_VERSION) { + + // 发送Y坐标 + if ((event_mask & PRINT_Y) && + wl_resource_get_version(ipc_output->resource) >= + ZDWL_IPC_OUTPUT_V2_Y_SINCE_VERSION) { zdwl_ipc_output_v2_send_y(ipc_output->resource, focused ? focused->geom.y : 0); } - if (wl_resource_get_version(ipc_output->resource) >= - ZDWL_IPC_OUTPUT_V2_WIDTH_SINCE_VERSION) { + + // 发送宽度 + if ((event_mask & PRINT_WIDTH) && + wl_resource_get_version(ipc_output->resource) >= + ZDWL_IPC_OUTPUT_V2_WIDTH_SINCE_VERSION) { zdwl_ipc_output_v2_send_width(ipc_output->resource, focused ? focused->geom.width : 0); } - if (wl_resource_get_version(ipc_output->resource) >= - ZDWL_IPC_OUTPUT_V2_HEIGHT_SINCE_VERSION) { + + // 发送高度 + if ((event_mask & PRINT_HEIGHT) && + wl_resource_get_version(ipc_output->resource) >= + ZDWL_IPC_OUTPUT_V2_HEIGHT_SINCE_VERSION) { zdwl_ipc_output_v2_send_height(ipc_output->resource, focused ? focused->geom.height : 0); } - if (wl_resource_get_version(ipc_output->resource) >= - ZDWL_IPC_OUTPUT_V2_LAST_LAYER_SINCE_VERSION) { + + // 发送最后图层 + if ((event_mask & PRINT_LAST_LAYER) && + wl_resource_get_version(ipc_output->resource) >= + ZDWL_IPC_OUTPUT_V2_LAST_LAYER_SINCE_VERSION) { zdwl_ipc_output_v2_send_last_layer(ipc_output->resource, monitor->last_surface_ws_name); } - if (wl_resource_get_version(ipc_output->resource) >= - ZDWL_IPC_OUTPUT_V2_KB_LAYOUT_SINCE_VERSION) { + // 获取键盘布局(只在需要时) + if (event_mask & PRINT_KB_LAYOUT) { + keyboard = &kb_group->wlr_group->keyboard; + current = xkb_state_serialize_layout(keyboard->xkb_state, + XKB_STATE_LAYOUT_EFFECTIVE); + get_layout_abbr(kb_layout, + xkb_keymap_layout_get_name(keyboard->keymap, current)); + } + + // 发送键盘布局 + if ((event_mask & PRINT_KB_LAYOUT) && + wl_resource_get_version(ipc_output->resource) >= + ZDWL_IPC_OUTPUT_V2_KB_LAYOUT_SINCE_VERSION) { zdwl_ipc_output_v2_send_kb_layout(ipc_output->resource, kb_layout); } - if (wl_resource_get_version(ipc_output->resource) >= - ZDWL_IPC_OUTPUT_V2_KEYMODE_SINCE_VERSION) { + // 发送键模式 + if ((event_mask & PRINT_KEYMODE) && + wl_resource_get_version(ipc_output->resource) >= + ZDWL_IPC_OUTPUT_V2_KEYMODE_SINCE_VERSION) { zdwl_ipc_output_v2_send_keymode(ipc_output->resource, keymode.mode); } - if (wl_resource_get_version(ipc_output->resource) >= - ZDWL_IPC_OUTPUT_V2_SCALEFACTOR_SINCE_VERSION) { + // 发送缩放因子 + if ((event_mask & PRINT_SCALEFACTOR) && + wl_resource_get_version(ipc_output->resource) >= + ZDWL_IPC_OUTPUT_V2_SCALEFACTOR_SINCE_VERSION) { zdwl_ipc_output_v2_send_scalefactor(ipc_output->resource, monitor->wlr_output->scale * 100); } - zdwl_ipc_output_v2_send_frame(ipc_output->resource); + // 发送帧结束标记 + if (event_mask & PRINT_FRAME) { + zdwl_ipc_output_v2_send_frame(ipc_output->resource); + } } void dwl_ipc_output_set_client_tags(struct wl_client *client, @@ -240,7 +316,7 @@ void dwl_ipc_output_set_client_tags(struct wl_client *client, if (selmon == monitor) focusclient(focustop(monitor), 1); arrange(selmon, false); - printstatus(); + printstatus(PRINT_ALL); } void dwl_ipc_output_set_layout(struct wl_client *client, @@ -260,7 +336,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); - printstatus(); + printstatus(PRINT_ALL); } void dwl_ipc_output_set_tags(struct wl_client *client, diff --git a/src/mango.c b/src/mango.c index 62656db..1a1ea66 100644 --- a/src/mango.c +++ b/src/mango.c @@ -181,6 +181,28 @@ enum seat_config_shortcuts_inhibit { SHORTCUTS_INHIBIT_ENABLE, }; +// 事件掩码枚举 +enum print_event_type { + PRINT_ACTIVE = 1 << 0, + PRINT_TAG = 1 << 1, + PRINT_LAYOUT = 1 << 2, + PRINT_TITLE = 1 << 3, + PRINT_APPID = 1 << 4, + PRINT_LAYOUT_SYMBOL = 1 << 5, + PRINT_FULLSCREEN = 1 << 6, + PRINT_FLOATING = 1 << 7, + PRINT_X = 1 << 8, + PRINT_Y = 1 << 9, + PRINT_WIDTH = 1 << 10, + PRINT_HEIGHT = 1 << 11, + PRINT_LAST_LAYER = 1 << 12, + PRINT_KB_LAYOUT = 1 << 13, + PRINT_KEYMODE = 1 << 14, + PRINT_SCALEFACTOR = 1 << 15, + PRINT_FRAME = 1 << 16, + PRINT_ALL = (1 << 17) - 1 // 所有位都设为1 +}; + typedef struct Pertag Pertag; typedef struct Monitor Monitor; typedef struct Client Client; @@ -612,7 +634,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, unsigned int time); -static void printstatus(void); +static void printstatus(unsigned int event_mask); static void quitsignal(int signo); static void powermgrsetmode(struct wl_listener *listener, void *data); static void rendermon(struct wl_listener *listener, void *data); @@ -2148,7 +2170,7 @@ void closemon(Monitor *m) { } if (selmon) { focusclient(focustop(selmon), 1); - printstatus(); + printstatus(PRINT_ALL); } } @@ -2782,7 +2804,7 @@ void createmon(struct wl_listener *listener, void *data) { add_workspace_by_tag(i, m); } - printstatus(); + printstatus(PRINT_ALL); } void // fix for 0.5 @@ -3238,7 +3260,7 @@ void focusclient(Client *c, int lift) { client_activate_surface(old_keyboard_focus_surface, 0); } } - printstatus(); + printstatus(PRINT_ALL); if (!c) { @@ -3788,7 +3810,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(PRINT_ALL); } void maximizenotify(struct wl_listener *listener, void *data) { @@ -4143,8 +4165,10 @@ void pointerfocus(Client *c, struct wlr_surface *surface, double sx, double sy, wlr_seat_pointer_notify_motion(seat, time, sx, sy); } -void printstatus(void) { - wl_signal_emit(&print_status_manager->print_status, NULL); +// 修改printstatus函数,接受掩码参数 +void printstatus(unsigned int event_mask) { + wl_signal_emit(&print_status_manager->print_status, + (void *)(uintptr_t)event_mask); } void powermgrsetmode(struct wl_listener *listener, void *data) { @@ -4405,7 +4429,7 @@ run(char *startup_cmd) { if (fd_set_nonblock(STDOUT_FILENO) < 0) close(STDOUT_FILENO); - printstatus(); + printstatus(PRINT_ALL); /* At this point the outputs are initialized, choose initial selmon * based on cursor position, and set default cursor image */ @@ -4540,7 +4564,7 @@ setfloating(Client *c, int floating) { arrange(c->mon, false); setborder_color(c); - printstatus(); + printstatus(PRINT_ALL); } void reset_maximizescreen_size(Client *c) { @@ -4880,20 +4904,29 @@ struct mango_print_status_manager *mango_print_status_manager_create() { 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; + + uint32_t event_mask = (uintptr_t)data; + // 如果传入的是NULL(旧代码)或0,使用默认的所有事件 + if (!event_mask) { + event_mask = PRINT_ALL; + } + 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); + // 更新workspace状态(根据掩码决定是否更新) + if (event_mask & PRINT_TAG || event_mask & PRINT_ACTIVE) { + dwl_ext_workspace_printstatus(m); + } - // Update IPC output status - dwl_ipc_output_printstatus(m); + // 更新IPC输出状态(传入掩码) + dwl_ipc_output_printstatus(m, event_mask); } } @@ -5230,7 +5263,7 @@ void tag_client(const Arg *arg, Client *target_client) { } focusclient(target_client, 1); - printstatus(); + printstatus(PRINT_ALL); } void overview(Monitor *m) { grid(m); } @@ -5438,7 +5471,7 @@ void unmapnotify(struct wl_listener *listener, void *data) { } wlr_scene_node_destroy(&c->scene->node); - printstatus(); + printstatus(PRINT_ALL); motionnotify(0, NULL, 0, 0, 0, 0); } @@ -5586,7 +5619,7 @@ void updatetitle(struct wl_listener *listener, void *data) { if (title && c->foreign_toplevel) wlr_foreign_toplevel_handle_v1_set_title(c->foreign_toplevel, title); if (c == focustop(c->mon)) - printstatus(); + printstatus(PRINT_TITLE); } void // 17 fix to 0.5 @@ -5606,7 +5639,7 @@ urgent(struct wl_listener *listener, void *data) { c->isurgent = 1; if (client_surface(c)->mapped) setborder_color(c); - printstatus(); + printstatus(PRINT_ALL); } } @@ -5661,7 +5694,7 @@ toggleseltags: if (changefocus) focusclient(focustop(m), 1); arrange(m, want_animation); - printstatus(); + printstatus(PRINT_ALL); } void view(const Arg *arg, bool want_animation) { @@ -5804,7 +5837,7 @@ void activatex11(struct wl_listener *listener, void *data) { arrange(c->mon, false); } - printstatus(); + printstatus(PRINT_ALL); } void configurex11(struct wl_listener *listener, void *data) { @@ -5876,7 +5909,7 @@ void sethints(struct wl_listener *listener, void *data) { return; c->isurgent = xcb_icccm_wm_hints_get_urgency(c->surface.xwayland->hints); - printstatus(); + printstatus(PRINT_ALL); if (c->isurgent && surface && surface->mapped) setborder_color(c);