turn focusnext into dwm's focusstack

main
Devin J. Pohly 2020-04-23 00:47:15 -05:00
parent 59b09576b9
commit 623867a367
2 changed files with 25 additions and 14 deletions

View File

@ -32,11 +32,13 @@ static const struct xkb_rule_names xkb_rules = {
static const char *termcmd[] = { "kitty", "-o", "linux_display_server=wayland", NULL }; static const char *termcmd[] = { "kitty", "-o", "linux_display_server=wayland", NULL };
static const Key keys[] = { static const Key keys[] = {
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Return, spawn, {.v = termcmd } }, /* modifier key function argument */
{ MODKEY, XKB_KEY_j, focusnext, {0} }, { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Return, spawn, {.v = termcmd } },
{ MODKEY, XKB_KEY_t, setlayout, {.v = &layouts[0]} }, { MODKEY, XKB_KEY_j, focusstack, {.i = +1} },
{ MODKEY, XKB_KEY_f, setlayout, {.v = &layouts[1]} }, { MODKEY, XKB_KEY_k, focusstack, {.i = -1} },
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Q, quit, {0} }, { MODKEY, XKB_KEY_t, setlayout, {.v = &layouts[0]} },
{ MODKEY, XKB_KEY_f, setlayout, {.v = &layouts[1]} },
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Q, quit, {0} },
}; };
static const Button buttons[] = { static const Button buttons[] = {

27
dwl.c
View File

@ -125,7 +125,7 @@ static void createpointer(struct wlr_input_device *device);
static void cursorframe(struct wl_listener *listener, void *data); static void cursorframe(struct wl_listener *listener, void *data);
static void destroynotify(struct wl_listener *listener, void *data); static void destroynotify(struct wl_listener *listener, void *data);
static void focus(Client *c, struct wlr_surface *surface); static void focus(Client *c, struct wlr_surface *surface);
static void focusnext(const Arg *arg); static void focusstack(const Arg *arg);
static void inputdevice(struct wl_listener *listener, void *data); static void inputdevice(struct wl_listener *listener, void *data);
static bool keybinding(uint32_t mods, xkb_keysym_t sym); static bool keybinding(uint32_t mods, xkb_keysym_t sym);
static void keypress(struct wl_listener *listener, void *data); static void keypress(struct wl_listener *listener, void *data);
@ -409,20 +409,29 @@ focus(Client *c, struct wlr_surface *surface)
} }
void void
focusnext(const Arg *arg) focusstack(const Arg *arg)
{ {
/* Focus the client on the selected monitor which comes first in tiling /* Focus the next or previous client (in tiling order) on selmon */
* order after the currently selected client */
Client *sel = selclient(); Client *sel = selclient();
if (!sel) if (!sel)
return; return;
Client *c; Client *c;
wl_list_for_each(c, &sel->link, link) { if (arg->i > 0) {
if (&c->link == &clients) wl_list_for_each(c, &sel->link, link) {
continue; /* wrap past the sentinel node */ if (&c->link == &clients)
if (VISIBLEON(c, selmon)) continue; /* wrap past the sentinel node */
break; /* found it */ if (VISIBLEON(c, selmon))
break; /* found it */
}
} else {
wl_list_for_each_reverse(c, &sel->link, link) {
if (&c->link == &clients)
continue; /* wrap past the sentinel node */
if (VISIBLEON(c, selmon))
break; /* found it */
}
} }
/* If only one client is visible on selmon, then c == sel */
focus(c, c->xdg_surface->surface); focus(c, c->xdg_surface->surface);
} }