diff --git a/src/dispatch/bind_define.h b/src/dispatch/bind_define.h index 6cc6670..0268078 100644 --- a/src/dispatch/bind_define.h +++ b/src/dispatch/bind_define.h @@ -129,6 +129,7 @@ int32_t exchange_stack_client(const Arg *arg) { int32_t focusdir(const Arg *arg) { Client *c = NULL; c = direction_select(arg); + c = get_focused_stack_client(c); if (c) { focusclient(c, 1); if (warpcursor) diff --git a/src/fetch/client.h b/src/fetch/client.h index 4cd0364..ce5eae5 100644 --- a/src/fetch/client.h +++ b/src/fetch/client.h @@ -455,4 +455,77 @@ Client *get_scroll_stack_head(Client *c) { scroller_stack_head = scroller_stack_head->prev_in_stack; } return scroller_stack_head; -} \ No newline at end of file +} + +bool client_is_in_same_stack(Client *sc, Client *tc, Client *fc) { + if (!sc || !tc) + return false; + + uint32_t id = sc->mon->pertag->ltidxs[sc->mon->pertag->curtag]->id; + + if (id != SCROLLER && id != VERTICAL_SCROLLER && id != TILE && + id != VERTICAL_TILE && id != DECK && id != VERTICAL_DECK && + id != CENTER_TILE && id != RIGHT_TILE && id != TGMIX) + return false; + + if (id == SCROLLER || id == VERTICAL_SCROLLER) { + if (fc->prev_in_stack) + return false; + Client *source_stack_head = get_scroll_stack_head(sc); + Client *target_stack_head = get_scroll_stack_head(tc); + if (source_stack_head == target_stack_head) + return true; + else + return false; + } + + if (id == TILE || id == VERTICAL_TILE || id == DECK || + id == VERTICAL_DECK || id == RIGHT_TILE) { + if (!fc->ismaster) + return false; + else + return true; + } + + if (id == TGMIX) { + if (!fc->ismaster) + return false; + if (sc->mon->visible_tiling_clients <= 3) + return true; + } + + if (id == CENTER_TILE) { + if (!fc->ismaster) + return false; + if (sc->geom.x == tc->geom.x) + return true; + else + return false; + } + + return false; +} + +Client *get_focused_stack_client(Client *sc) { + if (!sc || sc->isfloating) + return sc; + + Client *tc = NULL; + Client *fc = focustop(sc->mon); + + wl_list_for_each(tc, &fstack, flink) { + if (tc->iskilling || tc->isunglobal) + continue; + if (!VISIBLEON(tc, sc->mon)) + continue; + if (tc == fc) + continue; + + if (client_is_in_same_stack(sc, tc, fc)) { + wlr_log(WLR_ERROR, "11"); + return tc; + } + } + wlr_log(WLR_ERROR, "22"); + return sc; +} diff --git a/src/mango.c b/src/mango.c index 250b89c..615c60d 100644 --- a/src/mango.c +++ b/src/mango.c @@ -776,6 +776,8 @@ static Client *find_client_by_direction(Client *tc, const Arg *arg, static void exit_scroller_stack(Client *c); static Client *get_scroll_stack_head(Client *c); static bool client_only_in_one_tag(Client *c); +static Client *get_focused_stack_client(Client *sc); +static bool client_is_in_same_stack(Client *sc, Client *tc, Client *fc); #include "data/static_keymap.h" #include "dispatch/bind_declare.h"