dotfiles/awesome/components/pastel/top-panel.lua

167 lines
5.6 KiB
Lua
Raw Normal View History

2022-07-19 19:45:11 +02:00
-- ===================================================================
-- Initialization
-- ===================================================================
local awful = require("awful")
local beautiful = require("beautiful")
local wibox = require("wibox")
2022-07-19 22:11:37 +02:00
local theme = require("theme")
local lain = require("lain")
2022-07-27 01:43:14 +02:00
local tag_list = require("widgets.tag-list")
local layout_box = require("widgets.layout-box")
2022-07-21 17:11:07 +02:00
local battery_widget = require("widgets.battery-widget.battery")
local volume_widget = require("widgets.volume-widget.volume")
2022-07-22 14:47:26 +02:00
local pl = require("powerline")
2022-07-19 19:45:11 +02:00
-- import widgets
local task_list = require("widgets.task-list")
-- ===================================================================
2022-07-21 22:32:00 +02:00
-- Custom Widgets
2022-07-19 19:45:11 +02:00
-- ===================================================================
2022-07-21 22:32:00 +02:00
local top_panel = {}
2022-07-19 19:45:11 +02:00
2022-07-19 22:11:37 +02:00
local updates_indicator = wibox.widget{
{
layout = wibox.layout.fixed.horizontal,
{
{
widget = awful.widget.watch('bash -c "checkupdates | wc -l"', 360),
},
2022-07-21 23:26:42 +02:00
top = 0, bottom = 2, left = 0, right = 0,
2022-07-19 22:11:37 +02:00
widget = wibox.container.margin
},
2022-07-21 17:58:30 +02:00
{
{
image = "/usr/share/icons/Papirus/48x48/apps/org.kde.archUpdate.svg",
forced_width = 18,
widget = wibox.widget.imagebox,
},
2022-07-21 23:26:42 +02:00
top = 5, bottom = 0, left = 5, right = 0,
2022-07-21 17:58:30 +02:00
widget = wibox.container.margin
}
2022-07-19 22:11:37 +02:00
},
widget = wibox.container.background
}
2022-07-21 22:32:00 +02:00
local frequency_widget = wibox.widget{
layout = wibox.layout.fixed.horizontal,
awful.widget.watch('bash -c "/usr/bin/cat /proc/cpuinfo | grep MHz | cut -b 12- | sort -r | head -n 1 | xargs printf \'%f / 1000\n\' | bc -l | awk \'{printf \\"%.2f\\n\\", $0}\'"', 1),
wibox.widget.textbox('GHz')
}
local memory_widget = wibox.widget{
layout = wibox.layout.fixed.horizontal,
lain.widget.mem({
settings = function()
widget:set_markup(lain.util.markup.font(theme.font, mem_now.used .. " MB"))
end,
}),
}
local cpu_widget = wibox.widget{
layout = wibox.layout.fixed.horizontal,
lain.widget.cpu({
settings = function()
widget:set_markup(lain.util.markup.font(theme.font, "CPU: " .. cpu_now.usage .. "%"))
end,
})
}
2022-11-19 15:07:15 +01:00
local clock = wibox.widget.textclock('%a %b %d, %H:%M:%S', 1)
local tag_lists = {}
local current_tag_list = wibox.widget {
layout = wibox.layout.fixed.horizontal
}
local layout_boxes = {}
local current_layout_box = wibox.widget {
layout = wibox.layout.fixed.horizontal
}
local task_lists = {}
local current_task_list = wibox.widget {
layout = wibox.layout.fixed.horizontal
}
2022-07-21 22:32:00 +02:00
-- ===================================================================
-- Bar Creation
-- ===================================================================
2022-07-19 19:45:11 +02:00
top_panel.create = function(s)
2022-07-23 19:31:38 +02:00
local panel = awful.wibar({
screen = s,
position = "top",
ontop = true,
height = beautiful.top_panel_height,
width = s.geometry.width,
bg = theme.bg_normal .. "99"
})
for t in screen do
tag_lists[t] = tag_list.create(t)
layout_boxes[t] = layout_box.create(t)
end
current_tag_list:add(tag_lists[s])
current_layout_box:add(layout_boxes[s])
2022-07-23 19:31:38 +02:00
panel:setup {
expand = "none",
layout = wibox.layout.align.horizontal,
task_list.create(s),
current_tag_list,
2022-07-23 19:31:38 +02:00
{
layout = wibox.layout.fixed.horizontal,
pl(wibox.widget{}, theme.bg_normal .. "00", theme.top_panel_powerline),
pl(wibox.container.margin(wibox.widget.systray(), 0, 0, 5, 5), theme.top_panel_powerline, theme.bg_normal),
pl(volume_widget({widget_type='icon_and_text'}), theme.bg_normal, theme.top_panel_powerline),
pl(awful.widget.watch('bash -c "sensors | grep Tctl | cut -f 10 -d \' \' | cut -c 2-"', 5), theme.top_panel_powerline, theme.bg_normal),
pl(memory_widget, theme.bg_normal, theme.top_panel_powerline),
pl(cpu_widget, theme.top_panel_powerline, theme.bg_normal),
pl(frequency_widget, theme.bg_normal, theme.top_panel_powerline),
pl(updates_indicator, theme.top_panel_powerline, theme.bg_normal),
pl(current_layout_box, theme.bg_normal, theme.top_panel_powerline),
2022-11-19 15:07:15 +01:00
pl(clock, theme.top_panel_powerline, theme.top_panel_powerline),
2022-07-23 19:31:38 +02:00
}
}
-- ===================================================================
-- Functionality
-- ===================================================================
2023-01-15 20:16:02 +01:00
-- hide panel when client is fullscreen
local function change_panel_visibility(client)
if client.screen == s then
panel.ontop = not client.fullscreen
end
end
-- connect panel visibility function to relevant signals
client.connect_signal("property::fullscreen", change_panel_visibility)
client.connect_signal("focus", change_panel_visibility)
client.connect_signal("focus", function (c, _)
current_tag_list:reset(current_tag_list)
current_tag_list:add(tag_lists[c.screen])
current_layout_box:reset(current_layout_box)
current_layout_box:add(layout_boxes[c.screen])
end)
2022-07-23 19:31:38 +02:00
-- connect panel visibility function to relevant signals
updates_indicator:connect_signal("button::press", function(c, _, _, button)
awful.spawn.with_shell('WINIT_X11_SCALE_FACTOR=1 alacritty -e bash -c "yay ; echo \'\nDone, press any key to exit...\' ; read"')
2022-07-23 19:31:38 +02:00
end)
2022-07-19 22:11:37 +02:00
2022-11-19 15:07:15 +01:00
clock:connect_signal("button::press", function(c, _, _, button)
awful.spawn('gnome-calendar')
end)
2022-07-19 19:45:11 +02:00
end
return top_panel