opt: optimize ipc event send

This commit is contained in:
DreamMaoMao 2026-05-28 12:45:30 +08:00
parent 5af4f917f5
commit a6fa3d8849
6 changed files with 97 additions and 55 deletions

View file

@ -3844,6 +3844,6 @@ void reset_option(void) {
int32_t reload_config(const Arg *arg) { int32_t reload_config(const Arg *arg) {
parse_config(); parse_config();
reset_option(); reset_option();
printstatus(); printstatus(IPC_WATCH_ARRANGGE);
return 1; return 1;
} }

View file

@ -573,7 +573,7 @@ int32_t setlayout(const Arg *arg) {
selmon->pertag->ltidxs[selmon->pertag->curtag] = &layouts[jk]; selmon->pertag->ltidxs[selmon->pertag->curtag] = &layouts[jk];
clear_fullscreen_and_maximized_state(selmon); clear_fullscreen_and_maximized_state(selmon);
arrange(selmon, false, false); arrange(selmon, false, false);
printstatus(); printstatus(IPC_WATCH_ARRANGGE);
return 0; return 0;
} }
} }
@ -587,7 +587,7 @@ int32_t setkeymode(const Arg *arg) {
} else { } else {
keymode.isdefault = false; keymode.isdefault = false;
} }
printstatus(); printstatus(IPC_WATCH_KEYMODE);
return 1; return 1;
} }
@ -1039,7 +1039,7 @@ int32_t switch_keyboard_layout(const Arg *arg) {
wlr_seat_keyboard_notify_modifiers(seat, &tkb->modifiers); wlr_seat_keyboard_notify_modifiers(seat, &tkb->modifiers);
} }
printstatus(); printstatus(IPC_WATCH_KB_LAYOUT);
return 0; return 0;
} }
@ -1083,7 +1083,7 @@ int32_t switch_layout(const Arg *arg) {
} }
clear_fullscreen_and_maximized_state(selmon); clear_fullscreen_and_maximized_state(selmon);
arrange(selmon, false, false); arrange(selmon, false, false);
printstatus(); printstatus(IPC_WATCH_ARRANGGE);
return 0; return 0;
} }
@ -1094,7 +1094,7 @@ int32_t switch_layout(const Arg *arg) {
jk == LENGTH(layouts) - 1 ? &layouts[0] : &layouts[jk + 1]; jk == LENGTH(layouts) - 1 ? &layouts[0] : &layouts[jk + 1];
clear_fullscreen_and_maximized_state(selmon); clear_fullscreen_and_maximized_state(selmon);
arrange(selmon, false, false); arrange(selmon, false, false);
printstatus(); printstatus(IPC_WATCH_ARRANGGE);
return 0; return 0;
} }
} }
@ -1452,7 +1452,7 @@ int32_t toggletag(const Arg *arg) {
focusclient(focustop(selmon), 1); focusclient(focustop(selmon), 1);
arrange(selmon, false, false); arrange(selmon, false, false);
} }
printstatus(); printstatus(IPC_WATCH_ARRANGGE);
return 0; return 0;
} }
@ -1478,7 +1478,7 @@ int32_t toggleview(const Arg *arg) {
} }
arrange(selmon, false, false); arrange(selmon, false, false);
} }
printstatus(); printstatus(IPC_WATCH_ARRANGGE);
return 0; return 0;
} }
@ -1650,7 +1650,7 @@ int32_t comboview(const Arg *arg) {
view(&(Arg){.ui = newtags}, false); view(&(Arg){.ui = newtags}, false);
} }
printstatus(); printstatus(IPC_WATCH_ARRANGGE);
return 0; return 0;
} }

View file

