diff --git a/awesomerc.lua.in b/awesomerc.lua.in index d3d904c21..8d999066c 100644 --- a/awesomerc.lua.in +++ b/awesomerc.lua.in @@ -152,7 +152,7 @@ mytasklist.buttons = awful.util.table.join( for s = 1, screen.count() do -- 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. -- We need one layoutbox per screen. 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), -- Prompt - awful.key({ modkey }, "r", - 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 }, "r", function () mypromptbox[mouse.screen]:run() end), awful.key({ modkey }, "x", function () awful.prompt.run({ prompt = "Run Lua code: " }, - mypromptbox[mouse.screen], + mypromptbox[mouse.screen].widget, awful.util.eval, nil, awful.util.getdir("cache") .. "/history_eval") end) diff --git a/lib/awful/widget/init.lua.in b/lib/awful/widget/init.lua.in index 0451385a0..3b0aa0f77 100644 --- a/lib/awful/widget/init.lua.in +++ b/lib/awful/widget/init.lua.in @@ -8,6 +8,7 @@ require("awful.widget.taglist") require("awful.widget.tasklist") require("awful.widget.button") require("awful.widget.launcher") +require("awful.widget.prompt") --- Widget module for awful module("awful.widget") diff --git a/lib/awful/widget/prompt.lua.in b/lib/awful/widget/prompt.lua.in new file mode 100644 index 000000000..0da5024dc --- /dev/null +++ b/lib/awful/widget/prompt.lua.in @@ -0,0 +1,43 @@ +--------------------------------------------------------------------------- +-- @author Julien Danjou <julien@danjou.info> +-- @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