Initial commit

This commit is contained in:
Hydroxycarbamide 2022-08-27 21:35:40 +02:00
commit 093dec7f93
143 changed files with 7456 additions and 0 deletions

127
src/widgets/audio.lua Normal file
View file

@ -0,0 +1,127 @@
------------------------------
-- This is the audio widget --
------------------------------
-- Awesome Libs
local awful = require("awful")
local color = require("src.theme.colors")
local dpi = require("beautiful").xresources.apply_dpi
local gears = require("gears")
local wibox = require("wibox")
require("src.core.signals")
-- Icon directory path
local icondir = awful.util.getdir("config") .. "src/assets/icons/audio/"
-- Returns the audio widget
return function(s)
local audio_widget = wibox.widget {
{
{
{
{
{
id = "icon",
widget = wibox.widget.imagebox,
resize = false
},
id = "icon_layout",
widget = wibox.container.place
},
top = dpi(2),
widget = wibox.container.margin,
id = "icon_margin"
},
spacing = dpi(10),
{
id = "label",
align = "center",
valign = "center",
widget = wibox.widget.textbox
},
id = "audio_layout",
layout = wibox.layout.fixed.horizontal
},
id = "container",
left = dpi(8),
right = dpi(8),
widget = wibox.container.margin
},
bg = color["Yellow200"],
fg = color["Grey900"],
shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, 5)
end,
widget = wibox.container.background
}
local get_volume = function()
awful.spawn.easy_async_with_shell(
"./.config/awesome/src/scripts/vol.sh volume",
function(stdout)
local icon = icondir .. "volume"
stdout = stdout:gsub("%%", "")
local volume = tonumber(stdout) or 0
audio_widget.container.audio_layout.spacing = dpi(5)
audio_widget.container.audio_layout.label.visible = true
if volume < 1 then
icon = icon .. "-mute"
audio_widget.container.audio_layout.spacing = dpi(0)
audio_widget.container.audio_layout.label.visible = false
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
audio_widget.container.audio_layout.label:set_text(volume .. "%")
audio_widget.container.audio_layout.icon_margin.icon_layout.icon:set_image(
gears.color.recolor_image(icon .. ".svg", color["Grey900"]))
awesome.emit_signal("get::volume", volume)
end
)
end
local check_muted = function()
awful.spawn.easy_async_with_shell(
"./.config/awesome/src/scripts/vol.sh mute",
function(stdout)
if stdout:match("yes") then
audio_widget.container.audio_layout.label.visible = false
audio_widget.container:set_right(0)
audio_widget.container.audio_layout.icon_margin.icon_layout.icon:set_image(
gears.color.recolor_image(icondir .. "volume-mute" .. ".svg", color["Grey900"]))
awesome.emit_signal("get::volume_mute", true)
else
audio_widget.container:set_right(10)
awesome.emit_signal("get::volume_mute", false)
get_volume()
end
end
)
end
-- Signals
Hover_signal(audio_widget, color["Yellow200"], color["Grey900"])
audio_widget:connect_signal(
"button::press",
function()
awesome.emit_signal("module::slider:update")
awesome.emit_signal("widget::volume_osd:rerun")
awesome.emit_signal("volume_controller::toggle", s)
awesome.emit_signal("volume_controller::toggle:keygrabber")
end
)
gears.timer {
timeout = 0.5,
call_now = true,
autostart = true,
callback = check_muted
}
check_muted()
return audio_widget
end

204
src/widgets/battery.lua Normal file
View file

@ -0,0 +1,204 @@
--------------------------------
-- This is the battery widget --
--------------------------------
-- Awesome Libs
local awful = require("awful")
local color = require("src.theme.colors")
local dpi = require("beautiful").xresources.apply_dpi
local gears = require("gears")
local naughty = require("naughty")
local watch = awful.widget.watch
local wibox = require("wibox")
require("src.core.signals")
-- Icon directory path
local icondir = awful.util.getdir("config") .. "src/assets/icons/battery/"
-- Returns the battery widget
return function()
local battery_widget = wibox.widget {
{
{
{
{
{
id = "icon",
image = gears.color.recolor_image(icondir .. "battery-unknown.svg", "#212121"),
widget = wibox.widget.imagebox,
resize = false
},
id = "icon_layout",
widget = wibox.container.place
},
id = "icon_margin",
top = dpi(2),
widget = wibox.container.margin
},
spacing = dpi(10),
{
visible = false,
align = 'center',
valign = 'center',
id = "label",
widget = wibox.widget.textbox
},
id = "battery_layout",
layout = wibox.layout.fixed.horizontal
},
id = "container",
left = dpi(8),
right = dpi(8),
widget = wibox.container.margin
},
bg = color["Purple200"],
fg = color["Grey900"],
shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, 5)
end,
widget = wibox.container.background
}
local battery_tooltip = awful.tooltip {
objects = { battery_widget },
text = "",
mode = "inside",
preferred_alignments = "middle",
margins = dpi(10)
}
local get_battery_info = function()
awful.spawn.easy_async_with_shell(
[[ upower -i $(upower -e | grep BAT) | grep "time to " ]],
function(stdout)
if stdout == nil or stdout == '' then
battery_tooltip:set_text('No Battery Found')
return
end
local rem_time = ""
if stdout:match("hour") then
rem_time = "Hours"
else
rem_time = "Minutes"
end
local bat_time = stdout:match("%d+,%d") or stdout:match("%d+.%d") or ""
if stdout:match("empty") then
battery_tooltip:set_text("Remaining battery time: " .. bat_time .. " " .. rem_time)
elseif stdout:match("time to full") then
battery_tooltip:set_text("Battery fully charged in: " .. bat_time .. " " .. rem_time)
end
end
)
end
get_battery_info()
local last_battery_check = os.time()
local notify_critical_battery = true
local battery_warning = function()
naughty.notification {
icon = gears.color.recolor_image(icondir .. "battery-alert.svg", color["White"]),
app_name = "System notification",
title = "Battery is low",
message = "Battery is almost empty",
urgency = "critical"
}
end
local update_battery = function(status)
awful.spawn.easy_async_with_shell(
[[sh -c "upower -i $(upower -e | grep BAT) | grep percentage | awk '{print \$2}' |tr -d '\n%'"]],
function(stdout)
local battery_percentage = tonumber(stdout)
if not battery_percentage then
return
end
battery_widget.container.battery_layout.spacing = dpi(5)
battery_widget.container.battery_layout.label.visible = true
battery_widget.container.battery_layout.label:set_text(battery_percentage .. '%')
local icon = 'battery'
if status == 'fully-charged' or status == 'charging' and battery_percentage == 100 then
icon = icon .. '-' .. 'charging'
battery_widget.container.battery_layout.icon_margin.icon_layout.icon:set_image(gears.surface.load_uncached(
gears.color.recolor_image(icondir .. icon .. '.svg', "#212121")))
return
end
if battery_percentage > 0 and battery_percentage < 10 and status == 'discharging' then
icon = icon .. '-' .. 'alert'
if (os.difftime(os.time(), last_battery_check) > 300 or notify_critical_battery) then
last_battery_check = os.time()
notify_critical_battery = false
battery_warning()
end
battery_widget.container.battery_layout.icon_margin.icon_layout.icon:set_image(gears.surface.load_uncached(
gears.color.recolor_image(icondir .. icon .. '.svg', "#212121")))
return
end
if battery_percentage > 0 and battery_percentage < 10 then
icon = icon .. '-' .. status .. '-' .. 'outline'
elseif battery_percentage >= 10 and battery_percentage < 20 then
icon = icon .. '-' .. status .. '-' .. '10'
elseif battery_percentage >= 20 and battery_percentage < 30 then
icon = icon .. '-' .. status .. '-' .. '20'
elseif battery_percentage >= 30 and battery_percentage < 40 then
icon = icon .. '-' .. status .. '-' .. '30'
elseif battery_percentage >= 40 and battery_percentage < 50 then
icon = icon .. '-' .. status .. '-' .. '40'
elseif battery_percentage >= 50 and battery_percentage < 60 then
icon = icon .. '-' .. status .. '-' .. '50'
elseif battery_percentage >= 60 and battery_percentage < 70 then
icon = icon .. '-' .. status .. '-' .. '60'
elseif battery_percentage >= 70 and battery_percentage < 80 then
icon = icon .. '-' .. status .. '-' .. '70'
elseif battery_percentage >= 80 and battery_percentage < 90 then
icon = icon .. '-' .. status .. '-' .. '80'
elseif battery_percentage >= 90 and battery_percentage < 100 then
icon = icon .. '-' .. status .. '-' .. '90'
end
battery_widget.container.battery_layout.icon_margin.icon_layout.icon:set_image(gears.surface.load_uncached(
gears.color.recolor_image(icondir .. icon .. '.svg', "#212121")))
end
)
end
Hover_signal(battery_widget, color["Purple200"], color["Grey900"])
battery_widget:connect_signal(
'button::press',
function()
awful.spawn("xfce4-power-manager-settings")
end
)
battery_widget:connect_signal(
"mouse::enter",
function()
get_battery_info()
end
)
watch(
[[sh -c "upower -i $(upower -e | grep BAT) | grep state | awk '{print \$2}' | tr -d '\n'"]],
5,
function(widget, stdout)
local status = stdout:gsub('%\n', '')
if status == nil or status == '' then
battery_widget.container.battery_layout.spacing = dpi(0)
battery_widget.container.battery_layout.label.visible = false
battery_tooltip:set_text('No battery found')
battery_widget.container.battery_layout.icon_margin.icon_layout.icon:set_image(gears.surface.load_uncached(
gears.color.recolor_image(icondir .. 'battery-off' .. '.svg', "#212121")))
end
update_battery(status)
end
)
return battery_widget
end

