Add new notification-center module with various widgets, add rubato animations and other fixes and improvements

This commit is contained in:
Kievits Rene
2022-05-31 01:16:00 +02:00
parent 61ad7b2c50
commit 9049f5c51c
73 changed files with 4914 additions and 450 deletions

View File

@@ -0,0 +1,371 @@
-------------------------------------
-- This is the notification-center --
-------------------------------------
-- Awesome Libs
local awful = require("awful")
local color = require("src.theme.colors")
local dpi = require("beautiful").xresources.apply_dpi
local gears = require("gears")
local wibox = require("wibox")
-- Icon directory path
local icondir = awful.util.getdir("config") .. "src/assets/icons/notifications/"
return function(s)
--#region Activation area
local activation_area = awful.popup {
bg = '#00000000',
widget = wibox.container.background,
ontop = true,
screen = s,
type = 'dock',
placement = function(c)
awful.placement.top(c)
end,
}
activation_area:setup({
widget = wibox.container.background,
forced_height = dpi(1),
forced_width = dpi(300),
bg = '#00000000',
layout = wibox.layout.fixed.horizontal
})
--#endregion
--#region Widgets
local nl = require("src.modules.notification-center.notification_list").notification_list
local music_widget = require("src.modules.notification-center.song_info")()
local time_date = require("src.modules.notification-center.time_date")()
local weather_widget = require("src.modules.notification-center.weather")()
local profile_widget = require("src.modules.notification-center.profile")()
local status_bars_widget = require("src.modules.notification-center.status_bars")()
--#endregion
--#region Notification buttons
local clear_all_widget = wibox.widget { -- Clear all button
{
{
{
text = "Clear",
valign = "center",
align = "center",
widget = wibox.widget.textbox,
id = "clearall"
},
id = "background4",
fg = color["Grey900"],
bg = color["Blue200"],
shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, 12)
end,
forced_width = dpi(80),
forced_height = dpi(40),
widget = wibox.container.background
},
id = "margin3",
margins = dpi(10),
widget = wibox.container.margin
},
id = "place",
widget = wibox.container.place,
valign = "bottom",
halign = "right",
}
local left_button = wibox.widget {
{
{
widget = wibox.container.background,
bg = color["Grey700"],
shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, dpi(8))
end,
forced_height = dpi(30),
forced_width = dpi(30),
id = "circle"
},
left = dpi(5),
right = dpi(5),
widget = wibox.container.margin,
id = "margin"
},
visible = true,
valign = "center",
halign = "left",
widget = wibox.container.place,
}
local right_button = wibox.widget {
{
{
widget = wibox.container.background,
bg = color["Purple200"],
shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, dpi(8))
end,
forced_height = dpi(30),
forced_width = dpi(30),
id = "circle"
},
left = dpi(5),
right = dpi(5),
widget = wibox.container.margin,
id = "margin"
},
valign = "center",
halign = "right",
visible = false,
widget = wibox.container.place,
}
local toggle_button = wibox.widget {
{
left_button,
right_button,
widget = wibox.layout.flex.horizontal
},
active = false,
widget = wibox.container.background,
bg = color["Grey900"],
border_color = color["Grey800"],
border_width = dpi(2),
forced_height = dpi(40),
forced_width = dpi(80),
shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, dpi(10))
end,
}
toggle_button:connect_signal(
"button::press",
function()
if toggle_button.active then
left_button.visible = true
right_button.visible = false
toggle_button.active = not toggle_button.active
toggle_button.border_color = color["Grey800"]
user_vars.dnd = false
else
left_button.visible = false
right_button.visible = true
toggle_button.active = not toggle_button.active
toggle_button.border_color = color["Purple200"]
user_vars.dnd = true
end
end
)
local dnd = wibox.widget { -- Clear all button
{
{
{
{
text = "Do Not Disturb",
valign = "center",
align = "center",
widget = wibox.widget.textbox,
id = "clearall"
},
toggle_button,
spacing = dpi(10),
layout = wibox.layout.fixed.horizontal,
id = "layout12"
},
id = "background4",
fg = color["Pink200"],
shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, 12)
end,
forced_height = dpi(40),
widget = wibox.container.background
},
id = "margin3",
margins = dpi(10),
widget = wibox.container.margin
},
id = "place",
widget = wibox.container.place,
valign = "bottom",
halign = "right",
}
-- TODO: Add rubato animation. For this the widget needs to be rewritten to use a single moving square
local no_notification_widget = wibox.widget {
{
{
valign = "center",
halign = "center",
resize = true,
forced_height = dpi(200),
forced_width = dpi(200),
image = icondir .. "megamind.svg",
widget = wibox.widget.imagebox,
id = "icon"
},
{
id = "txt",
markup = "<span color='#414141' font='JetBrainsMono Nerd Font, ExtraBold 20'>No Notifications?</span>",
valign = "center",
halign = "center",
widget = wibox.widget.textbox
},
id = "lay",
layout = wibox.layout.fixed.vertical
},
valign = "center",
halign = "center",
widget = wibox.container.place
}
--#endregion
--#region Notification center
local notification_center = awful.popup {
widget = wibox.container.background,
bg = color["Grey900"],
border_color = color["Grey800"],
border_width = dpi(4),
placement = function(c)
awful.placement.top(c, { margins = dpi(10) })
end,
ontop = true,
screen = s,
visible = false,
shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, 12)
end,
}
-- TODO: Currently awesome doesn't come with a scroll container, there is a PR(#3309) and once its merged we can use it
local function notification_center_setup()
notification_center:setup({
widget = notification_center,
-- Custom widgets
{
time_date,
require("src.modules.notification-center.spacingline_widget")(),
{
{
weather_widget,
{
profile_widget,
layout = wibox.layout.fixed.vertical
},
layout = wibox.layout.fixed.horizontal
},
layout = wibox.layout.fixed.horizontal
},
status_bars_widget,
music_widget,
layout = wibox.layout.fixed.vertical
},
-- Notification list
{
{
{
nl,
height = dpi(680),
strategy = "max",
widget = wibox.container.constraint
},
{
no_notification_widget,
strategy = "max",
height = dpi(400),
widget = wibox.container.constraint
},
{
dnd,
nil,
clear_all_widget,
layout = wibox.layout.align.horizontal
},
id = "layout5",
layout = wibox.layout.align.vertical
},
id = "margin6",
margins = dpi(20),
widget = wibox.container.margin
},
id = "yes",
spacing_widget = {
{
fg = color["Grey800"],
bg = color["Grey800"],
widget = wibox.container.background
},
top = dpi(40),
bottom = dpi(40),
widget = wibox.container.margin
},
spacing = dpi(1),
forced_height = dpi(800),
forced_width = dpi(1000),
layout = wibox.layout.flex.horizontal
})
end
--#endregion
--#region Signals
-- Toggle notification_center visibility when mouse is over activation_area
activation_area:connect_signal(
"mouse::enter",
function()
notification_center.visible = true
notification_center_setup()
end
)
-- Update the notification center popup and check if there are no notifications
awesome.connect_signal(
"notification_center:update::needed",
function()
if #nl == 0 then
math.randomseed(os.time())
local prob = math.random(1, 10)
if (prob == 5) or (prob == 6) then
no_notification_widget.lay.icon.image = icondir .. "megamind.svg"
no_notification_widget.lay.txt.markup = "<span color='#414141' font='JetBrainsMono Nerd Font, ExtraBold 20'>No Notifications?</span>"
else
no_notification_widget.lay.icon.image = icondir .. "bell-outline.svg"
no_notification_widget.lay.txt.markup = "<span color='#414141' font='JetBrainsMono Nerd Font, ExtraBold 20'>No Notification</span>"
end
no_notification_widget.visible = true
else
no_notification_widget.visible = false
end
notification_center_setup()
end
)
-- Hide notification_center when mouse leaves it
notification_center:connect_signal(
"mouse::leave",
function()
notification_center.visible = false
end
)
-- Clear all notifications on button press
clear_all_widget:connect_signal(
"button::press",
function()
local size = #nl
for i = 0, size do
nl[i] = nil
end
awesome.emit_signal("notification_center:update::needed")
end
)
Hover_signal(clear_all_widget, color["Blue200"], color["Grey900"])
--#endregion
end

