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.

234 lines
8.5 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
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. local gears = require("gears")
  9. local awmtk2 = require("awmtk2")
  10. local wibox = require("wibox")
  11. local awful = require("awful")
  12. local beautiful = require("beautiful")
  13. local builder = require("builder")
  14. local json = require("dkjson")
  15. local function read_file(fname)
  16. local fhandler = io.open(fname,"r")
  17. if fhandler then
  18. local data = fhandler:read("*a")
  19. fhandler:close()
  20. return data
  21. end
  22. end
  23. -- {{{ Placeholder Icons
  24. client.connect_signal("request::titlebars",function(c)
  25. if (not c.icon) and beautiful.icon_default then
  26. c.icon = beautiful.icon_default._native
  27. end
  28. end)
  29. -- }}}
  30. do -- {{{ Global widgets
  31. local config_file = io.open(root_path.."/themes/"..global.theme.."/config/global.json","r")
  32. local config
  33. if config_file then
  34. config = config_file:read("*a")
  35. config_file:close()
  36. else
  37. config = "[]"
  38. end
  39. for k,v in pairs(json.decode(config) or {}) do
  40. require(k)(v)
  41. end
  42. end -- }}}
  43. do --{{{ Screen
  44. local wibar_config = {}
  45. local style = awmtk2.create_style("wibar",awmtk2.generic.composite_widget,{})
  46. for _,v in pairs({"wibar_top","wibar_bottom","wibar_left","wibar_right"}) do
  47. style[v] = awmtk2.create_delta(v, {},
  48. (beautiful.widgets and beautiful.widgets.wibar) or {},
  49. style.wibar)
  50. wibar_config[v] = read_file(root_path.."/themes/"..global.theme.."/config/"..v..".json")
  51. end
  52. local templates = awmtk2.create_template_lib("wibar",awmtk2.templates,{})
  53. local t = awmtk2.build_templates(templates,style)
  54. awful.screen.connect_for_each_screen(function(s)
  55. for _,v in pairs({"wibar_top","wibar_bottom","wibar_left","wibar_right"}) do
  56. local contents = { widget = wibox.container.background }
  57. if wibar_config[v] then
  58. contents = builder(wibar_config[v],{
  59. client = c,
  60. style = style[v],
  61. buttons = buttons,
  62. screen = s
  63. })
  64. s[v] = awful.wibar({
  65. -- There really isn't a better way to do this. I wish there was.
  66. position = v:gsub("wibar_",""),
  67. screen = s,
  68. visible = true,
  69. stretch = style[v].stretch,
  70. ontop = style[v].ontop,
  71. width = style[v].width,
  72. height = style[v].height,
  73. border_width = style[v].border_width,
  74. border_color = style[v].border_color,
  75. opacity = style[v].opacity or 1,
  76. shape = style[v].shape,
  77. bg = style[v].bg_normal,
  78. bgimage = style[v].bgimage_normal,
  79. fg = style[v].fg,
  80. input_passthrough = style[v].input_passthrough
  81. })
  82. s[v]:setup(t.wibar(contents))
  83. end
  84. end
  85. end)
  86. end -- }}}
  87. do -- {{{ Titlebars
  88. local titlebar_config = {}
  89. local style = awmtk2.create_style("titlebar",awmtk2.generic.composite_widget,{})
  90. for _,v in pairs({"titlebar_top","titlebar_left","titlebar_right","titlebar_bottom"}) do
  91. -- Create styles for each titlebar
  92. style[v] = awmtk2.create_delta(v, {},
  93. (beautiful.widgets and beautiful.widgets.titlebar) or {},
  94. style.titlebar)
  95. -- Load in json layouts for titlebars
  96. titlebar_config[v] = read_file(root_path.."/themes/"..global.theme.."/config/"..v..".json")
  97. end
  98. local templates = awmtk2.create_template_lib("titlebar",awmtk2.templates,{})
  99. local t = awmtk2.build_templates(templates,style)
  100. -- Add titlebars to normal windows
  101. table.insert(awful.rules.rules,
  102. { rule_any = {type = { "normal", "dialog" }
  103. }, properties = { titlebars_enabled = true }
  104. }
  105. )
  106. local window_shape_hide = function(cr, width, height)
  107. return gears.shape.partially_rounded_rect(cr,width,height,
  108. false,false,false,false,0)
  109. end
  110. local window_shape = beautiful.window_shape or function(cr, width, height)
  111. return gears.shape.partially_rounded_rect(cr,width,height,
  112. true,true,false,false,beautiful.window_rounding)
  113. end
  114. client.connect_signal("manage", function(c)
  115. c.shape = window_shape
  116. end)
  117. local titlebars_on = true
  118. awesome.connect_signal("titlebar::toggle",function()
  119. titlebars_on = not titlebars_on
  120. for _,c in ipairs(client.get()) do
  121. if titlebars_on then
  122. for _, pos in ipairs({"top","bottom","left","right"}) do
  123. awful.titlebar.show(c,pos)
  124. end
  125. c.shape = window_shape
  126. c:emit_signal("titlebar::perform_action",function(titlebar)
  127. titlebar.widget.visible = true
  128. end)
  129. else
  130. for _, pos in ipairs({"top","bottom","left","right"}) do
  131. awful.titlebar.hide(c,pos)
  132. end
  133. c.shape = window_shape_hide
  134. c:emit_signal("titlebar::perform_action",function(titlebar)
  135. titlebar.widget.visible = false
  136. end)
  137. end
  138. end
  139. end)
  140. -- Second manage call to create hidden titlebars
  141. client.connect_signal("manage",function(c)
  142. -- Drag and resize buttons
  143. local buttons = gears.table.join(
  144. awful.button({}, 1, function()
  145. c:emit_signal("request::activate","titlebar",{raise=true})
  146. awful.mouse.client.move(c)
  147. end),
  148. awful.button({}, 3, function()
  149. c:emit_signal("request::activate","titlebar",{raise=true})
  150. awful.mouse.client.resize(c)
  151. end)
  152. )
  153. -- Building the titlebars
  154. for k,v in pairs({"titlebar_top","titlebar_bottom","titlebar_left","titlebar_right"}) do
  155. -- Build content of the titlebar
  156. local contents = { widget = wibox.widget.textbox, text = "" }
  157. if titlebar_config[v] then
  158. contents = builder(titlebar_config[v],{
  159. client = c,
  160. screen = c.screen,
  161. style = style[v],
  162. buttons = buttons
  163. })
  164. end
  165. -- Create the base
  166. local titlebar = awful.titlebar(c,{
  167. size = style[v].size or 0,
  168. position = v:gsub("titlebar_",""),
  169. bg_normal = style[v].bg_normal,
  170. bg_focus = style[v].bg_focus,
  171. bgimage_normal = style[v].bgimage_normal,
  172. bgimage_focus = style[v].bgimage_focus,
  173. fg_normal = style[v].fg_normal,
  174. fg_focus = style[v].fg_focus,
  175. font = style[v].font
  176. })
  177. -- Compile and build titlebar
  178. titlebar:setup(t.titlebar({
  179. contents,
  180. widget = wibox.container.background
  181. }))
  182. -- Since new clients will be placed without titlebars, we need to apply placement rules again
  183. awful.rules.rules[1].properties.placement(c)
  184. -- Callbacks for focus/unfocus of titlebars
  185. if style[v].onfocus then
  186. c:connect_signal("focus",function()
  187. style[v].onfocus(titlebar)
  188. end)
  189. end
  190. if style[v].onunfocus then
  191. c:connect_signal("unfocus",function()
  192. style[v].onunfocus(titlebar)
  193. end)
  194. end
  195. -- Activate focus callback if our client is focused
  196. if (c == client.focus) and (style[v].onfocus) then
  197. style[v].onfocus(titlebar)
  198. end
  199. -- Add a titlebar toggle signal
  200. c:connect_signal("titlebar::toggle",function(c)
  201. titlebar.widget.visible = not titlebar.widget.visible
  202. if titlebar.widget.visible then
  203. awful.titlebar.show(c,v:gsub("titlebar_",""))
  204. c.shape = window_shape
  205. else
  206. awful.titlebar.hide(c,v:gsub("titlebar_",""))
  207. c.shape = window_shape_hide
  208. end
  209. end)
  210. c:connect_signal("titlebar::perform_action",function(c,f)
  211. f(titlebar)
  212. end)
  213. -- Add rules for hiding titlebars on creation
  214. if (not titlebars_on) or
  215. (c.titlebars_enabled == false) or
  216. (c.requests_no_titlebar == true) then
  217. titlebar.widget.visible = false
  218. c.shape = window_shape_hide
  219. awful.titlebar.hide(c,v:gsub("titlebar_",""))
  220. end
  221. end
  222. end)
  223. end --}}}