Add support to wallpaper module for multiple screens (#125)
* Add support for multiple screens * Add documentation * Update wallpaper module to use single argument for screen * Update docs for wallpaper module * Fix arguments
This commit is contained in:
parent
7542251b72
commit
298a6e6c8d
|
@ -48,6 +48,15 @@ bling.module.wallpaper.setup {
|
||||||
recursive = false,
|
recursive = false,
|
||||||
change_timer = 600
|
change_timer = 600
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- setup for multiple screens at once
|
||||||
|
-- the 'screen' argument can be a table of screen objects
|
||||||
|
bling.module.wallpaper.setup {
|
||||||
|
set_function = bling.module.wallpaper.setters.random,
|
||||||
|
screen = screen, -- The awesome 'screen' variable is an array of all screen objects
|
||||||
|
wallpaper = {"/path/to/a/folder", "/path/to/another/folder"},
|
||||||
|
change_timer = 631
|
||||||
|
}
|
||||||
```
|
```
|
||||||
### Details
|
### Details
|
||||||
|
|
||||||
|
@ -73,6 +82,11 @@ A wallpaper is one of the following elements:
|
||||||
* everything gears.wallpaper functions can manage (cairo surface, cairo pattern string)
|
* everything gears.wallpaper functions can manage (cairo surface, cairo pattern string)
|
||||||
* a list containing any of the elements above
|
* a list containing any of the elements above
|
||||||
|
|
||||||
|
To set up for multiple screens, two possible methods are:
|
||||||
|
* Call the `setup` function for each screen, passing the appropriate configuration and `screen` arg
|
||||||
|
* Call the `setup` function once, passing a table of screens as the `screen` arg. This applies the same configuration to all screens in the table
|
||||||
|
_Note_: Multiple screen setup only works for the `simple` and `random` setters
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
-- This is a valid wallpaper definition
|
-- This is a valid wallpaper definition
|
||||||
bling.module.wallpaper.setup {
|
bling.module.wallpaper.setup {
|
||||||
|
@ -100,6 +114,7 @@ Here are the defaults:
|
||||||
-- Default parameters
|
-- Default parameters
|
||||||
bling.module.wallpaper.setup {
|
bling.module.wallpaper.setup {
|
||||||
screen = nil, -- the screen to apply the wallpaper, as seen in gears.wallpaper functions
|
screen = nil, -- the screen to apply the wallpaper, as seen in gears.wallpaper functions
|
||||||
|
screens = nil, -- an array of screens to apply the wallpaper on. If 'screen' is also provided, this is overridden
|
||||||
change_timer = nil, -- the timer in seconds. If set, call the set_function every change_timer seconds
|
change_timer = nil, -- the timer in seconds. If set, call the set_function every change_timer seconds
|
||||||
set_function = nil, -- the setter function
|
set_function = nil, -- the setter function
|
||||||
|
|
||||||
|
|
|
@ -53,36 +53,37 @@ function apply(wallpaper_object, args)
|
||||||
args.offset = args.offset or { x = 0, y = 0 }
|
args.offset = args.offset or { x = 0, y = 0 }
|
||||||
args.scale = args.scale or 1
|
args.scale = args.scale or 1
|
||||||
local positions = {
|
local positions = {
|
||||||
["centered"] = function()
|
["centered"] = function(s)
|
||||||
gears.wallpaper.centered(
|
gears.wallpaper.centered(
|
||||||
wallpaper_object,
|
wallpaper_object,
|
||||||
args.screen,
|
s,
|
||||||
args.background,
|
args.background,
|
||||||
args.scale
|
args.scale
|
||||||
)
|
)
|
||||||
end,
|
end,
|
||||||
["tiled"] = function()
|
["tiled"] = function(s)
|
||||||
gears.wallpaper.tiled(wallpaper_object, args.screen, args.offset)
|
gears.wallpaper.tiled(wallpaper_object, s, args.offset)
|
||||||
end,
|
end,
|
||||||
["maximized"] = function()
|
["maximized"] = function(s)
|
||||||
gears.wallpaper.maximized(
|
gears.wallpaper.maximized(
|
||||||
wallpaper_object,
|
wallpaper_object,
|
||||||
args.screen,
|
s,
|
||||||
args.ignore_aspect,
|
args.ignore_aspect,
|
||||||
args.offset
|
args.offset
|
||||||
)
|
)
|
||||||
end,
|
end,
|
||||||
["fit"] = function()
|
["fit"] = function(s)
|
||||||
gears.wallpaper.fit(wallpaper_object, args.screen, args.background)
|
gears.wallpaper.fit(wallpaper_object, s, args.background)
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
local call_func = nil
|
||||||
if
|
if
|
||||||
type(wallpaper_object) == "string"
|
type(wallpaper_object) == "string"
|
||||||
and gears.filesystem.file_readable(wallpaper_object)
|
and gears.filesystem.file_readable(wallpaper_object)
|
||||||
then
|
then
|
||||||
-- path of an image file, we use a position function
|
-- path of an image file, we use a position function
|
||||||
local p = args.position or "centered"
|
local p = args.position or "centered"
|
||||||
positions[p]()
|
call_func = positions[p]
|
||||||
elseif type(wallpaper_object) == "function" then
|
elseif type(wallpaper_object) == "function" then
|
||||||
-- function
|
-- function
|
||||||
wallpaper_object(args)
|
wallpaper_object(args)
|
||||||
|
@ -91,10 +92,13 @@ function apply(wallpaper_object, args)
|
||||||
and args.position
|
and args.position
|
||||||
then
|
then
|
||||||
-- if the user sets a position function, wallpaper_object should be a cairo surface
|
-- if the user sets a position function, wallpaper_object should be a cairo surface
|
||||||
positions[args.position]()
|
call_func = positions[args.position]
|
||||||
else
|
else
|
||||||
gears.wallpaper.set(wallpaper_object)
|
gears.wallpaper.set(wallpaper_object)
|
||||||
end
|
end
|
||||||
|
if call_func then
|
||||||
|
call_func(args.screen)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Converts `args.wallpaper` to a list of `wallpaper_objects` readable by `apply` function).
|
--- Converts `args.wallpaper` to a list of `wallpaper_objects` readable by `apply` function).
|
||||||
|
@ -154,7 +158,15 @@ local simple_index = 0
|
||||||
function setters.simple(args)
|
function setters.simple(args)
|
||||||
local wallpapers = prepare_list(args)
|
local wallpapers = prepare_list(args)
|
||||||
simple_index = (simple_index % #wallpapers) + 1
|
simple_index = (simple_index % #wallpapers) + 1
|
||||||
apply(wallpapers[simple_index], args)
|
if type(args.screen) == 'table' then
|
||||||
|
for _,v in ipairs(args.screen) do
|
||||||
|
args.screen = v
|
||||||
|
apply(wallpapers[simple_index], args)
|
||||||
|
args.screen = nil
|
||||||
|
end
|
||||||
|
else
|
||||||
|
apply(wallpapers[simple_index], args)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Set a random wallpaper from a list.
|
--- Set a random wallpaper from a list.
|
||||||
|
@ -164,7 +176,15 @@ end
|
||||||
-- @see prepare_list
|
-- @see prepare_list
|
||||||
function setters.random(args)
|
function setters.random(args)
|
||||||
local wallpapers = prepare_list(args)
|
local wallpapers = prepare_list(args)
|
||||||
apply(wallpapers[math.random(#wallpapers)], args)
|
if type(args.screen) == 'table' then
|
||||||
|
for _,v in ipairs(args.screen) do
|
||||||
|
args.screen = v
|
||||||
|
apply(wallpapers[math.random(#wallpapers)], args)
|
||||||
|
args.screen = nil
|
||||||
|
end
|
||||||
|
else
|
||||||
|
apply(wallpapers[math.random(#wallpapers)], args)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local simple_schedule_object = nil
|
local simple_schedule_object = nil
|
||||||
|
@ -310,7 +330,10 @@ function setup(args)
|
||||||
config.set_function = config.set_function
|
config.set_function = config.set_function
|
||||||
or (config.wallpaper and setters.simple or setters.awesome_wallpaper)
|
or (config.wallpaper and setters.simple or setters.awesome_wallpaper)
|
||||||
local function set_wallpaper(s)
|
local function set_wallpaper(s)
|
||||||
config.screen = s or config.screen
|
if type(config.screen) ~= 'table' then
|
||||||
|
if config.screen and s and config.screen ~= s then return end
|
||||||
|
config.screen = s or config.screen
|
||||||
|
end
|
||||||
config.set_function(config)
|
config.set_function(config)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue