awful.widget.prompt: import

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2009-04-27 22:08:33 +02:00
parent c6a63d9250
commit 1cbb1c0666
3 changed files with 47 additions and 10 deletions

View File

@ -152,7 +152,7 @@ mytasklist.buttons = awful.util.table.join(
for s = 1, screen.count() do for s = 1, screen.count() do
-- Create a promptbox for each screen -- Create a promptbox for each screen
mypromptbox[s] = widget({ type = "textbox", align = "left" }) mypromptbox[s] = awful.widget.prompt({ align = "left" })
-- Create an imagebox widget which will contains an icon indicating which layout we're using. -- Create an imagebox widget which will contains an icon indicating which layout we're using.
-- We need one layoutbox per screen. -- We need one layoutbox per screen.
mylayoutbox[s] = widget({ type = "imagebox", align = "right" }) mylayoutbox[s] = widget({ type = "imagebox", align = "right" })
@ -238,19 +238,12 @@ globalkeys = awful.util.table.join(
awful.key({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end), awful.key({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end),
-- Prompt -- Prompt
awful.key({ modkey }, "r", awful.key({ modkey }, "r", function () mypromptbox[mouse.screen]:run() end),
function ()
awful.prompt.run({ prompt = "Run: " },
mypromptbox[mouse.screen],
function (...) mypromptbox[mouse.screen].text = awful.util.spawn(unpack(arg)) end,
awful.completion.shell,
awful.util.getdir("cache") .. "/history")
end),
awful.key({ modkey }, "x", awful.key({ modkey }, "x",
function () function ()
awful.prompt.run({ prompt = "Run Lua code: " }, awful.prompt.run({ prompt = "Run Lua code: " },
mypromptbox[mouse.screen], mypromptbox[mouse.screen].widget,
awful.util.eval, nil, awful.util.eval, nil,
awful.util.getdir("cache") .. "/history_eval") awful.util.getdir("cache") .. "/history_eval")
end) end)

View File

@ -8,6 +8,7 @@ require("awful.widget.taglist")
require("awful.widget.tasklist") require("awful.widget.tasklist")
require("awful.widget.button") require("awful.widget.button")
require("awful.widget.launcher") require("awful.widget.launcher")
require("awful.widget.prompt")
--- Widget module for awful --- Widget module for awful
module("awful.widget") module("awful.widget")

View File

@ -0,0 +1,43 @@
---------------------------------------------------------------------------
-- @author Julien Danjou &lt;julien@danjou.info&gt;
-- @copyright 2009 Julien Danjou
-- @release @AWESOME_VERSION@
---------------------------------------------------------------------------
local setmetatable = setmetatable
local unpack = unpack
local capi = { widget = widget }
local completion = require("awful.completion")
local util = require("awful.util")
local prompt = require("awful.prompt")
module("awful.widget.prompt")
--- Run method for promptbox.
-- @param promptbox The promptbox to run.
local function run(promptbox)
return prompt.run({ prompt = promptbox.prompt },
promptbox.widget,
function (...) promptbox.widget.text = util.spawn(unpack(arg)) end,
completion.shell,
util.getdir("cache") .. "/history")
end
--- Create a prompt widget which will launch a command.
-- @param args Standard widget table arguments, with prompt to change the
-- default prompt.
-- @return A launcher widget.
function new(args)
local args = args or {}
local promptbox = {}
args.type = "textbox"
promptbox.widget = capi.widget(args)
promptbox.run = run
promptbox.prompt = args.prompt or "Run: "
return promptbox
end
setmetatable(_M, { __call = function (_, ...) return new(unpack(arg)) end })
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80