131
src/widgets/bluetooth.lua Normal file
View file

@ -0,0 +1,131 @@
----------------------------------
-- This is the bluetooth widget --
----------------------------------
-- Awesome Libs
local awful = require("awful")
local color = require("src.theme.colors")
local dpi = require("beautiful").xresources.apply_dpi
local gears = require("gears")
local naughty = require("naughty")
local wibox = require("wibox")
require("src.core.signals")
-- Icon directory path
local icondir = awful.util.getdir("config") .. "src/assets/icons/bluetooth/"
-- Returns the bluetooth widget
return function()
local bluetooth_widget = wibox.widget {
{
{
{
id = "icon",
image = gears.color.recolor_image(icondir .. "bluetooth-off.svg"),
widget = wibox.widget.imagebox,
resize = false
},
id = "icon_layout",
widget = wibox.container.place
},
id = "icon_margin",
left = dpi(8),
right = dpi(8),
widget = wibox.container.margin
},
bg = color["Blue200"],
fg = color["Grey900"],
shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, 5)
end,
widget = wibox.container.background
}
local bluetooth_tooltip = awful.tooltip {
objects = { bluetooth_widget },
text = "",
mode = "inside",
preferred_alignments = "middle",
margins = dpi(10)
}
local bluetooth_state = "off"
local connected_device = "nothing"
awful.widget.watch(
"rfkill list bluetooth",
5,
function(_, stdout)
local icon = icondir .. "bluetooth"
if stdout:match('Soft blocked: yes') or stdout:gsub("\n", "") == '' then
icon = icon .. "-off"
bluetooth_state = "off"
bluetooth_tooltip:set_text("Bluetooth is turned " .. bluetooth_state .. "\n")
else
icon = icon .. "-on"
bluetooth_state = "on"
awful.spawn.easy_async_with_shell(
'./.config/awesome/src/scripts/bt.sh',
function(stdout2)
if stdout2 == nil or stdout2:gsub("\n", "") == "" then
bluetooth_tooltip:set_text("Bluetooth is turned " .. bluetooth_state .. "\n" .. "You are currently not connected")
else
connected_device = stdout2:gsub("%(", ""):gsub("%)", "")
bluetooth_tooltip:set_text("Bluetooth is turned " .. bluetooth_state .. "\n" .. "You are currently connected to:\n" .. connected_device)
end
end
)
end
bluetooth_widget.icon_margin.icon_layout.icon:set_image(gears.color.recolor_image(icon .. ".svg", color["Grey900"]))
end,
bluetooth_widget
)
-- Signals
Hover_signal(bluetooth_widget, color["Blue200"], color["Grey900"])
bluetooth_widget:connect_signal(
"button::press",
function()
awful.spawn.easy_async_with_shell(
"rfkill list bluetooth",
function(stdout)
if stdout:gsub("\n", "") ~= '' then
if bluetooth_state == "off" then
awful.spawn.easy_async_with_shell(
[[
rfkill unblock bluetooth
sleep 1
bluetoothctl power on
]] ,
function()
naughty.notification {
title = "System Notification",
app_name = "Bluetooth",
message = "Bluetooth activated"
}
end
)
else
awful.spawn.easy_async_with_shell(
[[
bluetoothctl power off
rfkill block bluetooth
]] ,
function()
naughty.notification {
title = "System Notification",
app_name = "Bluetooth",
message = "Bluetooth deactivated"
}
end
)
end
end
end
)
end
)
return bluetooth_widget
end

64
src/widgets/clock.lua Normal file
View file

@ -0,0 +1,64 @@
------------------------------
-- This is the clock widget --
------------------------------
-- Awesome Libs
local awful = require("awful")
local color = require("src.theme.colors")
local dpi = require("beautiful").xresources.apply_dpi
local gears = require("gears")
local wibox = require("wibox")
require("src.core.signals")
-- Icon directory path
local icondir = awful.util.getdir("config") .. "src/assets/icons/clock/"
-- Returns the clock widget
return function()
local clock_widget = wibox.widget {
{
{
{
{
{
id = "icon",
image = gears.color.recolor_image(icondir .. "clock.svg", color["Grey900"]),
widget = wibox.widget.imagebox,
resize = false
},
id = "icon_layout",
widget = wibox.container.place
},
id = "icon_margin",
top = dpi(2),
widget = wibox.container.margin
},
spacing = dpi(10),
{
id = "label",
align = "center",
valign = "center",
format = "%H:%M",
widget = wibox.widget.textclock
},
id = "clock_layout",
layout = wibox.layout.fixed.horizontal
},
id = "container",
left = dpi(8),
right = dpi(8),
widget = wibox.container.margin
},
bg = color["Orange200"],
fg = color["Grey900"],
shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, 5)
end,
widget = wibox.container.background
}
Hover_signal(clock_widget, color["Orange200"], color["Grey900"])
return clock_widget
end

226
src/widgets/cpu_info.lua Normal file
View file

