textbox: use newindex API
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
39e1fc7011
commit
5aa2768861
|
@ -96,12 +96,12 @@ mytasklist:text_set({ ["focus"] = "<bg color='"..bg_focus.."'/> <span color='"..
|
|||
-- Create a textbox widget
|
||||
mytextbox = widget.new({ type = "textbox", name = "mytextbox", align = "right" })
|
||||
-- Set the default text in textbox
|
||||
mytextbox:text_set("<b><small> awesome " .. AWESOME_VERSION .. " </small></b>")
|
||||
mytextbox.text = "<b><small> awesome " .. AWESOME_VERSION .. " </small></b>"
|
||||
mypromptbox = widget.new({ type = "textbox", name = "mypromptbox", align = "left" })
|
||||
|
||||
-- Create an iconbox widget
|
||||
myiconbox = widget.new({ type = "textbox", name = "myiconbox", align = "left" })
|
||||
myiconbox:text_set("<bg image=\"@AWESOME_ICON_PATH@/awesome16.png\" resize=\"true\"/>")
|
||||
myiconbox.text = "<bg image=\"@AWESOME_ICON_PATH@/awesome16.png\" resize=\"true\"/>"
|
||||
|
||||
-- Create a systray
|
||||
mysystray = widget.new({ type = "systray", name = "mysystray", align = "right" })
|
||||
|
@ -115,7 +115,7 @@ for s = 1, screen.count() do
|
|||
mylayoutbox[s]:mouse_add(mouse.new({ }, 3, function () awful.layout.inc(layouts, -1) end))
|
||||
mylayoutbox[s]:mouse_add(mouse.new({ }, 4, function () awful.layout.inc(layouts, 1) end))
|
||||
mylayoutbox[s]:mouse_add(mouse.new({ }, 5, function () awful.layout.inc(layouts, -1) end))
|
||||
mylayoutbox[s]:text_set("<bg image=\"@AWESOME_ICON_PATH@/layouts/tilew.png\" resize=\"true\"/>")
|
||||
mylayoutbox[s].text = "<bg image=\"@AWESOME_ICON_PATH@/layouts/tilew.png\" resize=\"true\"/>"
|
||||
end
|
||||
|
||||
-- Create a statusbar for each screen and add it
|
||||
|
@ -334,7 +334,7 @@ end
|
|||
-- (tag switch, new client, etc)
|
||||
function hook_arrange(screen)
|
||||
local layout = awful.layout.get(screen)
|
||||
mylayoutbox[screen]:text_set("<bg image=\"@AWESOME_ICON_PATH@/layouts/" .. layout .. "w.png\" resize=\"true\"/>")
|
||||
mylayoutbox[screen].text = "<bg image=\"@AWESOME_ICON_PATH@/layouts/" .. layout .. "w.png\" resize=\"true\"/>"
|
||||
|
||||
-- Uncomment if you want mouse warping
|
||||
--[[
|
||||
|
@ -356,9 +356,9 @@ end
|
|||
-- Hook called every second
|
||||
function hook_timer ()
|
||||
-- For unix time_t lovers
|
||||
mytextbox:text_set(" " .. os.time() .. " time_t ")
|
||||
mytextbox.text = " " .. os.time() .. " time_t "
|
||||
-- Otherwise use:
|
||||
-- mytextbox:text_set(" " .. os.date() .. " ")
|
||||
-- mytextbox.text = " " .. os.date() .. " "
|
||||
end
|
||||
|
||||
-- Set up some hooks
|
||||
|
|
|
@ -618,7 +618,7 @@ function P.prompt(args, textbox, exe_callback, completion_callback)
|
|||
if not textbox or not exe_callback then
|
||||
return
|
||||
end
|
||||
textbox:text_set(prompt .. prompt_text_with_cursor(text, inv_col, cur_col, cur_pos))
|
||||
textbox.text = prompt .. prompt_text_with_cursor(text, inv_col, cur_col, cur_pos)
|
||||
keygrabber.run(
|
||||
function (mod, key)
|
||||
local has_ctrl = false
|
||||
|
@ -631,16 +631,16 @@ function P.prompt(args, textbox, exe_callback, completion_callback)
|
|||
-- Get out cases
|
||||
if has_ctrl then
|
||||
if key == "g" then
|
||||
textbox:text_set("")
|
||||
textbox.text = ""
|
||||
return false
|
||||
end
|
||||
else
|
||||
if key == "Return" then
|
||||
textbox:text_set( "")
|
||||
textbox.text = ""
|
||||
exe_callback(command)
|
||||
return false
|
||||
elseif key == "Escape" then
|
||||
textbox:text_set("")
|
||||
textbox.text = ""
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
@ -716,7 +716,7 @@ function P.prompt(args, textbox, exe_callback, completion_callback)
|
|||
end
|
||||
|
||||
-- Update textbox
|
||||
textbox:text_set(prompt .. prompt_text_with_cursor(command, inv_col, cur_col, cur_pos))
|
||||
textbox.text = prompt .. prompt_text_with_cursor(command, inv_col, cur_col, cur_pos)
|
||||
|
||||
return true
|
||||
end)
|
||||
|
|
|
@ -94,49 +94,6 @@ textbox_destructor(widget_t *w)
|
|||
p_delete(&d);
|
||||
}
|
||||
|
||||
/** Set the text of a textbox.
|
||||
* \param L The Lua VM state.
|
||||
* \return The number of elements pushed on stack.
|
||||
* \luastack
|
||||
* \lvalue A widget.
|
||||
* \lparam The text to set.
|
||||
*/
|
||||
static int
|
||||
luaA_textbox_text_set(lua_State *L)
|
||||
{
|
||||
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
||||
const char *text = luaL_checkstring(L, 2);
|
||||
textbox_data_t *d = (*widget)->data;
|
||||
|
||||
p_delete(&d->text);
|
||||
a_iso2utf8(text, &d->text);
|
||||
|
||||
widget_invalidate_bywidget(*widget);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Set the width of a textbox.
|
||||
* \param L The Lua VM state.
|
||||
* \return The number of elements pushed on stack.
|
||||
* \luastack
|
||||
* \lvalue A widget.
|
||||
* \lparam The width to set.
|
||||
*/
|
||||
static int
|
||||
luaA_textbox_width_set(lua_State *L)
|
||||
{
|
||||
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
||||
int width = luaL_checknumber(L, 2);
|
||||
textbox_data_t *d = (*widget)->data;
|
||||
|
||||
d->width = width;
|
||||
|
||||
widget_invalidate_bywidget(*widget);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** The __index method for a textbox object.
|
||||
* \param L The Lua VM state.
|
||||
* \return The number of elements pushed on stack.
|
||||
|
@ -151,18 +108,17 @@ luaA_textbox_index(lua_State *L)
|
|||
|
||||
switch(a_tokenize(attr, len))
|
||||
{
|
||||
case A_TK_TEXT_SET:
|
||||
lua_pushcfunction(L, luaA_textbox_text_set);
|
||||
return 1;
|
||||
case A_TK_WIDTH_SET:
|
||||
lua_pushcfunction(L, luaA_textbox_width_set);
|
||||
return 1;
|
||||
case A_TK_TEXT:
|
||||
lua_pushstring(L, d->text);
|
||||
return 1;
|
||||
case A_TK_WIDTH:
|
||||
lua_pushnumber(L, d->width);
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
widget_invalidate_bywidget(*widget);
|
||||
}
|
||||
|
||||
/** The __newindex method for a textbox object.
|
||||
|
@ -174,23 +130,27 @@ luaA_textbox_newindex(lua_State *L)
|
|||
{
|
||||
size_t len;
|
||||
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
||||
const char *value, *attr = luaL_checklstring(L, 2, &len);
|
||||
const char *buf, *attr = luaL_checklstring(L, 2, &len);
|
||||
textbox_data_t *d = (*widget)->data;
|
||||
|
||||
switch(a_tokenize(attr, len))
|
||||
{
|
||||
case A_TK_TEXT:
|
||||
if((value = luaL_checkstring(L, 3)))
|
||||
if((buf = luaL_checkstring(L, 3)))
|
||||
{
|
||||
p_delete(&d->text);
|
||||
d->text = a_strdup(value);
|
||||
widget_invalidate_bywidget(*widget);
|
||||
a_iso2utf8(buf, &d->text);
|
||||
}
|
||||
break;
|
||||
case A_TK_WIDTH:
|
||||
d->width = luaL_checknumber(L, 3);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
widget_invalidate_bywidget(*widget);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -216,11 +176,4 @@ textbox_new(alignment_t align)
|
|||
return w;
|
||||
}
|
||||
|
||||
/* This is used for building documentation. */
|
||||
static const struct luaL_reg awesome_textbox_meta[] __attribute__ ((unused)) =
|
||||
{
|
||||
{ "text_set", luaA_textbox_text_set },
|
||||
{ "width_set", luaA_textbox_width_set }
|
||||
};
|
||||
|
||||
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
||||
|
|
Loading…
Reference in New Issue