opt: optimize ipc event send

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

View file

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

View file

@ -572,7 +572,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;
}
}
@ -586,7 +586,7 @@ int32_t setkeymode(const Arg *arg) {
} else {
keymode.isdefault = false;
}
printstatus();
printstatus(IPC_WATCH_KEYMODE);
return 1;
}
@ -1038,7 +1038,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;
}
@ -1082,7 +1082,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;
}
@ -1093,7 +1093,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;
}
}
@ -1451,7 +1451,7 @@ int32_t toggletag(const Arg *arg) {
focusclient(focustop(selmon), 1);
arrange(selmon, false, false);
}
printstatus();
printstatus(IPC_WATCH_ARRANGGE);
return 0;
}
@ -1477,7 +1477,7 @@ int32_t toggleview(const Arg *arg) {
}
arrange(selmon, false, false);
}
printstatus();
printstatus(IPC_WATCH_ARRANGGE);
return 0;
}
@ -1649,7 +1649,7 @@ int32_t comboview(const Arg *arg) {
view(&(Arg){.ui = newtags}, false);
}
printstatus();
printstatus(IPC_WATCH_ARRANGGE);
return 0;
}

View file

@ -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,

View file

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

View file

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

View file

@ -151,6 +151,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 };
@ -197,6 +202,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;
@ -448,6 +467,8 @@ typedef struct {
struct wl_listener modifiers;
struct wl_listener key;
struct wl_listener destroy;
u_int32_t layout_index;
} KeyboardGroup;
typedef struct {
@ -701,7 +722,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);
@ -2609,7 +2630,7 @@ void closemon(Monitor *m) {
}
if (selmon) {
focusclient(focustop(selmon), 1);
printstatus();
printstatus(IPC_WATCH_ARRANGGE);
}
}
@ -3369,7 +3390,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
@ -3866,7 +3887,7 @@ void focusclient(Client *c, int32_t lift) {
client_activate_surface(old_keyboard_focus_surface, 0);
}
}
printstatus();
printstatus(IPC_WATCH_ARRANGGE);
if (!c) {
@ -4247,6 +4268,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) {
@ -4533,7 +4562,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) {
@ -4934,7 +4963,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 powermgrsetmode(struct wl_listener *listener, void *data) {
struct wlr_output_power_v1_set_mode_event *event = 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);
@ -6095,7 +6151,7 @@ void tag_client(const Arg *arg, Client *target_client) {
}
focusclient(target_client, 1);
printstatus();
printstatus(IPC_WATCH_ARRANGGE);
}
// 目标窗口有其他窗口和它同个tag就返回0
@ -6414,7 +6470,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);
}
@ -6568,7 +6624,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(IPC_WATCH_ARRANGGE);
}
void // 17 fix to 0.5
@ -6588,7 +6644,7 @@ urgent(struct wl_listener *listener, void *data) {
c->isurgent = 1;
if (client_surface(c)->mapped)
setborder_color(c);
printstatus();
printstatus(IPC_WATCH_ARRANGGE);
}
}
@ -6647,7 +6703,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) {
@ -6817,7 +6873,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) {
@ -6906,7 +6962,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);