@ -0,0 +1,226 @@
---------------------------------
-- This is the CPU Info widget --
---------------------------------
-- Awesome Libs
local awful = require("awful")
local color = require("src.theme.colors")
local dpi = require("beautiful").xresources.apply_dpi
local gears = require("gears")
local watch = awful.widget.watch
local wibox = require("wibox")
require("src.core.signals")
local icon_dir = awful.util.getdir("config") .. "src/assets/icons/cpu/"
--TODO: Add tooltip with more CPU and per core information
return function(widget, clock_mode)
local cpu_usage_widget = wibox.widget {
{
{
{
{
{
id = "icon",
widget = wibox.widget.imagebox,
image = gears.color.recolor_image(icon_dir .. "cpu.svg", color["Grey900"]),
resize = false
},
id = "icon_layout",
widget = wibox.container.place
},
top = dpi(2),
widget = wibox.container.margin,
id = "icon_margin"
},
spacing = dpi(10),
{
id = "label",
align = "center",
valign = "center",
widget = wibox.widget.textbox
},
id = "cpu_layout",
layout = wibox.layout.fixed.horizontal
},
id = "container",
left = dpi(8),
right = dpi(8),
widget = wibox.container.margin
},
bg = color["Blue200"],
fg = color["Grey900"],
shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, 5)
end,
widget = wibox.container.background
}
local cpu_temp = wibox.widget {
{
{
{
{
{
id = "icon",
widget = wibox.widget.imagebox,
resize = false
},
id = "icon_layout",
widget = wibox.container.place
},
top = dpi(2),
widget = wibox.container.margin,
id = "icon_margin"
},
spacing = dpi(10),
{
id = "label",
align = "center",
valign = "center",
widget = wibox.widget.textbox
},
id = "cpu_layout",
layout = wibox.layout.fixed.horizontal
},
id = "container",
left = dpi(8),
right = dpi(8),
widget = wibox.container.margin
},
bg = color["Green200"],
fg = color["Grey900"],
shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, 5)
end,
widget = wibox.container.background
}
local cpu_clock = wibox.widget {
{
{
{
{
{
id = "icon",
widget = wibox.widget.imagebox,
image = icon_dir .. "cpu.svg",
resize = false
},
id = "icon_layout",
widget = wibox.container.place
},
top = dpi(2),
widget = wibox.container.margin,
id = "icon_margin"
},
spacing = dpi(10),
{
id = "label",
align = "center",
valign = "center",
widget = wibox.widget.textbox
},
id = "cpu_layout",
layout = wibox.layout.fixed.horizontal
},
id = "container",
left = dpi(8),
right = dpi(8),
widget = wibox.container.margin
},
bg = color["Purple200"],
fg = color["Grey900"],
shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, 5)
end,
widget = wibox.container.background
}
local total_prev = 0
local idle_prev = 0
watch(
[[ cat "/proc/stat" | grep '^cpu ' ]],
3,
function(_, stdout)
local user, nice, system, idle, iowait, irq, softirq, steal, guest, guest_nice =
stdout:match("(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s(%d+)%s")
local total = user + nice + system + idle + iowait + irq + softirq + steal
local diff_idle = idle - idle_prev
local diff_total = total - total_prev
local diff_usage = (1000 * (diff_total - diff_idle) / diff_total + 5) / 10
cpu_usage_widget.container.cpu_layout.label.text = tostring(math.floor(diff_usage)) .. "%"
total_prev = total
idle_prev = idle
collectgarbage("collect")
end
)
watch(
[[ bash -c "sensors | grep 'Tctl:' | awk '{print $2}'" ]],
3,
function(_, stdout)
local temp_icon
local temp_color
local temp_num = tonumber(stdout:match("%d+"))
if temp_num < 50 then
temp_color = color["Green200"]
temp_icon = icon_dir .. "thermometer-low.svg"
elseif temp_num >= 50 and temp_num < 80 then
temp_color = color["Orange200"]
temp_icon = icon_dir .. "thermometer.svg"
elseif temp_num >= 80 then
temp_color = color["Red200"]
temp_icon = icon_dir .. "thermometer-high.svg"
end
Hover_signal(cpu_temp, temp_color, color["Grey900"])
cpu_temp.container.cpu_layout.icon_margin.icon_layout.icon:set_image(temp_icon)
cpu_temp:set_bg(temp_color)
cpu_temp.container.cpu_layout.label.text = math.floor(temp_num) .. "°C"
end
)
watch(
[[ bash -c "cat /proc/cpuinfo | grep "MHz" | awk '{print int($4)}'" ]],
3,
function(_, stdout)
local cpu_freq = {}
for value in stdout:gmatch("%d+") do
table.insert(cpu_freq, value)
end
local average = 0
if clock_mode == "average" then
for i = 1, #cpu_freq do
average = average + cpu_freq[i]
end
average = math.floor(average / #cpu_freq)
cpu_clock.container.cpu_layout.label.text = tonumber(average) .. "Mhz"
elseif clock_mode then
cpu_clock.container.cpu_layout.label.text = tonumber(cpu_freq[clock_mode]) .. "Mhz"
end
end
)
Hover_signal(cpu_usage_widget, color["Blue200"], color["Grey900"])
Hover_signal(cpu_clock, color["Purple200"], color["Grey900"])
if widget == "usage" then
return cpu_usage_widget
elseif widget == "temp" then
return cpu_temp
elseif widget == "freq" then
return cpu_clock
end
end

92
src/widgets/date.lua Normal file
View file

@ -0,0 +1,92 @@
-----------------------------
-- This is the date widget --
-----------------------------
-- Awesome Libs
local awful = require("awful")
local color = require("src.theme.colors")
local dpi = require("beautiful").xresources.apply_dpi
local gears = require("gears")
local wibox = require("wibox")
require("src.core.signals")
-- Icon directory path
local icondir = awful.util.getdir("config") .. "src/assets/icons/date/"
-- Returns the date widget
return function()
local date_widget = wibox.widget {
{
{
{
{
{
id = "icon",
image = gears.color.recolor_image(icondir .. "calendar.svg", color["Grey900"]),
widget = wibox.widget.imagebox,
resize = false
},
id = "icon_layout",
widget = wibox.container.place
},
id = "icon_margin",
top = dpi(2),
widget = wibox.container.margin
},
spacing = dpi(10),
{
id = "label",
align = "center",
valign = "center",
widget = wibox.widget.textbox
},
id = "date_layout",
layout = wibox.layout.fixed.horizontal
},
id = "container",
left = dpi(8),
right = dpi(8),
widget = wibox.container.margin
},
bg = color["Teal200"],
fg = color["Grey900"],
shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, 5)
end,
widget = wibox.container.background
}
local set_date = function()
date_widget.container.date_layout.label:set_text(os.date("%Y-%m-%d"))
end
-- Updates the date every minute, dont blame me if you miss silvester
gears.timer {
timeout = 60,
autostart = true,
call_now = true,
callback = function()
set_date()
end
}
-- Signals
Hover_signal(date_widget, color["Teal200"], color["Grey900"])
date_widget:connect_signal(
"mouse::enter",
function()
awesome.emit_signal("widget::calendar_osd:stop", true)
end
)
date_widget:connect_signal(
"mouse::leave",
function()
awesome.emit_signal("widget::calendar_osd:rerun", true)
end
)
return date_widget
end

151
src/widgets/gpu_info.lua Normal file
View file

