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.

125 lines
4.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. -- JSON layout builder
  9. local json = require("dkjson")
  10. local gears = require("gears")
  11. local wibox = require("wibox")
  12. local awful = require("awful")
  13. local builtins = {
  14. h_spacer = function(o)
  15. return {
  16. forced_width = o.size or 3,
  17. widget = wibox.container.background
  18. }
  19. end,
  20. v_spacer = function(o)
  21. return {
  22. forced_height = o.size or 3,
  23. widget = wibox.container.background
  24. }
  25. end
  26. -- Insert your other builtins here
  27. }
  28. -- Load a bunch of builtins from awful.titlebar
  29. for _,name in pairs({
  30. "titlewidget","iconwidget","floatingbutton",
  31. "maximizedbutton","minimizebutton","closebutton",
  32. "ontopbutton","stickybutton"
  33. }) do
  34. builtins[name] = function(o)
  35. o.widget = awful.titlebar.widget[name](o.client)
  36. return o
  37. end
  38. end
  39. return function(description,opts)
  40. local style = opts.style or {}
  41. local c = opts.client
  42. local s = opts.screen
  43. local buttons = opts.buttons
  44. -- Build a layout given a JSON description, a style and client
  45. -- (if applicable)
  46. local layout = {}
  47. local test,err = json.decode(description)
  48. if not test then
  49. error("Builder failure: "..err)
  50. end
  51. local function inner_builder(struct)
  52. if struct.widget then -- External widget descriptions
  53. return require(struct.widget)(gears.table.join({
  54. layout = (struct.layout and inner_builder(struct.layout)), client = (struct.client and c),
  55. screen = (struct.screen and s)
  56. },struct.options or {},opts.passthrough or {}))
  57. elseif struct.list then -- List descriptions
  58. local list = {
  59. layout = wibox.layout.fixed[(
  60. (struct.vertical and "vertical") or
  61. "horizontal"
  62. )],
  63. spacing = style.spacing
  64. }
  65. for k,v in pairs(struct.list) do
  66. if v.draggable then
  67. list.buttons = buttons
  68. else
  69. table.insert(list,inner_builder(v))
  70. end
  71. end
  72. return list
  73. elseif struct.align then -- Align structure descriptions
  74. local orient = (
  75. (struct.vertical and "vertical") or
  76. "horizontal"
  77. )
  78. local list = {
  79. {
  80. layout = wibox.layout.fixed[orient],
  81. spacing = style.spacing
  82. },{
  83. layout = wibox.layout.flex[orient],
  84. spacing = style.spacing
  85. },{
  86. -- Simulating "spacing" parameter
  87. widget = builtins[(struct.vertical and "v_spacer") or
  88. "h_spacer"]({size = style.spacing}),
  89. layout = wibox.layout.fixed[orient],
  90. spacing = style.spacing
  91. },
  92. layout = wibox.layout.align[orient]
  93. }
  94. for k,v in pairs({"left","center","right"}) do
  95. for _,obj in pairs(struct.align[v]) do
  96. if obj.draggable then
  97. list[k].buttons = buttons
  98. else
  99. table.insert(list[k],inner_builder(obj))
  100. end
  101. end
  102. end
  103. -- Part of simulating "spacing" parameter
  104. table.insert(list[1],builtins[(struct.vertical and "v_spacer") or
  105. "h_spacer"]({size = style.spacing}))
  106. return list
  107. elseif struct.builtin then -- Builtin widget descriptions
  108. if not builtins[struct.builtin] then
  109. error("Builtin not defined: "..struct.builtin)
  110. end
  111. return builtins[struct.builtin](gears.table.join({
  112. client = (struct.client and c)
  113. },struct.options or {}))
  114. end
  115. -- If this gets interpreted it's safe to say none of the constructions
  116. -- above got matched.
  117. print("Object where the error occured: ")
  118. gears.debug.dump(struct)
  119. error("Builder error: invalid object description")
  120. end
  121. return inner_builder(test,layout),test.context_options
  122. end