On Wed, May 11, 2011 at 12:01 AM, Zsolt Udvari <[email protected]> wrote:
>> That is definitely not true. Whatever function you use to generate
>> menus is called when the menu is opened.
> And if you've created a menu (e.g. "main menu"), and you will install
> an application and want insert into "main menu", how can do this? Is
> it possible? Or only a workaround: delete the "main menu" and
> re-create?
>
> Zsolt
>
Don't create a 'main menu'. Create a function that returns a 'main menu'

Then your f_main_menu() is called by your button that opens the menu.

I don't do this for applications, but the concept is similar for tags,
especially note how button 3 is used to call a function,
'menu_taglist'.


function tag_restore_defaults(t)
    local t_defaults = shifty.config.tags[t.name] or shifty.config.defaults

    for k, v in pairs(t_defaults) do
        awful.tag.setproperty(t, k, v)
    end
end

function menu_taglist(menu, t)
    if not menu then
        menu = {}
    end
    num_screens = screen.count()
    next_screen = nil
    prev_screen = nil

    menu.items = {}
    menu.items = {
        {(t.selected and "Hide") or "Merge", function()
            t.selected = not t.selected end},
        {"Rename", function() shifty.rename(t) end},
        {"Restore", function() tag_restore_defaults(t) end},
        {"Delete", function() shifty.del(t) end},
    }

    if num_screens > 1 then
        -- decide to show 'move next' only or also prev screen
        next_screen = awful.util.cycle(num_screens, t.screen + 1)
        table.insert(menu.items, 2, {"Move to screen " .. next_screen,
                function() tag_to_screen(t, next_screen) end})

        if num_screens > 2 then
            prev_screen = awful.util.cycle(num_screens, t.screen + 1)
            table.insert(menu.items, 3, {"Move to screen " .. prev_screen,
                    function() tag_to_screen(t, prev_screen) end})
        end
    end

    local m = awful.menu.new(menu)
    m:show()
    return m
end

widgets.taglist = {}
widgets.taglist.buttons = awful.util.table.join(
        awful.button({}, 1, awful.tag.viewonly),
        awful.button({settings.modkey}, 1, awful.client.movetotag),
        awful.button({}, 2, awful.tag.viewtoggle),
        awful.button({settings.modkey}, 3, awful.client.toggletag),
        awful.button({}, 3, function(t)
            if instance then instance:hide(); instance = nil
            else instance = menu_taglist({width = 165}, t) end
        end),
        awful.button({}, 4, awful.tag.viewnext),
        awful.button({}, 5, awful.tag.viewprev)
    )

-- 
To unsubscribe, send mail to [email protected].

Reply via email to