@ -0,0 +1,151 @@
---------------------------------
-- This is the CPU Info widget --
---------------------------------
-- Awesome Libs
local awful = require("awful")
local color = require("src.theme.colors")
local dpi = require("beautiful").xresources.apply_dpi
local gears = require("gears")
local watch = awful.widget.watch
local wibox = require("wibox")
require("src.core.signals")
local icon_dir = awful.util.getdir("config") .. "src/assets/icons/cpu/"
return function(widget)
local gpu_usage_widget = wibox.widget {
{
{
{
{
{
id = "icon",
widget = wibox.widget.imagebox,
image = gears.color.recolor_image(icon_dir .. "gpu.svg", color["Grey900"]),
resize = false
},
id = "icon_layout",
widget = wibox.container.place
},
top = dpi(2),
widget = wibox.container.margin,
id = "icon_margin"
},
spacing = dpi(10),
{
id = "label",
align = "center",
valign = "center",
widget = wibox.widget.textbox
},
id = "gpu_layout",
layout = wibox.layout.fixed.horizontal
},
id = "container",
left = dpi(8),
right = dpi(8),
widget = wibox.container.margin
},
bg = color["Green200"],
fg = color["Grey900"],
shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, 5)
end,
widget = wibox.container.background
}
Hover_signal(gpu_usage_widget, color["Green200"], color["Grey900"])
local gpu_temp_widget = wibox.widget {
{
{
{
{
{
id = "icon",
widget = wibox.widget.imagebox,
image = gears.color.recolor_image(icon_dir .. "cpu.svg", color["Grey900"]),
resize = false
},
id = "icon_layout",
widget = wibox.container.place
},
top = dpi(2),
widget = wibox.container.margin,
id = "icon_margin"
},
spacing = dpi(10),
{
id = "label",
align = "center",
valign = "center",
widget = wibox.widget.textbox
},
id = "gpu_layout",
layout = wibox.layout.fixed.horizontal
},
id = "container",
left = dpi(8),
right = dpi(8),
widget = wibox.container.margin
},
bg = color["Blue200"],
fg = color["Grey900"],
shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, 5)
end,
widget = wibox.container.background
}
-- GPU Utilization
watch(
[[ bash -c "nvidia-smi -q -d UTILIZATION | grep Gpu | awk '{print $3}'"]],
3,
function(_, stdout)
gpu_usage_widget.container.gpu_layout.label.text = stdout:gsub("\n", "") .. "%"
awesome.emit_signal("update::gpu_usage_widget", tonumber(stdout))
end
)
-- GPU Temperature
watch(
[[ bash -c "nvidia-smi -q -d TEMPERATURE | grep 'GPU Current Temp' | awk '{print $5}'"]],
3,
function(_, stdout)
local temp_icon
local temp_color
local temp_num = tonumber(stdout)
if temp_num then
if temp_num < 50 then
temp_color = color["Green200"]
temp_icon = icon_dir .. "thermometer-low.svg"
elseif temp_num >= 50 and temp_num < 80 then
temp_color = color["Orange200"]
temp_icon = icon_dir .. "thermometer.svg"
elseif temp_num >= 80 then
temp_color = color["Red200"]
temp_icon = icon_dir .. "thermometer-high.svg"
end
else
temp_num = "NaN"
temp_color = color["Green200"]
temp_icon = icon_dir .. "thermometer-low.svg"
end
Hover_signal(gpu_temp_widget, temp_color, color["Grey900"])
gpu_temp_widget.container.gpu_layout.icon_margin.icon_layout.icon:set_image(temp_icon)
gpu_temp_widget:set_bg(temp_color)
gpu_temp_widget.container.gpu_layout.label.text = tostring(temp_num) .. "°C"
awesome.emit_signal("update::gpu_temp_widget", temp_num, temp_icon)
end
)
if widget == "usage" then
return gpu_usage_widget
elseif widget == "temp" then
return gpu_temp_widget
end
end

391
src/widgets/kblayout.lua Normal file
View file

