yes, I'm very commit lazy
This commit is contained in:
@@ -3,286 +3,303 @@
|
||||
-------------------------------------
|
||||
|
||||
-- Awesome Libs
|
||||
local awful = require("awful")
|
||||
local dpi = require("beautiful").xresources.apply_dpi
|
||||
local gears = require("gears")
|
||||
local wibox = require("wibox")
|
||||
local dnd_widget = require("awful.widget.toggle_widget")
|
||||
local dpi = require('beautiful').xresources.apply_dpi
|
||||
local gfilesystem = require('gears.filesystem')
|
||||
local base = require('wibox.widget.base')
|
||||
local wibox = require('wibox')
|
||||
local apopup = require('awful.popup')
|
||||
local aplacement = require('awful.placement')
|
||||
local gshape = require('gears.shape')
|
||||
local gcolor = require('gears.color')
|
||||
|
||||
local capi = {
|
||||
awesome = awesome,
|
||||
}
|
||||
-- Own Libs
|
||||
local dnd_widget = require('awful.widget.toggle_widget')
|
||||
local notification_list = require('src.modules.notification-center.widgets.notification_list')()
|
||||
local weather_widget = require('src.modules.notification-center.widgets.weather')()
|
||||
local profile_widget = require('src.modules.notification-center.widgets.profile')()
|
||||
local status_bars = require('src.modules.notification-center.widgets.status_bars')()
|
||||
local music_widget = require('src.modules.notification-center.widgets.song_info')()
|
||||
local hover = require('src.tools.hover')
|
||||
|
||||
-- Icon directory path
|
||||
local icondir = gears.filesystem.get_configuration_dir() .. "src/assets/icons/notifications/"
|
||||
local icondir = gfilesystem.get_configuration_dir() .. 'src/assets/icons/notifications/'
|
||||
|
||||
return function(s)
|
||||
local capi = {
|
||||
client = client,
|
||||
}
|
||||
|
||||
local dnd = dnd_widget({
|
||||
text = "Do not disturb",
|
||||
color = Theme_config.notification_center.dnd_color,
|
||||
fg = Theme_config.notification_center.dnd_fg,
|
||||
size = dpi(40)
|
||||
})
|
||||
local instance = nil
|
||||
|
||||
dnd:get_widget():connect_signal("dnd::toggle", function(enabled)
|
||||
User_config.dnd = enabled
|
||||
end)
|
||||
local info_center = {}
|
||||
|
||||
--#region Activation area
|
||||
function info_center:toggle()
|
||||
if self.container.visible then
|
||||
self.container.visible = false
|
||||
else
|
||||
self.container.visible = true
|
||||
end
|
||||
end
|
||||
|
||||
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,
|
||||
}
|
||||
function info_center.new(args)
|
||||
args = args or {}
|
||||
|
||||
activation_area:setup({
|
||||
widget = wibox.container.background,
|
||||
forced_height = dpi(1),
|
||||
forced_width = dpi(300),
|
||||
bg = '#00000000',
|
||||
layout = wibox.layout.fixed.horizontal
|
||||
})
|
||||
|
||||
capi.awesome.connect_signal(
|
||||
"notification_center_activation::toggle",
|
||||
function(screen, hide)
|
||||
if screen == s then
|
||||
activation_area.visible = hide
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
--#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
|
||||
local w = base.make_widget_from_value {
|
||||
{
|
||||
{
|
||||
{
|
||||
text = "Clear",
|
||||
valign = "center",
|
||||
align = "center",
|
||||
widget = wibox.widget.textbox,
|
||||
id = "clearall"
|
||||
{
|
||||
{
|
||||
{ -- Time
|
||||
halign = 'center',
|
||||
valign = 'center',
|
||||
format = "<span foreground='#18FFFF' font='JetBrainsMono Nerd Font, Bold 46'><b>%H:%M</b></span>",
|
||||
widget = wibox.widget.textclock,
|
||||
},
|
||||
{ -- Date and Day
|
||||
{ -- Date
|
||||
halign = 'left',
|
||||
valign = 'bottom',
|
||||
format = "<span foreground='#69F0AE' font='JetBrainsMono Nerd Font, Regular 18'><b>%d</b></span><span foreground='#18FFFF' font='JetBrainsMono Nerd Font, Regular 18'><b> %b %Y</b></span>",
|
||||
widget = wibox.widget.textclock,
|
||||
},
|
||||
{ -- Day
|
||||
halign = 'left',
|
||||
valign = 'top',
|
||||
format = "<span foreground='#69F0AE' font='JetBrainsMono Nerd Font, Bold 20'><b>%A</b></span>",
|
||||
widget = wibox.widget.textclock,
|
||||
},
|
||||
layout = wibox.layout.flex.vertical,
|
||||
},
|
||||
spacing = dpi(20),
|
||||
layout = wibox.layout.fixed.horizontal,
|
||||
},
|
||||
widget = wibox.container.place,
|
||||
},
|
||||
margins = dpi(20),
|
||||
widget = wibox.container.margin,
|
||||
},
|
||||
{
|
||||
{
|
||||
{
|
||||
bg = Theme_config.notification_center.spacing_line.color,
|
||||
widget = wibox.container.background,
|
||||
},
|
||||
widget = wibox.container.constraint,
|
||||
height = dpi(2),
|
||||
strategy = 'exact',
|
||||
},
|
||||
left = dpi(60),
|
||||
right = dpi(60),
|
||||
widget = wibox.container.margin,
|
||||
},
|
||||
id = "background4",
|
||||
fg = Theme_config.notification_center.clear_all_button.fg,
|
||||
bg = Theme_config.notification_center.clear_all_button.bg,
|
||||
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
|
||||
},
|
||||
widget = wibox.container.place,
|
||||
valign = "bottom",
|
||||
halign = "right",
|
||||
}
|
||||
|
||||
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 = Theme_config.notification_center.bg,
|
||||
border_color = Theme_config.notification_center.border_color,
|
||||
border_width = Theme_config.notification_center.border_width,
|
||||
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, dpi(12))
|
||||
end,
|
||||
}
|
||||
|
||||
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.vertical,
|
||||
},
|
||||
layout = wibox.layout.fixed.horizontal
|
||||
layout = wibox.layout.fixed.horizontal,
|
||||
},
|
||||
layout = wibox.layout.fixed.horizontal
|
||||
layout = wibox.layout.fixed.horizontal,
|
||||
},
|
||||
status_bars_widget,
|
||||
status_bars,
|
||||
music_widget,
|
||||
layout = wibox.layout.fixed.vertical
|
||||
layout = wibox.layout.fixed.vertical,
|
||||
},
|
||||
-- Notification list
|
||||
{
|
||||
{
|
||||
{
|
||||
nl,
|
||||
notification_list,
|
||||
height = dpi(680),
|
||||
strategy = "max",
|
||||
widget = wibox.container.constraint
|
||||
},
|
||||
{
|
||||
no_notification_widget,
|
||||
strategy = "max",
|
||||
height = dpi(400),
|
||||
widget = wibox.container.constraint
|
||||
strategy = 'max',
|
||||
widget = wibox.container.constraint,
|
||||
},
|
||||
{
|
||||
{
|
||||
dnd,
|
||||
{
|
||||
{
|
||||
{
|
||||
valign = 'center',
|
||||
halign = 'center',
|
||||
resize = true,
|
||||
image = icondir .. 'megamind.svg',
|
||||
widget = wibox.widget.imagebox,
|
||||
id = 'no_notification_icon',
|
||||
},
|
||||
widget = wibox.container.constraint,
|
||||
height = dpi(200),
|
||||
width = dpi(200),
|
||||
strategy = 'exact',
|
||||
},
|
||||
{
|
||||
markup = "<span color='#414141' font='JetBrainsMono Nerd Font, ExtraBold 20'>No Notifications?</span>",
|
||||
valign = 'center',
|
||||
halign = 'center',
|
||||
widget = wibox.widget.textbox,
|
||||
id = 'no_notification_text',
|
||||
},
|
||||
layout = wibox.layout.fixed.vertical,
|
||||
},
|
||||
widget = wibox.container.place,
|
||||
},
|
||||
strategy = 'max',
|
||||
height = dpi(400),
|
||||
widget = wibox.container.constraint,
|
||||
},
|
||||
{
|
||||
{
|
||||
dnd_widget {
|
||||
text = 'Do not disturb',
|
||||
color = Theme_config.notification_center.dnd_color,
|
||||
fg = Theme_config.notification_center.dnd_fg,
|
||||
size = dpi(40),
|
||||
},
|
||||
id = 'dnd',
|
||||
widget = wibox.container.place,
|
||||
valign = "center",
|
||||
halign = "center"
|
||||
},
|
||||
nil,
|
||||
clear_all_widget,
|
||||
layout = wibox.layout.align.horizontal
|
||||
{ -- Clear all button
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
text = 'Clear',
|
||||
valign = 'center',
|
||||
halign = 'center',
|
||||
widget = wibox.widget.textbox,
|
||||
id = 'clear',
|
||||
},
|
||||
fg = Theme_config.notification_center.clear_all_button.fg,
|
||||
bg = Theme_config.notification_center.clear_all_button.bg,
|
||||
shape = function(cr, width, height)
|
||||
gshape.rounded_rect(cr, width, height, 12)
|
||||
end,
|
||||
id = 'clear_all_bg',
|
||||
widget = wibox.container.background,
|
||||
},
|
||||
widget = wibox.container.constraint,
|
||||
width = dpi(80),
|
||||
height = dpi(40),
|
||||
strategy = 'exact',
|
||||
},
|
||||
margins = dpi(10),
|
||||
widget = wibox.container.margin,
|
||||
},
|
||||
widget = wibox.container.place,
|
||||
valign = 'bottom', --? Needed?
|
||||
halign = 'right', --? Needed?
|
||||
},
|
||||
layout = wibox.layout.align.horizontal,
|
||||
},
|
||||
id = "layout5",
|
||||
layout = wibox.layout.align.vertical
|
||||
layout = wibox.layout.align.vertical,
|
||||
},
|
||||
id = "margin6",
|
||||
margins = dpi(20),
|
||||
widget = wibox.container.margin
|
||||
widget = wibox.container.margin,
|
||||
},
|
||||
id = "yes",
|
||||
spacing_widget = {
|
||||
{
|
||||
bg = Theme_config.notification_center.spacing_color,
|
||||
widget = wibox.container.background
|
||||
},
|
||||
top = dpi(40),
|
||||
bottom = dpi(40),
|
||||
widget = wibox.container.margin
|
||||
thickness = dpi(2),
|
||||
color = Theme_config.notification_center.spacing_color,
|
||||
span_ratio = 0.9,
|
||||
widget = wibox.widget.separator,
|
||||
},
|
||||
spacing = dpi(1),
|
||||
forced_height = dpi(800),
|
||||
forced_width = dpi(1000),
|
||||
layout = wibox.layout.flex.horizontal
|
||||
})
|
||||
end
|
||||
spacing = dpi(2),
|
||||
layout = wibox.layout.flex.horizontal,
|
||||
},
|
||||
widget = wibox.container.constraint,
|
||||
height = dpi(800),
|
||||
width = dpi(1000),
|
||||
strategy = 'exact',
|
||||
}
|
||||
|
||||
--#endregion
|
||||
hover.bg_hover { widget = w:get_children_by_id('clear_all_bg')[1] }
|
||||
|
||||
--#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
|
||||
)
|
||||
assert(type(w) == 'table', 'Widget creation failed')
|
||||
|
||||
-- Update the notification center popup and check if there are no notifications
|
||||
capi.awesome.connect_signal(
|
||||
"notification_center:update::needed",
|
||||
function()
|
||||
if #nl == 0 then
|
||||
math.randomseed(os.time())
|
||||
local prob = math.random(1, 10)
|
||||
notification_list:connect_signal('new_children', function()
|
||||
if #notification_list.children == 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
|
||||
if (prob == 5) or (prob == 6) then
|
||||
w:get_children_by_id('no_notification_icon')[1].image = icondir .. 'megamind.svg'
|
||||
w:get_children_by_id('no_notification_text')[1].markup = "<span color='#414141' font='JetBrainsMono Nerd Font, ExtraBold 20'>No Notifications?</span>"
|
||||
else
|
||||
no_notification_widget.visible = false
|
||||
w:get_children_by_id('no_notification_icon')[1].image = icondir .. 'bell-outline.svg'
|
||||
w:get_children_by_id('no_notification_text')[1].markup = "<span color='#414141' font='JetBrainsMono Nerd Font, ExtraBold 20'>No Notification</span>"
|
||||
end
|
||||
notification_center_setup()
|
||||
w:get_children_by_id('no_notification_icon')[1].visible = true
|
||||
w:get_children_by_id('no_notification_text')[1].visible = true
|
||||
else
|
||||
w:get_children_by_id('no_notification_icon')[1].visible = false
|
||||
w:get_children_by_id('no_notification_text')[1].visible = false
|
||||
end
|
||||
)
|
||||
|
||||
local function mouse_leave()
|
||||
notification_center.visible = false
|
||||
end
|
||||
|
||||
capi.awesome.connect_signal("notification_center::block_mouse_events", function()
|
||||
notification_center:disconnect_signal("mouse::leave", mouse_leave)
|
||||
end)
|
||||
|
||||
capi.awesome.connect_signal("notification_center::unblock_mouse_events", function()
|
||||
notification_center:connect_signal("mouse::leave", mouse_leave)
|
||||
w:get_children_by_id('clear')[1]:connect_signal('button::press', function()
|
||||
notification_list.children = {}
|
||||
notification_list:emit_signal('new_children')
|
||||
end)
|
||||
|
||||
-- Hide notification_center when mouse leaves it
|
||||
notification_center:connect_signal(
|
||||
"mouse::leave",
|
||||
mouse_leave
|
||||
)
|
||||
w:get_children_by_id('dnd')[1]:get_widget():connect_signal('dnd::toggle', function(enabled)
|
||||
User_config.dnd = enabled
|
||||
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
|
||||
capi.awesome.emit_signal("notification_center:update::needed")
|
||||
w.container = apopup {
|
||||
widget = w,
|
||||
bg = Theme_config.notification_center.bg,
|
||||
border_color = Theme_config.notification_center.border_color,
|
||||
border_width = Theme_config.notification_center.border_width,
|
||||
placement = function(c)
|
||||
aplacement.top(c, { margins = dpi(10) })
|
||||
end,
|
||||
ontop = true,
|
||||
screen = args.screen,
|
||||
visible = false,
|
||||
}
|
||||
|
||||
local activation_area = apopup {
|
||||
bg = gcolor.transparent,
|
||||
widget = {
|
||||
forced_height = dpi(1),
|
||||
forced_width = dpi(300),
|
||||
bg = gcolor.transparent,
|
||||
layout = wibox.layout.fixed.horizontal,
|
||||
},
|
||||
ontop = true,
|
||||
screen = args.screen,
|
||||
type = 'dock',
|
||||
placement = function(c)
|
||||
aplacement.top(c)
|
||||
end,
|
||||
}
|
||||
|
||||
capi.client.connect_signal('property::fullscreen', function(c)
|
||||
if c.fullscreen then
|
||||
activation_area.visible = false
|
||||
else
|
||||
activation_area.visible = true
|
||||
end
|
||||
)
|
||||
end)
|
||||
|
||||
Hover_signal(clear_all_widget.margin3.background4)
|
||||
--#endregion
|
||||
activation_area:connect_signal('mouse::enter', function()
|
||||
w.container.visible = true
|
||||
end)
|
||||
|
||||
w.container:connect_signal('mouse::leave', function()
|
||||
w.container.visible = false
|
||||
end)
|
||||
|
||||
return w
|
||||
end
|
||||
|
||||
if not instance then
|
||||
instance = setmetatable(info_center, {
|
||||
__call = function(self, ...)
|
||||
self.new(...)
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
return instance
|
||||
|
||||
@@ -1,268 +0,0 @@
|
||||
-------------------------------------
|
||||
-- This is the notification-center --
|
||||
-------------------------------------
|
||||
|
||||
-- Awesome Libs
|
||||
local awful = require("awful")
|
||||
local dpi = require("beautiful").xresources.apply_dpi
|
||||
local gears = require("gears")
|
||||
local wibox = require("wibox")
|
||||
local naughty = require("naughty")
|
||||
|
||||
local capi = {
|
||||
awesome = awesome,
|
||||
}
|
||||
|
||||
-- Icon directory path
|
||||
local icondir = gears.filesystem.get_configuration_dir() .. "src/assets/icons/notifications/"
|
||||
|
||||
local nl = {}
|
||||
|
||||
nl.notification_list = { layout = require("src.lib.overflow_widget.overflow").vertical, scrollbar_width = 0,
|
||||
step = dpi(100), 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 = Theme_config.notification_center.notification_list.timer_fg,
|
||||
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_config.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 = Theme_config.notification_center.notification_list.close_color,
|
||||
bg = Theme_config.notification_center.notification_list.close_bg,
|
||||
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,
|
||||
}
|
||||
|
||||
local timer_close_widget = timer_widget
|
||||
|
||||
local notification = wibox.widget {
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
image = gears.color.recolor_image(icondir .. "notification-outline.svg",
|
||||
Theme_config.notification_center.notification_list.icon),
|
||||
resize = false,
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
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 = Theme_config.notification_center.notification_list.title_fg,
|
||||
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 = Theme_config.notification_center.notification_list.title_border_color,
|
||||
border_width = Theme_config.notification_center.notification_list.title_border_width,
|
||||
widget = wibox.container.background
|
||||
},
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
image = n.icon,
|
||||
resize = true,
|
||||
widget = wibox.widget.imagebox,
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
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 = Theme_config.notification_center.notification_list.notification_bg,
|
||||
border_color = Theme_config.notification_center.notification_list.notification_border_color,
|
||||
border_width = Theme_config.notification_center.notification_list.notification_border_width,
|
||||
shape = Theme_config.notification_center.notification_list.notification_shape,
|
||||
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, math.tointeger(i))
|
||||
capi.awesome.emit_signal("notification_center:update::needed")
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
Hover_signal(close_widget.const.background)
|
||||
|
||||
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, 1, notification)
|
||||
end
|
||||
|
||||
naughty.connect_signal(
|
||||
"request::display",
|
||||
function(n)
|
||||
nl.create_notification(n)
|
||||
capi.awesome.emit_signal("notification_center:update::needed")
|
||||
end
|
||||
)
|
||||
|
||||
return nl
|
||||
@@ -1,208 +0,0 @@
|
||||
--------------------------------
|
||||
-- This is the profile widget --
|
||||
--------------------------------
|
||||
|
||||
-- Awesome Libs
|
||||
local awful = require("awful")
|
||||
local dpi = require("beautiful").xresources.apply_dpi
|
||||
local gears = require("gears")
|
||||
local wibox = require("wibox")
|
||||
|
||||
-- Icon directory path
|
||||
local icondir = gears.filesystem.get_configuration_dir() .. "src/assets/icons/profile/"
|
||||
|
||||
return function()
|
||||
|
||||
local profile_widget = wibox.widget {
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
image = gears.surface.load_uncached(gears.filesystem.get_configuration_dir() ..
|
||||
"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",
|
||||
Theme_config.notification_center.profile.username_icon_color),
|
||||
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",
|
||||
Theme_config.notification_center.profile.os_prefix_icon_color),
|
||||
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",
|
||||
Theme_config.notification_center.profile.kernel_icon_color),
|
||||
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",
|
||||
Theme_config.notification_center.profile.uptime_icon_color),
|
||||
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 = Theme_config.notification_center.profile.fg,
|
||||
border_color = Theme_config.notification_center.profile.border_color,
|
||||
border_width = Theme_config.notification_center.profile.border_width,
|
||||
shape = Theme_config.notification_center.profile.shape,
|
||||
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
|
||||
@@ -1,501 +0,0 @@
|
||||
---------------------------
|
||||
-- This is the song-info --
|
||||
---------------------------
|
||||
|
||||
-- Awesome Libs
|
||||
local awful = require("awful")
|
||||
local dpi = require("beautiful").xresources.apply_dpi
|
||||
local gears = require("gears")
|
||||
local wibox = require("wibox")
|
||||
|
||||
local capi = {
|
||||
awesome = awesome,
|
||||
mouse = mouse,
|
||||
}
|
||||
|
||||
-- Icon directory path
|
||||
local icondir = gears.filesystem.get_configuration_dir() .. "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 = capi.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))
|
||||
capi.mouse.cursor = "left_ptr"
|
||||
local w = capi.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",
|
||||
Theme_config.notification_center.song_info.shuffle_disabled),
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
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",
|
||||
Theme_config.notification_center.song_info.shuffle_disabled)
|
||||
else
|
||||
awful.spawn.with_shell("playerctl shuffle on")
|
||||
shuffle_button.image = gears.color.recolor_image(icondir .. "shuffle.svg",
|
||||
Theme_config.notification_center.song_info.shuffle_enabled)
|
||||
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",
|
||||
Theme_config.notification_center.song_info.shuffle_enabled)
|
||||
else
|
||||
shuffle_button.image = gears.color.recolor_image(icondir .. "shuffle.svg",
|
||||
Theme_config.notification_center.song_info.shuffle_disabled)
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
update_shuffle()
|
||||
|
||||
local repeat_button = wibox.widget {
|
||||
resize = false,
|
||||
image = gears.color.recolor_image(icondir .. "repeat.svg", Theme_config.notification_center.song_info.repeat_disabled),
|
||||
widget = wibox.widget.imagebox,
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
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"),
|
||||
Theme_config.notification_center.song_info.repeat_single)
|
||||
elseif loop_mode == "None" then
|
||||
repeat_button.image = gears.color.recolor_image(gears.surface.load_uncached(icondir .. "repeat.svg"),
|
||||
Theme_config.notification_center.song_info.repeat_disabled)
|
||||
elseif loop_mode == "Playlist" then
|
||||
repeat_button.image = gears.color.recolor_image(gears.surface.load_uncached(icondir .. "repeat.svg"),
|
||||
Theme_config.notification_center.song_info.repeat_all)
|
||||
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,
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
image = gears.color.recolor_image(icondir .. "skip-prev.svg", Theme_config.notification_center.song_info.prev_enabled),
|
||||
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,
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
image = gears.color.recolor_image(icondir .. "play-pause.svg",
|
||||
Theme_config.notification_center.song_info.play_enabled),
|
||||
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,
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
image = gears.color.recolor_image(icondir .. "skip-next.svg", Theme_config.notification_center.song_info.next_enabled),
|
||||
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"),
|
||||
Theme_config.notification_center.song_info.repeat_all)
|
||||
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"),
|
||||
Theme_config.notification_center.song_info.repeat_single)
|
||||
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"),
|
||||
Theme_config.notification_center.song_info.repeat_disabled)
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
repeat_button:buttons(gears.table.join(awful.button({}, 1, loop_handler)))
|
||||
|
||||
button_hover_effect(prev_button, "skip-prev.svg", Theme_config.notification_center.song_info.prev_enabled,
|
||||
Theme_config.notification_center.song_info.prev_hover)
|
||||
button_hover_effect(pause_play_button, "play-pause.svg", Theme_config.notification_center.song_info.play_enabled,
|
||||
Theme_config.notification_center.song_info.play_hover)
|
||||
button_hover_effect(next_button, "skip-next.svg", Theme_config.notification_center.song_info.next_enabled,
|
||||
Theme_config.notification_center.song_info.next_hover)
|
||||
|
||||
--#endregion
|
||||
|
||||
-- Main music widget
|
||||
local music_widget = wibox.widget {
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{ -- Album art
|
||||
{
|
||||
image = icondir .. "default_image.svg",
|
||||
resize = true,
|
||||
clip_shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(8))
|
||||
end,
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
widget = wibox.widget.imagebox,
|
||||
id = "imagebox"
|
||||
},
|
||||
width = dpi(80),
|
||||
height = dpi(80),
|
||||
strategy = "exact",
|
||||
widget = wibox.container.constraint,
|
||||
id = "const"
|
||||
},
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{ --Title
|
||||
valign = "center",
|
||||
align = "center",
|
||||
widget = wibox.widget.textbox,
|
||||
id = "textbox4"
|
||||
},
|
||||
fg = Theme_config.notification_center.song_info.title_fg,
|
||||
id = "textbox5",
|
||||
widget = wibox.container.background
|
||||
},
|
||||
id = "textbox_const",
|
||||
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 = Theme_config.notification_center.song_info.artist_fg,
|
||||
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 = Theme_config.notification_center.song_info.duration_fg,
|
||||
widget = wibox.container.background,
|
||||
id = "background3"
|
||||
},
|
||||
right = dpi(10),
|
||||
widget = wibox.container.margin,
|
||||
id = "margin4"
|
||||
},
|
||||
{ -- Progressbar
|
||||
{
|
||||
color = Theme_config.notification_center.song_info.progress_color,
|
||||
background_color = Theme_config.notification_center.song_info.progress_background_color,
|
||||
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 = Theme_config.notification_center.song_info.duration_fg,
|
||||
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 = Theme_config.notification_center.song_info.border_color,
|
||||
border_width = Theme_config.notification_center.song_info.border_width,
|
||||
shape = Theme_config.notification_center.song_info.shape,
|
||||
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
|
||||
-- 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")
|
||||
or icondir .. "default_image.svg"
|
||||
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>"
|
||||
, Theme_config.notification_center.song_info.duration_fg, 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>"
|
||||
, Theme_config.notification_center.song_info.duration_fg, 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()
|
||||
--!Rewrite entire playerctl module for better performance
|
||||
--get_spotify_metadata()
|
||||
end
|
||||
}
|
||||
|
||||
-- get_spotify_metadata() on awesome reload
|
||||
capi.awesome.connect_signal("startup", function()
|
||||
get_spotify_metadata(true)
|
||||
end)
|
||||
|
||||
return music_widget
|
||||
end
|
||||
@@ -1,22 +0,0 @@
|
||||
------------------------------------------------
|
||||
-- This is the spacing widget under the clock --
|
||||
------------------------------------------------
|
||||
|
||||
-- Awesome Libs
|
||||
local dpi = require("beautiful").xresources.apply_dpi
|
||||
local wibox = require("wibox")
|
||||
|
||||
return function()
|
||||
|
||||
return wibox.widget {
|
||||
{
|
||||
forced_height = dpi(2),
|
||||
bg = Theme_config.notification_center.spacing_line.color,
|
||||
widget = wibox.container.background
|
||||
},
|
||||
left = dpi(80),
|
||||
right = dpi(80),
|
||||
widget = wibox.container.margin
|
||||
}
|
||||
|
||||
end
|
||||
@@ -1,840 +0,0 @@
|
||||
------------------------------------
|
||||
-- This is the status_bars widget --
|
||||
------------------------------------
|
||||
|
||||
-- Awesome Libs
|
||||
local awful = require("awful")
|
||||
local dpi = require("beautiful").xresources.apply_dpi
|
||||
local gears = require("gears")
|
||||
local wibox = require("wibox")
|
||||
|
||||
local rubato = require("src.lib.rubato")
|
||||
|
||||
local capi = {
|
||||
awesome = awesome,
|
||||
}
|
||||
|
||||
-- Icon directory path
|
||||
local icondir = gears.filesystem.get_configuration_dir() .. "src/assets/icons/"
|
||||
|
||||
--- Signal bars widget for the notification-center
|
||||
---@diagnostic disable-next-line: undefined-doc-name
|
||||
---@return wibox.widget
|
||||
return function()
|
||||
|
||||
---Creates a layout with bar widgets based on the given table
|
||||
---@param widget_table table
|
||||
---@return table
|
||||
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 = Theme_config.notification_center.status_bar.cpu_usage_color,
|
||||
background_color = Theme_config.notification_center.status_bar.bar_bg_color,
|
||||
max_value = 100,
|
||||
value = 0,
|
||||
forced_height = dpi(8),
|
||||
shape = function(cr)
|
||||
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",
|
||||
Theme_config.notification_center.status_bar.cpu_usage_color),
|
||||
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)
|
||||
}
|
||||
|
||||
w:connect_signal("mouse::enter", function()
|
||||
capi.awesome.emit_signal("notification_center::block_mouse_events")
|
||||
end)
|
||||
|
||||
w:connect_signal("mouse::leave", function()
|
||||
capi.awesome.emit_signal("notification_center::unblock_mouse_events")
|
||||
end)
|
||||
|
||||
capi.awesome.connect_signal(
|
||||
"update::cpu_usage",
|
||||
function(cpu_usage)
|
||||
tooltip.text = "CPU Usage: " .. cpu_usage .. "%"
|
||||
rubato_timer.target = cpu_usage
|
||||
end
|
||||
)
|
||||
elseif widget == "cpu_temp" then
|
||||
w = wibox.widget {
|
||||
{
|
||||
{
|
||||
{ --Bar
|
||||
color = Theme_config.notification_center.status_bar.cpu_temp_color,
|
||||
background_color = Theme_config.notification_center.status_bar.bar_bg_color,
|
||||
max_value = 100,
|
||||
value = 0,
|
||||
forced_height = dpi(8),
|
||||
shape = function(cr)
|
||||
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",
|
||||
Theme_config.notification_center.status_bar.cpu_temp_color),
|
||||
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)
|
||||
}
|
||||
w:connect_signal("mouse::enter", function()
|
||||
capi.awesome.emit_signal("notification_center::block_mouse_events")
|
||||
end)
|
||||
|
||||
w:connect_signal("mouse::leave", function()
|
||||
capi.awesome.emit_signal("notification_center::unblock_mouse_events")
|
||||
end)
|
||||
capi.awesome.connect_signal(
|
||||
"update::cpu_temp",
|
||||
function(cpu_temp)
|
||||
local temp_icon
|
||||
if cpu_temp < 50 then
|
||||
temp_icon = icondir .. "cpu/thermometer-low.svg"
|
||||
elseif cpu_temp >= 50 and cpu_temp < 80 then
|
||||
temp_icon = icondir .. "cpu/thermometer.svg"
|
||||
elseif cpu_temp >= 80 then
|
||||
temp_icon = icondir .. "cpu/thermometer-high.svg"
|
||||
end
|
||||
w:get_children_by_id("icon1")[1].image = gears.color.recolor_image(temp_icon,
|
||||
Theme_config.notification_center.status_bar.cpu_temp_color)
|
||||
tooltip.text = "CPU Temp: " .. cpu_temp .. "°C"
|
||||
rubato_timer.target = cpu_temp
|
||||
end
|
||||
)
|
||||
elseif widget == "ram_usage" then
|
||||
w = wibox.widget {
|
||||
{
|
||||
{
|
||||
{ --Bar
|
||||
color = Theme_config.notification_center.status_bar.ram_usage_color,
|
||||
background_color = Theme_config.notification_center.status_bar.bar_bg_color,
|
||||
max_value = 100,
|
||||
value = 0,
|
||||
forced_height = dpi(8),
|
||||
shape = function(cr)
|
||||
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",
|
||||
Theme_config.notification_center.status_bar.ram_usage_color),
|
||||
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)
|
||||
}
|
||||
w:connect_signal("mouse::enter", function()
|
||||
capi.awesome.emit_signal("notification_center::block_mouse_events")
|
||||
end)
|
||||
|
||||
w:connect_signal("mouse::leave", function()
|
||||
capi.awesome.emit_signal("notification_center::unblock_mouse_events")
|
||||
end)
|
||||
capi.awesome.connect_signal(
|
||||
"update::ram_widget",
|
||||
function(MemTotal, _, MemAvailable)
|
||||
if not MemTotal or not MemAvailable then
|
||||
return
|
||||
end
|
||||
local ram_usage = math.floor(((MemTotal - MemAvailable) / MemTotal * 100) + 0.5)
|
||||
tooltip.text = "RAM Usage: " .. ram_usage .. "%"
|
||||
rubato_timer.target = ram_usage
|
||||
end
|
||||
)
|
||||
elseif widget == "gpu_usage" then
|
||||
w = wibox.widget {
|
||||
{
|
||||
{
|
||||
{ --Bar
|
||||
color = Theme_config.notification_center.status_bar.gpu_usage_color,
|
||||
background_color = Theme_config.notification_center.status_bar.bar_bg_color,
|
||||
max_value = 100,
|
||||
value = 0,
|
||||
forced_height = dpi(8),
|
||||
shape = function(cr)
|
||||
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",
|
||||
Theme_config.notification_center.status_bar.gpu_usage_color),
|
||||
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)
|
||||
}
|
||||
w:connect_signal("mouse::enter", function()
|
||||
capi.awesome.emit_signal("notification_center::block_mouse_events")
|
||||
end)
|
||||
|
||||
w:connect_signal("mouse::leave", function()
|
||||
capi.awesome.emit_signal("notification_center::unblock_mouse_events")
|
||||
end)
|
||||
capi.awesome.connect_signal(
|
||||
"update::gpu_usage",
|
||||
function(gpu_usage)
|
||||
if not gpu_usage then return end
|
||||
tooltip.text = "GPU Usage: " .. gpu_usage .. "%"
|
||||
rubato_timer.target = tonumber(gpu_usage)
|
||||
end
|
||||
)
|
||||
elseif widget == "gpu_temp" then
|
||||
w = wibox.widget {
|
||||
{
|
||||
{
|
||||
{ --Bar
|
||||
color = Theme_config.notification_center.status_bar.gpu_temp_color,
|
||||
background_color = Theme_config.notification_center.status_bar.bar_bg_color,
|
||||
max_value = 100,
|
||||
value = 0,
|
||||
forced_height = dpi(8),
|
||||
shape = function(cr)
|
||||
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",
|
||||
Theme_config.notification_center.status_bar.gpu_temp_color),
|
||||
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)
|
||||
}
|
||||
w:connect_signal("mouse::enter", function()
|
||||
capi.awesome.emit_signal("notification_center::block_mouse_events")
|
||||
end)
|
||||
|
||||
w:connect_signal("mouse::leave", function()
|
||||
capi.awesome.emit_signal("notification_center::unblock_mouse_events")
|
||||
end)
|
||||
capi.awesome.connect_signal(
|
||||
"update::gpu_temp",
|
||||
function(gpu_temp)
|
||||
local temp_icon
|
||||
local temp_num = tonumber(gpu_temp) or "NaN"
|
||||
|
||||
if temp_num then
|
||||
|
||||
if temp_num < 50 then
|
||||
temp_icon = icondir .. "cpu/thermometer-low.svg"
|
||||
elseif temp_num >= 50 and temp_num < 80 then
|
||||
temp_icon = icondir .. "cpu/thermometer.svg"
|
||||
elseif temp_num >= 80 then
|
||||
temp_icon = icondir .. "cpu/thermometer-high.svg"
|
||||
end
|
||||
else
|
||||
temp_num = "NaN"
|
||||
temp_icon = icondir .. "cpu/thermometer-low.svg"
|
||||
end
|
||||
w:get_children_by_id("icon1")[1].image = gears.color.recolor_image(temp_icon,
|
||||
Theme_config.notification_center.status_bar.gpu_temp_color)
|
||||
tooltip.text = "GPU Temp: " .. temp_num .. "°C"
|
||||
rubato_timer.target = temp_num
|
||||
end
|
||||
)
|
||||
elseif widget == "volume" then
|
||||
w = wibox.widget {
|
||||
{
|
||||
{
|
||||
{ --Bar
|
||||
color = Theme_config.notification_center.status_bar.volume_color,
|
||||
background_color = Theme_config.notification_center.status_bar.bar_bg_color,
|
||||
max_value = 100,
|
||||
value = 0,
|
||||
forced_height = dpi(8),
|
||||
shape = function(cr)
|
||||
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",
|
||||
Theme_config.notification_center.status_bar.volume_color),
|
||||
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,
|
||||
subscribed = function(v)
|
||||
bar.value = v
|
||||
end
|
||||
}
|
||||
|
||||
local tooltip = awful.tooltip {
|
||||
objects = { w },
|
||||
mode = "inside",
|
||||
preferred_alignments = "middle",
|
||||
margins = dpi(10)
|
||||
}
|
||||
w:connect_signal("mouse::enter", function()
|
||||
capi.awesome.emit_signal("notification_center::block_mouse_events")
|
||||
end)
|
||||
|
||||
w:connect_signal("mouse::leave", function()
|
||||
capi.awesome.emit_signal("notification_center::unblock_mouse_events")
|
||||
end)
|
||||
capi.awesome.connect_signal(
|
||||
"audio::get",
|
||||
function(muted, volume)
|
||||
local icon = icondir .. "audio/volume"
|
||||
volume = tonumber(volume)
|
||||
if not volume then
|
||||
return
|
||||
end
|
||||
if muted then
|
||||
icon = icon .. "-mute"
|
||||
else
|
||||
if volume < 1 then
|
||||
icon = icon .. "-mute"
|
||||
elseif volume >= 1 and volume < 34 then
|
||||
icon = icon .. "-low"
|
||||
elseif volume >= 34 and volume < 67 then
|
||||
icon = icon .. "-medium"
|
||||
elseif volume >= 67 then
|
||||
icon = icon .. "-high"
|
||||
end
|
||||
end
|
||||
w:get_children_by_id("icon1")[1].image = gears.color.recolor_image(icon .. ".svg",
|
||||
Theme_config.notification_center.status_bar.volume_color)
|
||||
tooltip.text = "Volume: " .. volume .. "%"
|
||||
rubato_timer.target = volume
|
||||
end
|
||||
)
|
||||
elseif widget == "microphone" then
|
||||
w = wibox.widget {
|
||||
{
|
||||
{
|
||||
{ --Bar
|
||||
color = Theme_config.notification_center.status_bar.microphone_color,
|
||||
background_color = Theme_config.notification_center.status_bar.bar_bg_color,
|
||||
max_value = 100,
|
||||
value = 0,
|
||||
forced_height = dpi(8),
|
||||
shape = function(cr)
|
||||
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",
|
||||
Theme_config.notification_center.status_bar.microphone_color),
|
||||
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,
|
||||
subscribed = function(v)
|
||||
bar.value = v
|
||||
end
|
||||
}
|
||||
|
||||
local tooltip = awful.tooltip {
|
||||
objects = { w },
|
||||
mode = "inside",
|
||||
preferred_alignments = "middle",
|
||||
margins = dpi(10)
|
||||
}
|
||||
w:connect_signal("mouse::enter", function()
|
||||
capi.awesome.emit_signal("notification_center::block_mouse_events")
|
||||
end)
|
||||
|
||||
w:connect_signal("mouse::leave", function()
|
||||
capi.awesome.emit_signal("notification_center::unblock_mouse_events")
|
||||
end)
|
||||
capi.awesome.connect_signal(
|
||||
"microphone::get",
|
||||
function(muted, volume)
|
||||
if not volume then
|
||||
return
|
||||
end
|
||||
local icon = icondir .. "audio/microphone"
|
||||
volume = tonumber(volume)
|
||||
if not volume then
|
||||
return
|
||||
end
|
||||
if muted or (volume < 1) then
|
||||
icon = icon .. "-off"
|
||||
end
|
||||
w:get_children_by_id("icon1")[1].image = gears.color.recolor_image(icon .. ".svg",
|
||||
Theme_config.notification_center.status_bar.microphone_color)
|
||||
tooltip.text = "Microphone: " .. volume .. "%"
|
||||
rubato_timer.target = volume
|
||||
end
|
||||
)
|
||||
elseif widget == "backlight" then
|
||||
w = wibox.widget {
|
||||
{
|
||||
{
|
||||
{ --Bar
|
||||
color = Theme_config.notification_center.status_bar.backlight_color,
|
||||
background_color = Theme_config.notification_center.status_bar.bar_bg_color,
|
||||
max_value = 100,
|
||||
value = 0,
|
||||
forced_height = dpi(8),
|
||||
shape = function(cr)
|
||||
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",
|
||||
Theme_config.notification_center.status_bar.backlight_color),
|
||||
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)
|
||||
}
|
||||
w:connect_signal("mouse::enter", function()
|
||||
capi.awesome.emit_signal("notification_center::block_mouse_events")
|
||||
end)
|
||||
|
||||
w:connect_signal("mouse::leave", function()
|
||||
capi.awesome.emit_signal("notification_center::unblock_mouse_events")
|
||||
end)
|
||||
capi.awesome.connect_signal(
|
||||
"brightness::get",
|
||||
function(brightness)
|
||||
local icon = icondir .. "brightness"
|
||||
if brightness >= 0 and brightness < 34 then
|
||||
icon = icon .. "-low"
|
||||
elseif brightness >= 34 and brightness < 67 then
|
||||
icon = icon .. "-medium"
|
||||
elseif brightness >= 67 then
|
||||
icon = icon .. "-high"
|
||||
end
|
||||
w:get_children_by_id("icon1")[1]:set_image(gears.color.recolor_image(icon .. ".svg",
|
||||
Theme_config.notification_center.status_bar.backlight_color))
|
||||
tooltip.text = "Backlight: " .. brightness .. "%"
|
||||
rubato_timer.target = brightness
|
||||
end
|
||||
)
|
||||
elseif widget == "battery" then
|
||||
w = wibox.widget {
|
||||
{
|
||||
{
|
||||
{ --Bar
|
||||
color = Theme_config.notification_center.status_bar.battery_color,
|
||||
background_color = Theme_config.notification_center.status_bar.bar_bg_color,
|
||||
max_value = 100,
|
||||
value = 0,
|
||||
forced_height = dpi(8),
|
||||
shape = function(cr)
|
||||
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",
|
||||
Theme_config.notification_center.status_bar.battery_color),
|
||||
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)
|
||||
}
|
||||
w:connect_signal("mouse::enter", function()
|
||||
capi.awesome.emit_signal("notification_center::block_mouse_events")
|
||||
end)
|
||||
|
||||
w:connect_signal("mouse::leave", function()
|
||||
capi.awesome.emit_signal("notification_center::unblock_mouse_events")
|
||||
end)
|
||||
capi.awesome.connect_signal(
|
||||
"update::battery_widget",
|
||||
function(battery, battery_icon)
|
||||
w:get_children_by_id("icon1")[1].image = gears.color.recolor_image(battery_icon,
|
||||
Theme_config.notification_center.status_bar.battery_color)
|
||||
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(User_config.status_bar_widgets),
|
||||
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 = Theme_config.notification_center.status_bar.border_color,
|
||||
border_width = Theme_config.notification_center.status_bar.border_width,
|
||||
shape = Theme_config.notification_center.status_bar.shape,
|
||||
widget = wibox.container.background
|
||||
},
|
||||
top = dpi(10),
|
||||
left = dpi(20),
|
||||
right = dpi(20),
|
||||
bottom = dpi(10),
|
||||
widget = wibox.container.margin
|
||||
}
|
||||
|
||||
return signal_bars
|
||||
|
||||
end
|
||||
@@ -1,65 +0,0 @@
|
||||
----------------------------------
|
||||
-- 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>%d</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
|
||||
@@ -1,224 +0,0 @@
|
||||
--------------------------------
|
||||
-- This is the weather widget --
|
||||
--------------------------------
|
||||
|
||||
-- Awesome Libs
|
||||
local awful = require("awful")
|
||||
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 = gears.filesystem.get_configuration_dir() .. "src/assets/icons/weather/"
|
||||
|
||||
return function()
|
||||
|
||||
local api_secrets = {
|
||||
key = User_config.weather_secrets.key,
|
||||
city_id = User_config.weather_secrets.city_id,
|
||||
unit = User_config.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 = Theme_config.notification_center.weather.description_fg,
|
||||
widget = wibox.container.background
|
||||
},
|
||||
{ -- line
|
||||
forced_height = dpi(4),
|
||||
forced_width = dpi(10),
|
||||
bg = Theme_config.notification_center.weather.line_bg,
|
||||
widget = wibox.container.background,
|
||||
id = "line"
|
||||
},
|
||||
{
|
||||
{ -- Speed
|
||||
{
|
||||
image = gears.color.recolor_image(icondir .. "weather-windy.svg",
|
||||
Theme_config.notification_center.weather.speed_icon_color),
|
||||
resize = true,
|
||||
forced_width = dpi(24),
|
||||
forced_height = dpi(24),
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
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,
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
image = gears.color.recolor_image(icondir .. "humidity.svg",
|
||||
Theme_config.notification_center.weather.humidity_icon_color),
|
||||
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 = Theme_config.notification_center.weather.border_color,
|
||||
border_width = Theme_config.notification_center.weather.border_width,
|
||||
shape = Theme_config.notification_center.weather.shape,
|
||||
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 = Theme_config.notification_center.weather.line_color
|
||||
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
|
||||
@@ -0,0 +1,71 @@
|
||||
-------------------------------------
|
||||
-- This is the notification-center --
|
||||
-------------------------------------
|
||||
|
||||
-- Awesome Libs
|
||||
local dpi = require('beautiful').xresources.apply_dpi
|
||||
local wibox = require('wibox')
|
||||
local naughty = require('naughty')
|
||||
local gtimer = require('gears.timer')
|
||||
|
||||
local hover = require('src.tools.hover')
|
||||
|
||||
return setmetatable({}, {
|
||||
__call = function()
|
||||
local ret = wibox.widget {
|
||||
layout = require('src.lib.overflow_widget.overflow').vertical,
|
||||
scrollbar_width = 0,
|
||||
step = dpi(100),
|
||||
spacing = dpi(20),
|
||||
}
|
||||
|
||||
--!No, :get_children_by_id() does not work here for some reason, yes I hate it too
|
||||
--[[ naughty.connect_signal('notification_surface', function(b)
|
||||
local start_time = os.time()
|
||||
local w = wibox.template.make_from_value(b)
|
||||
w = w:get_widget()
|
||||
assert(type(w) == 'table', 'w is not a wibox.widget.base')
|
||||
|
||||
-- Change the clock to a timer how long ago the notification was created
|
||||
w.children[1].children[1].children[1].children[1].children[1].children[2].children[1].children[1] = wibox.widget {
|
||||
text = 'now',
|
||||
font = 'JetBrainsMono Nerd Font, Bold 12',
|
||||
halign = 'center',
|
||||
valign = 'center',
|
||||
widget = wibox.widget.textbox,
|
||||
}
|
||||
|
||||
hover.bg_hover { widget = w.children[1].children[1].children[1].children[1].children[1].children[2].children[1].children[2].children[1].children[1] }
|
||||
w.children[1].children[1].children[1].children[1].children[1].children[2].children[1].children[2]:connect_signal('button::press', function()
|
||||
ret:remove_widgets(w)
|
||||
ret:emit_signal('new_children')
|
||||
end)
|
||||
|
||||
gtimer {
|
||||
timeout = 1,
|
||||
autostart = true,
|
||||
call_now = true,
|
||||
callback = function()
|
||||
local time_ago = math.floor(os.time() - start_time)
|
||||
local timer_text = w.children[1].children[1].children[1].children[1].children[1].children[2].children[1].children[1]
|
||||
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,
|
||||
}
|
||||
|
||||
ret:add(w)
|
||||
ret:emit_signal('new_children')
|
||||
end) ]]
|
||||
|
||||
return ret
|
||||
end,
|
||||
})
|
||||
174
awesome/src/modules/notification-center/widgets/profile.lua
Normal file
174
awesome/src/modules/notification-center/widgets/profile.lua
Normal file
@@ -0,0 +1,174 @@
|
||||
--------------------------------
|
||||
-- This is the profile widget --
|
||||
--------------------------------
|
||||
|
||||
-- Awesome Libs
|
||||
local aspawn = require('awful.spawn')
|
||||
local dpi = require('beautiful').xresources.apply_dpi
|
||||
local gcolor = require('gears.color')
|
||||
local gfilesystem = require('gears.filesystem')
|
||||
local gshape = require('gears.shape')
|
||||
local gsurface = require('gears.surface')
|
||||
local gtimer = require('gears.timer')
|
||||
local wibox = require('wibox')
|
||||
|
||||
-- Icon directory path
|
||||
local icondir = gfilesystem.get_configuration_dir() .. 'src/assets/icons/profile/'
|
||||
|
||||
local instance = nil
|
||||
|
||||
if not instance then
|
||||
instance = setmetatable({}, { __call = function()
|
||||
local w = wibox.widget {
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
---@diagnostic disable-next-line: param-type-mismatch
|
||||
image = gsurface.load_uncached(gfilesystem.get_configuration_dir() .. 'src/assets/userpfp/userpfp.png'),
|
||||
valign = 'center',
|
||||
halign = 'center',
|
||||
clip_shape = function(cr, width, height)
|
||||
gshape.rounded_rect(cr, width, height, dpi(12))
|
||||
end,
|
||||
widget = wibox.widget.imagebox,
|
||||
},
|
||||
strategy = 'exact',
|
||||
widget = wibox.container.constraint,
|
||||
},
|
||||
margins = dpi(20),
|
||||
widget = wibox.container.margin,
|
||||
},
|
||||
{
|
||||
{
|
||||
{
|
||||
{ -- Username
|
||||
image = gcolor.recolor_image(icondir .. 'user.svg',
|
||||
Theme_config.notification_center.profile.username_icon_color),
|
||||
valign = 'center',
|
||||
halign = 'left',
|
||||
resize = false,
|
||||
widget = wibox.widget.imagebox,
|
||||
},
|
||||
{ -- Username
|
||||
id = 'username',
|
||||
valign = 'center',
|
||||
halign = 'left',
|
||||
widget = wibox.widget.textbox,
|
||||
},
|
||||
spacing = dpi(10),
|
||||
layout = wibox.layout.fixed.horizontal,
|
||||
},
|
||||
{
|
||||
{
|
||||
image = gcolor.recolor_image(icondir .. 'laptop.svg',
|
||||
Theme_config.notification_center.profile.os_prefix_icon_color),
|
||||
valign = 'center',
|
||||
halign = 'left',
|
||||
resize = false,
|
||||
widget = wibox.widget.imagebox,
|
||||
},
|
||||
{ -- OS
|
||||
id = 'os',
|
||||
valign = 'center',
|
||||
halign = 'left',
|
||||
widget = wibox.widget.textbox,
|
||||
},
|
||||
spacing = dpi(10),
|
||||
layout = wibox.layout.fixed.horizontal,
|
||||
},
|
||||
{
|
||||
{
|
||||
image = gcolor.recolor_image(icondir .. 'penguin.svg',
|
||||
Theme_config.notification_center.profile.kernel_icon_color),
|
||||
valign = 'center',
|
||||
halign = 'left',
|
||||
resize = false,
|
||||
widget = wibox.widget.imagebox,
|
||||
},
|
||||
{ -- Kernel
|
||||
id = 'kernel',
|
||||
valign = 'center',
|
||||
halign = 'left',
|
||||
widget = wibox.widget.textbox,
|
||||
},
|
||||
spacing = dpi(10),
|
||||
layout = wibox.layout.fixed.horizontal,
|
||||
},
|
||||
{
|
||||
{
|
||||
image = gcolor.recolor_image(icondir .. 'clock.svg',
|
||||
Theme_config.notification_center.profile.uptime_icon_color),
|
||||
valign = 'center',
|
||||
halign = 'left',
|
||||
resize = false,
|
||||
widget = wibox.widget.imagebox,
|
||||
},
|
||||
{ -- Uptime
|
||||
id = 'uptime',
|
||||
valign = 'center',
|
||||
halign = 'left',
|
||||
widget = wibox.widget.textbox,
|
||||
},
|
||||
spacing = dpi(10),
|
||||
layout = wibox.layout.fixed.horizontal,
|
||||
},
|
||||
spacing = dpi(5),
|
||||
layout = wibox.layout.flex.vertical,
|
||||
},
|
||||
bottom = dpi(20),
|
||||
left = dpi(20),
|
||||
widget = wibox.container.margin,
|
||||
},
|
||||
widget = wibox.layout.fixed.vertical,
|
||||
},
|
||||
fg = Theme_config.notification_center.profile.fg,
|
||||
border_color = Theme_config.notification_center.profile.border_color,
|
||||
border_width = Theme_config.notification_center.profile.border_width,
|
||||
shape = Theme_config.notification_center.profile.shape,
|
||||
widget = wibox.container.background,
|
||||
},
|
||||
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,
|
||||
}
|
||||
|
||||
aspawn.easy_async_with_shell('cat /etc/os-release | grep -w NAME', function(stdout)
|
||||
w:get_children_by_id('os')[1].text = stdout:match('\"(.+)\"')
|
||||
end)
|
||||
|
||||
aspawn.easy_async_with_shell('uname -r', function(stdout)
|
||||
w:get_children_by_id('kernel')[1].text = stdout:match('(%d+%.%d+%.%d+)')
|
||||
end)
|
||||
|
||||
aspawn.easy_async_with_shell('echo $USER@$(hostname)', function(stdout)
|
||||
w:get_children_by_id('username')[1].text = stdout:gsub('\n', '') or ''
|
||||
end)
|
||||
|
||||
gtimer {
|
||||
timeout = 60,
|
||||
autostart = true,
|
||||
call_now = true,
|
||||
callback = function()
|
||||
aspawn.easy_async_with_shell('uptime -p', function(stdout)
|
||||
local hours = stdout:match('(%d+) hours') or 0
|
||||
local minutes = stdout:match('(%d+) minutes') or 0
|
||||
w:get_children_by_id('uptime')[1].text = hours .. 'h, ' .. minutes .. 'm'
|
||||
end)
|
||||
end,
|
||||
}
|
||||
|
||||
return w
|
||||
end, })
|
||||
end
|
||||
|
||||
return instance
|
||||
241
awesome/src/modules/notification-center/widgets/song_info.lua
Normal file
241
awesome/src/modules/notification-center/widgets/song_info.lua
Normal file
@@ -0,0 +1,241 @@
|
||||
---------------------------
|
||||
-- This is the song-info --
|
||||
---------------------------
|
||||
|
||||
-- Awesome Libs
|
||||
local dpi = require('beautiful').xresources.apply_dpi
|
||||
local wibox = require('wibox')
|
||||
local gfilesystem = require('gears.filesystem')
|
||||
local gtable = require('gears.table')
|
||||
local gcolor = require('gears.color')
|
||||
local gshape = require('gears.shape')
|
||||
local base = require('wibox.widget.base')
|
||||
local abutton = require('awful.button')
|
||||
|
||||
local mh = require('src.tools.helpers.playerctl')
|
||||
|
||||
-- Icon directory path
|
||||
local icondir = gfilesystem.get_configuration_dir() .. 'src/assets/icons/notifications/'
|
||||
|
||||
local music_player = {}
|
||||
|
||||
return setmetatable({}, { __call = function()
|
||||
local w = base.make_widget_from_value {
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{ -- Album art
|
||||
{
|
||||
image = icondir .. 'default_image.svg',
|
||||
resize = true,
|
||||
clip_shape = function(cr, width, height)
|
||||
gshape.rounded_rect(cr, width, height, dpi(8))
|
||||
end,
|
||||
valign = 'center',
|
||||
halign = 'center',
|
||||
widget = wibox.widget.imagebox,
|
||||
id = 'album_art',
|
||||
},
|
||||
width = dpi(80),
|
||||
height = dpi(80),
|
||||
strategy = 'exact',
|
||||
widget = wibox.container.constraint,
|
||||
},
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{ --Title
|
||||
valign = 'center',
|
||||
halign = 'center',
|
||||
text = 'Unknown Title',
|
||||
id = 'title',
|
||||
widget = wibox.widget.textbox,
|
||||
},
|
||||
fg = Theme_config.notification_center.song_info.title_fg,
|
||||
widget = wibox.container.background,
|
||||
},
|
||||
strategy = 'max',
|
||||
width = dpi(400),
|
||||
widget = wibox.container.constraint,
|
||||
},
|
||||
widget = wibox.container.place,
|
||||
},
|
||||
{
|
||||
{
|
||||
{
|
||||
{ --Artist
|
||||
halign = 'center',
|
||||
valign = 'center',
|
||||
id = 'artist',
|
||||
text = 'Unknown Artist',
|
||||
widget = wibox.widget.textbox,
|
||||
},
|
||||
fg = Theme_config.notification_center.song_info.artist_fg,
|
||||
widget = wibox.container.background,
|
||||
},
|
||||
strategy = 'max',
|
||||
width = dpi(400),
|
||||
widget = wibox.container.constraint,
|
||||
},
|
||||
widget = wibox.container.place,
|
||||
},
|
||||
{ --Buttons
|
||||
{
|
||||
{
|
||||
resize = false,
|
||||
image = gcolor.recolor_image(icondir .. 'shuffle.svg',
|
||||
Theme_config.notification_center.song_info.shuffle_disabled),
|
||||
valign = 'center',
|
||||
halign = 'center',
|
||||
id = 'shuffle',
|
||||
widget = wibox.widget.imagebox,
|
||||
},
|
||||
{
|
||||
resize = false,
|
||||
valign = 'center',
|
||||
halign = 'center',
|
||||
id = 'prev',
|
||||
image = gcolor.recolor_image(icondir .. 'skip-prev.svg', Theme_config.notification_center.song_info.prev_enabled),
|
||||
widget = wibox.widget.imagebox,
|
||||
},
|
||||
{
|
||||
resize = false,
|
||||
valign = 'center',
|
||||
halign = 'center',
|
||||
id = 'play_pause',
|
||||
image = gcolor.recolor_image(icondir .. 'play-pause.svg',
|
||||
Theme_config.notification_center.song_info.play_enabled),
|
||||
widget = wibox.widget.imagebox,
|
||||
},
|
||||
{
|
||||
resize = false,
|
||||
valign = 'center',
|
||||
halign = 'center',
|
||||
id = 'next',
|
||||
image = gcolor.recolor_image(icondir .. 'skip-next.svg', Theme_config.notification_center.song_info.next_enabled),
|
||||
widget = wibox.widget.imagebox,
|
||||
},
|
||||
{
|
||||
resize = false,
|
||||
image = gcolor.recolor_image(icondir .. 'repeat.svg', Theme_config.notification_center.song_info.repeat_disabled),
|
||||
widget = wibox.widget.imagebox,
|
||||
valign = 'center',
|
||||
halign = 'center',
|
||||
id = 'repeat',
|
||||
},
|
||||
spacing = dpi(15),
|
||||
layout = wibox.layout.fixed.horizontal,
|
||||
},
|
||||
widget = wibox.container.place,
|
||||
},
|
||||
layout = wibox.layout.flex.vertical,
|
||||
},
|
||||
fill_space = true,
|
||||
spacing = dpi(10),
|
||||
layout = wibox.layout.fixed.horizontal,
|
||||
},
|
||||
{ --Song Duration
|
||||
{
|
||||
{
|
||||
{
|
||||
widget = wibox.widget.textbox,
|
||||
id = 'position',
|
||||
text = '00:00',
|
||||
valign = 'center',
|
||||
halign = 'center',
|
||||
},
|
||||
fg = Theme_config.notification_center.song_info.duration_fg,
|
||||
widget = wibox.container.background,
|
||||
},
|
||||
right = dpi(10),
|
||||
widget = wibox.container.margin,
|
||||
},
|
||||
{ -- Progressbar
|
||||
{
|
||||
color = Theme_config.notification_center.song_info.progress_color,
|
||||
background_color = Theme_config.notification_center.song_info.progress_background_color,
|
||||
max_value = 100,
|
||||
value = 0,
|
||||
id = 'progress',
|
||||
forced_height = dpi(5),
|
||||
shape = function(cr, width)
|
||||
gshape.rounded_bar(cr, width, dpi(5))
|
||||
end,
|
||||
widget = wibox.widget.progressbar,
|
||||
},
|
||||
widget = wibox.container.place,
|
||||
},
|
||||
{
|
||||
{
|
||||
{
|
||||
widget = wibox.widget.textbox,
|
||||
id = 'length',
|
||||
text = '00:00',
|
||||
valign = 'center',
|
||||
halign = 'center',
|
||||
},
|
||||
fg = Theme_config.notification_center.song_info.duration_fg,
|
||||
widget = wibox.container.background,
|
||||
},
|
||||
left = dpi(10),
|
||||
widget = wibox.container.margin,
|
||||
},
|
||||
layout = wibox.layout.align.horizontal,
|
||||
},
|
||||
widget = wibox.layout.fixed.vertical,
|
||||
},
|
||||
widget = wibox.container.margin,
|
||||
margins = dpi(10),
|
||||
},
|
||||
border_color = Theme_config.notification_center.song_info.border_color,
|
||||
border_width = Theme_config.notification_center.song_info.border_width,
|
||||
shape = Theme_config.notification_center.song_info.shape,
|
||||
widget = wibox.container.background,
|
||||
},
|
||||
widget = wibox.container.margin,
|
||||
top = dpi(10),
|
||||
bottom = dpi(20),
|
||||
left = dpi(20),
|
||||
right = dpi(20),
|
||||
}
|
||||
assert(type(w) == 'table', 'Widget must be a table')
|
||||
|
||||
gtable.crush(w, music_player, true)
|
||||
|
||||
local music_handler = mh(w)
|
||||
|
||||
--#region Buttons
|
||||
w:get_children_by_id('play_pause')[1]:buttons(gtable.join(
|
||||
abutton({}, 1, function()
|
||||
music_handler:play_pause()
|
||||
end)
|
||||
))
|
||||
|
||||
w:get_children_by_id('next')[1]:buttons(gtable.join(
|
||||
abutton({}, 1, function()
|
||||
music_handler:next()
|
||||
end)
|
||||
))
|
||||
|
||||
w:get_children_by_id('prev')[1]:buttons(gtable.join(
|
||||
abutton({}, 1, function()
|
||||
music_handler:prev()
|
||||
end)
|
||||
))
|
||||
|
||||
w:get_children_by_id('repeat')[1]:buttons(gtable.join(
|
||||
abutton({}, 1, function()
|
||||
music_handler:set_loop_status()
|
||||
end)
|
||||
))
|
||||
|
||||
w:get_children_by_id('shuffle')[1]:buttons(gtable.join(
|
||||
abutton({}, 1, function()
|
||||
music_handler:set_shuffle()
|
||||
end)
|
||||
))
|
||||
--#endregion
|
||||
return w
|
||||
end, })
|
||||
266
awesome/src/modules/notification-center/widgets/status_bars.lua
Normal file
266
awesome/src/modules/notification-center/widgets/status_bars.lua
Normal file
@@ -0,0 +1,266 @@
|
||||
------------------------------------
|
||||
-- This is the status_bars widget --
|
||||
------------------------------------
|
||||
|
||||
-- Awesome Libs
|
||||
local awful = require('awful')
|
||||
local dpi = require('beautiful').xresources.apply_dpi
|
||||
local gears = require('gears')
|
||||
local wibox = require('wibox')
|
||||
local base = require('wibox.widget.base')
|
||||
local gfilesystem = require('gears.filesystem')
|
||||
|
||||
local rubato = require('src.lib.rubato')
|
||||
|
||||
-- Own Libs
|
||||
local audio = require('src.tools.helpers.audio')
|
||||
local backlight = require('src.tools.helpers.backlight')
|
||||
--local battery = require('src.tools.helpers.battery')
|
||||
local cpu_usage = require('src.tools.helpers.cpu_usage')
|
||||
local cpu_temp = require('src.tools.helpers.cpu_temp')
|
||||
local ram = require('src.tools.helpers.ram')
|
||||
local gpu_usage = require('src.tools.helpers.gpu_usage')
|
||||
local gpu_temp = require('src.tools.helpers.gpu_temp')
|
||||
|
||||
-- Icon directory path
|
||||
local icondir = gfilesystem.get_configuration_dir() .. 'src/assets/icons/'
|
||||
|
||||
return setmetatable({}, { __call = function()
|
||||
|
||||
---Creates a layout with bar widgets based on the given table
|
||||
---@param widget_table table
|
||||
---@return table
|
||||
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 = base.make_widget_from_value {
|
||||
{
|
||||
{
|
||||
{
|
||||
{ --Bar
|
||||
color = Theme_config.notification_center.status_bar.cpu_usage_color,
|
||||
background_color = Theme_config.notification_center.status_bar.bar_bg_color,
|
||||
max_value = 100,
|
||||
value = 0,
|
||||
forced_height = dpi(8),
|
||||
shape = function(cr)
|
||||
gears.shape.rounded_bar(cr, dpi(58), dpi(8))
|
||||
end,
|
||||
id = 'progress_role',
|
||||
widget = wibox.widget.progressbar,
|
||||
},
|
||||
halign = 'center',
|
||||
valign = 'center',
|
||||
widget = wibox.container.place,
|
||||
},
|
||||
direction = 'east',
|
||||
widget = wibox.container.rotate,
|
||||
},
|
||||
widget = wibox.container.constraint,
|
||||
height = dpi(58), --120 Base size - (10+10) margin - (4+4) Border - 24 Icon - 10 spacing = 58
|
||||
width = dpi(24),
|
||||
strategy = 'exact',
|
||||
},
|
||||
{
|
||||
{ --Icon
|
||||
id = 'image_role',
|
||||
halign = 'center',
|
||||
valign = 'center',
|
||||
widget = wibox.widget.imagebox,
|
||||
},
|
||||
height = dpi(24),
|
||||
width = dpi(24),
|
||||
widget = wibox.container.constraint,
|
||||
},
|
||||
spacing = dpi(10),
|
||||
layout = wibox.layout.fixed.vertical,
|
||||
}
|
||||
|
||||
assert(type(w) == 'table', 'Widget creation failed')
|
||||
|
||||
local bar = w:get_children_by_id('progress_role')[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),
|
||||
}
|
||||
|
||||
if widget == 'cpu_usage' then
|
||||
cpu_usage:connect_signal('update::cpu_usage', function(_, v)
|
||||
tooltip.text = 'CPU Usage: ' .. v .. '%'
|
||||
rubato_timer.target = v
|
||||
w:get_children_by_id('image_role')[1].image = gears.color.recolor_image(icondir .. 'cpu/cpu.svg',
|
||||
Theme_config.notification_center.status_bar.cpu_usage_color)
|
||||
end)
|
||||
elseif widget == 'cpu_temp' then
|
||||
cpu_temp:connect_signal('update::cpu_temp', function(_, v)
|
||||
local temp_icon
|
||||
if v < 50 then
|
||||
temp_icon = icondir .. 'cpu/thermometer-low.svg'
|
||||
elseif v >= 50 and v < 80 then
|
||||
temp_icon = icondir .. 'cpu/thermometer.svg'
|
||||
elseif v >= 80 then
|
||||
temp_icon = icondir .. 'cpu/thermometer-high.svg'
|
||||
end
|
||||
w:get_children_by_id('image_role')[1].image = gears.color.recolor_image(temp_icon,
|
||||
Theme_config.notification_center.status_bar.cpu_temp_color)
|
||||
tooltip.text = 'CPU Temp: ' .. v .. '°C'
|
||||
rubato_timer.target = v
|
||||
end)
|
||||
elseif widget == 'ram_usage' then
|
||||
ram:connect_signal('update::ram_widget', function(_, MemTotal, _, MemAvailable)
|
||||
if not MemTotal or not MemAvailable then return end
|
||||
local ram_usage = math.floor(((MemTotal - MemAvailable) / MemTotal * 100) + 0.5)
|
||||
tooltip.text = 'RAM Usage: ' .. ram_usage .. '%'
|
||||
rubato_timer.target = ram_usage
|
||||
w:get_children_by_id('image_role')[1].image = gears.color.recolor_image(icondir .. 'cpu/ram.svg',
|
||||
Theme_config.notification_center.status_bar.ram_usage_color)
|
||||
end)
|
||||
elseif widget == 'gpu_usage' then
|
||||
gpu_usage:connect_signal('update::gpu_usage', function(_, v)
|
||||
if not v then return end
|
||||
tooltip.text = 'GPU Usage: ' .. v .. '%'
|
||||
rubato_timer.target = tonumber(v)
|
||||
w:get_children_by_id('image_role')[1].image = gears.color.recolor_image(icondir .. 'cpu/gpu.svg',
|
||||
Theme_config.notification_center.status_bar.gpu_usage_color)
|
||||
end)
|
||||
elseif widget == 'gpu_temp' then
|
||||
gpu_temp:connect_signal('update::gpu_temp', function(_, v)
|
||||
local temp_icon, temp_num
|
||||
|
||||
if v then
|
||||
temp_num = tonumber(v)
|
||||
if temp_num < 50 then
|
||||
temp_icon = icondir .. 'cpu/thermometer-low.svg'
|
||||
elseif temp_num >= 50 and temp_num < 80 then
|
||||
temp_icon = icondir .. 'cpu/thermometer.svg'
|
||||
elseif temp_num >= 80 then
|
||||
temp_icon = icondir .. 'cpu/thermometer-high.svg'
|
||||
end
|
||||
else
|
||||
temp_num = 'NaN'
|
||||
temp_icon = icondir .. 'cpu/thermometer-low.svg'
|
||||
end
|
||||
w:get_children_by_id('image_role')[1].image = gears.color.recolor_image(temp_icon,
|
||||
Theme_config.notification_center.status_bar.gpu_temp_color)
|
||||
tooltip.text = 'GPU Temp: ' .. temp_num .. '°C'
|
||||
rubato_timer.target = temp_num
|
||||
end)
|
||||
elseif widget == 'volume' then
|
||||
audio:connect_signal('sink::get', function(_, muted, volume)
|
||||
local icon = icondir .. 'audio/volume'
|
||||
volume = tonumber(volume)
|
||||
if not volume then
|
||||
return
|
||||
end
|
||||
if muted then
|
||||
icon = icon .. '-mute'
|
||||
else
|
||||
if volume < 1 then
|
||||
icon = icon .. '-mute'
|
||||
elseif volume >= 1 and volume < 34 then
|
||||
icon = icon .. '-low'
|
||||
elseif volume >= 34 and volume < 67 then
|
||||
icon = icon .. '-medium'
|
||||
elseif volume >= 67 then
|
||||
icon = icon .. '-high'
|
||||
end
|
||||
end
|
||||
w:get_children_by_id('image_role')[1].image = gears.color.recolor_image(icon .. '.svg',
|
||||
Theme_config.notification_center.status_bar.volume_color)
|
||||
tooltip.text = 'Volume: ' .. volume .. '%'
|
||||
rubato_timer.target = volume
|
||||
end)
|
||||
elseif widget == 'microphone' then
|
||||
audio:connect_signal('source::get', function(_, muted, volume)
|
||||
if not volume then
|
||||
return
|
||||
end
|
||||
local icon = icondir .. 'audio/microphone'
|
||||
volume = tonumber(volume)
|
||||
if not volume then
|
||||
return
|
||||
end
|
||||
if muted or (volume < 1) then
|
||||
icon = icon .. '-off'
|
||||
end
|
||||
w:get_children_by_id('image_role')[1].image = gears.color.recolor_image(icon .. '.svg',
|
||||
Theme_config.notification_center.status_bar.microphone_color)
|
||||
tooltip.text = 'Microphone: ' .. volume .. '%'
|
||||
rubato_timer.target = volume
|
||||
end)
|
||||
elseif widget == 'backlight' then
|
||||
backlight:connect_signal('brightness::get', function(_, v)
|
||||
local icon = icondir .. 'brightness'
|
||||
if v >= 0 and v < 34 then
|
||||
icon = icon .. '-low'
|
||||
elseif v >= 34 and v < 67 then
|
||||
icon = icon .. '-medium'
|
||||
elseif v >= 67 then
|
||||
icon = icon .. '-high'
|
||||
end
|
||||
w:get_children_by_id('image_role')[1]:set_image(gears.color.recolor_image(icon .. '.svg',
|
||||
Theme_config.notification_center.status_bar.backlight_color))
|
||||
tooltip.text = 'Backlight: ' .. v .. '%'
|
||||
rubato_timer.target = v
|
||||
end)
|
||||
elseif widget == 'battery' then
|
||||
--[[ battery:connect_signal('update::battery_widget', function(battery, battery_icon)
|
||||
w:get_children_by_id('image_role')[1].image = gears.color.recolor_image(battery_icon,
|
||||
Theme_config.notification_center.status_bar.battery_color)
|
||||
tooltip.text = 'Battery: ' .. battery .. '%'
|
||||
rubato_timer.target = battery
|
||||
end) ]]
|
||||
end
|
||||
table.insert(bar_layout, w)
|
||||
end
|
||||
|
||||
return bar_layout
|
||||
end
|
||||
|
||||
return wibox.widget {
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
create_bar_layout(User_config.status_bar_widgets),
|
||||
width = dpi(480),
|
||||
strategy = 'exact',
|
||||
widget = wibox.container.constraint,
|
||||
},
|
||||
widget = wibox.container.place,
|
||||
},
|
||||
magins = dpi(10),
|
||||
layout = wibox.container.margin,
|
||||
},
|
||||
border_color = Theme_config.notification_center.status_bar.border_color,
|
||||
border_width = Theme_config.notification_center.status_bar.border_width,
|
||||
shape = Theme_config.notification_center.status_bar.shape,
|
||||
widget = wibox.container.background,
|
||||
},
|
||||
widget = wibox.container.constraint,
|
||||
height = dpi(120),
|
||||
width = dpi(500),
|
||||
strategy = 'exact',
|
||||
},
|
||||
top = dpi(10),
|
||||
left = dpi(20),
|
||||
right = dpi(20),
|
||||
bottom = dpi(10),
|
||||
widget = wibox.container.margin,
|
||||
}
|
||||
|
||||
end, })
|
||||
203
awesome/src/modules/notification-center/widgets/weather.lua
Normal file
203
awesome/src/modules/notification-center/widgets/weather.lua
Normal file
@@ -0,0 +1,203 @@
|
||||
--------------------------------
|
||||
-- This is the weather widget --
|
||||
--------------------------------
|
||||
|
||||
-- Awesome Libs
|
||||
local dpi = require('beautiful').xresources.apply_dpi
|
||||
local wibox = require('wibox')
|
||||
local gfilesystem = require('gears.filesystem')
|
||||
local gtimer = require('gears.timer')
|
||||
local aspawn = require('awful.spawn')
|
||||
local gcolor = require('gears.color')
|
||||
|
||||
local json_lua = require('src.lib.json-lua.json-lua')
|
||||
|
||||
-- Icon directory path
|
||||
local icondir = gfilesystem.get_configuration_dir() .. 'src/assets/icons/weather/'
|
||||
|
||||
local instance = nil
|
||||
|
||||
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',
|
||||
}
|
||||
|
||||
if not instance then
|
||||
instance = setmetatable({}, { __call = function()
|
||||
|
||||
local w = wibox.widget {
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{ -- Icon
|
||||
valign = 'center',
|
||||
halign = 'center',
|
||||
widget = wibox.widget.imagebox,
|
||||
id = 'icon',
|
||||
},
|
||||
widget = wibox.container.constraint,
|
||||
width = dpi(64),
|
||||
height = dpi(64),
|
||||
strategy = 'exact',
|
||||
},
|
||||
{ -- Temperature
|
||||
text = 'NaN°C',
|
||||
valign = 'center',
|
||||
halign = 'center',
|
||||
widget = wibox.widget.textbox,
|
||||
font = 'JetBrains Mono Bold 24',
|
||||
id = 'temp',
|
||||
},
|
||||
{ -- City, Country
|
||||
text = 'City, Country',
|
||||
valign = 'center',
|
||||
halign = 'center',
|
||||
widget = wibox.widget.textbox,
|
||||
id = 'city_country',
|
||||
},
|
||||
{
|
||||
{ -- Description
|
||||
text = 'NaN',
|
||||
valign = 'center',
|
||||
halign = 'center',
|
||||
widget = wibox.widget.textbox,
|
||||
id = 'description',
|
||||
},
|
||||
fg = Theme_config.notification_center.weather.description_fg,
|
||||
widget = wibox.container.background,
|
||||
},
|
||||
{ -- line
|
||||
{
|
||||
bg = Theme_config.notification_center.weather.line_color,
|
||||
widget = wibox.container.background,
|
||||
},
|
||||
widget = wibox.container.constraint,
|
||||
height = dpi(2),
|
||||
width = dpi(10),
|
||||
strategy = 'exact',
|
||||
},
|
||||
{
|
||||
{ -- Speed
|
||||
{
|
||||
image = gcolor.recolor_image(icondir .. 'weather-windy.svg',
|
||||
Theme_config.notification_center.weather.speed_icon_color),
|
||||
valign = 'center',
|
||||
halign = 'center',
|
||||
widget = wibox.widget.imagebox,
|
||||
},
|
||||
widget = wibox.container.constraint,
|
||||
width = dpi(24),
|
||||
height = dpi(24),
|
||||
strategy = 'exact',
|
||||
},
|
||||
{
|
||||
text = 'NaN m/s',
|
||||
valign = 'center',
|
||||
halign = 'center',
|
||||
widget = wibox.widget.textbox,
|
||||
id = 'speed',
|
||||
},
|
||||
spacing = dpi(10),
|
||||
layout = wibox.layout.fixed.horizontal,
|
||||
},
|
||||
{
|
||||
{ -- Humidity
|
||||
{
|
||||
{
|
||||
widget = wibox.widget.imagebox,
|
||||
valign = 'center',
|
||||
halign = 'center',
|
||||
image = gcolor.recolor_image(icondir .. 'humidity.svg',
|
||||
Theme_config.notification_center.weather.humidity_icon_color),
|
||||
},
|
||||
widget = wibox.container.constraint,
|
||||
width = dpi(24),
|
||||
height = dpi(24),
|
||||
strategy = 'exact',
|
||||
},
|
||||
{
|
||||
text = 'NaN%',
|
||||
valign = 'center',
|
||||
halign = 'center',
|
||||
widget = wibox.widget.textbox,
|
||||
id = 'humidity',
|
||||
},
|
||||
spacing = dpi(10),
|
||||
layout = wibox.layout.fixed.horizontal,
|
||||
},
|
||||
widget = wibox.container.place,
|
||||
},
|
||||
spacing = dpi(10),
|
||||
layout = wibox.layout.fixed.vertical,
|
||||
},
|
||||
margins = dpi(20),
|
||||
widget = wibox.container.margin,
|
||||
},
|
||||
widget = wibox.container.place,
|
||||
},
|
||||
border_color = Theme_config.notification_center.weather.border_color,
|
||||
border_width = Theme_config.notification_center.weather.border_width,
|
||||
shape = Theme_config.notification_center.weather.shape,
|
||||
widget = wibox.container.background,
|
||||
},
|
||||
top = dpi(20),
|
||||
left = dpi(20),
|
||||
right = dpi(10),
|
||||
bottom = dpi(10),
|
||||
widget = wibox.container.margin,
|
||||
},
|
||||
widget = wibox.container.constraint,
|
||||
width = dpi(250),
|
||||
strategy = 'exact',
|
||||
}
|
||||
|
||||
gtimer {
|
||||
timeout = 900,
|
||||
autostart = true,
|
||||
call_now = true,
|
||||
callback = function()
|
||||
aspawn.easy_async_with_shell("curl -sf 'http://api.openweathermap.org/data/2.5/weather?id=" ..
|
||||
User_config.weather_secrets.city_id .. '&units=' .. User_config.weather_secrets.unit .. '&appid=' .. User_config.weather_secrets.key .. "'",
|
||||
function(stdout)
|
||||
if not stdout:match('error') then
|
||||
local weather_metadata = json_lua:decode(stdout)
|
||||
if weather_metadata then
|
||||
w:get_children_by_id('icon')[1].image = icondir .. icon_table[weather_metadata.weather[1].icon] .. '.svg'
|
||||
w:get_children_by_id('temp')[1].text = math.floor(weather_metadata.main.temp + 0.5) .. '°C'
|
||||
w:get_children_by_id('city_country')[1].text = weather_metadata.name .. ', ' .. weather_metadata.sys.country
|
||||
w:get_children_by_id('description')[1].text = weather_metadata.weather[1].description:sub(1, 1):upper() ..
|
||||
weather_metadata.weather[1].description:sub(2)
|
||||
w:get_children_by_id('speed')[1].text = weather_metadata.wind.speed .. ' m/s'
|
||||
w:get_children_by_id('humidity')[1].text = weather_metadata.main.humidity .. '%'
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
end,
|
||||
}
|
||||
|
||||
return w
|
||||
|
||||
end, })
|
||||
end
|
||||
|
||||
return instance
|
||||
Reference in New Issue
Block a user