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.

79 lines
3.1 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. -- This file is part of Reno desktop.
  2. --
  3. -- 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.
  4. --
  5. -- 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.
  6. --
  7. -- You should have received a copy of the GNU General Public License along with Reno desktop. If not, see <https://www.gnu.org/licenses/>.
  8. -- XDG application menu for the global context menu
  9. local awmtk2 = require("awmtk2")
  10. local wibox = require("wibox")
  11. local gears = require("gears")
  12. local menugen = require("context_menu")
  13. local menuutils = require("menubar").utils
  14. local count = function(t)
  15. local n = 0
  16. for _,_ in pairs(t) do
  17. n = n + 1
  18. end
  19. return n
  20. end
  21. return function(args)
  22. local style = awmtk2.create_style("xdg_menu",
  23. awmtk2.generic.menu,args.style,args.vertical)
  24. local templates = awmtk2.create_template_lib("xdg_menu",awmtk2.templates,args.templates)
  25. local t = awmtk2.build_templates(templates,style,args.vertical)
  26. -- Add a "loading" indicator while XDG is still parsing data
  27. local widget = wibox.widget({
  28. t.container({
  29. markup = "Loading XDG menu...",
  30. widget = wibox.widget.textbox
  31. }),
  32. layout = wibox.layout.fixed.vertical,
  33. spacing = 0,
  34. id = "xdg_menu_root"
  35. })
  36. local function exclude(name)
  37. for _,v in pairs(args.exclude or {}) do
  38. if name:match(v) then
  39. return true
  40. end
  41. end
  42. return false
  43. end
  44. awesome.connect_signal("xdg::all_finished",function()
  45. local items = {}
  46. for k,v in pairs(xdg.categories) do
  47. local noprocess = false
  48. for _,v2 in pairs(args.exclude_category or {}) do
  49. if k == v2 then
  50. noprocess = true
  51. end
  52. end
  53. if (not noprocess) and (count(v.apps) > 0) then
  54. local category = {k,{},menuutils.lookup_icon_uncached(v.icon)}
  55. for _,item in pairs(v.apps) do
  56. if not exclude(item.name) then
  57. table.insert(category[2], {
  58. item.name,
  59. item.exec:gsub("%%%w","") or "",
  60. gears.filesystem.file_readable(item.icon or "") and item.icon
  61. })
  62. end
  63. end
  64. table.insert(items,category)
  65. end
  66. end
  67. -- uhhh there's a lot of things about async, some of which i can't explain
  68. local xdg_menu_root = widget:get_children_by_id("xdg_menu_root")[1]
  69. xdg_menu_root:reset()
  70. local menu = menugen({
  71. items = items,
  72. parent = args.menu_parent
  73. })
  74. xdg_menu_root:add(menu)
  75. end)
  76. return widget
  77. end