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.

146 lines
5.9 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
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. -- Wallpaper list widget
  9. local awful = require("awful")
  10. local pager = require("pager")
  11. local beautiful = require("beautiful")
  12. local gears = require("gears")
  13. local wibox = require("wibox")
  14. local awmtk2 = require("awmtk2")
  15. local thumbnailer = require("thumbnail")
  16. local function ls(path)
  17. local ls_data = io.popen("find "..path.." -maxdepth 1 -type f \\( -name \\*.jpg -o -name \\*.png \\) -exec realpath {} \\;")
  18. local output = {}
  19. if ls_data then
  20. ls_data:read("*a"):gsub("[^\n]+",function(capt)
  21. table.insert(output,capt)
  22. end)
  23. ls_data:close()
  24. return output
  25. end
  26. error("Failed to process directory "..path)
  27. end
  28. return function(args)
  29. local style = awmtk2.create_style("wallpapers",
  30. awmtk2.generic.popup,args.style)
  31. local templates = awmtk2.create_template_lib("wallpapers",awmtk2.templates,args.templates)
  32. local t = awmtk2.build_templates(templates,style,args.vertical)
  33. -- set wallpaper
  34. local fhandler = io.open(root_path.."/wallpaper.txt","r")
  35. if fhandler then
  36. local wallpaper_path = fhandler:read("*a")
  37. gears.wallpaper.maximized(wallpaper_path,args.screen)
  38. else
  39. -- try to set wallpaper from theme settings
  40. if beautiful.wallpaper then
  41. gears.wallpaper.maximized(beautiful.wallpaper,args.screen)
  42. end
  43. end
  44. -- update wallpaper preference and set wallpaper
  45. local function set_wallpaper(s)
  46. local handler = io.open(root_path.."/wallpaper.txt","w")
  47. handler:write(s)
  48. handler:close()
  49. gears.wallpaper.maximized(s,args.screen)
  50. end
  51. if not args.path then
  52. args.path = os.getenv("HOME")..".local/share/wallpapers/"
  53. end
  54. args.path = args.path:gsub("$HOME",os.getenv("HOME"))
  55. -- read wallpapers from wallpaper directory
  56. local image_list = ls(args.path)
  57. -- generate thumbnails to save memory
  58. thumbnailer.generate(args.path,args.path.."/.thumbnails",60)
  59. -- create a layout for wallpaper buttons
  60. local layout = wibox.widget({
  61. layout = wibox.layout.grid,
  62. forced_num_cols = args.columns or 4,
  63. homogenous = true,
  64. expand = true,
  65. orientation = "vertical",
  66. spacing = style.base.spacing
  67. })
  68. -- create layout popup
  69. local popup = awful.popup(t.popup({
  70. t.container(layout,{
  71. bg = style.container.bg_highlight,
  72. bgimage = style.container.bgimage_highlight
  73. }),
  74. t.textbox({
  75. markup = "Page 0/0",
  76. id = "page_index"
  77. }),
  78. layout = wibox.layout.fixed.vertical
  79. },{
  80. visible = false
  81. }))
  82. local page_index = popup.widget:get_children_by_id("page_index")[1]
  83. -- set up a pager for having multiple pages of wallpapers
  84. local pager_size = ((args.rows and args.columns) and args.rows*args.columns) or 20
  85. local pager = pager(layout,{},pager_size)
  86. -- add wallpaper buttons
  87. for _,v in pairs(image_list) do
  88. local new_button = wibox.widget(t.button(t.icon({
  89. image = args.path.."/.thumbnails/"..v:match("/[^/]*$"),
  90. resize = true,
  91. height = args.height or 60,
  92. width = args.width or 100
  93. })))
  94. new_button:connect_signal("button::press",style.button.onpress)
  95. new_button:connect_signal("button::release",style.button.onrelease)
  96. new_button:connect_signal("button::press",function(self,x,y,button)
  97. if button == 1 then
  98. set_wallpaper(v)
  99. elseif button == 4 then
  100. pager:prev()
  101. page_index:set_markup("Page "..tostring(pager.index+1).."/"..
  102. tostring(math.ceil(#image_list/pager_size)))
  103. elseif button == 5 then
  104. pager:next()
  105. page_index:set_markup("Page "..tostring(pager.index+1).."/"..
  106. tostring(math.ceil(#image_list/pager_size)))
  107. end
  108. end)
  109. table.insert(pager.list,new_button)
  110. end
  111. page_index:set_markup("Page "..tostring(pager.index+1).."/"..
  112. tostring(math.ceil(#image_list/pager_size)))
  113. -- update pager
  114. pager:update()
  115. -- make popup togglable
  116. popup:connect_signal("button::press",function(self,x,y,button)
  117. if button == 3 then
  118. popup.visible = false
  119. end
  120. end)
  121. -- create popup button
  122. local clip_widget
  123. do
  124. local style = awmtk2.create_style("wallpapers",
  125. awmtk2.generic.iconified_widget,args.style)
  126. local templates = awmtk2.create_template_lib("wallpapers",awmtk2.templates,args.templates)
  127. local t = awmtk2.build_templates(templates,style,args.vertical)
  128. clip_widget = wibox.widget(t.button(t.icon({
  129. image = beautiful.wallpapers_icon,
  130. resize = true,
  131. })))
  132. clip_widget:connect_signal("button::press",style.button.onpress)
  133. clip_widget:connect_signal("button::release",style.button.onrelease)
  134. clip_widget:connect_signal("button::press",function(self,x,y,button)
  135. if button == 1 then
  136. popup.visible = (not popup.visible)
  137. if popup.visible then
  138. popup:move_next_to(mouse.current_widget_geometry)
  139. end
  140. end
  141. end)
  142. end
  143. return clip_widget
  144. end