View File

@@ -0,0 +1,261 @@
-------------------------------------
-- This is the notification-center --
-------------------------------------
-- Awesome Libs
local awful = require("awful")
local color = require("src.theme.colors")
local dpi = require("beautiful").xresources.apply_dpi
local gears = require("gears")
local wibox = require("wibox")
local naughty = require("naughty")
-- Icon directory path
local icondir = awful.util.getdir("config") .. "src/assets/icons/notifications/"
local nl = {}
nl.notification_list = { layout = wibox.layout.fixed.vertical, spacing = dpi(20) }
-- @param {table} notification
-- @return {widget} notifications_list
function nl.create_notification(n)
n.time = os.time()
local time_ago_text = "- ago"
local timer_widget = wibox.widget {
{
{
text = time_ago_text,
widget = wibox.widget.textbox,
id = "txt"
},
id = "background",
fg = color["Teal200"],
widget = wibox.container.background
},
margins = dpi(10),
widget = wibox.container.margin,
}
gears.timer {
timeout = 1,
autostart = true,
call_now = true,
callback = function()
local time_ago = math.floor(os.time() - n.time)
local timer_text = timer_widget.background.txt
if time_ago < 5 then
timer_text:set_text("now")
elseif time_ago < 60 then
timer_text:set_text(time_ago .. "s ago")
elseif time_ago < 3600 then
timer_text:set_text(math.floor(time_ago / 60) .. "m ago")
elseif time_ago < 86400 then
timer_text:set_text(math.floor(time_ago / 3600) .. "h ago")
else
timer_text:set_text(math.floor(time_ago / 86400) .. "d ago")
end
end
}
local close_widget = wibox.widget {
{
{
{
{
font = user_vars.font.specify .. ", 10",
text = "",
align = "center",
valign = "center",
widget = wibox.widget.textbox
},
start_angle = 4.71239,
thickness = dpi(2),
min_value = 0,
max_value = 360,
value = 360,
widget = wibox.container.arcchart,
id = "arc_chart"
},
id = "background",
fg = color["Teal200"],
widget = wibox.container.background
},
strategy = "exact",
width = dpi(20),
height = dpi(20),
widget = wibox.container.constraint,
id = "const"
},
margins = dpi(10),
widget = wibox.container.margin,
id = "arc_margin"
}
local timer_close_widget = timer_widget
local notification = wibox.widget {
{
{
{
{
{
{
{
{
{
{
image = gears.color.recolor_image(icondir .. "notification-outline.svg", color["Teal200"]),
resize = false,
widget = wibox.widget.imagebox
},
right = dpi(5),
widget = wibox.container.margin
},
{
markup = n.app_name or 'System Notification',
align = "center",
valign = "center",
widget = wibox.widget.textbox
},
layout = wibox.layout.fixed.horizontal
},
fg = color["Teal200"],
widget = wibox.container.background
},
margins = dpi(10),
widget = wibox.container.margin
},
nil,
{
timer_widget,
layout = wibox.layout.fixed.horizontal,
id = "arc_app_layout_2"
},
id = "arc_app_layout",
layout = wibox.layout.align.horizontal
},
id = "arc_app_bg",
border_color = color["Grey800"],
border_width = dpi(2),
widget = wibox.container.background
},
{
{
{
{
{
image = n.icon,
resize = true,
widget = wibox.widget.imagebox,
clip_shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, 10)
end
},
width = naughty.config.defaults.icon_size,
height = naughty.config.defaults.icon_size,
strategy = "exact",
widget = wibox.container.constraint
},
halign = "center",
valign = "top",
widget = wibox.container.place
},
id = "margin01",
left = dpi(20),
bottom = dpi(15),
top = dpi(15),
right = dpi(10),
widget = wibox.container.margin
},
{
{
{
markup = n.title,
widget = wibox.widget.textbox,
align = "left"
},
{
markup = n.message,
widget = wibox.widget.textbox,
align = "left"
},
layout = wibox.layout.fixed.vertical
},
left = dpi(10),
bottom = dpi(10),
top = dpi(10),
right = dpi(20),
widget = wibox.container.margin
},
layout = wibox.layout.fixed.horizontal
},
id = "widget_layout",
layout = wibox.layout.fixed.vertical
},
id = "min_size",
strategy = "min",
width = dpi(100),
widget = wibox.container.constraint
},
id = "max_size",
strategy = "max",
width = Theme.notification_max_width or dpi(500),
widget = wibox.container.constraint
},
pk = #nl.notification_list + 1,
bg = color["Grey900"],
border_color = color["Grey800"],
border_width = dpi(4),
shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, 8)
end,
widget = wibox.container.background
}
close_widget:connect_signal(
"button::press",
function(_, _, _, button)
if button == 1 then
for i, b in pairs(nl.notification_list) do
if b.pk == notification.pk then
table.remove(nl.notification_list, i)
awesome.emit_signal("notification_center:update::needed")
break
end
end
end
end
)
Hover_signal(close_widget.const.background, color["Grey900"], color["Teal200"])
notification:connect_signal(
"mouse::enter",
function()
notification:get_children_by_id("arc_app_layout_2")[1]:set(1, close_widget)
end
)
notification:connect_signal(
"mouse::leave",
function()
notification:get_children_by_id("arc_app_layout_2")[1]:set(1, timer_close_widget)
end
)
table.insert(nl.notification_list, notification)
end
naughty.connect_signal(
"request::display",
function(n)
nl.create_notification(n)
awesome.emit_signal("notification_center:update::needed")
end
)
return nl

View File

