Skip to content

Instantly share code, notes, and snippets.

@blueyed
Created September 9, 2015 18:57
Show Gist options
  • Select an option

  • Save blueyed/d7ba5d51fafff1605fff to your computer and use it in GitHub Desktop.

Select an option

Save blueyed/d7ba5d51fafff1605fff to your computer and use it in GitHub Desktop.

Revisions

  1. blueyed created this gist Sep 9, 2015.
    29 changes: 29 additions & 0 deletions awesome-swap-back-and-forth.lua
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    -- Generic back and forth switching between master and client. {{{
    -- Bind it like this:
    -- awful.key({ modkey, "Control" }, "Return", function (c) my_swap_back_and_forth.run(c, awful.client.getmaster) end),
    local my_swap_back_and_forth = {
    previous_by_tag_and_f = {}
    }
    my_swap_back_and_forth.run = function (c, swapf)
    local f = swapf or awful.client.getmaster

    local prev = my_swap_back_and_forth.previous_by_tag_and_f
    if not prev.tag then
    prev.tag = {}
    end

    local swap_with = f()
    local tag = c:tags()[1]

    if c == swap_with then
    if prev.tag.f then
    swap_with = prev.tag.f
    else
    bnote("No previous client to swap with.")
    return
    end
    end
    prev.tag.f = swap_with
    c:swap(swap_with)
    end
    -- }}}