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.

117 lines
4.7 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
  1. -- POLYMENU - brutal deluxe
  2. -- This isn't in the widgets folder because it's too meta to be there
  3. local awful = require("awful")
  4. local gears = require("gears")
  5. local menubar_utils = require("menubar.utils")
  6. local wibox = require("wibox")
  7. local awmtk2 = require("awmtk2")
  8. local function position_popup(popup,widget,style)
  9. -- Position the popup somewhere nearby our original widget
  10. popup:move_next_to(mouse.current_wibox)
  11. -- Figure out the geometry of the base widget
  12. local widget_geo
  13. for k,v in pairs(mouse.current_widgets or {}) do
  14. if widget == v then
  15. widget_geo = mouse.current_widget_geometries[k]
  16. end
  17. end
  18. -- Align y coordinate of the popup to the button
  19. if widget_geo then
  20. local wibox_geo = mouse.current_wibox:geometry()
  21. if popup.current_anchor == "front" then
  22. popup.y = widget_geo.y + wibox_geo.y - style.popup.margins
  23. else
  24. popup.y = widget_geo.y + wibox_geo.y + style.popup.margins + widget_geo.height - popup:geometry().height
  25. end
  26. end
  27. -- Finally, make widget visible
  28. popup.visible = true
  29. end
  30. return function(args)
  31. -- A way to communicate that all widgets in menu got closed
  32. args.on_close = args.on_close or function() end
  33. local style = awmtk2.create_style("menu", awmtk2.default, args.style)
  34. local templates = awmtk2.create_template_lib("menu", awmtk2.templates, args.templates)
  35. local t = awmtk2.build_templates(templates,style)
  36. local function menu_builder(element,layer,root_layer)
  37. local new_element = wibox.widget(t.button(t.article({
  38. icon = element[3],
  39. resize = true,
  40. title = element[1]
  41. }),{
  42. forced_width = style.button.forced_width,
  43. forced_height = style.button.forced_height
  44. }))
  45. local onpress = function(widget)
  46. style.button.onrelease(widget)
  47. if root_layer.focused then
  48. root_layer.focused:emit_signal("cascade::kill")
  49. end
  50. end
  51. if type(element[2]) == "string" then
  52. new_element:connect_signal("button::press",style.button.onpress)
  53. new_element:connect_signal("button::press",function(widget)
  54. awful.spawn(element[2])
  55. end)
  56. new_element:connect_signal("button::release",onpress)
  57. elseif type(element[2]) == "function" then
  58. new_element:connect_signal("button::press",style.button.onpress)
  59. new_element:connect_signal("button::press",element[2])
  60. new_element:connect_signal("button::release",onpress)
  61. elseif type(element[2]) == "table" then
  62. local layout = {
  63. spacing = style.base.spacing,
  64. layout = wibox.layout.fixed.vertical
  65. }
  66. for k,v in pairs(element[2]) do
  67. table.insert(layout,menu_builder(v,layout,root_layer))
  68. end
  69. local next_layer = awful.popup(t.popup(layout,{
  70. visible = false,
  71. ontop = true,
  72. preferred_positions = {"right","left"},
  73. preferred_anchors = {"front","back"},
  74. }))
  75. local function open_layer(widget)
  76. if layer.focused == widget and
  77. next_layer.visible then
  78. return
  79. end
  80. if layer.focused then
  81. layer.focused:emit_signal("cascade::close")
  82. end
  83. layer.focused = widget
  84. position_popup(next_layer, new_element, style)
  85. end
  86. local onclose = function()
  87. style.button.onrelease(new_element)
  88. if layout.focused then
  89. layout.focused:emit_signal("cascade::close")
  90. end
  91. next_layer.visible = false
  92. end
  93. new_element:connect_signal("cascade::close",onclose)
  94. new_element:connect_signal("cascade::kill",onclose)
  95. -- that sweet "just move the mouse 4head" navigation
  96. if style.base.menu_slide then
  97. new_element:connect_signal("mouse::enter",open_layer)
  98. new_element:connect_signal("mouse::enter",style.button.onpress)
  99. else
  100. new_element:connect_signal("button::press",style.button.onpress)
  101. new_element:connect_signal("button::press",open_layer)
  102. end
  103. end
  104. return new_element
  105. end
  106. local root_layer = {
  107. layout = wibox.layout.fixed.vertical,
  108. id = "menu_root",
  109. spacing = style.base.spacing
  110. }
  111. for k,v in pairs(args.items) do
  112. table.insert(root_layer,menu_builder(v,root_layer,root_layer))
  113. end
  114. return root_layer
  115. end