From 56e76a4baf5dcb5259d8478dbcc84b2feec49d3d Mon Sep 17 00:00:00 2001 From: Aire-One Date: Wed, 27 Nov 2024 01:51:29 +0100 Subject: [PATCH] feat(slots): make predefined slots HOF --- .cspell.json | 9 +++++-- spec/helper.lua | 12 ++++++++++ src/awesome-slot/slots/client.lua | 15 ++++++------ src/awesome-slot/slots/ruled.lua | 15 ++++++------ src/awesome-slot/slots/screen.lua | 39 +++++++++++++++++-------------- src/awesome-slot/slots/tag.lua | 8 ++++--- 6 files changed, 60 insertions(+), 38 deletions(-) diff --git a/.cspell.json b/.cspell.json index 8f98d0f..0847b86 100644 --- a/.cspell.json +++ b/.cspell.json @@ -2,7 +2,9 @@ "$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json", "version": "0.2", "useGitignore": true, - "ignorePaths": [".git"], + "ignorePaths": [ + ".git" + ], "enableGlobDot": true, "words": [ "Aire-One", @@ -14,7 +16,9 @@ "dryrun", "fatalwarnings", "fullscreen", + "halign", "hasitem", + "imagebox", "JohnnyMorganz", "keygrabber", "ldoc", @@ -30,6 +34,7 @@ "rockspec", "rockspecs", "staticfct", - "stylua" + "stylua", + "wibox" ] } diff --git a/spec/helper.lua b/spec/helper.lua index 40ef8cd..de070a5 100644 --- a/spec/helper.lua +++ b/spec/helper.lua @@ -16,3 +16,15 @@ package.loaded["ruled.notification"] = {} package.loaded["awful.keyboard"] = { append_client_keybindings = function() end, } + +package.loaded["awful.mouse"] = {} + +package.loaded["beautiful"] = {} + +package.loaded["wibox.widget.imagebox"] = {} + +package.loaded["wibox.container.tile"] = {} + +package.loaded["awful.wallpaper"] = {} + +package.loaded["awful.layout"] = {} diff --git a/src/awesome-slot/slots/client.lua b/src/awesome-slot/slots/client.lua index 085d49f..c1cf731 100644 --- a/src/awesome-slot/slots/client.lua +++ b/src/awesome-slot/slots/client.lua @@ -1,18 +1,17 @@ +local keyboard = require "awful.keyboard" +local mouse = require "awful.mouse" + local client_slots = {} function client_slots.append_mousebindings(params) - local mouse = require "awful.mouse" - - for _, bindings in pairs(params.mousebindings) do - mouse.append_client_mousebindings(bindings) + return function() + mouse.append_client_mousebindings(params.mousebindings) end end function client_slots.append_keybindings(params) - local keyboard = require "awful.keyboard" - - for _, bindings in pairs(params.keybindings) do - keyboard.append_client_keybindings(bindings) + return function() + keyboard.append_client_keybindings(params.keybindings) end end diff --git a/src/awesome-slot/slots/ruled.lua b/src/awesome-slot/slots/ruled.lua index d3debca..c8131c7 100644 --- a/src/awesome-slot/slots/ruled.lua +++ b/src/awesome-slot/slots/ruled.lua @@ -1,18 +1,17 @@ +local client = require "ruled.client" +local notification = require "ruled.notification" + local ruled_slots = {} function ruled_slots.append_client_rules(params) - local client = require "ruled.client" - - for _, rule in pairs(params.rules) do - client.append_rule(rule) + return function() + client.append_rules(params.rules) end end function ruled_slots.append_notification_rules(params) - local notification = require "ruled.notification" - - for _, rule in pairs(params.rules) do - notification.append_rule(rule) + return function() + notification.append_rules(params.rules) end end diff --git a/src/awesome-slot/slots/screen.lua b/src/awesome-slot/slots/screen.lua index 3752482..2167b54 100644 --- a/src/awesome-slot/slots/screen.lua +++ b/src/awesome-slot/slots/screen.lua @@ -1,22 +1,27 @@ +local beautiful = require "beautiful" +local imagebox = require "wibox.widget.imagebox" +local tile = require "wibox.container.tile" +local wallpaper = require "awful.wallpaper" + local screen_slots = {} -function screen_slots.wallpaper(screen, params) - local beautiful = require "beautiful" - local wallpaper = require "gears.wallpaper" - - params = params or { - wallpaper = beautiful.wallpaper, - } - - local w = params.wallpaper - - if w then - -- If wallpaper is a function, call it with the screen - if type(w) == "function" then - w = w(screen) - end - - wallpaper.maximized(w, screen, true) +function screen_slots.wallpaper(params) + return function(screen) + wallpaper { + screen = screen, + widget = { + { + image = params.wallpaper or beautiful.wallpaper, + upscale = true, + downscale = true, + widget = imagebox, + }, + valign = "center", + halign = "center", + tiled = false, + widget = tile, + }, + } end end diff --git a/src/awesome-slot/slots/tag.lua b/src/awesome-slot/slots/tag.lua index f6eb8ac..b362209 100644 --- a/src/awesome-slot/slots/tag.lua +++ b/src/awesome-slot/slots/tag.lua @@ -1,9 +1,11 @@ +local layout = require "awful.layout" + local tag_slots = {} function tag_slots.default_layouts(params) - local layout = require "awful.layout" - - layout.append_default_layouts(params.layouts) + return function() + layout.append_default_layouts(params.layouts) + end end return tag_slots