widgets: remove name property

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-11-12 11:48:51 +01:00
parent 506e453a2f
commit 4fcf48e247
6 changed files with 25 additions and 52 deletions

View File

@ -48,7 +48,7 @@ function add(c, args)
local tb = capi.wibox(args) local tb = capi.wibox(args)
local title = capi.widget({ type = "textbox", name = "title", align = "flex" }) local title = capi.widget({ type = "textbox", align = "flex" })
title.text = " " .. util.escape(c.name) .. " " title.text = " " .. util.escape(c.name) .. " "
-- Redirect relevant events to the client the titlebar belongs to -- Redirect relevant events to the client the titlebar belongs to
@ -61,7 +61,7 @@ function add(c, args)
title:buttons(bts) title:buttons(bts)
function title.mouse_enter(s) hooks.user.call('mouse_enter', c) end function title.mouse_enter(s) hooks.user.call('mouse_enter', c) end
local appicon = capi.widget({ type = "imagebox", name = "appicon", align = "left" }) local appicon = capi.widget({ type = "imagebox", align = "left" })
appicon.image = c.icon appicon.image = c.icon
-- Also redirect events for appicon (So the entire titlebar behaves consistently) -- Also redirect events for appicon (So the entire titlebar behaves consistently)
@ -70,13 +70,13 @@ function add(c, args)
local closef local closef
if theme.titlebar_close_button_focus then if theme.titlebar_close_button_focus then
closef = widget.button({ name = "closef", align = "right", closef = widget.button({ align = "right",
image = theme.titlebar_close_button_focus }) image = theme.titlebar_close_button_focus })
end end
local close local close
if theme.titlebar_close_button_normal then if theme.titlebar_close_button_normal then
close = widget.button({ name = "close", align = "right", close = widget.button({ align = "right",
image = theme.titlebar_close_button_normal }) image = theme.titlebar_close_button_normal })
end end
@ -107,7 +107,8 @@ function add(c, args)
end end
end end
tb.widgets = { appicon, title, closef, close } tb.widgets = { appicon = appicon, title = title,
closef = closef, close = close }
c.titlebar = tb c.titlebar = tb
@ -121,21 +122,13 @@ end
function update(c, prop) function update(c, prop)
if c.titlebar and data[c] then if c.titlebar and data[c] then
local widgets = c.titlebar.widgets local widgets = c.titlebar.widgets
local title, close, closef
for k, v in pairs(widgets) do
if v.name == "title" then title = v
elseif v.name == "close" then close = v
elseif v.name == "closef" then closef = v
elseif v.name == "appicon" then appicon = v end
if title and close and closef and appicon then break end
end
if prop == "name" then if prop == "name" then
if title then if widgets.title then
title.text = " " .. util.escape(c.name) .. " " widgets.title.text = " " .. util.escape(c.name) .. " "
end end
elseif prop == "icon" then elseif prop == "icon" then
if appicon then if widgets.appicon then
appicon.image = c.icon widgets.appicon.image = c.icon
end end
elseif prop == "geometry" then elseif prop == "geometry" then
if data[c].width then if data[c].width then
@ -152,13 +145,13 @@ function update(c, prop)
if capi.client.focus == c then if capi.client.focus == c then
c.titlebar.fg = data[c].fg_focus c.titlebar.fg = data[c].fg_focus
c.titlebar.bg = data[c].bg_focus c.titlebar.bg = data[c].bg_focus
if closef then closef.visible = true end if widgets.closef then widgets.closef.visible = true end
if close then close.visible = false end if widgets.close then widgets.close.visible = false end
else else
c.titlebar.fg = data[c].fg c.titlebar.fg = data[c].fg
c.titlebar.bg = data[c].bg c.titlebar.bg = data[c].bg
if closef then closef.visible = false end if widgets.closef then widgets.closef.visible = false end
if close then close.visible = true end if widgets.close then widgets.close.visible = true end
end end
end end
end end

View File

