You are not logged in.

#1 2008-11-10 15:30:45

mccord
Member
Registered: 2008-10-12
Posts: 11

[Solved] awesome textbox + unescaped ampersand

hi
i seem to have a little problem with my awesome config:
whenever the tasklist (for example a website title) or my conkytextbox (mpd artist or title) contains an ampersand ('&') awesome throws the following error:

markup_parse:175: unable to parse text "..."
Error on line 1: Character '  ' is not valid at the start of an entity name:
the & character begins an entity; if this ampersand isnt supposed to be an entity, escape it as &amp

and the textboxes stay empty.

my question is what am i doing wrong or how could i escape the ampersands, that get fed into the textboxes?

i'm using awesome-git (updated today)
my rc.lua

-------------------------------------------------------------------------------------
--{{{ Imports

require("awful")
require("beautiful")

--}}}
-------------------------------------------------------------------------------------
--{{{ Initialize some constants

tags                = {}
statusbar           = {}
promptbox           = {}
layouticon          = {}
taglist             = {}
tasklist            = {}

--}}}
-------------------------------------------------------------------------------------
--{{{ Variables

modMask             = "Mod4"

term                = "SHELL=/bin/zsh urxvtc"
browser             = "firefox"
fileManager         = "thunar"

theme               = "default"

newBecomeMaster     = false
honorSizeHints      = false

layouts = { "tile"
                      , "tileleft"
                      , "tilebottom"
                      , "tiletop"
                      , "fairh"
                      , "fairv"
                      , "magnifier"
                      , "max"
                      , "floating"
                      }
            
layoutText = { ["tile"] = "Tiled"
                      , ["tileleft"] = "TileLeft"
                      , ["tilebottom"] = "TileBottom"
                      , ["tiletop"] = "TileTop"
                      , ["fairh"] = "FairH"
                      , ["fairv"] = "FairV"
                      , ["magnifier"] = "Magnifier"
                      , ["max"] = "Max"
                      , ["floating"] = "Floating"
                      }

floatApps           = {
    ["MPlayer"]     = true,
    ["Gimp"]        = true,
    --["pidgin"]    = true,
    ["Mirage"]      = true,
    ["smplayer"]  = true,
    ["tvtime"]    = true
                    }

themePath           = os.getenv("HOME").."/.config/awesome/themes/"..theme

--}}}
-------------------------------------------------------------------------------------
--{{{ Menu

awesomemenu       = {
   {"Edit config"   , term.." -e nano "..awful.util.getdir("config").."/rc.lua" },
   {"Restart"       , awesome.restart },
   {"Quit"          , awesome.quit }
                    }

mainmenu            = {
    { "terminal"     , term },
    { "firefox"       , browser },
    { "pcmanfm"      , fileManager },
    { "Awesome"     , awesomemenu }
                    }

--}}}
-------------------------------------------------------------------------------------
--{{{ Tags

for s = 1, screen.count() do
    tags[s] = {}
    tags[s][1] = tag({ name = "#", layout = layouts[1], mwfact = 0.618033988769 })
    tags[s][1].screen = s
    tags[s][2] = tag({ name = "www", layout = layouts[1], mwfact = 0.618033988769 })
    tags[s][2].screen = s
    tags[s][3] = tag({ name = "im", layout = layouts[1], mwfact = 0.618033988769 })
    tags[s][3].screen = s
    tags[s][4] = tag({ name = "files", layout = layouts[1], mwfact = 0.618033988769 })
    tags[s][4].screen = s
    tags[s][5] = tag({ name = "games", layout = "floating" })
    tags[s][5].screen = s
    for tagnumber = 6, 9 do
        tags[s][tagnumber] = tag({ name = tagnumber - 5, layout = layouts[1] })
        tags[s][tagnumber].screen = s
    end
    tags[s][1].selected = true
end

--}}}
-------------------------------------------------------------------------------------
--{{{ Markup

function setBg(color, text)
    return '<bg color="'..color..'" />'..text
end

function setFg(color, text)
    return '<span color="'..color..'">'..text..'</span>'
end

function setBgFg(bgcolor, fgcolor, text)
    return '<bg color="'..bgcolor..'" /><span color="'..fgcolor..'">'..text..'</span>'
end

function setFont(font, text)
    return '<span font_desc="'..font..'">'..text..'</span>'
end

--}}}
-------------------------------------------------------------------------------------
--{{{ Register some variables

beautiful.init(themePath)
awful.beautiful.register(beautiful)

--[[for i,v in pairs(startup) do
        awful.util.spawn(v)
    end
  ]]

--}}}
-------------------------------------------------------------------------------------
--{{{ Widgets

spacer = " "
spacertb = widget({ type = "textbox", name = "spacertb", align = "right" })
spacertb.text = " "

clockwidget = widget({ type = "textbox", name = "clockwidget", align = "right" })
function clockInfo(clockformat)
    clockwidget.text = spacer..os.date(clockformat)..spacer
end
conkywidget = widget({ type = "textbox", name = "conkywidget", align = "right" })

mysystray = widget({ type = "systray", name = "mysystray", align = "right" })

--~ launcher = awful.widget.launcher({ name = "launcher",
--~                                    image = os.getenv("HOME").."/.config/awesome/icons/launcher.png",
--~                                    menu = { id="mainmenu", items=mainmenu },
--~                                    align = "right" })

taglist.buttons     = { button({ }          , 1, awful.tag.viewonly),
                        button({ modMask }  , 1, awful.client.movetotag),
                        button({ }          , 3, function (tag) tag.selected = not tag.selected end),
                        button({ modMask }  , 3, awful.client.toggletag),
                        button({ }          , 4, awful.tag.viewnext),
                        button({ }          , 5, awful.tag.viewprev) }
tasklist.buttons    = { button({ }          , 1, function (c) client.focus = c; c:raise() end),
                        button({ }          , 4, function () awful.client.focus.byidx(1) end),
                        button({ }          , 5, function () awful.client.focus.byidx(-1) end) }

for s = 1, screen.count() do
    promptbox[s] = widget({ type = "textbox", name = "promptbox"..s, align = "left" })
    layouticon[s] = widget({ type = "textbox", name = "layouticon" })
    layouticon[s]:buttons({ button({ }      , 1, function () awful.layout.inc(layouts, 1) end),
                            button({ }      , 3, function () awful.layout.inc(layouts, -1) end),
                            button({ }      , 4, function () awful.layout.inc(layouts, 1) end),
                            button({ }      , 5, function () awful.layout.inc(layouts, -1) end) })
    taglist[s] = awful.widget.taglist.new(s, awful.widget.taglist.label.all, taglist.buttons)
    tasklist[s] = awful.widget.tasklist.new(function(c)
                                                if c == client.focus then 
                                                    return spacer..c.name..spacer
                                                end
                                            end, tasklist.buttons)
 
    statusbar[s] = wibox({
        position = "top", 
        height = "16", 
        name = "statusbar"..s, 
        fg = beautiful.fg_normal, 
        bg = beautiful.bg_normal, 
        -- border_color = beautiful.border_normal, 
        -- border_width = beautiful.border_width 
    })
    statusbar[s].widgets = ({
        taglist[s],
        layouticon[s],
        tasklist[s],
        promptbox[s],
    conkywidget,
        clockwidget,
    mysystray
    })
    statusbar[s].screen = s
end

--}}}
-------------------------------------------------------------------------------------
--{{{ Bindings

awesome.buttons({
    button({ }                      , 3         , function () awful.menu.new({ id = "mainmenu", items = mainmenu }) end),
    button({ }                      , 4         , awful.tag.viewnext),
    button({ }                      , 5         , awful.tag.viewprev)
})

keynumber = 9
for i = 1, keynumber do
    keybinding({ modMask }, "F"..i,                                                                             -- Swap to specified tag
    function ()
        local screen = mouse.screen
        if tags[screen][i] then
            awful.tag.viewonly(tags[screen][i])
        end
    end):add()
    keybinding({ modMask, "Control" }, "F"..i,                                                                  -- View an extra tag
    function ()
        local screen = mouse.screen
        if tags[screen][i] then
            tags[screen][i].selected = not tags[screen][i].selected
        end
    end):add()
    keybinding({ modMask, "Shift" }, "F"..i,                                                                    -- Swap focused client to specified tag
    function ()
        if client.focus then
            if tags[client.focus.screen][i] then
                awful.client.movetotag(tags[client.focus.screen][i])
            end
        end
    end):add()
end
keybinding({ modMask }              , "Left"    , awful.tag.viewprev):add()                                                         -- View next tag
keybinding({ modMask }              , "Right"   , awful.tag.viewnext):add()                                                         -- View previous tag
keybinding({ modMask }              , "x"       , function () awful.util.spawn(term) end):add()                                     -- Spawn term
keybinding({ modMask }              , "f"       , function () awful.util.spawn(browser) end):add()                                  -- Spawn browser
keybinding({ modMask }              , "t"       , function () awful.util.spawn(fileManager) end):add()                              -- Spawn filemanager
keybinding({ modMask, "Control" }   , "r"       , function () promptbox[mouse.screen].text = awful.util.escape(awful.util.restart()) end):add() -- Reload awesome
keybinding({ modMask, "Shift" }     , "q"       , awesome.quit):add()                                                               -- Exit awesome
keybinding({ modMask }              , "m"       , awful.client.maximize):add()                                                      -- Maximize the focused client
keybinding({ modMask }              , "c"       , function () client.focus:kill() end):add()                                        -- Kill the focused client
keybinding({ modMask }              , "j"       , function () awful.client.focus.byidx(1); client.focus:raise() end):add()          -- Focus next client
keybinding({ modMask }              , "k"       , function () awful.client.focus.byidx(-1);  client.focus:raise() end):add()        -- Focus previous client
keybinding({ modMask, "Control" }   , "space"   , awful.client.togglefloating):add()                                                -- Toggle current client floating
keybinding({ modMask, "Control" }   , "Return"  , function () client.focus:swap(awful.client.master()) end):add()                   -- Swap master client
keybinding({ modMask }              , "Tab"     , awful.client.focus.history.previous):add()                                        -- Tab through clients
keybinding({ modMask }              , "u"       , awful.client.urgent.jumpto):add()                                                 -- Jump to urgent client
keybinding({ modMask, "Shift" }     , "r"       , function () client.focus:redraw() end):add()                                      -- Redraw current client
keybinding({ modMask }              , "l"       , function () awful.tag.incmwfact(0.05) end):add()                                  -- Increase master width factor
keybinding({ modMask }              , "h"       , function () awful.tag.incmwfact(-0.05) end):add()                                 -- Decrease master width factor
keybinding({ modMask, "Shift" }     , "h"       , function () awful.tag.incnmaster(1) end):add()                                    -- Increase amount of master windows
keybinding({ modMask, "Shift" }     , "l"       , function () awful.tag.incnmaster(-1) end):add()                                   -- Decrease amount of master windows
keybinding({ modMask, "Control" }   , "h"       , function () awful.tag.incncol(1) end):add()                                       -- Increase amount of columns
keybinding({ modMask, "Control" }   , "l"       , function () awful.tag.incncol(-1) end):add()                                      -- Decrease amount of columns
keybinding({ modMask }              , "space"   , function () awful.layout.inc(layouts, 1) end):add()                               -- Change current layout
keybinding({ modMask, "Shift" }     , "space"   , function () awful.layout.inc(layouts, -1) end):add()                              -- Change current layout
keybinding({ modMask }              , "r"       , function () awful.prompt.run({ prompt = "Run: " }, promptbox[mouse.screen], awful.util.spawn, awful.completion.bash, os.getenv("HOME").."/.cache/awesome/history") end):add() -- Run the prompt
--keybinding({ }                      , "#160"    , function () awful.util.spawn("dvol -t") end):add()                                -- Toggle mute
--keybinding({ }                      , "#174"    , function () awful.util.spawn("dvol -d 2") end):add()                              -- Decrease volume
--keybinding({ }                      , "#176"    , function () awful.util.spawn("dvol -i 2") end):add()                              -- Increase volume
keybinding({ }                      , "#162"    , function () awful.util.spawn("mpc toggle") end):add()                             -- Toggle mpd
keybinding({ }                      , "#164"    , function () awful.util.spawn("mpc stop") end):add()                               -- Stop mpd
keybinding({ }                      , "#153"    , function () awful.util.spawn("mpc next") end):add()                               -- Next mpd song
keybinding({ }                      , "#144"    , function () awful.util.spawn("mpc prev") end):add()                               -- Previous mpd song
keybinding({ }                      , "#159"    , function () awful.util.spawn("urxvtc -e ncmpcpp") end):add()                      -- Spawn mpd client

--}}}
-------------------------------------------------------------------------------------
--{{{ Hooks

function hookFocus(c)
    if not awful.client.ismarked(c) then
        c.border_color = beautiful.border_focus
    end
end

function hookUnfocus(c)
    if not awful.client.ismarked(c) then
        c.border_color = beautiful.border_normal
    end
end

function hookMarked(c)
    c.border_color = beautiful.border_marked
end

function hookUnmarked(c)
    c.border_color = beautiful.border_focus
end

function hookMouseEnter(c)
    if awful.layout.get(c.screen) ~= "magnifier"
        and awful.client.focus.filter(c) then
        client.focus = c
    end
end

function hookManage(c) -- New client appears
    c:buttons({
        button({ }, 1, function (c) client.focus = c; c:raise() end),
        button({ modMask }, 1, function (c) c:mouse_move() end),
        button({ modMask }, 3, function (c) c:mouse_resize() end)
    })
    
    c.border_width = beautiful.border_width
    c.border_color = beautiful.border_normal
    client.focus = c

    local cls = c.class
    local inst = c.instance
    if floatApps[cls] then
        c.floating = floatApps[cls]
    elseif floatApps[inst] then
        c.floating = floatApps[inst]
    end
    
    if not newBecomeMaster then
        awful.client.setslave(c)
    end

    if honorSizeHints then
        c.honorsizehints = true
    else
    c.honorsizehints = false
    end
end

function hookArrange(screen) -- Tag switch etc
     local layout = awful.layout.get(screen)
    if layout then
        layouticon[screen].text = returnLayoutText(awful.layout.get(screen))
    else
        layouticon[screen].text = nil
    end
 
    if not client.focus then
        local c = awful.client.focus.history.get(screen, 0)
        if c then client.focus = c end
    end
end

function hookOneSecond()
    clockInfo("%d.%m.%Y %T")
end

function returnLayoutText(layout)
    return setFg(beautiful.fg_focus, " | ")..layoutText[layout]..setFg(beautiful.fg_focus, " | ")
end


awful.hooks.focus.register(hookFocus)
awful.hooks.unfocus.register(hookUnfocus)
awful.hooks.marked.register(hookMarked)
awful.hooks.unmarked.register(hookUnmarked)
awful.hooks.mouse_enter.register(hookMouseEnter)
awful.hooks.manage.register(hookManage)
awful.hooks.arrange.register(hookArrange)
awful.hooks.timer.register(1, hookOneSecond)


--}}}

my .conkyrc

update_interval 2.0
mpd_host localhost       #z.B.: localhost
mpd_port 6600       #Standard: 6600

TEXT
conkywidget.text = "playing: ${mpd_smart} | cpu: ${cpu}% | mem used: $mem | down: ${downspeed eth0}kb | up: ${upspeed eth0}kb | free: ${fs_free /home} |"

if you need more info let me know!
thanks in advance smile

Last edited by mccord (2008-11-10 18:31:18)

Offline

#2 2008-11-10 17:07:48

Gigamo
Member
Registered: 2008-01-19
Posts: 394

Re: [Solved] awesome textbox + unescaped ampersand

Probably better to report a bug (http://awesome.naquadah.org/bugs), seems like one to me.

Offline

#3 2008-11-10 18:09:49

mccord
Member
Registered: 2008-10-12
Posts: 11

Re: [Solved] awesome textbox + unescaped ampersand

ok thanks, i opened a bug report smile

edit: bug report was closed with a hint to awful.util.escape() tongue
using that function to escape the text now and everything works as it should!

Last edited by mccord (2008-11-10 18:36:51)

Offline

Board footer

Powered by FluxBB