On Wed, Nov 05, 2008 at 12:07:52PM +0100, Julien Danjou wrote:
> Hi,
> 
> I've added some compatibility code into awesome git version.
> This will allow to launch (almost) smoothly awesome 3.1, without having
> it dying at startup.
> 
> The only thing I can't fix for now is the statusbar/titlebar:widgets()
> which is now wibox.widget = {}.
> So the default awesome 3.0 configuration file runs out of the box with
> this little change:
> 
> statusbar[s]:widgets({ })
> to
> statusbar[s].widgets = { }
> 
> I said run, not works. It will run, but many things will not work, like
> mouse bindings, but well, explicit deprecation are printed at startup so
> you can (more) easily upgrade your configuration file to the new API.
> 
> If you are still running awesome 3.0, I'd like you to give it a try and
> report any fatal error you may encounter because of the API changes.

If you mean "users of 3.0, try to build awesome-git and see if it
works with your old config", then I did just that. I used the current
git d4bfaa859808e213cf2ec57f61475fbf1842c1dc. My old rc.lua is a
slightly tweaked default config.

So awesome-git started successfully with no modifications to the old
config at all, but obviously there was no statusbar and lots of
deprecation warnings.

Then I went forward and started copy-pasting pieces of the new default
config into my old one. I arrived at the attached config that still
doesn't work and I can't figure out why. There is no statusbar, but
right-clicking on the desktop does bring up awesome menu.

The warnings go like this:

W: awesome: luaA_dofunction:314: error running function: 
/home/solka/.config/awesome/rc.lua:400: attempt to index field '?' (a nil value)
W: awesome: luaA_dofunction:314: error running function: 
/home/solka/.config/awesome/rc.lua:432: attempt to index global 'mytextbox' (a 
number value)
W: awesome: luaA_dofunction:314: error running function: 
/home/solka/.config/awesome/rc.lua:432: attempt to index global 'mytextbox' (a 
number value)
W: awesome: luaA_dofunction:314: error running function: 
/home/solka/.config/awesome/rc.lua:432: attempt to index global 'mytextbox' (a 
number value)
W: awesome: luaA_dofunction:314: error running function: 
/home/solka/.config/awesome/rc.lua:400: attempt to index field '?' (a nil value)

but lines 400 and 432 look fine to me.

--
Sergey
-- awesome 3 configuration file

-- Include awesome library, with lots of useful function!
require("awful")
require("beautiful")

-- {{{ Variable definitions
-- This is a file path to a theme file which will defines colors.
-- theme_path = "/usr/local/share/awesome/themes/default"
theme_path = os.getenv("HOME") .. "/.config/awesome/themes/slk"

-- This is used later as the default terminal and editor to run.
terminal = "urxvt"
editor = os.getenv("EDITOR") or "nano"
editor_cmd = terminal .. " -e " .. editor

-- Default modkey.
-- Usually, Mod4 is the key with a logo between Control and Alt.
-- If you do not like this or do not have such a key,
-- I suggest you to remap Mod4 to another key using xmodmap or other tools.
-- However, you can use another modifier like Mod1, but it may interact with 
others.
-- modkey = "Mod4"
modkey = "Mod3"

-- Table of layouts to cover with awful.layout.inc, order matters.
layouts =
{
    "max",
    "tile",
    -- "tileleft",
    -- "tilebottom",
    -- "tiletop",
    "magnifier",
    -- "spiral",
    -- "dwindle",
    -- "floating"
}

-- Table of clients that should be set floating. The index may be either
-- the application class or instance. The instance is useful when running
-- a console app in a terminal like (Music on Console)
--    xterm -name mocp -e mocp
floatapps =
{
    -- by class
    ["MPlayer"] = true,
    ["pinentry"] = true,
    ["gimp"] = true,
    -- by instance
    ["mocp"] = true
}

-- Applications to be moved to a pre-defined tag by class or instance.
-- Use the screen and tags indices.
apptags =
{
    ["Firefox"] = { screen = 1, tag = 1 },
    ["Iceweasel"] = { screen = 1, tag = 1 },
    ["Emacs"] = { screen = 1, tag = 5 },
    ["Pidgin"] = { screen = screen.count(), tag = 9 },
    ["Stardict"] = { screen = screen.count(), tag = 9 },
    ["Quodlibet"] = { screen = screen.count(), tag = 8 },
    -- ["mocp"] = { screen = 2, tag = 4 },
}

-- Define if we want to use titlebar on all applications.
use_titlebar = false
-- }}}

