You are not logged in.
I have a dual screen setup and would like a different png on each display
I see...
rc.lua
local function set_wallpaper(s)
    -- Wallpaper
    if beautiful.wallpaper then
        local wallpaper = beautiful.wallpaper
        -- If wallpaper is a function, call it with the screen
        if type(wallpaper) == "function" then
            wallpaper = wallpaper(s)
        end
        gears.wallpaper.maximized(wallpaper, s, true)
    end
endtheme.lua
theme.wallpaper = themes_path.."default/Shelby1.jpg"How do I enter the theme.lua code for two images?
Last edited by Sorky (2018-10-09 11:18:48)
Offline

I don't use Awesome, and I suck at Lua, but the comment makes one option quite obvious: make 'wallpaper' a function that returns a different image file based on the value of it's argument.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
I tried, but I'm not experienced enough!
What I tried...
theme.wallpaper = function (s)
	local wallpapers = {
		"default/Shelby1.png",
		"default/Shelby2.png"
	}
  return wallpapers[s] 
  endOffline

I have no idea what kind of value/object 's' is. That'd be the first hurdle. Check the documentation, then do some testing. Use a conditional on type(s), and keep in mind that lua arrays are 1-based, so even if s is a integer/numeric it may not be 1 or 2 but 0 and 1, or something else entirely.
Also the wallpapers in that array will almost certainly need a full path - prepend them with the full path or the path variable (if it is available in the function scope).
Last edited by Trilby (2018-09-23 16:22:12)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Anyone know how Awesome
theme.wallpaper
is meant to be defined (as a function)?
Offline
I figured it out - I was so close - Just needed to determine that s.index was the element in 's' that indicated the screen number
theme.wallpapers = {	theme.dir .. "Shelby1.png",
		        theme.dir .. "Shelby2.png"		}
theme.wallpaper = function( s ) return theme.wallpapers[s.index] endOffline
For what it's worth - Here's my final solution (for now)...
Original
local function set_wallpaper(s)
    -- Wallpaper
    if beautiful.wallpaper then
        local wallpaper = beautiful.wallpaper
        -- If wallpaper is a function, call it with the screen
        if type(wallpaper) == "function" then
            wallpaper = wallpaper(s)
        end
        gears.wallpaper.maximized(wallpaper, s, true)
    end
endBecame
local function set_wallpaper(s)
	wallpaper_safety =	function(arg)	if 	type(arg) == "table" then	return tostring( arg[s.index] or "" )
						elseif	type(arg) == "string" then	return arg
						else 					return ""
						end
				end
	gears.wallpaper.maximized( (theme.dir or "") .. wallpaper_safety( beautiful.wallpaper ), s, true )
endWhy? It worked with any of these and left a blank background (a) if there were more screens than assigned or (b) if variables were not defined or (c) there were typing errors
theme.dir = string.match(debug.getinfo(1,"S").source,"/.*/")
theme.wallpaper = "Shelby1.png"					-- All screens
theme.wallpaper = { "Shelby1.png" }				-- Just did screen 1
theme.wallpaper = { "Shelby1.png", "Shelby2.png" }		-- Did both screensLast edited by Sorky (2018-10-07 21:58:24)
Offline