@@ -0,0 +1,207 @@
--------------------------------
-- This is the profile widget --
--------------------------------
-- Awesome Libs
local awful = require("awful")
local color = require("src.theme.colors")
local dpi = require("beautiful").xresources.apply_dpi
local gears = require("gears")
local wibox = require("wibox")
-- Icon directory path
local icondir = awful.util.getdir("config") .. "src/assets/icons/profile/"
return function()
local profile_widget = wibox.widget {
{
{
{
{
{
{
image = gears.surface.load_uncached(awful.util.getdir("config") .. "src/assets/userpfp/crylia.png"),
id = "icon",
valign = "center",
halign = "center",
clip_shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, dpi(12))
end,
widget = wibox.widget.imagebox
},
strategy = "exact",
widget = wibox.container.constraint
},
id = "icon_margin",
margins = dpi(20),
widget = wibox.container.margin
},
{
{
{
{
{ -- Username
id = "username_prefix",
image = gears.color.recolor_image(icondir .. "user.svg", color["Blue200"]),
valign = "center",
halign = "left",
resize = false,
widget = wibox.widget.imagebox
},
{ -- Username
id = "username",
valign = "center",
align = "left",
widget = wibox.widget.textbox
},
spacing = dpi(10),
layout = wibox.layout.fixed.horizontal
},
{
{
id = "os_prefix",
image = gears.color.recolor_image(icondir .. "laptop.svg", color["Blue200"]),
valign = "center",
halign = "left",
resize = false,
widget = wibox.widget.imagebox
},
{ -- OS
id = "os",
valign = "center",
align = "left",
widget = wibox.widget.textbox
},
spacing = dpi(10),
layout = wibox.layout.fixed.horizontal
},
{
{
id = "kernel_prefix",
image = gears.color.recolor_image(icondir .. "penguin.svg", color["Blue200"]),
valign = "center",
halign = "left",
resize = false,
widget = wibox.widget.imagebox
},
{ -- Kernel
id = "kernel",
valign = "center",
align = "left",
widget = wibox.widget.textbox
},
spacing = dpi(10),
layout = wibox.layout.fixed.horizontal
},
{
{
id = "uptime_prefix",
image = gears.color.recolor_image(icondir .. "clock.svg", color["Blue200"]),
valign = "center",
halign = "left",
resize = false,
widget = wibox.widget.imagebox
},
{ -- Uptime
id = "uptime",
valign = "center",
align = "left",
widget = wibox.widget.textbox
},
spacing = dpi(10),
id = "uptime_layout",
layout = wibox.layout.fixed.horizontal
},
spacing = dpi(5),
id = "info_layout",
layout = wibox.layout.flex.vertical
},
id = "text_margin",
widget = wibox.container.constraint
},
id = "text_container",
bottom = dpi(20),
left = dpi(20),
widget = wibox.container.margin
},
id = "text_container_wrapper",
widget = wibox.layout.fixed.vertical
},
id = "wrapper",
fg = color["Green200"],
border_color = color["Grey800"],
border_width = dpi(4),
shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, dpi(8))
end,
widget = wibox.container.background
},
id = "const",
strategy = "exact",
width = dpi(250),
height = dpi(350),
widget = wibox.container.constraint
},
top = dpi(20),
left = dpi(10),
right = dpi(20),
bottom = dpi(10),
widget = wibox.container.margin
}
local function get_os_name_pretty()
awful.spawn.easy_async_with_shell(
"cat /etc/os-release | grep -w NAME",
function(stdout)
profile_widget:get_children_by_id("os")[1].text = stdout:match("\"(.+)\"")
end
)
end
-- function to get and set the kernel version
local function get_kernel_version()
awful.spawn.easy_async_with_shell(
"uname -r",
function(stdout)
profile_widget:get_children_by_id("kernel")[1].text = stdout:match("(%d+%.%d+%.%d+)")
end
)
end
--function to get the username and hostname
local function get_user_hostname()
awful.spawn.easy_async_with_shell(
"echo $USER@$(hostname)",
function(stdout)
profile_widget:get_children_by_id("username")[1].text = stdout:gsub("\n", "") or ""
end
)
end
-- function to fetch uptime async
local function get_uptime()
awful.spawn.easy_async_with_shell("uptime -p", function(stdout)
local hours = stdout:match("(%d+) hours") or 0
local minutes = stdout:match("(%d+) minutes") or 0
profile_widget:get_children_by_id("uptime")[1].text = hours .. "h, " .. minutes .. "m"
end)
end
get_os_name_pretty()
get_kernel_version()
get_user_hostname()
gears.timer {
timeout = 60,
autostart = true,
call_now = true,
callback = get_uptime
}
return profile_widget
end

View File