@ -239,7 +239,7 @@ void dwl_ipc_output_set_client_tags(struct wl_client *client,
if (selmon == monitor) if (selmon == monitor)
focusclient(focustop(monitor), 1); focusclient(focustop(monitor), 1);
arrange(selmon, false, false); arrange(selmon, false, false);
printstatus(); printstatus(IPC_WATCH_ARRANGGE);
} }
void dwl_ipc_output_set_layout(struct wl_client *client, 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]; monitor->pertag->ltidxs[monitor->pertag->curtag] = &layouts[index];
clear_fullscreen_and_maximized_state(monitor); clear_fullscreen_and_maximized_state(monitor);
arrange(monitor, false, false); arrange(monitor, false, false);
printstatus(); printstatus(IPC_WATCH_ARRANGGE);
} }
void dwl_ipc_output_set_tags(struct wl_client *client, void dwl_ipc_output_set_tags(struct wl_client *client,

View file

@ -9,20 +9,6 @@
#include <sys/un.h> #include <sys/un.h>
#include <unistd.h> #include <unistd.h>
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 ipc_watch_client {
struct wl_list link; struct wl_list link;
int fd; int fd;

View file

@ -1225,5 +1225,5 @@ arrange(Monitor *m, bool want_animation, bool from_view) {
checkidleinhibitor(NULL); checkidleinhibitor(NULL);
} }
printstatus(); printstatus(IPC_WATCH_ARRANGGE);
} }

View file