@ -40,7 +40,7 @@ local function taglist_update (screen, w, label, buttons, data)
-- Add more widgets -- Add more widgets
if len < #tags then if len < #tags then
for i = len + 1, #tags do for i = len + 1, #tags do
w[i] = capi.widget({ type = "textbox", name = "taglist" .. i }) w[i] = capi.widget({ type = "textbox" })
end end
-- Remove widgets -- Remove widgets
elseif len > #tags then elseif len > #tags then
@ -189,8 +189,8 @@ local function tasklist_update(w, buttons, label, data)
-- Add more widgets -- Add more widgets
if len < #clients then if len < #clients then
for i = len * 2 + 1, #clients * 2, 2 do for i = len * 2 + 1, #clients * 2, 2 do
w[i] = capi.widget({ type = "imagebox", name = "tasklist_icon" .. i, align = "flex" }) w[i] = capi.widget({ type = "imagebox", align = "flex" })
w[i + 1] = capi.widget({ type = "textbox", name = "tasklist_text" .. i, align = "flex" }) w[i + 1] = capi.widget({ type = "textbox", align = "flex" })
end end
-- Remove widgets -- Remove widgets
elseif len > #clients then elseif len > #clients then

View File

@ -69,7 +69,7 @@ function player.new ()
y = gamedata.field.y + gamedata.field.h - (16 + 5) }) y = gamedata.field.y + gamedata.field.h - (16 + 5) })
p.screen = 1 p.screen = 1
w = widget({ type = "imagebox", name = "player" }) w = widget({ type = "imagebox" })
w.image = image("@AWESOME_ICON_PATH@/invaders/player.png") w.image = image("@AWESOME_ICON_PATH@/invaders/player.png")
p.widgets = w p.widgets = w
@ -180,8 +180,7 @@ function enemies.new (t)
x = gamedata.field.x, x = gamedata.field.x,
y = gamedata.field.y }) y = gamedata.field.y })
e.screen = 1 e.screen = 1
w = widget({ type = "imagebox", w = widget({ type = "imagebox" })
name = "enemy"..t })
w.image = gamedata.enemies[t] w.image = gamedata.enemies[t]
e.widgets = w e.widgets = w
@ -385,8 +384,7 @@ function game.highscore_show ()
y = gamedata.field.y + math.floor(gamedata.field.h / 2) - 55 }) y = gamedata.field.y + math.floor(gamedata.field.h / 2) - 55 })
gamedata.highscore.window.screen = 1 gamedata.highscore.window.screen = 1
gamedata.highscore.table = widget({ type = "textbox", gamedata.highscore.table = widget({ type = "textbox" })
name = "highscore" })
gamedata.highscore.window.widgets = gamedata.highscore.table gamedata.highscore.window.widgets = gamedata.highscore.table
gamedata.highscore.table.text = " Highscores:\n" gamedata.highscore.table.text = " Highscores:\n"
@ -453,8 +451,7 @@ function game.highscore (score)
y = gamedata.field.y + math.floor(gamedata.field.h / 2) }) y = gamedata.field.y + math.floor(gamedata.field.h / 2) })
gamedata.highscore.window.screen = 1 gamedata.highscore.window.screen = 1
gamedata.namebox = widget({ type = "textbox", gamedata.namebox = widget({ type = "textbox" })
name = "foobar" })
gamedata.namebox.text = " Name: |" gamedata.namebox.text = " Name: |"
gamedata.highscore.window.widgets = gamedata.namebox gamedata.highscore.window.widgets = gamedata.namebox
@ -511,12 +508,10 @@ function run(args)
gamedata.field.north.screen = 1 gamedata.field.north.screen = 1
gamedata.field.status = widget({ type = "textbox", gamedata.field.status = widget({ type = "textbox",
name = "status",
align = "right" }) align = "right" })
gamedata.field.status.text = gamedata.score.." | "..gamedata.round .. " " gamedata.field.status.text = gamedata.score.." | "..gamedata.round .. " "
gamedata.field.caption = widget({ type = "textbox", gamedata.field.caption = widget({ type = "textbox",
name = "caption",
align = "left" }) align = "left" })
gamedata.field.caption.text = " Awesome Invaders" gamedata.field.caption.text = " Awesome Invaders"

View File