@@ -0,0 +1,466 @@
---------------------------
-- This is the song-info --
---------------------------
-- Awesome Libs
local awful = require("awful")
local color = require("src.theme.colors")
local dpi = require("beautiful").xresources.apply_dpi
local gears = require("gears")
local wibox = require("wibox")
local naughty = require("naughty")
-- Icon directory path
local icondir = awful.util.getdir("config") .. "src/assets/icons/notifications/"
return function(s)
--#region Music control button widgets
local function button_hover_effect(widget, svg, color, color2)
local mouse_enter = function()
widget.image = gears.surface.load_uncached(gears.color.recolor_image(icondir .. svg, color2))
local w = mouse.current_wibox
if w then
w.cursor = "hand1"
end
end
local mouse_leave = function()
widget.image = gears.surface.load_uncached(gears.color.recolor_image(icondir .. svg, color))
mouse.cursor = "left_ptr"
local w = mouse.current_wibox
if w then
w.cursor = "left_ptr"
end
end
widget:disconnect_signal("mouse::enter", mouse_enter)
widget:connect_signal("mouse::enter", mouse_enter)
widget:disconnect_signal("mouse::leave", mouse_leave)
widget:connect_signal("mouse::leave", mouse_leave)
end
local shuffle_button = wibox.widget {
resize = false,
image = gears.color.recolor_image(icondir .. "shuffle.svg", color["Grey800"]),
widget = wibox.widget.imagebox,
}
local function suffle_handler()
awful.spawn.easy_async_with_shell(
"playerctl shuffle",
function(stdout)
if stdout:match("On") then
awful.spawn.with_shell("playerctl shuffle off")
shuffle_button.image = gears.color.recolor_image(icondir .. "shuffle.svg", color["Grey800"])
else
awful.spawn.with_shell("playerctl shuffle on")
shuffle_button.image = gears.color.recolor_image(icondir .. "shuffle.svg", color["Green200"])
end
end
)
end
local function update_shuffle()
awful.spawn.easy_async_with_shell(
"playerctl shuffle",
function(stdout)
if stdout:match("On") then
shuffle_button.image = gears.color.recolor_image(icondir .. "shuffle.svg", color["Green200"])
else
shuffle_button.image = gears.color.recolor_image(icondir .. "shuffle.svg", color["Grey800"])
end
end
)
end
update_shuffle()
local repeat_button = wibox.widget {
resize = false,
image = gears.color.recolor_image(icondir .. "repeat.svg", color["Grey800"]),
widget = wibox.widget.imagebox,
id = "imagebox"
}
-- On first time load set the correct loop
local function update_loop()
awful.spawn.easy_async_with_shell(
"playerctl loop",
function(stdout)
local loop_mode = stdout:gsub("\n", "")
if loop_mode == "Track" then
repeat_button.image = gears.color.recolor_image(gears.surface.load_uncached(icondir .. "repeat-once.svg"), color["Green200"])
elseif loop_mode == "None" then
repeat_button.image = gears.color.recolor_image(gears.surface.load_uncached(icondir .. "repeat.svg"), color["Grey800"])
elseif loop_mode == "Playlist" then
repeat_button.image = gears.color.recolor_image(gears.surface.load_uncached(icondir .. "repeat.svg"), color["Green200"])
end
end
)
end
update_loop()
-- Activate shuffle when button is clicked
shuffle_button:buttons(gears.table.join(
awful.button({}, 1, suffle_handler)))
local prev_button = wibox.widget {
resize = false,
image = gears.color.recolor_image(icondir .. "skip-prev.svg", color["Teal200"]),
widget = wibox.widget.imagebox
}
-- Activate previous song when button is clicked
prev_button:buttons(gears.table.join(
awful.button({}, 1, function()
awful.spawn.easy_async_with_shell(
"playerctl previous && sleep 1",
function()
update_loop()
end
)
end)
))
local pause_play_button = wibox.widget {
resize = false,
image = gears.color.recolor_image(icondir .. "play-pause.svg", color["Teal200"]),
widget = wibox.widget.imagebox
}
-- Activate play/pause when button is clicked
pause_play_button:buttons(gears.table.join(
awful.button({}, 1, function()
awful.spawn.with_shell("playerctl play-pause")
end)
))
local next_button = wibox.widget {
resize = false,
image = gears.color.recolor_image(icondir .. "skip-next.svg", color["Teal200"]),
widget = wibox.widget.imagebox
}
-- Activate next song when button is clicked
next_button:buttons(gears.table.join(
awful.button({}, 1, function()
awful.spawn.easy_async_with_shell(
"playerctl next && sleep 1",
function()
update_loop()
end
)
end)
))
--- This function updates the repeat button svg and changes the mode on click
local function loop_handler()
awful.spawn.easy_async_with_shell(
"playerctl loop",
function(stdout)
local loop_mode = stdout:gsub("\n", "")
if loop_mode == "None" then
awful.spawn.with_shell("playerctl loop playlist")
repeat_button.image = gears.color.recolor_image(gears.surface.load_uncached(icondir .. "repeat.svg"), color["Green200"])
elseif loop_mode == "Playlist" then
awful.spawn.with_shell("playerctl loop track")
repeat_button.image = gears.color.recolor_image(gears.surface.load_uncached(icondir .. "repeat-once.svg"), color["Green200"])
elseif loop_mode == "Track" then
awful.spawn.with_shell("playerctl loop none")
repeat_button.image = gears.color.recolor_image(gears.surface.load_uncached(icondir .. "repeat.svg"), color["Grey800"])
end
end
)
end
repeat_button:buttons(gears.table.join(awful.button({}, 1, loop_handler)))
button_hover_effect(prev_button, "skip-prev.svg", color["Teal200"], color["Teal300"])
button_hover_effect(pause_play_button, "play-pause.svg", color["Teal200"], color["Teal300"])
button_hover_effect(next_button, "skip-next.svg", color["Teal200"], color["Teal300"])
--#endregion
-- Main music widget
local music_widget = wibox.widget {
{
{
{
{
{
{ -- Album art
{
image = "default image",
resize = true,
clip_shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, dpi(8))
end,
widget = wibox.widget.imagebox,
id = "imagebox"
},
width = dpi(80),
height = dpi(80),
strategy = "exact",
widget = wibox.container.constraint,
id = "const"
},
{
{
{
{
{ --Title
halign = "center",
align = "center",
widget = wibox.widget.textbox,
id = "textbox4"
},
fg = color["Pink200"],
id = "textbox5",
widget = wibox.container.background
},
strategy = "max",
width = dpi(400),
widget = wibox.container.constraint
},
halign = "center",
valign = "center",
id = "textbox_container4",
widget = wibox.container.place
},
{
{
{
{ --Artist
halign = "center",
align = "center",
widget = wibox.widget.textbox,
id = "textbox3"
},
fg = color["Teal200"],
id = "background",
widget = wibox.container.background
},
strategy = "max",
width = dpi(400),
widget = wibox.container.constraint
},
halign = "center",
valign = "center",
id = "artist_container",
widget = wibox.container.place
},
{ --Buttons
{
{
shuffle_button,
prev_button,
pause_play_button,
next_button,
repeat_button,
spacing = dpi(15),
layout = wibox.layout.fixed.horizontal,
id = "layout5"
},
halign = "center",
widget = wibox.container.place,
id = "place2"
},
widget = wibox.container.margin,
id = "margin6"
},
layout = wibox.layout.flex.vertical,
id = "layout4"
},
fill_space = true,
spacing = dpi(10),
layout = wibox.layout.fixed.horizontal,
id = "layout3"
},
widget = wibox.container.margin,
id = "margin5"
},
{ --Song Duration
{
{
{
markup = "0:00",
widget = wibox.widget.textbox,
id = "textbox2"
},
fg = color["Lime200"],
widget = wibox.container.background,
id = "background3"
},
right = dpi(10),
widget = wibox.container.margin,
id = "margin4"
},
{ -- Progressbar
{
color = color["Purple200"],
background_color = color["Grey800"],
max_value = 100,
value = 50,
forced_height = dpi(5),
shape = function(cr, width)
gears.shape.rounded_bar(cr, width, dpi(5))
end,
widget = wibox.widget.progressbar,
id = "progressbar1"
},
valign = "center",
halign = "center",
widget = wibox.container.place,
id = "place1"
},
{
{
{
text = "00:00",
widget = wibox.widget.textbox,
id = "text1"
},
id = "background2",
fg = color["Lime200"],
widget = wibox.container.background
},
id = "margin3",
left = dpi(10),
widget = wibox.container.margin
},
id = "layout2",
layout = wibox.layout.align.horizontal
},
id = "layout1",
spacing = dpi(10),
layout = wibox.layout.fixed.vertical
},
id = "margin2",
widget = wibox.container.margin,
margins = dpi(10)
},
id = "background1",
border_color = color["Grey800"],
border_width = dpi(4),
shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, dpi(8))
end,
widget = wibox.container.background
},
id = "margin1",
widget = wibox.container.margin,
top = dpi(10),
bottom = dpi(20),
left = dpi(20),
right = dpi(20)
}
-- Used to check if the music changed and if everthing should be updated
local trackid = ""
local artist = ""
local title = ""
-- Function to get spotify title, artist, album, album_art, length and track_id
local function get_spotify_metadata(skip_check)
skip_check = skip_check or false
awful.spawn.easy_async_with_shell(
"playerctl metadata",
function(stdout)
-- Only fetch info if the track changed or if the title/artist is empty
if skip_check or (not stdout:match(trackid)) or (not stdout:match(artist)) or (not stdout:match(title)) then
update_loop()
update_shuffle()
-- Get the song title
awful.spawn.easy_async_with_shell(
"playerctl metadata xesam:title",
function(stdout2)
local tit = stdout2:gsub("\n", "")
title = tit
music_widget:get_children_by_id("textbox4")[1].text = tit
end
)
-- Get the song artist
awful.spawn.easy_async_with_shell(
"playerctl metadata xesam:artist",
function(stdout2)
local art = stdout2:gsub("\n", "")
artist = art
music_widget:get_children_by_id("textbox3")[1].text = art
end
)
-- Get the song album image
awful.spawn.easy_async_with_shell(
"playerctl metadata mpris:artUrl",
function(album_art)
local url = album_art:gsub("\n", "")
awful.spawn.easy_async_with_shell(
-- TODO: curl does not stdout and is returns before it finished. This causes the image to sometimes not show correctly.
-- !Find a better solution than sleep 0.1
-- Maybe cache the image? Not sure if that would be a waste of space or not.
"curl -s " .. url .. " -o /tmp/album_art.jpg && echo /tmp/album_art.jpg && sleep 0.5",
function()
music_widget:get_children_by_id("imagebox")[1].image = gears.surface.load_uncached("/tmp/album_art.jpg")
end
)
end
)
-- Get the length of the song
awful.spawn.easy_async_with_shell(
"playerctl metadata mpris:length",
function(stdout2)
local length = stdout2:gsub("\n", "")
if length ~= "" then
local length_formated = string.format("%02d:%02d", math.floor(tonumber(length or 1) / 60000000) or 0, (math.floor(tonumber(length or 1) / 1000000) % 60) or 0)
music_widget:get_children_by_id("progressbar1")[1].max_value = tonumber(math.floor(tonumber(length) / 1000000))
music_widget:get_children_by_id("text1")[1].markup = string.format("<span foreground='%s' font='JetBrainsMono Nerd Font, Bold 14'>%s</span>", color["Teal200"], length_formated)
end
end
)
end
awful.spawn.easy_async_with_shell(
"playerctl metadata mpris:trackid",
function(stdout2)
trackid = stdout2:gsub("\n", "")
end
)
-- Update track id
trackid, artist, title = stdout, music_widget:get_children_by_id("textbox3")[1].text, music_widget:get_children_by_id("textbox4")[1].text
end
)
-- Always update the current song progression
awful.spawn.easy_async_with_shell(
"playerctl position",
function(stdout)
local time = stdout:gsub("\n", "")
if time ~= "" then
local time_formated = string.format("%02d:%02d", math.floor(tonumber(time or "1") / 60), math.floor(tonumber(time or "1")) % 60)
music_widget:get_children_by_id("textbox2")[1].markup = string.format("<span foreground='%s' font='JetBrainsMono Nerd Font, Bold 14'>%s</span>", color["Teal200"], time_formated)
music_widget:get_children_by_id("progressbar1")[1].value = tonumber(time)
end
end
)
end
-- Call every second, if performance is bad, set the timer to a higher value
gears.timer {
timeout = 1,
autostart = true,
call_now = true,
callback = function()
get_spotify_metadata()
end
}
-- get_spotify_metadata() on awesome reload
awesome.connect_signal("startup", function()
get_spotify_metadata(true)
end)
return music_widget
end