-- {{{ Initialization
-- Initialize theme (colors).
beautiful.init(theme_path)

-- Register theme in awful.
-- This allows to not pass plenty of arguments to each function
-- to inform it about colors we want it to draw.
awful.beautiful.register(beautiful)

-- {{{ Tags
-- Define tags table.
tags = {}
for s = 1, screen.count() do
    -- Each screen has its own tag table.
    tags[s] = {}
    -- Create 9 tags per screen.
    for tagnumber = 1, 9 do
        tags[s][tagnumber] = tag({ name = tagnumber, layout = layouts[1] })
        -- Add tags to screen one by one
        tags[s][tagnumber].screen = s
    end
    -- I'm sure you want to see at least one tag.
    tags[s][1].selected = true
end
-- }}}

-- Set tile layout for the 9th tag on the rightemost screen
tags[screen.count()][9].layout = "tile"
tags[screen.count()][9].mwfact = 0.7

-- {{{ Statusbar
-- Create a textbox widget
mytextbox = widget({ type = "textbox", align = "right" })
-- Set the default text in textbox
mytextbox.text = "<b><small> awesome " .. AWESOME_RELEASE .. " </small></b>"

-- Create a laucher widget and a main menu
myawesomemenu = {
   { "manual", terminal .. " -e man awesome" },
   { "edit config", editor_cmd .. " " .. awful.util.getdir("config") .. 
"/rc.lua" },
   { "restart", awesome.restart },
   { "quit", awesome.quit }
}

mymainmenu = {
   { "awesome", myawesomemenu, "/usr/local/share/awesome/icons/awesome16.png" },
   { "open terminal", terminal }
}

mylauncher = awful.widget.launcher({ image = 
"/usr/local/share/awesome/icons/awesome16.png",
                                     menu = { id="mymainmenu", 
items=mymainmenu, menu_toggle=true } })

-- Create a systray
mysystray = widget({ type = "systray", align = "right" })

-- Create a statusbar for each screen and add it
mywibox = {}
mypromptbox = {}
mylayoutbox = {}
mytaglist = {}
mytaglist.buttons = { button({ }, 1, awful.tag.viewonly),
                      button({ modkey }, 1, awful.client.movetotag),
                      button({ }, 3, function (tag) tag.selected = not 
tag.selected end),
                      button({ modkey }, 3, awful.client.toggletag),
                      button({ }, 4, awful.tag.viewnext),
                      button({ }, 5, awful.tag.viewprev) }
mytasklist = {}
mytasklist.buttons = { button({ }, 1, function (c) client.focus = c; c:raise() 
end),
                       button({ }, 3, function () awful.menu.clients({ 
width=250 }) 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

    -- Create a promptbox for each screen
    mypromptbox[s] = widget({ type = "textbox", 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 = "left" })
    mylayoutbox[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) })
    -- Create a taglist widget
    mytaglist[s] = awful.widget.taglist.new(s, awful.widget.taglist.label.all, 
mytaglist.buttons)

    -- Create a tasklist widget
    mytasklist[s] = awful.widget.tasklist.new(function(c)
                                                  return 
awful.widget.tasklist.label.currenttags(c, s)
                                              end, mytasklist.buttons)

    -- Create the wibox
    mywibox[s] = wibox({ position = "top", fg = beautiful.fg_normal, bg = 
beautiful.bg_normal })
    -- Add widgets to the wibox - order matters
    mywibox[s].widgets = { mylauncher,
                           mytaglist[s],
                           mytasklist[s],
                           mypromptbox[s],
                           s == screen.count() and mysystray or nil }
                           mytextbox,
                           mylayoutbox[s],
    mywibox[s].screen = s
end
-- }}}

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

-- {{{ Key bindings

-- Bind keyboard digits
-- Compute the maximum number of digit we need, limited to 9
keynumber = 0
for s = 1, screen.count() do
   keynumber = math.min(9, math.max(#tags[s], keynumber));
end

for i = 1, keynumber do
    keybinding({ modkey }, i,
                   function ()
                       local screen = mouse.screen
                       if tags[screen][i] then
                           awful.tag.viewonly(tags[screen][i])
                       end
                   end):add()
    keybinding({ modkey, "Control" }, i,
                   function ()
                       local screen = mouse.screen
                       if tags[screen][i] then
                           tags[screen][i].selected = not 
tags[screen][i].selected
                       end
                   end):add()
    keybinding({ modkey, "Shift" }, i,
                   function ()
                       local sel = client.focus
                       if sel then
                           if tags[sel.screen][i] then
                               awful.client.movetotag(tags[sel.screen][i])
                           end
                       end
                   end):add()
    keybinding({ modkey, "Control", "Shift" }, i,
                   function ()
                       local sel = client.focus
                       if sel then
                           if tags[sel.screen][i] then
                               awful.client.toggletag(tags[sel.screen][i])
                           end
                       end
                   end):add()
end

keybinding({ modkey }, "Left", awful.tag.viewprev):add()
keybinding({ modkey }, "Right", awful.tag.viewnext):add()
keybinding({ modkey }, "Escape", awful.tag.history.restore):add()

-- Standard program
keybinding({ modkey }, "t", function () awful.spawn(terminal) end):add()
keybinding({ modkey }, "space", function () awful.spawn("quodlibet 
--play-pause") end):add()
keybinding({ modkey }, "F1", function () awful.spawn("eee2ram.sh") end):add()
keybinding({ modkey }, "F3", function () awful.spawn("quodlibet --previous") 
end):add()
keybinding({ modkey }, "F4", function () awful.spawn("quodlibet --next") 
end):add()
keybinding({ modkey }, "F5", function () awful.spawn("xrandr-eee.py auto") 
end):add()
toggle_mute_cmd = "amixer get LineOut | grep off && amixer set LineOut unmute 
|| amixer set LineOut mute"
keybinding({ modkey }, "F7", function () awful.spawn(toggle_mute_cmd) end):add()
keybinding({ modkey }, "F8", function () awful.spawn("amixer set PCM 2dB-") 
end):add()
keybinding({ modkey }, "F9", function () awful.spawn("amixer set PCM 2dB+") 
end):add()
keybinding({ modkey }, "F12", function () awful.spawn('xlock') end):add()

keybinding({ modkey, "Control" }, "r", awesome.restart):add()
keybinding({ modkey, "Shift" }, "q", awesome.quit):add()

-- Client manipulation
keybinding({ modkey }, "m", awful.client.maximize):add()
-- keybinding({ modkey, "Shift" }, "c", function () client.focus:kill() 
end):add()
keybinding({ modkey }, "c", function () client.focus:kill() end):add()
keybinding({ modkey }, "j", function () awful.client.focusbyidx(1); 
client.focus:raise() end):add()
keybinding({ modkey }, "k", function () awful.client.focusbyidx(-1);  
client.focus:raise() end):add()
keybinding({ modkey, "Shift" }, "j", function () awful.client.swap(1) end):add()
keybinding({ modkey, "Shift" }, "k", function () awful.client.swap(-1) 
end):add()
keybinding({ modkey, "Control" }, "j", function () awful.screen.focus(1) 
end):add()
keybinding({ modkey, "Control" }, "k", function () awful.screen.focus(-1) 
end):add()
keybinding({ modkey, "Control" }, "space", awful.client.togglefloating):add()
keybinding({ modkey, "Control" }, "Return", function () 
client.focus:swap(awful.client.master()) end):add()
keybinding({ modkey }, "o", awful.client.movetoscreen):add()
keybinding({ modkey }, "Tab", awful.client.focus.history.previous):add()
keybinding({ modkey }, "u", awful.client.urgent.jumpto):add()
keybinding({ modkey, "Shift" }, "r", function () client.focus:redraw() 
end):add()

-- Layout manipulation
keybinding({ modkey }, "l", function () awful.tag.incmwfact(0.05) end):add()
keybinding({ modkey }, "h", function () awful.tag.incmwfact(-0.05) end):add()
keybinding({ modkey, "Shift" }, "h", function () awful.tag.incnmaster(1) 
end):add()
keybinding({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) 
end):add()
keybinding({ modkey, "Control" }, "h", function () awful.tag.incncol(1) 
end):add()
keybinding({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) 
end):add()
-- keybinding({ modkey }, "space", function () awful.layout.inc(layouts, 1) 
end):add()
-- keybinding({ modkey, "Shift" }, "space", function () 
awful.layout.inc(layouts, -1) end):add()
keybinding({ modkey }, "v", function () awful.layout.inc(layouts, 1) end):add()
keybinding({ modkey, "Shift" }, "v", function () awful.layout.inc(layouts, -1) 
end):add()

-- Prompt
-- keybinding({ modkey }, "F1", function ()
keybinding({ modkey }, "p", function ()
                               awful.prompt.run({ prompt = "Run: " }, 
mypromptbox[mouse.screen], awful.util.spawn, awful.completion.bash,
os.getenv("HOME") .. "/.cache/awesome/history") end):add()
keybinding({ modkey }, "F10", function ()
                                 awful.prompt.run({ prompt = "Run Lua code: " 
}, mypromptbox[mouse.screen], awful.util.eval, awful.prompt.bash,
os.getenv("HOME") .. "/.cache/awesome/history_eval") end):add()
keybinding({ modkey, "Ctrl" }, "i", function ()
                                        local s = mouse.screen
                                        if mypromptbox[s].text then
                                            mypromptbox[s].text = nil
                                        else
                                            mypromptbox[s].text = nil
                                            if client.focus.class then
                                                mypromptbox[s].text = "Class: " 
.. client.focus.class .. " "
                                            end
                                            if client.focus.instance then
                                                mypromptbox[s].text = 
mypromptbox[s].text .. "Instance: ".. client.focus.instance .. " "
                                            end
                                            if client.focus.role then
                                                mypromptbox[s].text = 
mypromptbox[s].text .. "Role: ".. client.focus.role
                                            end
                                        end
                                    end):add()

-- Client awful tagging: this is useful to tag some clients and then do stuff 
like move to tag on them
keybinding({ modkey }, "Return", awful.client.togglemarked):add()

for i = 1, keynumber do
    keybinding({ modkey, "Shift" }, "F" .. i,
                   function ()
                       local screen = mouse.screen
                       if tags[screen][i] then
                           for k, c in pairs(awful.client.getmarked()) do
                               awful.client.movetotag(tags[screen][i], c)
                           end
                       end
                   end):add()
end
-- }}}

-- {{{ Hooks
-- Hook function to execute when focusing a client.
function hook_focus(c)
    if not awful.client.ismarked(c) then
        c.border_color = beautiful.border_focus
    end
end

-- Hook function to execute when unfocusing a client.
function hook_unfocus(c)
    if not awful.client.ismarked(c) then
        c.border_color = beautiful.border_normal
    end
end

-- Hook function to execute when marking a client
function hook_marked(c)
    c.border_color = beautiful.border_marked
end

-- Hook function to execute when unmarking a client
function hook_unmarked(c)
    c.border_color = beautiful.border_focus
end

-- Hook function to execute when the mouse is over a client.
function hook_mouse_enter(c)
    -- Sloppy focus, but disabled for magnifier layout
    if awful.layout.get(c.screen) ~= "magnifier"
        and awful.client.focus.filter(c) then
        client.focus = c
    end
end

-- Hook function to execute when a new client appears.
function hook_mane(c)
    if use_titlebar then
        -- Add a titlebar
        awful.titlebar.add(c, { modkey = modkey })
    end
    -- Add mouse bindings
    c:buttons({
        button({ }, 1, function (c) client.focus = c; c:raise() end),
        button({ modkey }, 1, function (c) c:mouse_move() end),
        button({ modkey }, 3, function (c) c:mouse_resize() end)
    })
    -- New client may not receive focus
    -- if they're not focusable, so set border anyway.
    c.border_width = beautiful.border_width
    c.border_color = beautiful.border_normal
    client.focus = c

    -- Check if the application should be floating.
    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

    -- Check application->screen/tag mappings.
    local target
    if apptags[cls] then
        target = apptags[cls]
    elseif apptags[inst] then
        target = apptags[inst]
    end
    if target then
        c.screen = target.screen
        awful.client.movetotag(tags[target.screen][target.tag], c)
    end

    -- Honor size hints
    c.honorsizehints = false
end

-- Hook function to execute when arranging the screen
-- (tag switch, new client, etc)
function hook_arrange(screen)
    local layout = awful.layout.get(screen)
    if layout then
        mylayoutbox[screen].image = 
image("/usr/local/share/awesome/icons/layouts/" .. layout .. "w.png")
    else
        mylayoutbox[screen].image = nil
    end

    -- If no window has focus, give focus to the latest in history
    if not client.focus then
        local c = awful.client.focus.history.get(screen, 0)
        if c then client.focus = c end
    end

    -- Uncomment if you want mouse warping
    --[[
    if client.focus then
        local c_c = client.focus:fullgeometry()
        local m_c = mouse.coords()

        if m_c.x < c_c.x or m_c.x >= c_c.x + c_c.width or
            m_c.y < c_c.y or m_c.y >= c_c.y + c_c.height then
            if table.maxn(m_c.buttons) == 0 then
                mouse.coords({ x = c_c.x + 5, y = c_c.y + 5})
            end
        end
    end
    ]]
end

-- Hook called every second
function hook_timer ()
    -- For unix time_t lovers
    -- mytextbox.text = " " .. os.time() .. " time_t "
    -- Otherwise use:
    mytextbox.text = " " .. os.date() .. " "
end

-- Set up some hooks
awful.hooks.focus.register(hook_focus)
awful.hooks.unfocus.register(hook_unfocus)
awful.hooks.marked.register(hook_marked)
awful.hooks.unmarked.register(hook_unmarked)
awful.hooks.manage.register(hook_manage)
awful.hooks.mouse_enter.register(hook_mouse_enter)
awful.hooks.arrange.register(hook_arrange)
awful.hooks.timer.register(1, hook_timer)
-- }}}


-- Create a list of keybindings to be added when mod-u is pressed 
keybind_mod_u = {} 
 
function keychain_mod_u_add() 
    for k, v in pairs(keybind_mod_u) do 
        v:add() 
    end 
end 

function keychain_mod_u_remove() 
    for k, v in pairs(keybind_mod_u) do 
        v:remove() 
    end
end

mod_u_commands = {q = "quodlibet",
                  m = terminal .. " -e mutt",
                  a = "xterm -e alpine",
                  e = "emacs",
                  p = "pidgin",
                  f = "firefox",
                  d = terminal .. " -e sudo aptitude",
                  v = "vagalume",
                  i = "icedove",
                  s = "stardict",
                  y = terminal .. " -e ipython"}

for key, cmd in pairs(mod_u_commands) do
   table.insert(keybind_mod_u, 
                keybinding({}, key, function () 
                                       awful.spawn(cmd)
                                       keychain_mod_u_remove()
                                    end))
end

-- This is an example keybinding with an additional modifier
table.insert(keybind_mod_u, keybinding({ "Mod4" }, "b", function () 
    mytextbox.text = "You pressed Mod4 + b!"
    keychain_mod_u_remove()
end)) 

-- Escape key cancels
table.insert(keybind_mod_u, keybinding({}, "Escape", keychain_mod_u_remove)) 

keybinding({ modkey }, "u", keychain_mod_u_add):add()

Reply via email to