Reno is the second iteration of the AWMTK-powered AwesomeWM config.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

99 lines
3.6 KiB

-- Generic application menu
local awmtk2 = require("awmtk2")
local wibox = require("wibox")
local gears = require("gears")
local awful = require("awful")
local beautiful = require("beautiful")
local menugen = require("context_menu")
local menuutils = require("menubar").utils
return function(args)
local style = awmtk2.create_style("xdg_menu",awmtk2.default,args.style)
local templates = awmtk2.create_template_lib("xdg_menu",awmtk2.templates,args.templates)
local t = awmtk2.build_templates(templates,style)
-- Add a "loading" indicator while XDG is still parsing data
local widget = wibox.widget({
t.container({
markup = "Loading XDG menu...",
widget = wibox.widget.textbox
}),
layout = wibox.layout.fixed.vertical,
id = "xdg_menu_root"
})
local function exclude(name)
for k,v in pairs(args.exclude or {}) do
if name:match(v) then
return true
end
end
return false
end
awesome.connect_signal("xdg::all_finished",function()
if not args.parent then return end
local items = {}
for k,v in pairs(xdg.categories) do
local noprocess = false
for k2,v2 in pairs(args.exclude_category or {}) do
if k == v2 then
noprocess = true
end
end
if (not noprocess) and (#v.apps > 0) then
local category = {k,{},menuutils.lookup_icon_uncached(v.icon)}
for _,item in pairs(v.apps) do
if not exclude(item.name) then
table.insert(category[2], {
item.name,
item.exec:gsub("%%%w","") or "",
gears.filesystem.file_readable(item.icon or "") and item.icon
})
end
end
table.insert(items,category)
end
end
-- uhhh there's a lot of things about async, some of which i can't explain
local xdg_menu_root = widget:get_children_by_id("xdg_menu_root")[1]
xdg_menu_root:reset()
local menu = wibox.widget(menugen({
items = items,
}))
local menu_root = menu:get_children_by_id("menu_root")[1]
for k,v in pairs(menu_root.children) do
v:connect_signal("cascade::kill",function()
args.parent.visible = false
end)
args.parent:connect_signal("property::visible",function()
if not args.parent.visible then
v:emit_signal("cascade::close")
end
end)
menu:connect_signal("widget::redraw_needed",function()
if not menu.visible then
v:emit_signal("cascade::close")
end
end)
end
local appswitch = wibox.widget(t.button(t.textbox({
markup = "Applications",
id = "apptext"
})))
appswitch:connect_signal("button::press",function(self)
menu.visible = (not menu.visible)
local textbox = appswitch:get_children_by_id("apptext")[1]
if menu.visible then
style.button.onpress(self)
textbox:set_markup("<b>Applications</b>")
else
style.button.onrelease(self)
textbox:set_markup("Applications")
end
end)
menu.visible = false
xdg_menu_root:add(appswitch)
xdg_menu_root:add(menu)
end)
return widget
end