@ -0,0 +1,391 @@
------------------------------
-- This is the audio widget --
------------------------------
-- Awesome Libs
local awful = require("awful")
local color = require("src.theme.colors")
local dpi = require("beautiful").xresources.apply_dpi
local gears = require("gears")
local wibox = require("wibox")
require("src.core.signals")
-- Icon directory path
local icondir = awful.util.getdir("config") .. "src/assets/icons/kblayout/"
return function(s)
local kblayout_widget = wibox.widget {
{
{
{
{
{
id = "icon",
widget = wibox.widget.imagebox,
resize = false,
image = gears.color.recolor_image(icondir .. "keyboard.svg", color["Grey900"])
},
id = "icon_layout",
widget = wibox.container.place
},
top = dpi(2),
widget = wibox.container.margin,
id = "icon_margin"
},
spacing = dpi(10),
{
id = "label",
align = "center",
valign = "center",
widget = wibox.widget.textbox
},
id = "kblayout_layout",
layout = wibox.layout.fixed.horizontal
},
id = "container",
left = dpi(8),
right = dpi(8),
widget = wibox.container.margin
},
bg = color["Green200"],
fg = color["Grey900"],
shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, 5)
end,
widget = wibox.container.background
}
local function get_kblayout()
awful.spawn.easy_async_with_shell(
[[ setxkbmap -query | grep layout | awk '{print $2}' ]],
function(stdout)
local layout = stdout:gsub("\n", "")
kblayout_widget.container.kblayout_layout.label.text = layout
awesome.emit_signal("update::background:kblayout")
end
)
end
local function create_kb_layout_item(keymap)
-- TODO: Add more, too lazy rn
local longname, shortname
local xkeyboard_country_code = {
{ "af", "أفغانيش(Afghanistan)", "AFG" }, -- Afghanistan
{ "al", "Shqip(Albania)", "ALB" }, -- Albania
{ "am", "Hայերեն(Armenia)", "ARM" }, -- Armenia
{ "ara", "عربي(Arab)", "ARB" }, -- Arabic
{ "at", "Österreichisch (Austria)", "AUT" }, -- Austria
{ "az", "Azərbaycan(Azerbaijan)", "AZE" }, -- Azerbaijan
{ "ba", "Bosanski(Bosnia and Herzegovina)", "BIH" }, -- Bosnia and Herzegovina
{ "bd", "", "BGD" }, -- Bangladesh
{ "be", "", "BEL" }, -- Belgium
{ "bg", "", "BGR" }, -- Bulgaria
{ "br", "", "BRA" }, -- Brazil
{ "bt", "", "BTN" }, -- Bhutan
{ "bw", "", "BWA" }, -- Botswana
{ "by", "", "BLR" }, -- Belarus
{ "ca", "", "CAN" }, -- Canada
{ "cd", "", "COD" }, -- Congo
{ "ch", "", "CHE" }, -- Switzerland
{ "cm", "", "CMR" }, -- Cameroon
{ "cn", "", "CHN" }, -- China
{ "cz", "", "CZE" }, -- Czechia
{ "de", "Deutsch (Germany)", "GER" }, -- Germany
{ "dk", "", "DNK" }, -- Denmark
{ "ee", "", "EST" }, -- Estonia
{ "es", "", "ESP" }, -- Spain
{ "et", "", "ETH" }, -- Ethiopia
{ "eu", "?", "?" }, -- EurKey
{ "fi", "", "FIN" }, -- Finland
{ "fo", "", "FRO" }, -- Faroe Islands
{ "fr", "", "FRA" }, -- France
{ "gb", "English (Bri'ish)", "ENG" }, -- United Kingdom
{ "ge", "", "GEO" }, -- Georgia
{ "gh", "", "GHA" }, -- Ghana
{ "gn", "", "GIN" }, -- Guinea
{ "gr", "", "GRC" }, -- Greece
{ "hr", "", "HRV" }, -- Croatia
{ "hu", "", "HUN" }, -- Hungary
{ "ie", "", "IRL" }, -- Ireland
{ "il", "", "ISR" }, -- Israel
{ "in", "", "IND" }, -- India
{ "iq", "", "IRQ" }, -- Iraq
{ "ir", "", "IRN" }, -- Iran
{ "is", "", "ISL" }, -- Iceland
{ "it", "", "ITA" }, -- Italy
{ "jp", "", "JPN" }, -- Japan
{ "ke", "", "KEN" }, -- Kenya
{ "kg", "", "KGZ" }, -- Kyrgyzstan
{ "kh", "", "KHM" }, -- Cambodia
{ "kr", "", "KOR" }, -- Korea
{ "kz", "", "KAZ" }, -- Kazakhstan
{ "la", "", "LAO" }, -- Laos
{ "latam", "?", "?" }, -- Latin America
{ "latin", "?", "?" }, -- Latin
{ "lk", "", "LKA" }, -- Sri Lanka
{ "lt", "", "LTU" }, -- Lithuania
{ "lv", "", "LVA" }, -- Latvia
{ "ma", "", "MAR" }, -- Morocco
{ "mao", "?", "?" }, -- Maori
{ "me", "", "MNE" }, -- Montenegro
{ "mk", "", "MKD" }, -- Macedonia
{ "ml", "", "MLI" }, -- Mali
{ "mm", "", "MMR" }, -- Myanmar
{ "mn", "", "MNG" }, -- Mongolia
{ "mt", "", "MLT" }, -- Malta
{ "mv", "", "MDV" }, -- Maldives
{ "ng", "", "NGA" }, -- Nigeria
{ "nl", "", "NLD" }, -- Netherlands
{ "no", "", "NOR" }, -- Norway
{ "np", "", "NRL" }, -- Nepal
{ "ph", "", "PHL" }, -- Philippines
{ "pk", "", "PAK" }, -- Pakistan
{ "pl", "", "POL" }, -- Poland
{ "pt", "", "PRT" }, -- Portugal
{ "ro", "", "ROU" }, -- Romania
{ "rs", "", "SRB" }, -- Serbia
{ "ru", "Русский (Russia)", "RUS" }, -- Russia
{ "se", "", "SWE" }, -- Sweden
{ "si", "", "SVN" }, -- Slovenia
{ "sk", "", "SVK" }, -- Slovakia
{ "sn", "", "SEN" }, -- Senegal
{ "sy", "", "SYR" }, -- Syria
{ "th", "", "THA" }, -- Thailand
{ "tj", "", "TJK" }, -- Tajikistan
{ "tm", "", "TKM" }, -- Turkmenistan
{ "tr", "", "TUR" }, -- Turkey
{ "tw", "", "TWN" }, -- Taiwan
{ "tz", "", "TZA" }, -- Tanzania
{ "ua", "", "UKR" }, -- Ukraine
{ "us", "English (United States)", "USA" }, -- USA
{ "uz", "", "UZB" }, -- Uzbekistan
{ "vn", "", "VNM" }, -- Vietnam
{ "za", "", "ZAF" } -- South Africa
}
for _, c in ipairs(xkeyboard_country_code) do
if c[1] == keymap then
longname = c[2]
shortname = c[3]
end
end
local kb_layout_item = wibox.widget {
{
{
-- Short name e.g. GER, ENG, RUS
{
{
text = shortname,
widget = wibox.widget.textbox,
font = user_vars.font.extrabold,
id = "shortname"
},
fg = color["Red200"],
widget = wibox.container.background,
id = "background2"
},
{
{
text = longname,
widget = wibox.widget.textbox,
font = user_vars.font.bold,
id = "longname",
},
fg = color["Purple200"],
widget = wibox.container.background,
id = "background1"
},
spacing = dpi(15),
layout = wibox.layout.fixed.horizontal,
id = "container"
},
margins = dpi(10),
widget = wibox.container.margin,
id = "margin"
},
shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, 8)
end,
bg = color["Grey800"],
fg = color["White"],
widget = wibox.container.background,
id = "background",
keymap = keymap
}
-- TODO: Hover effects, this is more pain than I'm willing to take for now
awesome.connect_signal(
"update::background:kblayout",
function()
awful.spawn.easy_async_with_shell(
[[ setxkbmap -query | grep layout | awk '{print $2}' ]],
function(stdout)
local layout = stdout:gsub("\n", "")
if kb_layout_item.keymap == layout then
kb_layout_item.bg = color["DeepPurple200"]
kb_layout_item:get_children_by_id("background2")[1].fg = color["Grey900"]
kb_layout_item:get_children_by_id("background1")[1].fg = color["Grey900"]
else
kb_layout_item.bg = color["Grey800"]
kb_layout_item:get_children_by_id("background2")[1].fg = color["Red200"]
kb_layout_item:get_children_by_id("background1")[1].fg = color["Purple200"]
end
end
)
end
)
get_kblayout()
kb_layout_item:connect_signal(
"button::press",
function()
awful.spawn.easy_async_with_shell(
"setxkbmap " .. keymap,
function()
awesome.emit_signal("kblayout::hide:kbmenu")
mousegrabber.stop()
get_kblayout()
end
)
end
)
return kb_layout_item
end
local function get_kblist()
local kb_layout_items = {
layout = wibox.layout.fixed.vertical,
spacing = dpi(10)
}
for i, keymap in pairs(user_vars.kblayout) do
kb_layout_items[i] = create_kb_layout_item(keymap)
end
local cont = {
{
kb_layout_items,
margins = dpi(10),
widget = wibox.container.margin
},
layout = wibox.layout.fixed.vertical,
}
return cont
end
local kb_menu_widget = awful.popup {
screen = s,
shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, 12)
end,
widget = wibox.container.background,
bg = color["Grey900"],
fg = color["White"],
border_width = dpi(4),
border_color = color["Grey800"],
width = dpi(100),
max_height = dpi(600),
visible = false,
ontop = true,
placement = function(c) awful.placement.align(c, { position = "top_right", margins = { right = dpi(255), top = dpi(60) } }) end
}
kb_menu_widget:connect_signal(
"mouse::leave",
function()
mousegrabber.run(
function()
kblayout_widget.bg = color["Green200"]
awesome.emit_signal("kblayout::hide:kbmenu")
mousegrabber.stop()
return true
end,
"arrow"
)
end
)
kb_menu_widget:connect_signal(
"mouse::enter",
function()
mousegrabber.stop()
end
)
kb_menu_widget:setup(
get_kblist()
)
local function toggle_kb_layout()
awful.spawn.easy_async_with_shell(
"setxkbmap -query | grep layout: | awk '{print $2}'",
function(stdout)
for j, n in ipairs(user_vars.kblayout) do
if stdout:match(n) then
if j == #user_vars.kblayout then
awful.spawn.easy_async_with_shell(
"setxkbmap " .. user_vars.kblayout[1],
function()
get_kblayout()
end
)
else
awful.spawn.easy_async_with_shell(
"setxkbmap " .. user_vars.kblayout[j + 1],
function()
get_kblayout()
end
)
end
end
end
end
)
end
awesome.connect_signal(
"kblayout::toggle",
function()
toggle_kb_layout()
end
)
-- Signals
Hover_signal(kblayout_widget, color["Green200"], color["Grey900"])
local kblayout_keygrabber = awful.keygrabber {
autostart = false,
stop_event = 'release',
keypressed_callback = function(self, mod, key, command)
awesome.emit_signal("kblayout::hide:kbmenu")
mousegrabber.stop()
end
}
kblayout_widget:connect_signal(
"button::press",
function()
mousegrabber.stop()
if kb_menu_widget.visible then
kb_menu_widget.visible = false
kblayout_keygrabber:stop()
else
kb_menu_widget.visible = true
kblayout_keygrabber:start()
end
end
)
awesome.connect_signal(
"kblayout::hide:kbmenu",
function()
kb_menu_widget.visible = false
kblayout_keygrabber:stop()
end
)
get_kblayout()
kb_menu_widget.visible = false
return kblayout_widget
end

