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
4.0 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
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. -- Global context menu base
  9. local awmtk2 = require("awmtk2")
  10. local wibox = require("wibox")
  11. local gears = require("gears")
  12. local awful = require("awful")
  13. local builder = require("builder")
  14. local digger = require("digger")
  15. return function(args)
  16. local style = awmtk2.create_style("root_menu",
  17. awmtk2.generic.composite_widget,{})
  18. local templates = awmtk2.create_template_lib("root_menu",awmtk2.templates,{})
  19. local t = awmtk2.build_templates(templates,style,args.vertical)
  20. -- Layout configuration
  21. local config_file = io.open(root_path.."/themes/"..global.theme.."/config/root_menu.json","r")
  22. local config
  23. if config_file then
  24. config = config_file:read("*a")
  25. config_file:close()
  26. else
  27. config = [[{"list": [{"widget": "widgets.rootcontrols"}],"vertical": true}]]
  28. end
  29. -- Not yet loaded menu popup (TODO: maybe make it more obvious that it's a global?)
  30. root_menu = awful.popup(t.popup({
  31. markup = "brainhurt the game",
  32. widget = wibox.widget.textbox
  33. }))
  34. -- Close popup on right click
  35. root_menu:connect_signal("button::press",function(_,_,_,b)
  36. if b == 3 then
  37. root_menu.visible = false
  38. end
  39. end)
  40. -- Build the menu based on the json config
  41. root_menu.widget = wibox.widget(t.popup(builder(
  42. config,
  43. {
  44. style = style.base,
  45. screen = mouse.screen,
  46. }
  47. )).widget)
  48. -- Generate a list of all existing menu_root objects
  49. local menus = digger(root_menu.widget,"menu_root")
  50. local root_menu_size = root_menu.width * root_menu.height
  51. root_menu:connect_signal("widget::size_changed",function()
  52. -- Attach callbacks to close the root_menu when new buttons appear
  53. local already_managed = {}
  54. for _,v in pairs(menus) do
  55. already_managed[v] = true
  56. end
  57. menus = digger(root_menu.widget,"menu_root")
  58. for _,v in pairs(menus) do
  59. if not already_managed[v] then
  60. v:connect_signal("cascade::kill",function()
  61. root_menu.visible = false
  62. end)
  63. end
  64. end
  65. end)
  66. -- Close the prime_menu if our menu becomes invisible
  67. root_menu:connect_signal("property::visible",function()
  68. local current_root_menu_size = root_menu.width * root_menu.height
  69. if current_root_menu_size ~= root_menu_size then
  70. root_menu:emit_signal("widget::size_changed")
  71. root_menu_size = current_root_menu_size
  72. end
  73. if not root_menu.visible then
  74. for _,v in pairs(menus) do
  75. v:emit_signal("cascade::kill")
  76. end
  77. end
  78. end)
  79. -- If any of the menus emit cascade::kill, close the menu
  80. for _,v in pairs(menus) do
  81. v:connect_signal("cascade::kill",function()
  82. root_menu.visible = false
  83. end)
  84. end
  85. -- Make the root_menu pop up on the desktop on right click
  86. local buttons = root.buttons()
  87. root.buttons(gears.table.join(buttons,
  88. awful.button({}, 3, function()
  89. root_menu.visible = (not root_menu.visible)
  90. if root_menu.visible then
  91. root_menu:move_next_to(gears.table.join(mouse.coords(),{
  92. width = 0,
  93. height = 0
  94. }))
  95. end
  96. end)
  97. ))
  98. return root_menu
  99. end