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

2 years ago
  1. -- Generic application menu
  2. local awmtk2 = require("awmtk2")
  3. local wibox = require("wibox")
  4. local gears = require("gears")
  5. local awful = require("awful")
  6. local beautiful = require("beautiful")
  7. local menugen = require("context_menu")
  8. local menuutils = require("menubar").utils
  9. return function(args)
  10. local style = awmtk2.create_style("xdg_menu",awmtk2.default,args.style)
  11. local templates = awmtk2.create_template_lib("xdg_menu",awmtk2.templates,args.templates)
  12. local t = awmtk2.build_templates(templates,style)
  13. -- Add a "loading" indicator while XDG is still parsing data
  14. local widget = wibox.widget({
  15. t.container({
  16. markup = "Loading XDG menu...",
  17. widget = wibox.widget.textbox
  18. }),
  19. layout = wibox.layout.fixed.vertical,
  20. id = "xdg_menu_root"
  21. })
  22. local function exclude(name)
  23. for k,v in pairs(args.exclude or {}) do
  24. if name:match(v) then
  25. return true
  26. end
  27. end
  28. return false
  29. end
  30. awesome.connect_signal("xdg::all_finished",function()
  31. if not args.parent then return end
  32. local items = {}
  33. for k,v in pairs(xdg.categories) do
  34. local noprocess = false
  35. for k2,v2 in pairs(args.exclude_category or {}) do
  36. if k == v2 then
  37. noprocess = true
  38. end
  39. end
  40. if (not noprocess) and (#v.apps > 0) then
  41. local category = {k,{},menuutils.lookup_icon_uncached(v.icon)}
  42. for _,item in pairs(v.apps) do
  43. if not exclude(item.name) then
  44. table.insert(category[2], {
  45. item.name,
  46. item.exec:gsub("%%%w","") or "",
  47. gears.filesystem.file_readable(item.icon or "") and item.icon
  48. })
  49. end
  50. end
  51. table.insert(items,category)
  52. end
  53. end
  54. -- uhhh there's a lot of things about async, some of which i can't explain
  55. local xdg_menu_root = widget:get_children_by_id("xdg_menu_root")[1]
  56. xdg_menu_root:reset()
  57. local menu = wibox.widget(menugen({
  58. items = items,
  59. }))
  60. local menu_root = menu:get_children_by_id("menu_root")[1]
  61. for k,v in pairs(menu_root.children) do
  62. v:connect_signal("cascade::kill",function()
  63. args.parent.visible = false
  64. end)
  65. args.parent:connect_signal("property::visible",function()
  66. if not args.parent.visible then
  67. v:emit_signal("cascade::close")
  68. end
  69. end)
  70. menu:connect_signal("widget::redraw_needed",function()
  71. if not menu.visible then
  72. v:emit_signal("cascade::close")
  73. end
  74. end)
  75. end
  76. local appswitch = wibox.widget(t.button(t.textbox({
  77. markup = "Applications",
  78. id = "apptext"
  79. })))
  80. appswitch:connect_signal("button::press",function(self)
  81. menu.visible = (not menu.visible)
  82. local textbox = appswitch:get_children_by_id("apptext")[1]
  83. if menu.visible then
  84. style.button.onpress(self)
  85. textbox:set_markup("<b>Applications</b>")
  86. else
  87. style.button.onrelease(self)
  88. textbox:set_markup("Applications")
  89. end
  90. end)
  91. menu.visible = false
  92. xdg_menu_root:add(appswitch)
  93. xdg_menu_root:add(menu)
  94. end)
  95. return widget
  96. end