View file

@ -0,0 +1,48 @@
----------------------------------
-- This is the layoutbox widget --
----------------------------------
-- Awesome Libs
local awful = require("awful")
local color = require("src.theme.colors")
local dpi = require("beautiful").xresources.apply_dpi
local gears = require("gears")
local wibox = require("wibox")
require("src.core.signals")
-- Returns the layoutbox widget
return function(s)
local layout = wibox.widget {
{
{
awful.widget.layoutbox {
screen = s
},
id = "icon_layout",
widget = wibox.container.place
},
id = "icon_margin",
left = dpi(5),
right = dpi(5),
forced_width = dpi(40),
widget = wibox.container.margin
},
bg = color["LightBlue200"],
shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, 5)
end,
widget = wibox.container.background
}
-- Signals
Hover_signal(layout, color["LightBlue200"], color["Grey900"])
layout:connect_signal(
"button::press",
function()
awful.layout.inc(-1)
end
)
return layout
end

337
src/widgets/network.lua Normal file
View file

@ -0,0 +1,337 @@
--------------------------------
-- This is the network widget --
--------------------------------
-- Awesome Libs
local awful = require("awful")
local color = require("src.theme.colors")
local dpi = require("beautiful").xresources.apply_dpi
local gears = require("gears")
local naughty = require("naughty")
local wibox = require("wibox")
require("src.core.signals")
-- Icon directory path
local icondir = awful.util.getdir("config") .. "src/assets/icons/network/"
-- Insert your interfaces here, get the from ip a
local interfaces = {
wlan_interface = user_vars.network.wlan,
lan_interface = user_vars.network.ethernet
}
local network_mode = nil
-- Returns the network widget
return function()
local startup = true
local reconnect_startup = true
local wifi_strength
local network_widget = wibox.widget {
{
{
{
{
{
id = 'icon',
image = gears.color.recolor_image(icondir .. "no-internet" .. ".svg", color["Grey900"]),
widget = wibox.widget.imagebox,
resize = false
},
id = "icon_layout",
widget = wibox.container.place
},
id = "icon_margin",
top = dpi(2),
widget = wibox.container.margin
},
spacing = dpi(10),
{
id = "label",
visible = false,
valign = "center",
align = "center",
widget = wibox.widget.textbox
},
id = "network_layout",
layout = wibox.layout.fixed.horizontal
},
id = "container",
left = dpi(8),
right = dpi(8),
widget = wibox.container.margin
},
bg = color["Red200"],
fg = color["Grey900"],
shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, 5)
end,
widget = wibox.container.background
}
local network_tooltip = awful.tooltip {
text = "Loading",
objects = { network_widget },
mode = "inside",
preferred_alignments = "middle",
margins = dpi(10)
}
local check_for_internet = [=[
status_ping=0
packets="$(ping -q -w2 -c2 1.1.1.1 | grep -o "100% packet loss")"
if [ ! -z "${packets}" ];
then
status_ping=0
else
status_ping=1
fi
if [ $status_ping -eq 0 ];
then
echo "Connected but no internet"
fi
]=]
local update_startup = function()
if startup then
startup = false
end
end
local update_reconnect_startup = function(status)
reconnect_startup = status
end
local update_tooltip = function(message)
network_tooltip:set_markup(message)
end
local network_notify = function(message, title, app_name, icon)
naughty.notification {
text = message,
title = title,
app_name = app_name,
icon = gears.color.recolor_image(icon, color["White"]),
timeout = 3
}
end
local update_wireless = function()
network_mode = "wireless"
local notify_connected = function(essid)
local message = "You are now connected to " .. essid
local title = "Connection successfull"
local app_name = "System Notification"
local icon = icondir .. "wifi-strength-4.svg"
network_notify(message, title, app_name, icon)
end
local update_wireless_data = function(healthy)
awful.spawn.easy_async_with_shell(
[[ iw dev ]] .. interfaces.wlan_interface .. [[ link ]],
function(stdout)
local essid = stdout:match("SSID: (.-)\n") or "N/A"
local bitrate = stdout:match("tx bitrate: (.+/s)") or "N/A"
local message = "Connected to <b>" .. essid .. "</b>\nSignal strength <b>" .. tostring(wifi_strength) .. "%</b>\n" .. "Bit rate <b>" .. tostring(bitrate) .. "</b>"
if healthy then
update_tooltip(message)
else
update_tooltip("You are connected but have no internet" .. message)
end
if reconnect_startup or startup then
notify_connected(essid)
update_reconnect_startup(false)
end
end
)
end
local update_wireless_icon = function(strength)
awful.spawn.easy_async_with_shell(
check_for_internet,
function(stdout)
local icon = "wifi-strength"
if not stdout:match("Connected but no internet") then
if startup or reconnect_startup then
awesome.emit_signal("system::network_connected")
end
icon = icon .. '-' .. tostring(strength)
update_wireless_data(true)
else
icon = icon .. "-" .. tostring(strength)
update_wireless_data(false)
end
network_widget.container.network_layout.spacing = dpi(8)
network_widget.container.network_layout.icon_margin.icon_layout.icon:set_image(gears.color.recolor_image(icondir .. icon .. ".svg", color["Grey900"]))
end
)
end
local update_wireless_strength = function()
awful.spawn.easy_async_with_shell(
[[ awk 'NR==3 {printf "%3.0f", ($3/70)*100}' /proc/net/wireless ]],
function(stdout)
if not tonumber(stdout) then
return
end
wifi_strength = tonumber(stdout)
network_widget.container.network_layout.spacing = dpi(8)
network_widget.container.network_layout.label.visible = true
network_widget.container.network_layout.label:set_text(tostring(wifi_strength .. "%"))
local wifi_strength_rounded = math.floor(wifi_strength / 25 + 0.5)
update_wireless_icon(wifi_strength_rounded)
end
)
end
update_wireless_strength()
update_startup()
end
local update_wired = function()
network_mode = "wired"
local notify_connected = function()
local message = "You are now connected to " .. interfaces.lan_interface
local title = "Connection successfull"
local app_name = "System Notification"
local icon = icondir .. "ethernet.svg"
network_notify(message, title, app_name, icon)
end
awful.spawn.easy_async_with_shell(
check_for_internet,
function(stdout)
local icon = "ethernet"
if stdout:match("Connected but no internet") then
icon = "no-internet"
update_tooltip(
"No internet"
)
else
update_tooltip("You are connected to:\nEthernet Interface <b>" .. interfaces.lan_interface .. "</b>")
if startup or reconnect_startup then
awesome.emit_signal("system::network_connected")
notify_connected()
update_startup()
end
update_reconnect_startup(false)
end
network_widget.container.network_layout.label.visible = false
network_widget.container.network_layout.spacing = dpi(0)
network_widget.container.network_layout.icon_margin.icon_layout.icon:set_image(icondir .. icon .. ".svg")
end
)
end
local update_disconnected = function()
local notify_wireless_disconnected = function(essid)
local message = "WiFi has been disconnected"
local title = "Connection lost"
local app_name = "System Notification"
local icon = icondir .. "wifi-strength-off-outline.svg"
network_notify(message, title, app_name, icon)
end
local notify_wired_disconnected = function(essid)
local message = "Ethernet has been unplugged"
local title = "Connection lost"
local app_name = "System Notification"
local icon = icondir .. "no-internet.svg"
network_notify(message, title, app_name, icon)
end
local icon = "wifi-strength-off-outline"
if network_mode == "wireless" then
icon = "wifi-strength-off-outline"
if not reconnect_startup then
update_reconnect_startup(true)
notify_wireless_disconnected()
end
elseif network_mode == "wired" then
icon = "no-internet"
if not reconnect_startup then
update_reconnect_startup(true)
notify_wired_disconnected()
end
end
network_widget.container.network_layout.label.visible = false
update_tooltip("Network unreachable")
network_widget.container.network_layout.spacing = dpi(0)
network_widget.container.network_layout.icon_margin.icon_layout.icon:set_image(gears.color.recolor_image(icondir .. icon .. ".svg", color["Grey900"]))
end
local check_network_mode = function()
awful.spawn.easy_async_with_shell(
[=[
wireless="]=] .. tostring(interfaces.wlan_interface) .. [=["
wired="]=] .. tostring(interfaces.lan_interface) .. [=["
net="/sys/class/net/"
wireless_state="down"
wired_state="down"
network_mode=""
function check_network_state(){
if [[ "${wireless_state}" == "up" ]];
then
network_mode="wireless"
elif [[ "${wired_state}" == "up" ]];
then
network_mode="wired"
else
network_mode="No internet connected"
fi
}
function check_network_directory(){
if [[ -n "${wireless}" && -d "${net}${wireless}" ]];
then
wireless_state="$(cat "${net}${wireless}/operstate")"
fi
if [[ -n "${wired}" && -d "${net}${wired}" ]];
then
wired_state="$(cat "${net}${wired}/operstate")"
fi
check_network_state
}
function print_network_mode(){
check_network_directory
printf "${network_mode}"
}
print_network_mode
]=],
function(stdout)
local mode = stdout:gsub("%\n", "")
if stdout:match("No internet connected") then
update_disconnected()
elseif stdout:match("wireless") then
update_wireless()
elseif stdout:match("wired") then
update_wired()
end
end
)
end
gears.timer {
timeout = 5,
autostart = true,
call_now = true,
callback = function()
check_network_mode()
end
}
-- Signals
Hover_signal(network_widget, color["Red200"], color["Grey900"])
network_widget:connect_signal(
"button::press",
function()
awful.spawn("gnome-control-center wlan")
end
)
return network_widget
end

