Drop-down terminal

From awesome

Jump to: navigation, search

[edit] Introduction

A drop-down terminal pops up from the top of the screen in video game console fashion and can be toggled with a single hotkey. Applications such as Yakuake, Guake or Tilda provide drop-down terminal functionality for the regular desktop environments. With awesome and the power of lua, however, we can mimic this functionality and still use our precious light-weight terminal applications.

Adding the following function to your rc.lua and calling it in a keybinding will create a new window for the drop-down terminal when it does not exist, and will toggle between hidden and visible if one does exist. The first argument is the program to run (eg. "urxvtc"), the second argument is the height (absolute pixels when > 1 or a height percentage when < 1, 0.2 (20% of the screen height) by default), and the third argument is the screen to toggle on. The second and third arguments are optional.

[edit] Function

-- This function is for awesome versions prior to 3.4

dropdown = {}

function dropdown_toggle(prog, height, s)
    if s == nil then s = mouse.screen end
    if height == nil then height = 0.2 end

    if not dropdown[prog] then
        -- Create table
        dropdown[prog] = {}

        -- Add unmanage hook for dropdown programs
        awful.hooks.unmanage.register(function (c)
            for scr, cl in pairs(dropdown[prog]) do
                if cl == c then
                    dropdown[prog][scr] = nil
                end
            end
        end)
    end

    if not dropdown[prog][s] then
        spawnw = function (c)
            -- Store client
            dropdown[prog][s] = c

            -- Float client
            awful.client.floating.set(c, true)

            -- Get screen geometry
            screengeom = screen[s].workarea

            -- Calculate height
            if height < 1 then
                height = screengeom.height*height
            end

            -- I like a different border with for the popup window
            -- So I don't confuse it with terminals in the layout
            bw = 2

            -- Resize client
            c:geometry({
                x = screengeom.x,
                -- The following will place the window on the bottom
                -- y = screengeom.y + screengeom.height - height,
                -- This one will place it on top
                y = screengeom.y,
                width = screengeom.width - bw,
                height = height - bw
            })

            -- Mark terminal as ontop
            c.ontop = true
            c.above = true
            c.border_width = bw

            -- Focus and raise client
            c:raise()
            client.focus = c

            -- Remove hook
            awful.hooks.manage.unregister(spawnw)
        end

        -- Add hook
        awful.hooks.manage.register(spawnw)

        -- Spawn program
        awful.util.spawn(prog)
    else
        -- Get client
        c = dropdown[prog][s]

        -- Switch the client to the current workspace
        awful.client.movetotag(awful.tag.selected(s), c)

        -- Focus and raise if not hidden
        if c.hide then
            c.hide = false
            c:raise()
            client.focus = c
        else
            c.hide = true
        end
    end
end


[edit] Scratch

Scratch is a drop-down applications and scratchpad manager for the awesome window manager. Its scratch.drop module is based on the above code and is compatable with awesome v3.4. For more information see the Scratchpad manager page.

Personal tools