opt: use event mask to decide whether print ipc message

This commit is contained in:
DreamMaoMao
2025-12-02 16:46:11 +08:00
parent 075d4979b6
commit 9196e2a50b
4 changed files with 205 additions and 96 deletions

View File

@@ -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);