63
src/widgets/power.lua Normal file
View file

@ -0,0 +1,63 @@
--------------------------------
-- This is the power widget --
--------------------------------
-- Awesome Libs
local awful = require("awful")
local color = require("src.theme.colors")
local dpi = require("beautiful").xresources.apply_dpi
local gears = require("gears")
local wibox = require("wibox")
require("src.core.signals")
-- Icon directory path
local icondir = awful.util.getdir("config") .. "src/assets/icons/power/"
return function()
local power_widget = wibox.widget {
{
{
{
{
{
id = "icon",
image = gears.color.recolor_image(icondir .. "power.svg", color["Grey900"]),
widget = wibox.widget.imagebox,
resize = false
},
id = "icon_layout",
widget = wibox.container.place
},
id = "icon_margin",
top = dpi(2),
widget = wibox.container.margin
},
id = "power_layout",
layout = wibox.layout.fixed.horizontal
},
id = "container",
left = dpi(8),
right = dpi(8),
widget = wibox.container.margin
},
bg = color["Red200"],
fg = color["Grey800"],
shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, 5)
end,
widget = wibox.container.background
}
-- Signals
Hover_signal(power_widget, color["Red200"], color["Grey900"])
power_widget:connect_signal(
"button::release",
function()
awesome.emit_signal("module::powermenu:show")
end
)
return power_widget
end

72
src/widgets/ram_info.lua Normal file
View file

@ -0,0 +1,72 @@
---------------------------------
-- This is the RAM Info widget --
---------------------------------
-- Awesome Libs
local awful = require("awful")
local color = require("src.theme.colors")
local dpi = require("beautiful").xresources.apply_dpi
local gears = require("gears")
local watch = awful.widget.watch
local wibox = require("wibox")
require("src.core.signals")
local icon_dir = awful.util.getdir("config") .. "src/assets/icons/cpu/"
return function()
local ram_widget = wibox.widget {
{
{
{
{
{
id = "icon",
widget = wibox.widget.imagebox,
image = gears.color.recolor_image(icon_dir .. "ram.svg", color["Grey900"]),
resize = false
},
id = "icon_layout",
widget = wibox.container.place
},
top = dpi(2),
widget = wibox.container.margin,
id = "icon_margin"
},
spacing = dpi(10),
{
id = "label",
align = "center",
valign = "center",
widget = wibox.widget.textbox
},
id = "ram_layout",
layout = wibox.layout.fixed.horizontal
},
id = "container",
left = dpi(8),
right = dpi(8),
widget = wibox.container.margin
},
bg = color["Red200"],
fg = color["Grey900"],
shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, 5)
end,
widget = wibox.container.background
}
Hover_signal(ram_widget, color["Red200"], color["Grey900"])
watch(
[[ bash -c "cat /proc/meminfo| grep Mem | awk '{print $2}'" ]],
3,
function(_, stdout)
local MemTotal, MemFree, MemAvailable = stdout:match("(%d+)\n(%d+)\n(%d+)\n")
ram_widget.container.ram_layout.label.text = tostring(string.format("%.1f", ((MemTotal - MemAvailable) / 1024 / 1024)) .. "/" .. string.format("%.1f", (MemTotal / 1024 / 1024)) .. "GB"):gsub(",", ".")
end
)
return ram_widget
end

48
src/widgets/systray.lua Normal file
View file

@ -0,0 +1,48 @@
--------------------------------
-- This is the power widget --
--------------------------------
-- Awesome Libs
local awful = require("awful")
local color = require("src.theme.colors")
local dpi = require("beautiful").xresources.apply_dpi
local gears = require("gears")
local wibox = require("wibox")
require("src.core.signals")
return function(s)
local systray = wibox.widget {
{
{
wibox.widget.systray(),
widget = wibox.container.margin,
id = 'st'
},
strategy = "exact",
layout = wibox.container.constraint,
id = "container"
},
widget = wibox.container.background,
shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, 5)
end,
bg = color["BlueGrey800"]
}
-- Signals
Hover_signal(systray.container, color["Red200"], color["Grey900"])
awesome.connect_signal("systray::update", function()
local num_entries = awesome.systray()
if num_entries == 0 then
systray.container.st:set_margins(0)
else
systray.container.st:set_margins(dpi(6))
end
end)
systray.container.st.widget:set_base_size(dpi(20))
return systray
end

220
src/widgets/taglist.lua Normal file
View file