Nicely done. Thanks for sharing the details for future users.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Thanks
PS: The change from 3.5 (where s is a number) to 4.0 (where s is a collection) is what I got confused by [would be interesting to get feedback from one of the devs on what I did and potentially updating the doco]
From: https://awesomewm.org/doc/api/documenta … ps.md.html
--- {{{ Wallpaper
-if beautiful.wallpaper then
-    for s = 1, screen.count() do
-        gears.wallpaper.maximized(beautiful.wallpaper, s, true)
-    end
-end
--- }}}
+local function set_wallpaper(s)
+    -- Wallpaper
+    if beautiful.wallpaper then
+        local wallpaper = beautiful.wallpaper
+        -- If wallpaper is a function, call it with the screen
+        if type(wallpaper) == "function" then
+            wallpaper = wallpaper(s)
+        end
+        gears.wallpaper.maximized(wallpaper, s, true)
+    end
+end
+
+-- Re-set wallpaper when a screen's geometry changes (e.g. different resolution)
+screen.connect_signal("property::geometry", set_wallpaper)Last edited by Sorky (2018-10-09 14:12:12)
Offline
Here's the main changes in my final, final solution (for now)...
rc.lua
<snip>
-- Usage .. "themes/@/theme.lua" ) -- @: [blackburn, copland, dremora, holo, multicolor, powerarrow, powerarrow-dark, rainbow, steamburn, vertex]
-- Usage .. "sorky/themes/@/theme.lua" ) -- @: [shelby]
beautiful.init( string.match( debug.getinfo( 1, "S" ).source, "/.*/" ) .. "sorky/themes/shelby/theme.lua" )
<snip>
-- {{{ Screen
-- Reset wallpaper when a screen's geometry changes (e.g. different resolution)
screen.connect_signal( "property::geometry", function(s) beautiful.wallpaper.maximized( beautiful.wallpaper, s, beautiful.wallpapers) end )
-- Create a wibox for each screen and add it
awful.screen.connect_for_each_screen(function(s) beautiful.at_screen_connect(s) end)
-- }}}
<snip>theme.lua
<snip>
local Gio	= require("lgi").Gio
local os	= { clock = os.clock }
math.randomseed(os.clock() % 1 * 1e6)
<snip>
local theme									= {}
theme.dir									= string.match( debug.getinfo( 1, "S" ).source, "/.*/" )
theme.icons									= theme.dir .. "icons/"
theme.wallpapers								= theme.dir .. "wallpapers/"
--theme.wallpaper								= "Shelby1.png"							-- Used on all screens
--theme.wallpaper								= { "Shelby1.png", "Shelby2.png" }				-- Used on different screens 
theme.wallpaper									= function(s) return get_random_image( theme.wallpapers ) end 	-- Provides random wallpapers for each screen 
<snip>
-- Gets a random image
function get_random_image( path ) 
	local images_in_path = {}
	local valid_image_ext = { ["jpg"]=1, ["jpeg"]=1, ["png"]=1, ["bmp"]=1 }
	local enumerator = Gio.File.new_for_path( path ):enumerate_children( "standard::name", 0 )
	for file in function() return enumerator:next_file() end do
		local file_name = file:get_attribute_as_string( "standard::name" )
		if valid_image_ext[file_name:lower():match("%.(.*)$")] then table.insert( images_in_path, file_name ) end
	end
	return images_in_path[math.random(#images_in_path)]
end
-- Wallpaper drawing function (allows for multiple wallpapers defined in various ways)
-- Becomes beautiful.wallpaper_maximized when theme is loaded by beautiful.init
function theme.wallpaper_maximized( wallpaper_mixed, s, wallpaper_path ) 
	local wallpaper = ""
	local wallpaper_path = wallpaper_path or ""
	local wallpaper_type = type( wallpaper_mixed )
	if 	wallpaper_type == "string" then		wallpaper = wallpaper_mixed
	elseif	wallpaper_type == "table" then		wallpaper = tostring( wallpaper_mixed[s.index] or "" )
	elseif	wallpaper_type == "function" then	wallpaper = tostring( wallpaper_mixed(s) or "" )
	end
	gears.wallpaper.maximized( wallpaper_path .. wallpaper, s, true )
end
function theme.at_screen_connect(s)
	-- Draw the appropriate wallpaper
	theme.wallpaper_maximized( theme.wallpaper, s, theme.wallpapers )
<snip>Comment: I put back the "wallpaper as a function" support as I found a use case (random background from a directory of many
Warning: Take care if copying my code as the rc.lua & theme are not from the default (I started with CopyCatz) - What you find may have other stuff I cut out!
Apologies: If you understand where it came from and don't like my changes rip & replace is a big part of my learning process
#Lots of Thanks to https://github.com/lcpz/awesome-copycats
Last edited by Sorky (2018-10-12 07:51:01)
Offline