From f0b32f45746c026d402651013b7e98315d6956a1 Mon Sep 17 00:00:00 2001 From: delta Date: Sat, 4 Mar 2023 22:04:55 +0100 Subject: restructure awesome config, add fresnel --- .config/awesome/misc/helpers.lua | 121 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 .config/awesome/misc/helpers.lua (limited to '.config/awesome/misc/helpers.lua') diff --git a/.config/awesome/misc/helpers.lua b/.config/awesome/misc/helpers.lua new file mode 100644 index 0000000..132a4df --- /dev/null +++ b/.config/awesome/misc/helpers.lua @@ -0,0 +1,121 @@ +local awful = require "awful" +local gears = require "gears" +local xresources = require "beautiful.xresources" +local n = require "naughty".notification +local dpi = xresources.apply_dpi +local vars = require "misc.vars" +local wibox = require "wibox" + +local h = {} + +-- utils + +function h.debug(message) + n { message = tostring(message) } +end + +function h.map(t, f) + local nt = {} + for k,v in pairs(t) do + nt[k] = f(v) + end + return nt +end + +function h.filter(t, f, dict) + local nt = {} + for k,v in pairs(t) do + if not f(v) then goto continue end + if dict then + nt[k] = v + else + table.insert(nt, v) + end + ::continue:: + end + return nt +end + +-- This is taken from http://lua-users.org/wiki/SortedIteration +-- This version is stripped of comments and empty lines + some stuff is renamed + +local function __gen_oindex( t ) + local oindex = {} + for key in pairs(t) do + table.insert(oindex, key) + end + table.sort(oindex) + return oindex +end + +local function onext(t, state) + local key = nil + if state == nil then + t.__oindex = __gen_oindex(t) + key = t.__oindex[1] + else + for i = 1,#t.__oindex do + if t.__oindex[i] == state then + key = t.__oindex[i+1] + end + end + end + if key then + return key, t[key] + end + t.__oindex = nil +end + +function h.opairs(t) + return onext, t, nil +end + +-- markup + +function h.markup_fg(color, text) + return "" .. text .. "" +end + +function h.markup_bg(color, text) + return "" .. text .. "" +end + +-- ui + +function h.font(factor) + return vars.text_font .. " " .. vars.font_size * (factor or 1) +end + +function h.symbol_font(factor) + return vars.symbol_font .. " " .. vars.font_size * (factor or 1) +end + +function h.styled(target) + return gears.table.crush({ + bg = vars.colors.bg, + border_color = vars.colors.bright.black, + border_width = vars.border_width, + shape = vars.shape + }, target) +end + +function h.popup(args) + args.widget = { + widget = wibox.container.margin, + margins = vars.big_padding, + args.widget + } + + return awful.popup(h.styled(args)) +end + +function h.tooltip(objects, callback) + awful.tooltip(h.styled { + objects = objects, + timer_function = callback, + margin_leftright = vars.padding, + margin_topbottom = vars.padding + }) +end + +return h -- cgit v1.2.3