Dynamic Menu Entries for Awesome WM
- Change icon on selection / unselection of a menu element (including root entries)
- Dynamic names and icons of submenu entries (i.e. NOT root entries). In other words, the
elements you see when you open the menu are still hardcoded. But the entries of submenus (
the menus that opens if you hover over an element) are re-generated on each hover.
- The posibility to add icons both left and right of the menu element
- Have different icons for the submenu indicator: if not selected, if selected but not expanded and if selected and expanded
- The posibility to have multiple, different submenu indicators for different menu elements
- This is described in the code example. Just start reading from the --example usage` comment.
- You will need to copy the whole file into your
rc.lua file. Make sure you remove the original variable mymainmenu.
- Tip: If you have the same logic for all icons (and you want to change the icon on selection), use a small helper function like this for arg3/4 for menu entries:
local function menuImage(imageName)
return function(isSelected)
local path = iconPath .. '/' .. imageName .. (isSelected and '_selected' or '') .. '.png'
return gears.surface.load(path)
end
end
- You proably also want to cache the icons, instead of creating new surfaces every time:
local menuImageCache = {}
local function menuImage(imageName)
return function(isSelected)
local path = iconPath .. '/' .. imageName .. (isSelected and '_selected' or '') .. '.png'
if not menuImageCache[path] then
menuImageCache[path] = gears.surface.load(path)
end
return menuImageCache[path]
end
end
- Tested with AwesomeWM Version 4.3.
- As this is using non-public APIs, ymmv with other versions