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.

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