@ -200,7 +200,7 @@ function notify(args)
end end
-- create textbox -- create textbox
local textbox = widget({ type = "textbox", name = "text", align = "flex" }) local textbox = widget({ type = "textbox", align = "flex" })
textbox:buttons({ button({ }, 1, run), textbox:buttons({ button({ }, 1, run),
button({ }, 3, die) }) button({ }, 3, die) })
textbox.text = string.format('<margin right="'..config.margin..'" left="'..config.margin..'"/><span font_desc="%s"><b>%s</b>%s</span>', font, title, text) textbox.text = string.format('<margin right="'..config.margin..'" left="'..config.margin..'"/><span font_desc="%s"><b>%s</b>%s</span>', font, title, text)
@ -209,7 +209,7 @@ function notify(args)
-- create iconbox -- create iconbox
local iconbox = nil local iconbox = nil
if icon then if icon then
iconbox = widget({ type = "imagebox", name = "icon", align = "left" }) iconbox = widget({ type = "imagebox", align = "left" })
iconbox:buttons({ button({ }, 1, run), iconbox:buttons({ button({ }, 1, run),
button({ }, 3, die) }) button({ }, 3, die) })
local img = image(icon) local img = image(icon)
@ -222,8 +222,7 @@ function notify(args)
end end
-- create container wibox -- create container wibox
notification.box = wibox({ name = "not" .. notification.idx, notification.box = wibox({ position = "floating",
position = "floating",
fg = fg, fg = fg,
bg = bg, bg = bg,
border_color = config.border_color, border_color = config.border_color,

View File

@ -105,8 +105,6 @@ struct widget_t
{ {
/** Ref count */ /** Ref count */
int refcount; int refcount;
/** widget_t name */
char *name;
/** Widget type is constructor */ /** Widget type is constructor */
widget_constructor_t *type; widget_constructor_t *type;
/** Widget destructor */ /** Widget destructor */

View File

@ -48,7 +48,6 @@ widget_delete(widget_t **widget)
button_array_wipe(&(*widget)->buttons); button_array_wipe(&(*widget)->buttons);
luaL_unref(globalconf.L, LUA_REGISTRYINDEX, (*widget)->mouse_enter); luaL_unref(globalconf.L, LUA_REGISTRYINDEX, (*widget)->mouse_enter);
luaL_unref(globalconf.L, LUA_REGISTRYINDEX, (*widget)->mouse_leave); luaL_unref(globalconf.L, LUA_REGISTRYINDEX, (*widget)->mouse_leave);
p_delete(&(*widget)->name);
p_delete(widget); p_delete(widget);
} }
@ -365,7 +364,7 @@ widget_invalidate_bywidget(widget_t *widget)
* \param L The Lua VM state. * \param L The Lua VM state.
* *
* \luastack * \luastack
* \lparam A table with at least a name and a type value. Optional attributes * \lparam A table with at least a type value. Optional attributes
* are: align. * are: align.
* \lreturn A brand new widget. * \lreturn A brand new widget.
*/ */
@ -383,8 +382,6 @@ luaA_widget_new(lua_State *L)
buf = luaA_getopt_lstring(L, 2, "align", "left", &len); buf = luaA_getopt_lstring(L, 2, "align", "left", &len);
align = draw_align_fromstr(buf, len); align = draw_align_fromstr(buf, len);
buf = luaA_getopt_string(L, 2, "name", NULL);
type = luaA_getopt_string(L, 2, "type", NULL); type = luaA_getopt_string(L, 2, "type", NULL);
if((wc = name_func_lookup(type, WidgetList))) if((wc = name_func_lookup(type, WidgetList)))
@ -402,8 +399,6 @@ luaA_widget_new(lua_State *L)
w->mouse_enter = w->mouse_leave = LUA_REFNIL; w->mouse_enter = w->mouse_leave = LUA_REFNIL;
w->name = a_strdup(buf);
return luaA_widget_userdata_new(L, w); return luaA_widget_userdata_new(L, w);
} }
@ -435,7 +430,6 @@ luaA_widget_buttons(lua_State *L)
* \return The number of elements pushed on stack. * \return The number of elements pushed on stack.
* \luastack * \luastack
* \lfield visible The widget visibility. * \lfield visible The widget visibility.
* \lfield name The widget name.
* \lfield mouse_enter A function to execute when the mouse enter the widget. * \lfield mouse_enter A function to execute when the mouse enter the widget.
* \lfield mouse_leave A function to execute when the mouse leave the widget. * \lfield mouse_leave A function to execute when the mouse leave the widget.
*/ */
@ -455,12 +449,6 @@ luaA_widget_index(lua_State *L)
case A_TK_VISIBLE: case A_TK_VISIBLE:
lua_pushboolean(L, (*widget)->isvisible); lua_pushboolean(L, (*widget)->isvisible);
return 1; return 1;
case A_TK_NAME:
if((*widget)->name)
lua_pushstring(L, (*widget)->name);
else
lua_pushnil(L);
return 1;
case A_TK_MOUSE_ENTER: case A_TK_MOUSE_ENTER:
if((*widget)->mouse_enter != LUA_REFNIL) if((*widget)->mouse_enter != LUA_REFNIL)
lua_rawgeti(L, LUA_REGISTRYINDEX, (*widget)->mouse_enter); lua_rawgeti(L, LUA_REGISTRYINDEX, (*widget)->mouse_enter);