View File

@@ -0,0 +1,23 @@
------------------------------------------------
-- This is the spacing widget under the clock --
------------------------------------------------
-- Awesome Libs
local color = require("src.theme.colors")
local dpi = require("beautiful").xresources.apply_dpi
local wibox = require("wibox")
return function()
return wibox.widget {
{
forced_height = dpi(2),
bg = color["Grey800"],
widget = wibox.container.background
},
left = dpi(80),
right = dpi(80),
widget = wibox.container.margin
}
end

View File

@@ -0,0 +1,712 @@
------------------------------------
-- This is the status_bars widget --
------------------------------------
-- Awesome Libs
local awful = require("awful")
local color = require("src.theme.colors")
local dpi = require("beautiful").xresources.apply_dpi
local gears = require("gears")
local wibox = require("wibox")
local rubato = require("src.lib.rubato")
-- Icon directory path
local icondir = awful.util.getdir("config") .. "src/assets/icons/"
--- Signal bars widget for the notification-center
---@return wibox.widget
return function()
---Creates a layout with bar widgets based on the given table
---@param widget_table string{}
---@return table @{layout}
local function create_bar_layout(widget_table)
local bar_layout = { layout = wibox.layout.flex.horizontal, spacing = dpi(10) }
for _, widget in pairs(widget_table) do
local w
if widget == "cpu_usage" then
w = wibox.widget {
{
{
{ --Bar
color = color["Blue200"],
background_color = color["Grey800"],
max_value = 100,
value = 0,
forced_height = dpi(8),
shape = function(cr, width, heigth)
gears.shape.rounded_bar(cr, dpi(58), dpi(8))
end,
id = "progressbar1",
widget = wibox.widget.progressbar
},
id = "background1",
halign = "center",
valign = "center",
widget = wibox.container.place
},
id = "background2",
forced_height = dpi(58), --120 Base size - (10+10) margin - (4+4) Border - 24 Icon - 10 spacing = 58
forced_width = dpi(24),
direction = "east",
widget = wibox.container.rotate
},
{
{ --Icon
image = gears.color.recolor_image(icondir .. "cpu/cpu.svg", color["Cyan200"]),
halign = "center",
valign = "center",
widget = wibox.widget.imagebox,
id = "icon1",
},
id = "background3",
height = dpi(24),
width = dpi(24),
widget = wibox.container.constraint
},
id = "cpu_layout",
spacing = dpi(10),
layout = wibox.layout.fixed.vertical
}
local bar = w:get_children_by_id("progressbar1")[1]
local rubato_timer = rubato.timed {
duration = 1,
pos = bar.value,
easing = rubato.linear,
subscribed = function(v)
bar.value = v
end
}
local tooltip = awful.tooltip {
objects = { w },
mode = "inside",
preferred_alignments = "middle",
margins = dpi(10)
}
awesome.connect_signal(
"update::cpu_usage_widget",
function(cpu_usage)
w:get_children_by_id("progressbar1")[1].value = cpu_usage
tooltip.text = "CPU Usage: " .. cpu_usage .. "%"
rubato_timer.target = cpu_usage
end
)
elseif widget == "cpu_temp" then
w = wibox.widget {
{
{
{ --Bar
color = color["Blue200"],
background_color = color["Grey800"],
max_value = 100,
value = 50,
forced_height = dpi(8),
shape = function(cr, width, heigth)
gears.shape.rounded_bar(cr, dpi(58), dpi(8))
end,
id = "progressbar1",
widget = wibox.widget.progressbar
},
id = "background1",
halign = "center",
valign = "center",
widget = wibox.container.place
},
id = "background2",
forced_height = dpi(58), --120 Base size - (10+10) margin - (4+4) Border - 24 Icon - 10 spacing = 58
forced_width = dpi(24),
direction = "east",
widget = wibox.container.rotate
},
{
{ --Icon
id = "icon1",
image = gears.color.recolor_image(icondir .. "cpu/thermometer.svg", color["Cyan200"]),
halign = "center",
valign = "center",
widget = wibox.widget.imagebox
},
id = "background3",
height = dpi(24),
width = dpi(24),
widget = wibox.container.constraint
},
id = "cpu_temp_layout",
spacing = dpi(10),
layout = wibox.layout.fixed.vertical
}
local bar = w:get_children_by_id("progressbar1")[1]
local rubato_timer = rubato.timed {
duration = 1,
pos = bar.value,
easing = rubato.linear,
subscribed = function(v)
bar.value = v
end
}
local tooltip = awful.tooltip {
objects = { w },
mode = "inside",
preferred_alignments = "middle",
margins = dpi(10)
}
awesome.connect_signal(
"update::cpu_temp_widget",
function(cpu_temp, cpu_temp_icon)
w:get_children_by_id("progressbar1")[1].value = cpu_temp
w:get_children_by_id("icon1")[1].image = gears.color.recolor_image(cpu_temp_icon, color["Blue200"])
tooltip.text = "CPU Temp: " .. cpu_temp .. "°C"
rubato_timer.target = cpu_temp
end
)
elseif widget == "ram_usage" then
w = wibox.widget {
{
{
{ --Bar
color = color["Red200"],
background_color = color["Grey800"],
max_value = 100,
value = 50,
forced_height = dpi(8),
shape = function(cr, width, heigth)
gears.shape.rounded_bar(cr, dpi(58), dpi(8))
end,
id = "progressbar1",
widget = wibox.widget.progressbar
},
id = "background1",
halign = "center",
valign = "center",
widget = wibox.container.place
},
id = "background2",
forced_height = dpi(58), --120 Base size - (10+10) margin - (4+4) Border - 24 Icon - 10 spacing = 58
forced_width = dpi(24),
direction = "east",
widget = wibox.container.rotate
},
{
{ --Icon
image = gears.color.recolor_image(icondir .. "cpu/ram.svg", color["Red200"]),
halign = "center",
valign = "center",
widget = wibox.widget.imagebox
},
height = dpi(24),
width = dpi(24),
widget = wibox.container.constraint
},
id = "ram_layout",
spacing = dpi(10),
layout = wibox.layout.fixed.vertical
}
local bar = w:get_children_by_id("progressbar1")[1]
local rubato_timer = rubato.timed {
duration = 1,
pos = bar.value,
easing = rubato.linear,
subscribed = function(v)
bar.value = v
end
}
local tooltip = awful.tooltip {
objects = { w },
mode = "inside",
preferred_alignments = "middle",
margins = dpi(10)
}
awesome.connect_signal(
"update::ram_widget",
function(ram_usage)
w:get_children_by_id("progressbar1")[1].value = ram_usage
tooltip.text = "RAM Usage: " .. ram_usage .. "%"
rubato_timer.target = ram_usage
end
)
elseif widget == "gpu_usage" then
w = wibox.widget {
{
{
{ --Bar
color = color["Green200"],
background_color = color["Grey800"],
max_value = 100,
value = 50,
forced_height = dpi(8),
shape = function(cr, width, heigth)
gears.shape.rounded_bar(cr, dpi(58), dpi(8))
end,
id = "progressbar1",
widget = wibox.widget.progressbar
},
id = "background1",
halign = "center",
valign = "center",
widget = wibox.container.place
},
id = "background2",
forced_height = dpi(58), --120 Base size - (10+10) margin - (4+4) Border - 24 Icon - 10 spacing = 58
forced_width = dpi(24),
direction = "east",
widget = wibox.container.rotate
},
{
{ --Icon
image = gears.color.recolor_image(icondir .. "cpu/gpu.svg", color["Green200"]),
halign = "center",
valign = "center",
widget = wibox.widget.imagebox
},
height = dpi(24),
width = dpi(24),
widget = wibox.container.constraint
},
id = "gpu_layout",
spacing = dpi(10),
layout = wibox.layout.fixed.vertical
}
local bar = w:get_children_by_id("progressbar1")[1]
local rubato_timer = rubato.timed {
duration = 1,
pos = bar.value,
easing = rubato.linear,
subscribed = function(v)
bar.value = v
end
}
local tooltip = awful.tooltip {
objects = { w },
mode = "inside",
preferred_alignments = "middle",
margins = dpi(10)
}
awesome.connect_signal(
"update::gpu_usage_widget",
function(gpu_usage)
w:get_children_by_id("progressbar1")[1].value = gpu_usage
tooltip.text = "GPU Usage: " .. gpu_usage .. "%"
rubato_timer.target = gpu_usage
end
)
elseif widget == "gpu_temp" then
w = wibox.widget {
{
{
{ --Bar
color = color["Green200"],
background_color = color["Grey800"],
max_value = 100,
value = 50,
forced_height = dpi(8),
shape = function(cr, width, heigth)
gears.shape.rounded_bar(cr, dpi(58), dpi(8))
end,
id = "progressbar1",
widget = wibox.widget.progressbar
},
id = "background1",
halign = "center",
valign = "center",
widget = wibox.container.place
},
id = "background2",
forced_height = dpi(58), --120 Base size - (10+10) margin - (4+4) Border - 24 Icon - 10 spacing = 58
forced_width = dpi(24),
direction = "east",
widget = wibox.container.rotate
},
{
{ --Icon
id = "icon1",
image = gears.color.recolor_image(icondir .. "cpu/gpu.svg", color["Green200"]),
halign = "center",
valign = "center",
widget = wibox.widget.imagebox
},
id = "background3",
height = dpi(24),
width = dpi(24),
widget = wibox.container.constraint
},
id = "gpu_temp_layout",
spacing = dpi(10),
layout = wibox.layout.fixed.vertical
}
local bar = w:get_children_by_id("progressbar1")[1]
local rubato_timer = rubato.timed {
duration = 1,
pos = bar.value,
easing = rubato.linear,
subscribed = function(v)
bar.value = v
end
}
local tooltip = awful.tooltip {
objects = { w },
mode = "inside",
preferred_alignments = "middle",
margins = dpi(10)
}
awesome.connect_signal(
"update::gpu_temp_widget",
function(gpu_temp, gpu_temp_icon)
w:get_children_by_id("progressbar1")[1].value = gpu_temp
w:get_children_by_id("icon1")[1].image = gears.color.recolor_image(gpu_temp_icon, color["Green200"])
tooltip.text = "GPU Temp: " .. gpu_temp .. "°C"
rubato_timer.target = gpu_temp
end
)
elseif widget == "volume" then
w = wibox.widget {
{
{
{ --Bar
color = color["Yellow200"],
background_color = color["Grey800"],
max_value = 100,
value = 50,
forced_height = dpi(8),
shape = function(cr, width, heigth)
gears.shape.rounded_bar(cr, dpi(58), dpi(8))
end,
id = "progressbar1",
widget = wibox.widget.progressbar
},
id = "background1",
halign = "center",
valign = "center",
widget = wibox.container.place
},
id = "background2",
forced_height = dpi(58), --120 Base size - (10+10) margin - (4+4) Border - 24 Icon - 10 spacing = 58
forced_width = dpi(24),
direction = "east",
widget = wibox.container.rotate
},
{
{ --Icon
id = "icon1",
image = gears.color.recolor_image(icondir .. "audio/volume-high.svg", color["Yellow200"]),
halign = "center",
valign = "center",
widget = wibox.widget.imagebox
},
id = "background3",
height = dpi(24),
width = dpi(24),
widget = wibox.container.constraint
},
id = "volume_layout",
spacing = dpi(10),
layout = wibox.layout.fixed.vertical
}
local bar = w:get_children_by_id("progressbar1")[1]
local rubato_timer = rubato.timed {
duration = 1,
pos = bar.value,
easing = rubato.linear,
subscribed = function(v)
bar.value = v
end
}
local tooltip = awful.tooltip {
objects = { w },
mode = "inside",
preferred_alignments = "middle",
margins = dpi(10)
}
awesome.connect_signal(
"update::volume_widget",
function(volume, volume_icon)
w:get_children_by_id("progressbar1")[1].value = volume
w:get_children_by_id("icon1")[1].image = gears.color.recolor_image(volume_icon, color["Yellow200"])
tooltip.text = "Volume: " .. volume .. "%"
rubato_timer.target = volume
end
)
elseif widget == "microphone" then
w = wibox.widget {
{
{
{ --Bar
color = color["Purple200"],
background_color = color["Grey800"],
max_value = 100,
value = 50,
forced_height = dpi(8),
shape = function(cr, width, heigth)
gears.shape.rounded_bar(cr, dpi(58), dpi(8))
end,
id = "progressbar1",
widget = wibox.widget.progressbar
},
id = "background1",
halign = "center",
valign = "center",
widget = wibox.container.place
},
id = "background2",
forced_height = dpi(58), --120 Base size - (10+10) margin - (4+4) Border - 24 Icon - 10 spacing = 58
forced_width = dpi(24),
direction = "east",
widget = wibox.container.rotate
},
{
{ --Icon
id = "icon1",
image = gears.color.recolor_image(icondir .. "audio/microphone.svg", color["Purple200"]),
halign = "center",
valign = "center",
widget = wibox.widget.imagebox
},
id = "background3",
height = dpi(24),
width = dpi(24),
widget = wibox.container.constraint
},
id = "microphone_layout",
spacing = dpi(10),
layout = wibox.layout.fixed.vertical
}
local bar = w:get_children_by_id("progressbar1")[1]
local rubato_timer = rubato.timed {
duration = 1,
pos = bar.value,
easing = rubato.linear,
subscribed = function(v)
bar.value = v
end
}
local tooltip = awful.tooltip {
objects = { w },
mode = "inside",
preferred_alignments = "middle",
margins = dpi(10)
}
awesome.connect_signal(
"update::microphone_widget",
function(microphone, microphone_icon)
w:get_children_by_id("progressbar1")[1].value = microphone
w:get_children_by_id("icon1")[1].image = gears.color.recolor_image(microphone_icon, color["Purple200"])
tooltip.text = "Microphone: " .. microphone .. "%"
rubato_timer.target = microphone
end
)
elseif widget == "backlight" then
w = wibox.widget {
{
{
{ --Bar
color = color["Pink200"],
background_color = color["Grey800"],
max_value = 100,
value = 50,
forced_height = dpi(8),
shape = function(cr, width, heigth)
gears.shape.rounded_bar(cr, dpi(58), dpi(8))
end,
id = "progressbar1",
widget = wibox.widget.progressbar
},
id = "background1",
halign = "center",
valign = "center",
widget = wibox.container.place
},
id = "background2",
forced_height = dpi(58), --120 Base size - (10+10) margin - (4+4) Border - 24 Icon - 10 spacing = 58
forced_width = dpi(24),
direction = "east",
widget = wibox.container.rotate
},
{
{ --Icon
id = "icon1",
image = gears.color.recolor_image(icondir .. "brightness/brightness-high.svg", color["Pink200"]),
halign = "center",
valign = "center",
widget = wibox.widget.imagebox
},
id = "background3",
height = dpi(24),
width = dpi(24),
widget = wibox.container.constraint
},
id = "brightness_layout",
spacing = dpi(10),
layout = wibox.layout.fixed.vertical
}
local bar = w:get_children_by_id("progressbar1")[1]
local rubato_timer = rubato.timed {
duration = 1,
pos = bar.value,
easing = rubato.linear,
subscribed = function(v)
bar.value = v
end
}
local tooltip = awful.tooltip {
objects = { w },
mode = "inside",
preferred_alignments = "middle",
margins = dpi(10)
}
awesome.connect_signal(
"update::backlight_widget",
function(backlight, backlight_icon)
w:get_children_by_id("progressbar1")[1].value = backlight
w:get_children_by_id("icon1")[1].image = gears.color.recolor_image(backlight_icon, color["Pink200"])
tooltip.text = "Backlight: " .. backlight .. "%"
rubato_timer.target = backlight
end
)
elseif widget == "battery" then
w = wibox.widget {
{
{
{ --Bar
color = color["Purple200"],
background_color = color["Grey800"],
max_value = 100,
value = 50,
forced_height = dpi(8),
shape = function(cr, width, heigth)
gears.shape.rounded_bar(cr, dpi(58), dpi(8))
end,
id = "progressbar1",
widget = wibox.widget.progressbar
},
id = "background1",
halign = "center",
valign = "center",
widget = wibox.container.place
},
id = "background2",
forced_height = dpi(58), --120 Base size - (10+10) margin - (4+4) Border - 24 Icon - 10 spacing = 58
forced_width = dpi(24),
direction = "east",
widget = wibox.container.rotate
},
{
{ --Icon
id = "icon1",
image = gears.color.recolor_image(icondir .. "battery/battery.svg", color["Purple200"]),
halign = "center",
valign = "center",
widget = wibox.widget.imagebox
},
id = "background3",
height = dpi(24),
width = dpi(24),
widget = wibox.container.constraint
},
id = "battery_layout",
spacing = dpi(10),
layout = wibox.layout.fixed.vertical
}
local bar = w:get_children_by_id("progressbar1")[1]
local rubato_timer = rubato.timed {
duration = 1,
pos = bar.value,
easing = rubato.linear,
subscribed = function(v)
bar.value = v
end
}
local tooltip = awful.tooltip {
objects = { w },
mode = "inside",
preferred_alignments = "middle",
margins = dpi(10)
}
awesome.connect_signal(
"update::battery_widget",
function(battery, battery_icon)
w:get_children_by_id("progressbar1")[1].value = battery
w:get_children_by_id("icon1")[1].image = gears.color.recolor_image(battery_icon, color["Purple200"])
tooltip.text = "Battery: " .. battery .. "%"
rubato_timer.target = battery
end
)
end
table.insert(bar_layout, w)
end
return bar_layout
end
local signal_bars = wibox.widget {
{
{
{
{
create_bar_layout({ "cpu_usage", "cpu_temp", "ram_usage", "battery", "microphone", "backlight", "volume", "gpu_temp", "gpu_usage" }),
width = dpi(480),
strategy = "exact",
widget = wibox.container.constraint
},
halign = "center",
valign = "center",
widget = wibox.container.place
},
magins = dpi(10),
layout = wibox.container.margin
},
forced_height = dpi(120),
forced_width = dpi(500),
border_color = color["Grey800"],
border_width = dpi(4),
shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, dpi(10))
end,
widget = wibox.container.background
},
top = dpi(10),
left = dpi(20),
right = dpi(20),
bottom = dpi(10),
widget = wibox.container.margin
}
return signal_bars
end

