Skip to content

Instantly share code, notes, and snippets.

@smblott-github
Created December 26, 2018 06:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smblott-github/5cc6595f6627244fdeac897668a19d72 to your computer and use it in GitHub Desktop.
Save smblott-github/5cc6595f6627244fdeac897668a19d72 to your computer and use it in GitHub Desktop.
<alt-Tab> for dwm
/* this implements <alt-Tab> for dwm, put it in config.h */
static int alt_tab_count = 0;
/* focus and restack a client */
static void focus_restack(Client *c)
{ if (c) { focus(c); restack(selmon); } }
static void start_alt_tab(const Arg *arg)
{ alt_tab_count = 0; }
static Client *next_visible(Client *c)
{
for(/* DO_NOTHING */; c && !ISVISIBLE(c); c=c->snext);
return c;
}
static int count_visible(void)
{
int count = 0;
for (Client *c=next_visible(selmon->stack); c; c = next_visible(c->snext))
count += 1;
return count;
}
static Client *get_nth_client(int n)
{
Client *c;
for (c=next_visible(selmon->stack); c && n--; c = next_visible(c->snext));
return c;
}
static void alt_tab(const Arg *arg)
{
// put all of the windows back in their original focus/stack position */
for (int i=0; i<alt_tab_count; i+=1)
focus_restack(get_nth_client(alt_tab_count));
// focus and restack the nth window */
alt_tab_count = (alt_tab_count + 1) % count_visible();
focus_restack(get_nth_client(alt_tab_count));
}
/*
static Key keys[] = {
// ...
{ 0, XK_Alt_L, start_alt_tab, {0} },
{ MODKEY, XK_Tab, alt_tab, {0} },
// ...
};
*/
@bartimois
Copy link

Could this search clients throughout different tags aswell?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment