From e1dc0c5b616ac7b4ec5c5201016982f64b9e2d31 Mon Sep 17 00:00:00 2001 From: salivala Date: Tue, 11 Nov 2025 12:34:09 -0500 Subject: [PATCH] impl comboview_spawn_on_empty --- src/config/parse_config.h | 4 ++++ src/dispatch/bind_declare.h | 3 ++- src/dispatch/bind_define.h | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/config/parse_config.h b/src/config/parse_config.h index 0e9e15c5..345fbc60 100644 --- a/src/config/parse_config.h +++ b/src/config/parse_config.h @@ -1014,6 +1014,10 @@ FuncType parse_func_name(char *func_name, Arg *arg, char *arg_value, func = spawn_on_empty; (*arg).v = strdup(arg_value); // 注意:之后需要释放这个内存 (*arg).ui = 1 << (atoi(arg_value2) - 1); + } else if (strcmp(func_name, "comboview_spawn_on_empty") == 0) { + func = comboview_spawn_on_empty; + (*arg).v = strdup(arg_value); // 注意:之后需要释放这个内存 + (*arg).ui = 1 << (atoi(arg_value2) - 1); } else if (strcmp(func_name, "quit") == 0) { func = quit; } else if (strcmp(func_name, "create_virtual_output") == 0) { diff --git a/src/dispatch/bind_declare.h b/src/dispatch/bind_declare.h index 5bc215a2..111db1e6 100644 --- a/src/dispatch/bind_declare.h +++ b/src/dispatch/bind_declare.h @@ -23,6 +23,7 @@ int tagmon(const Arg *arg); int spawn(const Arg *arg); int spawn_shell(const Arg *arg); int spawn_on_empty(const Arg *arg); +int comboview_spawn_on_empty(const Arg *arg); int setkeymode(const Arg *arg); int switch_keyboard_layout(const Arg *arg); int setlayout(const Arg *arg); @@ -68,4 +69,4 @@ int toggle_trackpad_enable(const Arg *arg); int setoption(const Arg *arg); int disable_monitor(const Arg *arg); int enable_monitor(const Arg *arg); -int toggle_monitor(const Arg *arg); \ No newline at end of file +int toggle_monitor(const Arg *arg); diff --git a/src/dispatch/bind_define.h b/src/dispatch/bind_define.h index 65c2b03e..50889130 100644 --- a/src/dispatch/bind_define.h +++ b/src/dispatch/bind_define.h @@ -810,6 +810,37 @@ int spawn_on_empty(const Arg *arg) { return 0; } +comboview_spawn_on_empty(const Arg *arg) { + unsigned int newtags = arg->ui & TAGMASK; + bool is_empty = true; + Client *c = NULL; + + if (!newtags || !selmon) + return 0; + + wl_list_for_each(c, &clients, link) { + if (arg->ui & c->tags && c->mon == selmon) { + is_empty = false; + break; + } + } + + if (tag_combo) { + selmon->tagset[selmon->seltags] |= newtags; + focusclient(focustop(selmon), 1); + arrange(selmon, false); + } else { + tag_combo = true; + view(&(Arg){.ui = newtags}, false); + } + if (is_empty) { + spawn(arg); + } + + printstatus(); + return 0; +} + int switch_keyboard_layout(const Arg *arg) { if (!kb_group || !kb_group->wlr_group || !seat) { wlr_log(WLR_ERROR, "Invalid keyboard group or seat"); @@ -1548,4 +1579,4 @@ int toggle_monitor(const Arg *arg) { } } return 0; -} \ No newline at end of file +}