View File

@@ -0,0 +1,65 @@
----------------------------------
-- This is the time_date widget --
----------------------------------
-- Awesome Libs
local dpi = require("beautiful").xresources.apply_dpi
local wibox = require("wibox")
return function()
local time_date = wibox.widget {
{
{
{
{ -- Time
{
id = "label",
align = "center",
valign = "center",
format = "<span foreground='#18FFFF' font='JetBrainsMono Nerd Font, Bold 46'><b>%H:%M</b></span>",
widget = wibox.widget.textclock
},
widget = wibox.container.margin
},
{ -- Date and Day
{ -- Date
{
id = "label",
align = "left",
valign = "bottom",
format = "<span foreground='#69F0AE' font='JetBrainsMono Nerd Font, Regular 18'><b>%e</b></span><span foreground='#18FFFF' font='JetBrainsMono Nerd Font, Regular 18'><b> %b %Y</b></span>",
widget = wibox.widget.textclock
},
widget = wibox.container.margin
},
{ -- Day
{
id = "label",
align = "left",
valign = "top",
format = "<span foreground='#69F0AE' font='JetBrainsMono Nerd Font, Bold 20'><b>%A</b></span>",
widget = wibox.widget.textclock
},
widget = wibox.container.margin
},
layout = wibox.layout.flex.vertical
},
spacing = dpi(20),
layout = wibox.layout.fixed.horizontal
},
valign = "center",
halign = "center",
widget = wibox.container.place
},
id = "background",
widget = wibox.container.background
},
id = "margin",
margins = dpi(20),
widget = wibox.container.margin
}
return time_date
end

