Refactor layout icon path search and also search in package.path (#137, closes #136)

This commit is contained in:
Nooo37 2021-11-06 19:33:58 +01:00 committed by GitHub
parent e4fd438e3e
commit 92dabc890e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 43 additions and 140 deletions

View File

@ -1,7 +1,4 @@
local awful = require("awful") local awful = require("awful")
local gears = require("gears")
local gcolor = require("gears.color")
local beautiful = require("beautiful")
local math = math local math = math
local mylayout = {} local mylayout = {}
@ -58,6 +55,7 @@ function mylayout.arrange(p)
-- iterate through slaves -- iterate through slaves
for idx = 1, nslaves do -- idx=nmaster+1,#p.clients do for idx = 1, nslaves do -- idx=nmaster+1,#p.clients do
local c = p.clients[idx + nmaster] local c = p.clients[idx + nmaster]
local g
if idx % 2 == 0 then if idx % 2 == 0 then
g = { g = {
x = area.x, x = area.x,
@ -83,20 +81,4 @@ function mylayout.arrange(p)
end end
end end
local icon_raw = gears.filesystem.get_configuration_dir() return mylayout
.. tostring(...):match("^.*bling"):gsub("%.", "/")
.. "/icons/layouts/centered.png"
local function get_icon()
if icon_raw ~= nil then
return gcolor.recolor_image(icon_raw, beautiful.fg_normal)
else
return nil
end
end
return {
layout = mylayout,
icon_raw = icon_raw,
get_icon = get_icon,
}

View File

@ -1,8 +1,3 @@
local awful = require("awful")
local gears = require("gears")
local gcolor = require("gears.color")
local beautiful = require("beautiful")
local mylayout = {} local mylayout = {}
mylayout.name = "deck" mylayout.name = "deck"
@ -39,20 +34,4 @@ function mylayout.arrange(p)
end end
end end
local icon_raw = gears.filesystem.get_configuration_dir() return mylayout
.. tostring(...):match("^.*bling"):gsub("%.", "/")
.. "/icons/layouts/deck.png"
local function get_icon()
if icon_raw ~= nil then
return gcolor.recolor_image(icon_raw, beautiful.fg_normal)
else
return nil
end
end
return {
layout = mylayout,
icon_raw = icon_raw,
get_icon = get_icon,
}

View File

@ -1,6 +1,3 @@
local gears = require("gears")
local gcolor = require("gears.color")
local beautiful = require("beautiful")
local math = math local math = math
local screen = screen local screen = screen
local mylayout = {} local mylayout = {}
@ -77,20 +74,4 @@ function mylayout.arrange(p)
divide(p, g, 1, #cls, cls, mwfact, mcount) divide(p, g, 1, #cls, cls, mwfact, mcount)
end end
local icon_raw = gears.filesystem.get_configuration_dir() return mylayout
.. tostring(...):match("^.*bling"):gsub("%.", "/")
.. "/icons/layouts/equalarea.png"
local function get_icon()
if icon_raw ~= nil then
return gcolor.recolor_image(icon_raw, beautiful.fg_normal)
else
return nil
end
end
return {
layout = mylayout,
icon_raw = icon_raw,
get_icon = get_icon,
}

View File

@ -1,7 +1,3 @@
local awful = require("awful")
local gears = require("gears")
local gcolor = require("gears.color")
local beautiful = require("beautiful")
local math = math local math = math
local mylayout = {} local mylayout = {}
@ -57,20 +53,4 @@ function mylayout.arrange(p)
end end
end end
local icon_raw = gears.filesystem.get_configuration_dir() return mylayout
.. tostring(...):match("^.*bling"):gsub("%.", "/")
.. "/icons/layouts/horizontal.png"
local function get_icon()
if icon_raw ~= nil then
return gcolor.recolor_image(icon_raw, beautiful.fg_normal)
else
return nil
end
end
return {
layout = mylayout,
icon_raw = icon_raw,
get_icon = get_icon,
}

View File

@ -1,30 +1,44 @@
local beautiful = require("beautiful") local beautiful = require("beautiful")
local gears = require("gears")
local mstab = require(... .. ".mstab") local M = {}
beautiful.layout_mstab = mstab.get_icon() local relative_lua_path = tostring(...)
local vertical = require(... .. ".vertical") local function get_layout_icon_path(name)
beautiful.layout_vertical = vertical.get_icon() local relative_icon_path = relative_lua_path
:match("^.*bling"):gsub("%.", "/")
.. "/icons/layouts/" .. name .. ".png"
local horizontal = require(... .. ".horizontal") for p in package.path:gmatch('([^;]+)') do
beautiful.layout_horizontal = horizontal.get_icon() p = p:gsub("?.*", "")
local absolute_icon_path = p .. relative_icon_path
if gears.filesystem.file_readable(absolute_icon_path) then
return absolute_icon_path
end
end
end
local centered = require(... .. ".centered") local function get_icon(icon_raw)
beautiful.layout_centered = centered.get_icon() if icon_raw ~= nil then
return gears.color.recolor_image(icon_raw, beautiful.fg_normal)
else
return nil
end
end
local equalarea = require(... .. ".equalarea") local layouts = {
beautiful.layout_equalarea = equalarea.get_icon() "mstab",
"vertical",
local deck = require(... .. ".deck") "horizontal",
beautiful.layout_deck = deck.get_icon() "centered",
"equalarea",
local layout = { "deck"
mstab = mstab.layout,
centered = centered.layout,
vertical = vertical.layout,
horizontal = horizontal.layout,
equalarea = equalarea.layout,
deck = deck.layout,
} }
return layout for _, layout_name in ipairs(layouts) do
local icon_raw = get_layout_icon_path(layout_name)
beautiful["layout_" .. layout_name] = get_icon(icon_raw)
M[layout_name] = require(... .. "." .. layout_name)
end
return M

View File

@ -1,7 +1,6 @@
local awful = require("awful") local awful = require("awful")
local gears = require("gears") local gears = require("gears")
local wibox = require("wibox") local wibox = require("wibox")
local gcolor = require("gears.color")
local beautiful = require("beautiful") local beautiful = require("beautiful")
local mylayout = {} local mylayout = {}
@ -242,16 +241,4 @@ function mylayout.arrange(p)
) )
end end
local icon_raw = gears.filesystem.get_configuration_dir() return mylayout
.. tostring(...):match("^.*bling"):gsub("%.", "/")
.. "/icons/layouts/mstab.png"
local function get_icon()
if icon_raw ~= nil then
return gcolor.recolor_image(icon_raw, beautiful.fg_normal)
else
return nil
end
end
return { layout = mylayout, icon_raw = icon_raw, get_icon = get_icon }

View File

@ -1,7 +1,3 @@
local awful = require("awful")
local gears = require("gears")
local gcolor = require("gears.color")
local beautiful = require("beautiful")
local math = math local math = math
local mylayout = {} local mylayout = {}
@ -57,20 +53,4 @@ function mylayout.arrange(p)
end end
end end
local icon_raw = gears.filesystem.get_configuration_dir() return mylayout
.. tostring(...):match("^.*bling"):gsub("%.", "/")
.. "/icons/layouts/vertical.png"
local function get_icon()
if icon_raw ~= nil then
return gcolor.recolor_image(icon_raw, beautiful.fg_normal)
else
return nil
end
end
return {
layout = mylayout,
icon_raw = icon_raw,
get_icon = get_icon,
}