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.

91 lines
3.7 KiB

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