View File

@@ -0,0 +1,219 @@
--------------------------------
-- This is the weather widget --
--------------------------------
-- Awesome Libs
local awful = require("awful")
local color = require("src.theme.colors")
local dpi = require("beautiful").xresources.apply_dpi
local gears = require("gears")
local wibox = require("wibox")
local naughty = require("naughty")
local json_lua = require("src.lib.json-lua.json-lua")
-- Icon directory path
local icondir = awful.util.getdir("config") .. "src/assets/icons/weather/"
return function()
local api_secrets = {
key = user_vars.weather_secrets.key,
city_id = user_vars.weather_secrets.city_id,
unit = user_vars.weather_secrets.unit
}
local weather_widget = wibox.widget {
{
{
{
{
{
{ -- Icon
valign = "center",
align = "center",
resize = true,
forced_width = dpi(64),
forced_height = dpi(64),
widget = wibox.widget.imagebox,
id = "icon"
},
id = "place2",
valing = "center",
halign = "center",
widget = wibox.container.place
},
{ -- Temperature
text = "0°C",
valign = "center",
align = "center",
widget = wibox.widget.textbox,
font = "JetBrains Mono Bold 24",
id = "temp"
},
{ -- City, Country
text = "City, Country",
valign = "center",
align = "center",
widget = wibox.widget.textbox,
id = "city_country",
},
{
{ -- Description
text = "Description",
valign = "center",
align = "center",
widget = wibox.widget.textbox,
id = "description"
},
fg = color["LightBlue200"],
widget = wibox.container.background
},
{ -- line
forced_height = dpi(4),
forced_width = dpi(10),
bg = color["Grey800"],
widget = wibox.container.background,
id = "line"
},
{
{ -- Speed
{
image = gears.color.recolor_image(icondir .. "weather-windy.svg", color["OrangeA200"]),
resize = true,
forced_width = dpi(24),
forced_height = dpi(24),
widget = wibox.widget.imagebox
},
{
text = "",
valign = "center",
align = "center",
widget = wibox.widget.textbox,
id = "speed"
},
spacing = dpi(10),
id = "layout3",
layout = wibox.layout.fixed.horizontal
},
id = "place4",
halign = "center",
valign = "center",
widget = wibox.container.place
},
{
{ -- Humidity
{
forced_width = dpi(24),
forced_height = dpi(24),
widget = wibox.widget.imagebox,
image = gears.color.recolor_image(icondir .. "humidity.svg", color["OrangeA200"]),
id = "humidity_icon"
},
{
text = "",
valign = "center",
align = "center",
widget = wibox.widget.textbox,
id = "humidity"
},
spacing = dpi(10),
id = "layoutHum",
layout = wibox.layout.fixed.horizontal
},
halign = "center",
valign = "center",
widget = wibox.container.place
},
id = "lyt",
spacing = dpi(10),
layout = wibox.layout.fixed.vertical
},
margins = dpi(20),
widget = wibox.container.margin,
},
id = "center",
halign = "center",
valign = "center",
widget = wibox.container.place
},
id = "background",
border_color = color["Grey800"],
border_width = dpi(4),
shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, dpi(12))
end,
widget = wibox.container.background
},
id = "margin",
top = dpi(20),
left = dpi(20),
right = dpi(10),
bottom = dpi(10),
forced_width = dpi(250),
widget = wibox.container.margin
}
local function fetch_weather_data()
awful.spawn.easy_async_with_shell(
"curl -sf 'http://api.openweathermap.org/data/2.5/weather?id=" .. api_secrets.city_id .. "&units=" .. api_secrets.unit .. "&appid=" .. api_secrets.key .. "'",
function(stdout)
if not stdout:match('error') then
local weather_metadata = json_lua:decode(stdout)
if weather_metadata then
local temp = weather_metadata.main.temp
local humidity = weather_metadata.main.humidity
local city = weather_metadata.name
local country = weather_metadata.sys.country
local weather_icon = weather_metadata.weather[1].icon
local description = weather_metadata.weather[1].description
local speed = weather_metadata.wind.speed
local icon_table = {
["01d"] = "weather-sunny",
["01n"] = "weather-clear-night",
["02d"] = "weather-partly-cloudy",
["02n"] = "weather-night-partly-cloudy",
["03d"] = "weather-cloudy",
["03n"] = "weather-clouds-night",
["04d"] = "weather-cloudy",
["04n"] = "weather-cloudy",
["09d"] = "weather-rainy",
["09n"] = "weather-rainy",
["10d"] = "weather-partly-rainy",
["10n"] = "weather-partly-rainy",
["11d"] = "weather-pouring",
["11n"] = "weather-pouring",
["13d"] = "weather-snowy",
["13n"] = "weather-snowy",
["50d"] = "weather-fog",
["50n"] = "weather-fog"
}
weather_widget:get_children_by_id("icon")[1].image = icondir .. icon_table[weather_icon] .. ".svg"
weather_widget:get_children_by_id("temp")[1].text = math.floor(temp + 0.5) .. "°C"
weather_widget:get_children_by_id("city_country")[1].text = city .. ", " .. country
weather_widget:get_children_by_id("description")[1].text = description:sub(1, 1):upper() .. description:sub(2)
weather_widget:get_children_by_id("line")[1].bg = color["Grey800"]
weather_widget:get_children_by_id("speed")[1].text = speed .. " m/s"
weather_widget:get_children_by_id("humidity")[1].text = humidity .. "%"
end
end
end
)
end
fetch_weather_data()
gears.timer {
timeout = 900,
autostart = true,
callback = function()
fetch_weather_data()
end
}
return weather_widget
end