@ -149,6 +149,11 @@
#define BAKED_POINTS_COUNT 256 #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 */ /* enums */
enum { TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT }; enum { TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT };
@ -194,6 +199,20 @@ enum seat_config_shortcuts_inhibit {
SHORTCUTS_INHIBIT_ENABLE, 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 Pertag Pertag;
typedef struct Monitor Monitor; typedef struct Monitor Monitor;
typedef struct Client Client; typedef struct Client Client;
@ -449,6 +468,8 @@ typedef struct {
struct wl_listener modifiers; struct wl_listener modifiers;
struct wl_listener key; struct wl_listener key;
struct wl_listener destroy; struct wl_listener destroy;
u_int32_t layout_index;
} KeyboardGroup; } KeyboardGroup;
typedef struct { 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 outputmgrtest(struct wl_listener *listener, void *data);
static void pointerfocus(Client *c, struct wlr_surface *surface, double sx, static void pointerfocus(Client *c, struct wlr_surface *surface, double sx,
double sy, uint32_t time); 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 quitsignal(int32_t signo);
static void powermgrsetmode(struct wl_listener *listener, void *data); static void powermgrsetmode(struct wl_listener *listener, void *data);
static void rendermon(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) { if (selmon) {
focusclient(focustop(selmon), 1); 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); add_workspace_by_tag(i, m);
} }
printstatus(); printstatus(IPC_WATCH_ARRANGGE);
} }
void // fix for 0.5 void // fix for 0.5
@ -3819,7 +3840,7 @@ void focusclient(Client *c, int32_t lift) {
client_activate_surface(old_keyboard_focus_surface, 0); client_activate_surface(old_keyboard_focus_surface, 0);
} }
} }
printstatus(); printstatus(IPC_WATCH_ARRANGGE);
if (!c) { if (!c) {
@ -4200,6 +4221,14 @@ void keypressmod(struct wl_listener *listener, void *data) {
wlr_seat_keyboard_notify_modifiers( wlr_seat_keyboard_notify_modifiers(
seat, &group->wlr_group->keyboard.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) { void pending_kill_client(Client *c) {
@ -4466,7 +4495,7 @@ mapnotify(struct wl_listener *listener, void *data) {
// make sure the animation is open type // make sure the animation is open type
c->is_pending_open_animation = true; c->is_pending_open_animation = true;
resize(c, c->geom, 0); resize(c, c->geom, 0);
printstatus(); printstatus(IPC_WATCH_ARRANGGE);
} }
void maximizenotify(struct wl_listener *listener, void *data) { 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函数接受掩码参数 // 修改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) { 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) if (fd_set_nonblock(STDOUT_FILENO) < 0)
close(STDOUT_FILENO); close(STDOUT_FILENO);
printstatus(); printstatus(IPC_WATCH_ARRANGGE);
/* At this point the outputs are initialized, choose initial selmon /* At this point the outputs are initialized, choose initial selmon
* based on cursor position, and set default cursor image */ * based on cursor position, and set default cursor image */
@ -5383,7 +5414,7 @@ setfloating(Client *c, int32_t floating) {
} }
setborder_color(c); setborder_color(c);
printstatus(); printstatus(IPC_WATCH_ARRANGGE);
} }
void reset_maximizescreen_size(Client *c) { 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) { void handle_print_status(struct wl_listener *listener, void *data) {
ipc_notify_keymode(); enum ipc_watch_type type = *(enum ipc_watch_type *)data;
ipc_notify_kb_layout();
ipc_notify_focusing_client();
ipc_notify_all_tags();
ipc_notify_all_clients();
ipc_notify_all_monitors();
Client *c = NULL; if (type & IPC_WATCH_KEYMODE) {
wl_list_for_each(c, &clients, link) { ipc_notify_keymode();
if (c->iskilling) }
continue; if (type & IPC_WATCH_KB_LAYOUT) {
ipc_notify_client(c); 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; Monitor *m = NULL;
@ -5729,9 +5778,16 @@ void handle_print_status(struct wl_listener *listener, void *data) {
continue; continue;
} }
ipc_notify_monitor(m); if (type & IPC_WATCH_MONITOR) {
ipc_notify_tags(m); ipc_notify_monitor(m);
ipc_notify_last_surface_ws_name(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_ext_workspace_printstatus(m);
dwl_ipc_output_printstatus(m); dwl_ipc_output_printstatus(m);
@ -6104,7 +6160,7 @@ void tag_client(const Arg *arg, Client *target_client) {
} }
focusclient(target_client, 1); focusclient(target_client, 1);
printstatus(); printstatus(IPC_WATCH_ARRANGGE);
} }
// 目标窗口有其他窗口和它同个tag就返回0 // 目标窗口有其他窗口和它同个tag就返回0
@ -6436,7 +6492,7 @@ void unmapnotify(struct wl_listener *listener, void *data) {
c->stack_proportion = 0.0f; c->stack_proportion = 0.0f;
wlr_scene_node_destroy(&c->scene->node); wlr_scene_node_destroy(&c->scene->node);
printstatus(); printstatus(IPC_WATCH_ARRANGGE);
motionnotify(0, NULL, 0, 0, 0, 0); motionnotify(0, NULL, 0, 0, 0, 0);
} }
@ -6593,7 +6649,7 @@ void updatetitle(struct wl_listener *listener, void *data) {
}); });
} }
if (c == focustop(c->mon)) if (c == focustop(c->mon))
printstatus(); printstatus(IPC_WATCH_ARRANGGE);
} }
void // 17 fix to 0.5 void // 17 fix to 0.5
@ -6613,7 +6669,7 @@ urgent(struct wl_listener *listener, void *data) {
c->isurgent = 1; c->isurgent = 1;
if (client_surface(c)->mapped) if (client_surface(c)->mapped)
setborder_color(c); setborder_color(c);
printstatus(); printstatus(IPC_WATCH_ARRANGGE);
} }
} }
@ -6672,7 +6728,7 @@ toggleseltags:
if (changefocus) if (changefocus)
focusclient(focustop(m), 1); focusclient(focustop(m), 1);
arrange(m, want_animation, true); arrange(m, want_animation, true);
printstatus(); printstatus(IPC_WATCH_ARRANGGE);
} }
void view(const Arg *arg, bool want_animation) { 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); arrange(c->mon, false, false);
} }
printstatus(); printstatus(IPC_WATCH_ARRANGGE);
} }
void configurex11(struct wl_listener *listener, void *data) { void configurex11(struct wl_listener *listener, void *data) {
@ -6931,7 +6987,7 @@ void sethints(struct wl_listener *listener, void *data) {
return; return;
c->isurgent = xcb_icccm_wm_hints_get_urgency(c->surface.xwayland->hints); c->isurgent = xcb_icccm_wm_hints_get_urgency(c->surface.xwayland->hints);
printstatus(); printstatus(IPC_WATCH_ARRANGGE);
if (c->isurgent && surface && surface->mapped) if (c->isurgent && surface && surface->mapped)
setborder_color(c); setborder_color(c);