From ba763332fcb9e372cd6392152e71f43998cc7bc8 Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Sun, 15 Jun 2025 15:55:18 +0800 Subject: [PATCH] feat: add dispatch focuslast --- src/config/parse_config.h | 2 ++ src/dispatch/dispatch.h | 3 ++- src/maomao.c | 25 +++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/config/parse_config.h b/src/config/parse_config.h index 66a73eb..9ab68cf 100644 --- a/src/config/parse_config.h +++ b/src/config/parse_config.h @@ -660,6 +660,8 @@ FuncType parse_func_name(char *func_name, Arg *arg, char *arg_value, func = tagtoright; } else if (strcmp(func_name, "killclient") == 0) { func = killclient; + } else if (strcmp(func_name, "focuslast") == 0) { + func = focuslast; } else if (strcmp(func_name, "setlayout") == 0) { func = setlayout; (*arg).v = strdup(arg_value); diff --git a/src/dispatch/dispatch.h b/src/dispatch/dispatch.h index 5632feb..452908b 100644 --- a/src/dispatch/dispatch.h +++ b/src/dispatch/dispatch.h @@ -57,4 +57,5 @@ void resizewin(const Arg *arg); void toggle_named_scratchpad(const Arg *arg); void toggle_render_border(const Arg *arg); void create_virtual_output(const Arg *arg); -void destroy_all_virtual_output(const Arg *arg); \ No newline at end of file +void destroy_all_virtual_output(const Arg *arg); +void focuslast(const Arg *arg); \ No newline at end of file diff --git a/src/maomao.c b/src/maomao.c index e993a5e..0b4f62d 100644 --- a/src/maomao.c +++ b/src/maomao.c @@ -4549,6 +4549,31 @@ void pending_kill_client(Client *c) { client_send_close(c); } +void focuslast(const Arg *arg) { + + Client *c, *prev = NULL; + wl_list_for_each(c, &fstack, flink) { + if (c->iskilling || c->isminied || c->isunglobal) + continue; + if (c) + break; + } + + struct wl_list *prev_node = c->flink.next; + prev = wl_container_of(prev_node, prev, flink); + + unsigned int target; + if (prev) { + if (prev->mon != selmon) { + selmon = prev->mon; + warp_cursor_to_selmon(selmon); + } + target = get_tags_first_tag(prev->tags); + view(&(Arg){.ui = target}, true); + focusclient(prev, 1); + } +} + void killclient(const Arg *arg) { Client *c; c = selmon->sel;