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.

100 lines
3.1 KiB

2 years ago
  1. -- Asynchronous XDG data aggregator
  2. local menu_utils = require("menubar.utils")
  3. local menu_gen = require("menubar.menu_gen")
  4. local awful = require("awful")
  5. local gears = require("gears")
  6. menu_utils.wm_name = ""
  7. -- Directories to scan for .desktop files
  8. local desktop_dirs = {}
  9. local desktop_dirs_complete = 0
  10. local icon_dirs = {}
  11. (os.getenv("XDG_DATA_DIRS")..":/home/yessiest/.local/share"):gsub("[^:]*",function(path)
  12. if gears.filesystem.dir_readable(path.."/applications") then
  13. table.insert(desktop_dirs, path.."/applications")
  14. end
  15. if gears.filesystem.dir_readable(path.."/icons") then
  16. table.insert(icon_dirs, path.."/icons")
  17. end
  18. end)
  19. -- Global xdg data cache
  20. xdg = {
  21. apps = {},
  22. categories = {
  23. Other = {
  24. icon = "applications-other",
  25. apps = {}
  26. },
  27. Wine = {
  28. icon = "wine",
  29. apps = {}
  30. }
  31. }
  32. }
  33. for k,v in pairs(menu_gen.all_categories) do
  34. xdg.categories[v.app_type] = {
  35. name = v.name,
  36. icon = v.icon_name,
  37. apps = {}
  38. }
  39. end
  40. -- Asynchronous scanning process
  41. for k,v in pairs(desktop_dirs) do
  42. awful.spawn.with_line_callback("find "..tostring(v).." -name *.desktop",{
  43. stdout = function(line)
  44. local data = menu_utils.parse_desktop_file(line)
  45. if data.NoDisplay then
  46. return
  47. end
  48. local appdata = {
  49. name = data.Name,
  50. category = "Other",
  51. exec = data.Exec,
  52. icon = (data.Icon and menu_utils.lookup_icon(data.Icon)),
  53. description = data.Comment
  54. }
  55. -- Match first available cateogry for sorting
  56. for k,v in pairs(data.Categories or {"Other"}) do
  57. if xdg.categories[v] then
  58. appdata.category = v
  59. break
  60. end
  61. -- Oh how do I love those Wine applications and their categories
  62. if v:match("^Wine") then
  63. appdata.category = "Wine"
  64. break
  65. end
  66. end
  67. -- Open terminal apps in the terminal (duh)
  68. if data.Terminal then
  69. appdata.exec = global.terminal.." -e "..appdata.exec
  70. end
  71. -- Just for you, Wine - special case because you're being a shit
  72. if (exec and exec:find("%W?wine ")) then
  73. appdata.category = "Wine"
  74. end
  75. table.insert(xdg.apps,appdata)
  76. table.insert(xdg.categories[appdata.category].apps,appdata)
  77. end,
  78. output_done = function()
  79. -- Call a global signal
  80. desktop_dirs_complete = desktop_dirs_complete + 1
  81. awesome.emit_signal("xdg::dir_finished",v)
  82. end
  83. })
  84. end
  85. awesome.connect_signal("xdg::dir_finished",function(dir)
  86. if desktop_dirs_complete == #desktop_dirs then
  87. awesome.emit_signal("xdg::all_finished")
  88. -- Clean up empty categories
  89. for k,v in pairs(xdg.categories) do
  90. if #v.apps == 0 then
  91. xdg.categories[k] = nil
  92. end
  93. end
  94. end
  95. end)