- add awesome-{memwidget,batterystat,fswidget}

- fix layout for tag buttons
- stack tag number on top of tag remove button
- replace clock to be clearer
This commit is contained in:
Izaya 2022-09-11 16:12:39 +10:00
parent 9e6879ca96
commit edda6d4508
1 changed files with 43 additions and 23 deletions

View File

@ -3,6 +3,9 @@ local wibox = require("wibox")
local gears = require("gears")
local beautiful = require("beautiful")
local longpress = require("awesome-longpress")
local batterystat = require("awesome-batterystat")
local memstat = require("awesome-memwidget")
local fswidget = require("awesome-fswidget")
local switcherpopup = {
iconSize = 128,
systraySize = 64,
@ -10,7 +13,6 @@ local switcherpopup = {
spacing = 5,
defaultLayout = awful.layout.suit.max,
iconPath = gears.filesystem.get_configuration_dir() .. "/awesome-switcherpopup/",
batteryPath = "/sys/class/power_supply/pad-battery/"
}
function switcherpopup.nextTagName(s)
print(#s.tags, #s.tags+1)
@ -24,16 +26,38 @@ function switcherpopup.new(s)
screen = s,
layout = wibox.layout.grid.vertical(math.floor(s.geometry.width / (switcherpopup.iconSize + switcherpopup.spacing)))
}
local clock = wibox.container.place(wibox.widget.textclock("%H:%M %Y-%m-%d"), "center", "center")
local tagindex = wibox.widget({widget = wibox.widget.textbox, align = "center"})
local clock = wibox.container.place(wibox.widget{
layout = wibox.layout.fixed.vertical,
wibox.widget{
widget = wibox.widget.textbox,
align = "center",
text = "time"
},
wibox.widget{
widget = wibox.widget.textbox,
align = "center",
text = "date"
}
})
function clock.update(self)
local naughty = require("naughty")
for k,v in ipairs(self.widget.children[1]) do
naughty.notify({text=tostring(k)..": "..tostring(v.text)})
end
self.widget.children[1].markup = string.format('<span size="xx-large">%s</span>',os.date("%H:%M"))
self.widget.children[2].markup = os.date("%Y-%m-%d")
end
local tagindex = wibox.widget({widget = wibox.widget.textbox, align = "center", valign = "center"})
local indicators = wibox.widget({layout=wibox.layout.grid.horizontal, spacing=5, mem, battery})
local unpack = unpack or table.unpack -- in Lua 5.1, table.unpack was just called 'unpack'
for k,v in ipairs({memstat, batterystat, fswidget}) do
indicators:add(unpack(v.all()))
end
local function updateSwitcherpopup()
tagindex.text = "Tag: "..tostring(awful.screen.focused().selected_tag.name)
local fp, fs = io.open(switcherpopup.batteryPath .. "/capacity","rb"), io.open(switcherpopup.batteryPath .. "/status","rb")
if fp and fs then
local status = fs:read()
tagindex.text = string.format("Battery: %s%%%s\n%s", fp:read(), status == "Charging" and "+" or "-", tagindex.text)
fp:close()
fs:close()
clock:update()
tagindex.markup = '<span size="xx-large" color="'..tostring(beautiful.bg_normal)..'">'..tostring(awful.screen.focused().selected_tag.name)..'</span>'
for k,v in ipairs(indicators) do
pcall(v.update, v)
end
tasklistWidget:reset()
for k,v in pairs(awful.screen.focused().selected_tag:clients()) do
@ -63,16 +87,14 @@ function switcherpopup.new(s)
end
end
screen.connect_signal("arrange",updateSwitcherpopup)
local function pictureButton(icon)
local rc = wibox.container.place(wibox.container.constraint(wibox.widget({
local function pictureButton(icon,text,fn,lfn)
local rc = wibox.container.constraint(wibox.widget({
widget=wibox.widget.imagebox,
forced_width = switcherpopup.buttonSize,
forced_height = switcherpopup.buttonSize,
image = switcherpopup.iconPath .. "/" .. icon
}),nil,switcherpopup.buttonSize,switcherpopup.buttonSize), "center", "top")
rc.content_fill_vertical = true
rc.content_fill_horizontal = true
return rc
}),nil,switcherpopup.buttonSize,switcherpopup.buttonSize)
return wibox.container.place(rc)
end
local close_button = pictureButton("window-close.svg")
close_button:buttons(gears.table.join(
@ -95,7 +117,7 @@ function switcherpopup.new(s)
popup.visible = false
end)
))
local destroy_tag_button = pictureButton("tag-destroy.svg")
local destroy_tag_button = pictureButton("tag-destroy.svg",s.selected_tag.name)
destroy_tag_button:buttons(gears.table.join(
destroy_tag_button:buttons(),
awful.button({}, 1, nil, function()
@ -130,19 +152,17 @@ function switcherpopup.new(s)
if nextTag > #s.tags then nextTag = 1 end
s.clients[1]:move_to_tag(s.tags[nextTag])
popup.visible = false
error("move attempted")
end
error("move failed?")
end)
local tagbuttons = wibox.widget({layout = wibox.layout.ratio.horizontal, spacing=0, prev_tag_button,create_tag_button,destroy_tag_button,next_tag_button,close_button})
local tagbuttons = wibox.widget({layout = wibox.layout.ratio.horizontal, prev_tag_button,create_tag_button,wibox.widget{layout=wibox.layout.stack, destroy_tag_button, tagindex},next_tag_button,close_button})
systray:set_screen(s)
systray:set_horizontal(true)
popup = awful.popup {
widget = {layout = wibox.layout.fixed.vertical, clock, tagindex, systray, tasklistWidget, wibox.container.constraint(tagbuttons, min, switcherpopup.buttonSize*5, switcherpopup.buttonSize)},
widget = {layout = wibox.layout.fixed.vertical, clock, wibox.container.place(indicators), wibox.container.place(systray), tasklistWidget, tagbuttons},
border_color = beautiful.border_focus,
border_width = 2,
ontop = true,
placement = awful.placement.centered,
ontop = true,
placement = awful.placement.centered,
visible = false,
}
function popup.show(self)