@ -0,0 +1,220 @@
--------------------------------
-- This is the taglist widget --
--------------------------------
-- Awesome Libs
local wibox = require("wibox")
local awful = require("awful")
local gears = require("gears")
local dpi = require("beautiful").xresources.apply_dpi
local color = require("src.theme.colors")
require("src.tools.icon_handler")
local list_update = function(widget, buttons, label, data, objects)
widget:reset()
for _, object in ipairs(objects) do
local tag_widget = wibox.widget {
{
{
{
text = "",
align = "center",
valign = "center",
visible = true,
font = user_vars.font.extrabold,
forced_width = dpi(25),
id = "label",
widget = wibox.widget.textbox
},
id = "margin",
left = dpi(5),
right = dpi(5),
widget = wibox.container.margin
},
id = "container",
layout = wibox.layout.fixed.horizontal
},
fg = color["White"],
shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, 5)
end,
widget = wibox.container.background
}
local function create_buttons(buttons, object)
if buttons then
local btns = {}
for _, b in ipairs(buttons) do
local btn = awful.button {
modifiers = b.modifiers,
button = b.button,
on_press = function()
b:emit_signal('press', object)
end,
on_release = function()
b:emit_signal('release', object)
end
}
btns[#btns + 1] = btn
end
return btns
end
end
tag_widget:buttons(create_buttons(buttons, object))
tag_widget.container.margin.label:set_text(object.index)
if object.urgent == true then
tag_widget:set_bg(color["RedA200"])
tag_widget:set_fg(color["Grey900"])
elseif object == awful.screen.focused().selected_tag then
tag_widget:set_bg(color["White"])
tag_widget:set_fg(color["Grey900"])
else
tag_widget:set_bg("#3A475C")
end
-- Set the icon for each client
for _, client in ipairs(object:clients()) do
tag_widget.container.margin:set_right(0)
local icon = wibox.widget {
{
id = "icon_container",
{
id = "icon",
resize = true,
widget = wibox.widget.imagebox
},
widget = wibox.container.place
},
forced_width = dpi(33),
margins = dpi(6),
widget = wibox.container.margin
}
icon.icon_container.icon:set_image(Get_icon(user_vars.icon_theme, client))
tag_widget.container:setup({
icon,
strategy = "exact",
layout = wibox.container.constraint,
})
end
--#region Hover_signal
local old_wibox, old_cursor, old_bg
tag_widget:connect_signal(
"mouse::enter",
function()
old_bg = tag_widget.bg
if object == awful.screen.focused().selected_tag then
tag_widget.bg = '#dddddd' .. 'dd'
else
tag_widget.bg = '#3A475C' .. 'dd'
end
local w = mouse.current_wibox
if w then
old_cursor, old_wibox = w.cursor, w
w.cursor = "hand1"
end
end
)
tag_widget:connect_signal(
"button::press",
function()
if object == awful.screen.focused().selected_tag then
tag_widget.bg = '#bbbbbb' .. 'dd'
else
tag_widget.bg = '#3A475C' .. 'dd'
end
end
)
tag_widget:connect_signal(
"button::release",
function()
if object == awful.screen.focused().selected_tag then
tag_widget.bg = '#dddddd' .. 'dd'
else
tag_widget.bg = '#3A475C' .. 'dd'
end
end
)
tag_widget:connect_signal(
"mouse::leave",
function()
tag_widget.bg = old_bg
if old_wibox then
old_wibox.cursor = old_cursor
old_wibox = nil
end
end
)
--#endregion
widget:add(tag_widget)
widget:set_spacing(dpi(6))
end
end
return function(s)
return awful.widget.taglist(
s,
awful.widget.taglist.filter.noempty,
gears.table.join(
awful.button(
{},
1,
function(t)
t:view_only()
end
),
awful.button(
{ modkey },
1,
function(t)
if client.focus then
client.focus:move_to_tag(t)
end
end
),
awful.button(
{},
3,
function(t)
if client.focus then
client.focus:toggle_tag(t)
end
end
),
awful.button(
{ modkey },
3,
function(t)
if client.focus then
client.focus:toggle_tag(t)
end
end
),
awful.button(
{},
4,
function(t)
awful.tag.viewnext(t.screen)
end
),
awful.button(
{},
5,
function(t)
awful.tag.viewprev(t.screen)
end
)
),
{},
list_update,
wibox.layout.fixed.horizontal()
)
end

210
src/widgets/tasklist.lua Normal file
View file

@ -0,0 +1,210 @@
---------------------------------
-- This is the tasklist widget --
---------------------------------
-- Awesome Libs
local awful = require('awful')
local wibox = require('wibox')
local dpi = require('beautiful').xresources.apply_dpi
local gears = require('gears')
local color = require('src.theme.colors')
local list_update = function(widget, buttons, label, data, objects)
widget:reset()
for _, object in ipairs(objects) do
local task_widget = wibox.widget {
{
{
{
{
nil,
{
id = "icon",
resize = true,
widget = wibox.widget.imagebox
},
nil,
layout = wibox.layout.align.horizontal,
id = "layout_icon"
},
forced_width = dpi(33),
margins = dpi(3),
widget = wibox.container.margin,
id = "margin"
},
{
text = "",
align = "center",
valign = "center",
visible = true,
widget = wibox.widget.textbox,
id = "title"
},
layout = wibox.layout.fixed.horizontal,
id = "layout_it"
},
right = dpi(5),
left = dpi(5),
widget = wibox.container.margin,
id = "container"
},
bg = color["White"],
fg = color["Grey900"],
shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, 5)
end,
widget = wibox.container.background
}
local task_tool_tip = awful.tooltip {
objects = { task_widget },
mode = "inside",
preferred_alignments = "middle",
preferred_positions = "bottom",
margins = dpi(10),
gaps = 0,
delay_show = 1
}
local function create_buttons(buttons, object)
if buttons then
local btns = {}
for _, b in ipairs(buttons) do
local btn = awful.button {
modifiers = b.modifiers,
button = b.button,
on_press = function()
b:emit_signal('press', object)
end,
on_release = function()
b:emit_signal('release', object)
end
}
btns[#btns + 1] = btn
end
return btns
end
end
task_widget:buttons(create_buttons(buttons, object))
local text, _ = label(object, task_widget.container.layout_it.title)
if object == client.focus then
if text == nil or text == '' then
task_widget.container.layout_it.title:set_margins(0)
else
local text_full = text:match('>(.-)<')
if text_full then
if object.class == nil then
text = object.name
else
text = object.class:sub(1, 20)
end
task_tool_tip:set_text(text_full)
task_tool_tip:add_to_object(task_widget)
else
task_tool_tip:remove_from_object(task_widget)
end
end
task_widget:set_bg(color["White"])
task_widget:set_fg(color["Grey900"])
task_widget.container.layout_it.title:set_text(text)
else
task_widget:set_bg("#3A475C")
task_widget.container.layout_it.title:set_text('')
end
task_widget.container.layout_it.margin.layout_icon.icon:set_image(Get_icon(user_vars.icon_theme, object))
widget:add(task_widget)
widget:set_spacing(dpi(6))
--#region Hover_signal
local old_wibox, old_cursor, old_bg
task_widget:connect_signal(
"mouse::enter",
function()
old_bg = task_widget.bg
if object == client.focus then
task_widget.bg = '#dddddddd'
else
task_widget.bg = '#3A475Cdd'
end
local w = mouse.current_wibox
if w then
old_cursor, old_wibox = w.cursor, w
w.cursor = "hand1"
end
end
)
task_widget:connect_signal(
"button::press",
function()
if object == client.focus then
task_widget.bg = "#ffffffaa"
else
task_widget.bg = '#3A475Caa'
end
end
)
task_widget:connect_signal(
"button::release",
function()
if object == client.focus then
task_widget.bg = "#ffffffdd"
else
task_widget.bg = '#3A475Cdd'
end
end
)
task_widget:connect_signal(
"mouse::leave",
function()
task_widget.bg = old_bg
if old_wibox then
old_wibox.cursor = old_cursor
old_wibox = nil
end
end
)
--#endregion
end
return widget
end
return function(s)
return awful.widget.tasklist(
s,
awful.widget.tasklist.filter.currenttags,
awful.util.table.join(
awful.button(
{},
1,
function(c)
if c == client.focus then
c.minimized = true
else
c.minimized = false
if not c:isvisible() and c.first_tag then
c.first_tag:view_only()
end
c:emit_signal('request::activate')
c:raise()
end
end
),
awful.button(
{},
3,
function(c)
c:kill()
end
)
),
{},
list_update,
wibox.layout.fixed.horizontal()
)
end