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.

131 lines
5.1 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 test,err = json.decode(description)
  47. if not test then
  48. error("Builder failure: "..err)
  49. end
  50. local function inner_builder(struct,vertical)
  51. if struct.widget then -- External widget descriptions
  52. return require(struct.widget)(gears.table.join({
  53. layout = (struct.layout and inner_builder(struct.layout)), client = (struct.client and c),
  54. screen = (struct.screen and s),
  55. vertical = vertical
  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 _,v in pairs(struct.list) do
  66. if v.draggable then
  67. list.buttons = buttons
  68. else
  69. local new_obj = inner_builder(v,struct.vertical)
  70. if new_obj then
  71. table.insert(list,new_obj)
  72. end
  73. end
  74. end
  75. return list
  76. elseif struct.align then -- Align structure descriptions
  77. local orient = (
  78. (struct.vertical and "vertical") or
  79. "horizontal"
  80. )
  81. local list = {
  82. {
  83. layout = wibox.layout.fixed[orient],
  84. spacing = style.spacing
  85. },{
  86. layout = wibox.layout.flex[orient],
  87. spacing = style.spacing
  88. },{
  89. -- Simulating "spacing" parameter
  90. widget = builtins[(struct.vertical and "v_spacer") or
  91. "h_spacer"]({size = style.spacing}),
  92. layout = wibox.layout.fixed[orient],
  93. spacing = style.spacing
  94. },
  95. layout = wibox.layout.align[orient]
  96. }
  97. for k,v in pairs({"left","center","right"}) do
  98. for _,obj in pairs(struct.align[v]) do
  99. if obj.draggable then
  100. list[k].buttons = buttons
  101. else
  102. local new_obj = inner_builder(obj,struct.vertical)
  103. if new_obj then
  104. table.insert(list[k],new_obj)
  105. end
  106. end
  107. end
  108. end
  109. -- Part of simulating "spacing" parameter
  110. table.insert(list[1],builtins[(struct.vertical and "v_spacer") or
  111. "h_spacer"]({size = style.spacing}))
  112. return list
  113. elseif struct.builtin then -- Builtin widget descriptions
  114. if not builtins[struct.builtin] then
  115. error("Builtin not defined: "..struct.builtin)
  116. end
  117. return builtins[struct.builtin](gears.table.join({
  118. client = (struct.client and c)
  119. },struct.options or {}))
  120. end
  121. -- If this gets interpreted it's safe to say none of the constructions
  122. -- above got matched.
  123. print("Object where the error occured: ")
  124. gears.debug.dump(struct)
  125. error("Builder error: invalid object description")
  126. end
  127. return inner_builder(test),test.context_options
  128. end