cleanup and text placement tweak

This commit is contained in:
Izaya 2022-08-26 13:53:43 +10:00
parent d155461729
commit d081f4fb44

View File

@ -3,7 +3,6 @@ local wibox = require("wibox")
local gears = require("gears") local gears = require("gears")
local beautiful = require("beautiful") local beautiful = require("beautiful")
local menubar = require("menubar") local menubar = require("menubar")
local naughty = require "naughty"
local cairo = require("lgi").cairo local cairo = require("lgi").cairo
local Rsvg = require("lgi").Rsvg local Rsvg = require("lgi").Rsvg
local longpress = require("awesome-longpress") local longpress = require("awesome-longpress")
@ -12,40 +11,21 @@ local launcherpopup = {
spacing = 5, spacing = 5,
iconPath = gears.filesystem.get_configuration_dir() .. "/awesome-launcherpopup/", iconPath = gears.filesystem.get_configuration_dir() .. "/awesome-launcherpopup/",
updateOnSpawn = true, updateOnSpawn = true,
font = "sans",
fontSize = 15,
applications = {}, applications = {},
allInstances = {} allInstances = {}
} }
function launcherpopup.update() function launcherpopup.update()
naughty.notify({text="started update"})
menubar.menu_gen.generate(function(rv) menubar.menu_gen.generate(function(rv)
launcherpopup.applications = rv launcherpopup.applications = rv
for k,v in pairs(launcherpopup.allInstances) do for k,v in pairs(launcherpopup.allInstances) do
if k and v then if k and v then
w,e = pcall(v.populateMenu) w,e = pcall(v.populateMenu)
if not w then naughty.notify{text=e} end
end end
end end
end) end)
end end
local function tryLoadIcon(icon)
local img = icon
if dentry.icon:match("%.([^%.]+)$") == "svg" then
naughty.notify{text="is svg"}
img = cairo.ImageSurface(cairo.Format.ARGB32,launcherpopup.buttonsize,launcherpopup.buttonsize)
local cr = cairo.Context(img)
Rsvg.Handle.new_from_file(dentry.icon):render_cairo(cr)
end
return img
end
local function getFont(scale)
return string.format("%s %d",launcherpopup.font,launcherpopup.fontSize * (scale or 1))
end
function launcherpopup.new(s) function launcherpopup.new(s)
local menuStart = 1 local menuStart = 1
local launcherWidget = wibox.widget{ local launcherWidget = wibox.widget{
@ -113,9 +93,8 @@ function launcherpopup.new(s)
mwidget:add(mwicon) mwidget:add(mwicon)
local mwtext = wibox.container.constraint(wibox.widget{ local mwtext = wibox.container.constraint(wibox.widget{
widget = wibox.widget.textbox, widget = wibox.widget.textbox,
valign = center, valign = "top",
align = center, align = "center",
font = getFont(),
text = dentry.name text = dentry.name
},"exact",launcherpopup.buttonsize,launcherpopup.buttonsize * 0.5) },"exact",launcherpopup.buttonsize,launcherpopup.buttonsize * 0.5)
mwidget:add(mwtext) mwidget:add(mwtext)