reno/widgets/xdgmenu.lua

79 lines
3.0 KiB
Lua
Raw Normal View History

2022-08-31 12:20:58 +00:00
-- This file is part of Reno desktop.
--
-- Reno desktop is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
--
-- Reno desktop is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License along with Reno desktop. If not, see <https://www.gnu.org/licenses/>.
-- XDG application menu for the global context menu
2022-08-25 15:27:31 +00:00
local awmtk2 = require("awmtk2")
local wibox = require("wibox")
local gears = require("gears")
local menugen = require("context_menu")
local menuutils = require("menubar").utils
2023-01-16 12:47:51 +00:00
local count = function(t)
local n = 0
for _,_ in pairs(t) do
n = n + 1
end
return n
end
2022-08-25 15:27:31 +00:00
return function(args)
2022-09-05 21:54:11 +00:00
local style = awmtk2.create_style("xdg_menu",
2023-01-19 13:42:20 +00:00
awmtk2.generic.menu,args.style,args.vertical)
2022-08-25 15:27:31 +00:00
local templates = awmtk2.create_template_lib("xdg_menu",awmtk2.templates,args.templates)
2023-01-16 12:47:51 +00:00
local t = awmtk2.build_templates(templates,style,args.vertical)
2022-08-25 15:27:31 +00:00
-- 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,
2023-01-19 13:42:20 +00:00
spacing = 0,
2022-08-25 15:27:31 +00:00
id = "xdg_menu_root"
})
local function exclude(name)
2023-01-16 12:47:51 +00:00
for _,v in pairs(args.exclude or {}) do
2022-08-25 15:27:31 +00:00
if name:match(v) then
return true
end
end
return false
end
awesome.connect_signal("xdg::all_finished",function()
local items = {}
for k,v in pairs(xdg.categories) do
local noprocess = false
2023-01-16 12:47:51 +00:00
for _,v2 in pairs(args.exclude_category or {}) do
2022-08-25 15:27:31 +00:00
if k == v2 then
noprocess = true
end
end
2023-01-16 12:47:51 +00:00
if (not noprocess) and (count(v.apps) > 0) then
2022-08-25 15:27:31 +00:00
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()
2023-03-04 11:25:35 +00:00
menugen({
2022-08-25 15:27:31 +00:00
items = items,
2023-03-04 11:25:35 +00:00
parent = args.menu_parent
})
2022-08-25 15:27:31 +00:00
end)
return widget
end