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 gears = require("gears")
local gcolor = require("gears.color")
local beautiful = require("beautiful")
local math = math
local mylayout = {}
@ -58,6 +55,7 @@ function mylayout.arrange(p)
-- iterate through slaves
for idx = 1, nslaves do -- idx=nmaster+1,#p.clients do
local c = p.clients[idx + nmaster]
local g
if idx % 2 == 0 then
g = {
x = area.x,
@ -83,20 +81,4 @@ function mylayout.arrange(p)
end
end
local icon_raw = gears.filesystem.get_configuration_dir()
.. 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,
}
return mylayout

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 = {}
mylayout.name = "deck"
@ -39,20 +34,4 @@ function mylayout.arrange(p)
end
end
local icon_raw = gears.filesystem.get_configuration_dir()
.. 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,
}
return mylayout

View File

@ -1,6 +1,3 @@
local gears = require("gears")
local gcolor = require("gears.color")
local beautiful = require("beautiful")
local math = math
local screen = screen
local mylayout = {}
@ -77,20 +74,4 @@ function mylayout.arrange(p)
divide(p, g, 1, #cls, cls, mwfact, mcount)
end
local icon_raw = gears.filesystem.get_configuration_dir()
.. 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,
}
return mylayout

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 mylayout = {}
@ -57,20 +53,4 @@ function mylayout.arrange(p)
end
end
local icon_raw = gears.filesystem.get_configuration_dir()
.. 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,
}
return mylayout

View File

@ -1,30 +1,44 @@
local beautiful = require("beautiful")
local gears = require("gears")
local mstab = require(... .. ".mstab")
beautiful.layout_mstab = mstab.get_icon()
local M = {}
local relative_lua_path = tostring(...)
local vertical = require(... .. ".vertical")
beautiful.layout_vertical = vertical.get_icon()
local function get_layout_icon_path(name)
local relative_icon_path = relative_lua_path
:match("^.*bling"):gsub("%.", "/")
.. "/icons/layouts/" .. name .. ".png"
local horizontal = require(... .. ".horizontal")
beautiful.layout_horizontal = horizontal.get_icon()
for p in package.path:gmatch('([^;]+)') do
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")
beautiful.layout_centered = centered.get_icon()
local function get_icon(icon_raw)
if icon_raw ~= nil then
return gears.color.recolor_image(icon_raw, beautiful.fg_normal)
else
return nil
end
end
local equalarea = require(... .. ".equalarea")
beautiful.layout_equalarea = equalarea.get_icon()
local deck = require(... .. ".deck")
beautiful.layout_deck = deck.get_icon()
local layout = {
mstab = mstab.layout,
centered = centered.layout,
vertical = vertical.layout,
horizontal = horizontal.layout,
equalarea = equalarea.layout,
deck = deck.layout,
local layouts = {
"mstab",
"vertical",
"horizontal",
"centered",
"equalarea",
"deck"
}
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 gears = require("gears")
local wibox = require("wibox")
local gcolor = require("gears.color")
local beautiful = require("beautiful")
local mylayout = {}
@ -242,16 +241,4 @@ function mylayout.arrange(p)
)
end
local icon_raw = gears.filesystem.get_configuration_dir()
.. 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 }
return mylayout

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 mylayout = {}
@ -57,20 +53,4 @@ function mylayout.arrange(p)
end
end
local icon_raw = gears.filesystem.get_configuration_dir()
.. 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,
}
return mylayout