rewrote bluetooth to using the dbus, small changes to volume_controller, added more rubato animations
This commit is contained in:
500
awesome/src/modules/bluetooth_controller.lua
Normal file
500
awesome/src/modules/bluetooth_controller.lua
Normal file
@@ -0,0 +1,500 @@
|
||||
--------------------------------------
|
||||
-- This is the bluetooth controller --
|
||||
--------------------------------------
|
||||
|
||||
-- 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")
|
||||
|
||||
local rubato = require("src.lib.rubato")
|
||||
|
||||
local icondir = awful.util.getdir("config") .. "src/assets/icons/bluetooth/"
|
||||
|
||||
return function(s)
|
||||
|
||||
local function create_device(device, battery)
|
||||
local icon = device.Icon or "bluetooth-on"
|
||||
local device_widget = wibox.widget {
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
image = gears.color.recolor_image(icondir .. icon .. ".svg", color["Purple200"]),
|
||||
id = "icon",
|
||||
resize = false,
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
forced_width = dpi(24),
|
||||
forced_height = dpi(24),
|
||||
widget = wibox.widget.imagebox
|
||||
},
|
||||
id = "icon_container",
|
||||
strategy = "max",
|
||||
width = dpi(24),
|
||||
height = dpi(24),
|
||||
widget = wibox.container.constraint
|
||||
},
|
||||
{
|
||||
{
|
||||
{
|
||||
text = device.Alias or device.Name,
|
||||
id = "alias",
|
||||
widget = wibox.widget.textbox
|
||||
},
|
||||
{
|
||||
text = "Connecting...",
|
||||
id = "connecting",
|
||||
visible = false,
|
||||
font = user_vars.font.specify .. ", regular 10",
|
||||
widget = wibox.widget.textbox
|
||||
},
|
||||
id = "alias_container",
|
||||
layout = wibox.layout.fixed.horizontal
|
||||
},
|
||||
width = dpi(260),
|
||||
height = dpi(40),
|
||||
strategy = "max",
|
||||
widget = wibox.container.constraint
|
||||
},
|
||||
spacing = dpi(10),
|
||||
layout = wibox.layout.fixed.horizontal
|
||||
},
|
||||
{ -- Spacing
|
||||
forced_width = dpi(10),
|
||||
widget = wibox.container.background
|
||||
},
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
id = "con",
|
||||
resize = false,
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
forced_width = dpi(24),
|
||||
forced_height = dpi(24),
|
||||
widget = wibox.widget.imagebox
|
||||
},
|
||||
id = "place",
|
||||
strategy = "max",
|
||||
width = dpi(24),
|
||||
height = dpi(24),
|
||||
widget = wibox.container.constraint
|
||||
},
|
||||
id = "margin",
|
||||
margins = dpi(2),
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
id = "backgr",
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(4))
|
||||
end,
|
||||
bg = color["Blue200"],
|
||||
widget = wibox.container.background
|
||||
},
|
||||
id = "margin0",
|
||||
margin = dpi(5),
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
id = "device_layout",
|
||||
layout = wibox.layout.align.horizontal
|
||||
},
|
||||
id = "device_margin",
|
||||
margins = dpi(5),
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
bg = color["Grey900"],
|
||||
fg = color["LightBlue200"],
|
||||
border_color = color["Grey800"],
|
||||
border_width = dpi(2),
|
||||
id = "background",
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, 4)
|
||||
end,
|
||||
widget = wibox.container.background
|
||||
}
|
||||
|
||||
--! using :Connect freezes awesome, either find a solution or switch to console commands
|
||||
if device.Connected then
|
||||
device_widget:get_children_by_id("con")[1].image = gears.color.recolor_image(icondir .. "link-off.svg", color["Grey900"])
|
||||
device_widget:connect_signal(
|
||||
"button::press",
|
||||
function(c, d, e, key)
|
||||
if key == 1 then
|
||||
device:Disconnect()
|
||||
awesome.emit_signal("bluetooth::connect", device)
|
||||
end
|
||||
end
|
||||
)
|
||||
else
|
||||
device_widget:get_children_by_id("con")[1].image = gears.color.recolor_image(icondir .. "link.svg", color["Grey900"])
|
||||
device_widget:connect_signal(
|
||||
"button::press",
|
||||
function(c, d, e, key)
|
||||
if key == 1 then
|
||||
device:Connect()
|
||||
awesome.emit_signal("bluetooth::disconnect", device)
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
Hover_signal(device_widget, '#313131', color["LightBlue100"])
|
||||
return device_widget
|
||||
end
|
||||
|
||||
local connected_devices_list = wibox.widget {
|
||||
{
|
||||
{
|
||||
{
|
||||
step = dpi(50),
|
||||
spacing = dpi(10),
|
||||
layout = wibox.layout.overflow.vertical,
|
||||
scrollbar_width = 0,
|
||||
id = "connected_device_list"
|
||||
},
|
||||
id = "margin",
|
||||
margins = dpi(10),
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
id = "place",
|
||||
height = dpi(200),
|
||||
strategy = "max",
|
||||
widget = wibox.container.constraint
|
||||
},
|
||||
id = "connected_device_background",
|
||||
border_color = color["Grey800"],
|
||||
border_width = dpi(2),
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.partially_rounded_rect(cr, width, height, false, false, true, true, 4)
|
||||
end,
|
||||
widget = wibox.container.background
|
||||
}
|
||||
|
||||
local discovered_devices_list = wibox.widget {
|
||||
{
|
||||
{
|
||||
{
|
||||
spacing = dpi(10),
|
||||
step = dpi(50),
|
||||
layout = wibox.layout.overflow.vertical,
|
||||
scrollbar_width = 0,
|
||||
id = "discovered_device_list"
|
||||
},
|
||||
id = "margin",
|
||||
margins = dpi(10),
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
id = "place",
|
||||
height = dpi(200),
|
||||
strategy = "max",
|
||||
widget = wibox.container.constraint
|
||||
},
|
||||
id = "discovered_device_background",
|
||||
border_color = color["Grey800"],
|
||||
border_width = dpi(2),
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.partially_rounded_rect(cr, width, height, false, false, true, true, 4)
|
||||
end,
|
||||
widget = wibox.container.background
|
||||
}
|
||||
|
||||
local bluetooth_container = wibox.widget {
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
resize = false,
|
||||
image = gears.color.recolor_image(icondir .. "menu-down.svg", color["Purple200"]),
|
||||
widget = wibox.widget.imagebox,
|
||||
id = "icon"
|
||||
},
|
||||
id = "center",
|
||||
halign = "center",
|
||||
valign = "center",
|
||||
widget = wibox.container.place,
|
||||
},
|
||||
{
|
||||
{
|
||||
text = "Coupled Devices",
|
||||
widget = wibox.widget.textbox,
|
||||
id = "device_name"
|
||||
},
|
||||
margins = dpi(5),
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
id = "connected",
|
||||
layout = wibox.layout.fixed.horizontal
|
||||
},
|
||||
id = "connected_bg",
|
||||
bg = color["Grey800"],
|
||||
fg = color["Purple200"],
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, 4)
|
||||
end,
|
||||
widget = wibox.container.background
|
||||
},
|
||||
id = "connected_margin",
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
{
|
||||
id = "connected_list",
|
||||
widget = connected_devices_list,
|
||||
forced_height = 0
|
||||
},
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
resize = false,
|
||||
image = gears.color.recolor_image(icondir .. "menu-down.svg", color["LightBlueA200"]),
|
||||
widget = wibox.widget.imagebox,
|
||||
id = "icon",
|
||||
},
|
||||
id = "center",
|
||||
halign = "center",
|
||||
valign = "center",
|
||||
widget = wibox.container.place,
|
||||
},
|
||||
{
|
||||
{
|
||||
text = "Nearby Devices",
|
||||
widget = wibox.widget.textbox,
|
||||
id = "device_name"
|
||||
},
|
||||
margins = dpi(5),
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
id = "discovered",
|
||||
layout = wibox.layout.fixed.horizontal
|
||||
},
|
||||
id = "discovered_bg",
|
||||
bg = color["Grey800"],
|
||||
fg = color["Blue200"],
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, 4)
|
||||
end,
|
||||
widget = wibox.container.background
|
||||
},
|
||||
id = "discovered_margin",
|
||||
top = dpi(10),
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
{
|
||||
id = "discovered_list",
|
||||
widget = discovered_devices_list,
|
||||
forced_height = 0
|
||||
},
|
||||
id = "layout1",
|
||||
layout = wibox.layout.fixed.vertical
|
||||
},
|
||||
id = "margin",
|
||||
margins = dpi(15),
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(8))
|
||||
end,
|
||||
border_color = color["Grey800"],
|
||||
border_width = dpi(4),
|
||||
bg = color["Grey900"],
|
||||
id = "background",
|
||||
widget = wibox.container.background
|
||||
},
|
||||
width = dpi(400),
|
||||
strategy = "exact",
|
||||
widget = wibox.container.constraint
|
||||
}
|
||||
|
||||
-- Main container
|
||||
local bluetooth_controller_container = awful.popup {
|
||||
widget = wibox.container.background,
|
||||
ontop = true,
|
||||
bg = color["Grey900"],
|
||||
stretch = false,
|
||||
visible = false,
|
||||
screen = s,
|
||||
placement = function(c) awful.placement.align(c, { position = "top_right", margins = { right = dpi(380), top = dpi(60) } }) end,
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, 12)
|
||||
end
|
||||
}
|
||||
|
||||
local connected_devices, nearby_devices = {}, {}
|
||||
|
||||
-- function to check if a device is already in the list
|
||||
local function is_device_in_list(device)
|
||||
for i = 1, #connected_devices do
|
||||
if connected_devices[i].Address == device.Address then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
awesome.connect_signal(
|
||||
"bluetooth::device_changed",
|
||||
function(device, battery)
|
||||
if not is_device_in_list(device) then
|
||||
-- add device and battery to list
|
||||
if device.Paired then
|
||||
table.insert(connected_devices, device)
|
||||
else
|
||||
table.insert(nearby_devices, device)
|
||||
end
|
||||
end
|
||||
|
||||
if (#connected_devices + #nearby_devices) > 0 then
|
||||
local cd_list, dd_list = {}, {}
|
||||
for _, d in pairs(connected_devices) do
|
||||
if d.Paired then
|
||||
table.insert(cd_list, create_device(d))
|
||||
else
|
||||
table.insert(dd_list, create_device(d))
|
||||
end
|
||||
end
|
||||
for _, d in pairs(nearby_devices) do
|
||||
if d.Paired then
|
||||
table.insert(cd_list, create_device(d, battery))
|
||||
else
|
||||
table.insert(dd_list, create_device(d, battery))
|
||||
end
|
||||
end
|
||||
connected_devices_list:get_children_by_id("connected_device_list")[1].children = cd_list
|
||||
discovered_devices_list:get_children_by_id("discovered_device_list")[1].children = dd_list
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
-- Variables for easier access and better readability
|
||||
local connected_margin = bluetooth_container:get_children_by_id("connected_margin")[1]
|
||||
local connected_list = bluetooth_container:get_children_by_id("connected_list")[1]
|
||||
local connected_bg = bluetooth_container:get_children_by_id("connected_bg")[1]
|
||||
local connected = bluetooth_container:get_children_by_id("connected")[1].center
|
||||
|
||||
-- Click event for the microphone dropdown
|
||||
connected_margin:connect_signal(
|
||||
"button::press",
|
||||
function()
|
||||
local rubato_timer = rubato.timed {
|
||||
duration = 0.4,
|
||||
intro = 0.1,
|
||||
outro = 0.1,
|
||||
pos = connected_list.forced_height,
|
||||
easing = rubato.linear,
|
||||
subscribed = function(v)
|
||||
connected_list.forced_height = v
|
||||
end
|
||||
}
|
||||
if connected_list.forced_height == 0 then
|
||||
local size = (#connected_devices * 45) + ((#connected_devices - 1) * 10)
|
||||
if size < 210 then
|
||||
rubato_timer.target = dpi(size)
|
||||
else
|
||||
rubato_timer.target = dpi(210)
|
||||
end
|
||||
connected_margin.connected_bg.shape = function(cr, width, height)
|
||||
gears.shape.partially_rounded_rect(cr, width, height, true, true, false, false, 4)
|
||||
end
|
||||
connected.icon:set_image(gears.color.recolor_image(icondir .. "menu-up.svg", color["Purple200"]))
|
||||
else
|
||||
rubato_timer.target = 0
|
||||
connected_bg.shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, 4)
|
||||
end
|
||||
connected.icon:set_image(gears.color.recolor_image(icondir .. "menu-down.svg", color["Purple200"]))
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
-- Variables for easier access and better readability
|
||||
local discovered_margin = bluetooth_container:get_children_by_id("discovered_margin")[1]
|
||||
local discovered_list = bluetooth_container:get_children_by_id("discovered_list")[1]
|
||||
local discovered_bg = bluetooth_container:get_children_by_id("discovered_bg")[1]
|
||||
local discovered = bluetooth_container:get_children_by_id("discovered")[1].center
|
||||
|
||||
-- Click event for the microphone dropdown
|
||||
discovered_margin:connect_signal(
|
||||
"button::press",
|
||||
function()
|
||||
local rubato_timer = rubato.timed {
|
||||
duration = 0.4,
|
||||
intro = 0.1,
|
||||
outro = 0.1,
|
||||
pos = discovered_list.forced_height,
|
||||
easing = rubato.linear,
|
||||
subscribed = function(v)
|
||||
discovered_list.forced_height = v
|
||||
end
|
||||
}
|
||||
|
||||
if discovered_list.forced_height == 0 then
|
||||
local size = (#nearby_devices * dpi(45)) + ((#nearby_devices - 1) * dpi(10))
|
||||
if size < 210 then
|
||||
rubato_timer.target = dpi(size)
|
||||
else
|
||||
rubato_timer.target = dpi(20)
|
||||
end
|
||||
discovered_margin.discovered_bg.shape = function(cr, width, height)
|
||||
gears.shape.partially_rounded_rect(cr, width, height, true, true, false, false, 4)
|
||||
end
|
||||
discovered.icon:set_image(gears.color.recolor_image(icondir .. "menu-up.svg", color["LightBlue200"]))
|
||||
else
|
||||
rubato_timer.target = dpi(0)
|
||||
discovered_bg.shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, 4)
|
||||
end
|
||||
discovered.icon:set_image(gears.color.recolor_image(icondir .. "menu-down.svg", color["LightBlue200"]))
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
-- When the mouse leaves the popup it stops the mousegrabber and hides the popup.
|
||||
bluetooth_controller_container:connect_signal(
|
||||
"mouse::leave",
|
||||
function()
|
||||
mousegrabber.run(
|
||||
function()
|
||||
awesome.emit_signal("bluetooth_controller::toggle", s)
|
||||
mousegrabber.stop()
|
||||
return true
|
||||
end,
|
||||
"arrow"
|
||||
)
|
||||
end
|
||||
)
|
||||
|
||||
bluetooth_controller_container:connect_signal(
|
||||
"mouse::enter",
|
||||
function()
|
||||
mousegrabber.stop()
|
||||
end
|
||||
)
|
||||
|
||||
-- Draw the popup
|
||||
bluetooth_controller_container:setup {
|
||||
bluetooth_container,
|
||||
layout = wibox.layout.fixed.horizontal
|
||||
}
|
||||
|
||||
-- Toggle container visibility
|
||||
awesome.connect_signal(
|
||||
"bluetooth_controller::toggle",
|
||||
function(scr)
|
||||
if scr == s then
|
||||
bluetooth_controller_container.visible = not bluetooth_controller_container.visible
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
end
|
||||
@@ -92,7 +92,7 @@ return function()
|
||||
awesome.connect_signal(
|
||||
"update::cpu_usage_widget",
|
||||
function(cpu_usage)
|
||||
w:get_children_by_id("progressbar1")[1].value = cpu_usage
|
||||
--w:get_children_by_id("progressbar1")[1].value = cpu_usage
|
||||
tooltip.text = "CPU Usage: " .. cpu_usage .. "%"
|
||||
rubato_timer.target = cpu_usage
|
||||
end
|
||||
@@ -163,7 +163,7 @@ return function()
|
||||
awesome.connect_signal(
|
||||
"update::cpu_temp_widget",
|
||||
function(cpu_temp, cpu_temp_icon)
|
||||
w:get_children_by_id("progressbar1")[1].value = cpu_temp
|
||||
--w:get_children_by_id("progressbar1")[1].value = cpu_temp
|
||||
w:get_children_by_id("icon1")[1].image = gears.color.recolor_image(cpu_temp_icon, color["Blue200"])
|
||||
tooltip.text = "CPU Temp: " .. cpu_temp .. "°C"
|
||||
rubato_timer.target = cpu_temp
|
||||
@@ -233,7 +233,7 @@ return function()
|
||||
awesome.connect_signal(
|
||||
"update::ram_widget",
|
||||
function(ram_usage)
|
||||
w:get_children_by_id("progressbar1")[1].value = ram_usage
|
||||
--w:get_children_by_id("progressbar1")[1].value = ram_usage
|
||||
tooltip.text = "RAM Usage: " .. ram_usage .. "%"
|
||||
rubato_timer.target = ram_usage
|
||||
end
|
||||
@@ -302,7 +302,7 @@ return function()
|
||||
awesome.connect_signal(
|
||||
"update::gpu_usage_widget",
|
||||
function(gpu_usage)
|
||||
w:get_children_by_id("progressbar1")[1].value = gpu_usage
|
||||
--w:get_children_by_id("progressbar1")[1].value = gpu_usage
|
||||
tooltip.text = "GPU Usage: " .. gpu_usage .. "%"
|
||||
rubato_timer.target = gpu_usage
|
||||
end
|
||||
@@ -373,7 +373,7 @@ return function()
|
||||
awesome.connect_signal(
|
||||
"update::gpu_temp_widget",
|
||||
function(gpu_temp, gpu_temp_icon)
|
||||
w:get_children_by_id("progressbar1")[1].value = gpu_temp
|
||||
--w:get_children_by_id("progressbar1")[1].value = gpu_temp
|
||||
w:get_children_by_id("icon1")[1].image = gears.color.recolor_image(gpu_temp_icon, color["Green200"])
|
||||
tooltip.text = "GPU Temp: " .. gpu_temp .. "°C"
|
||||
rubato_timer.target = gpu_temp
|
||||
@@ -445,7 +445,7 @@ return function()
|
||||
awesome.connect_signal(
|
||||
"update::volume_widget",
|
||||
function(volume, volume_icon)
|
||||
w:get_children_by_id("progressbar1")[1].value = volume
|
||||
--w:get_children_by_id("progressbar1")[1].value = volume
|
||||
w:get_children_by_id("icon1")[1].image = gears.color.recolor_image(volume_icon, color["Yellow200"])
|
||||
tooltip.text = "Volume: " .. volume .. "%"
|
||||
rubato_timer.target = volume
|
||||
@@ -517,7 +517,7 @@ return function()
|
||||
awesome.connect_signal(
|
||||
"update::microphone_widget",
|
||||
function(microphone, microphone_icon)
|
||||
w:get_children_by_id("progressbar1")[1].value = microphone
|
||||
--w:get_children_by_id("progressbar1")[1].value = microphone
|
||||
w:get_children_by_id("icon1")[1].image = gears.color.recolor_image(microphone_icon, color["Purple200"])
|
||||
tooltip.text = "Microphone: " .. microphone .. "%"
|
||||
rubato_timer.target = microphone
|
||||
@@ -589,7 +589,7 @@ return function()
|
||||
awesome.connect_signal(
|
||||
"update::backlight_widget",
|
||||
function(backlight, backlight_icon)
|
||||
w:get_children_by_id("progressbar1")[1].value = backlight
|
||||
--w:get_children_by_id("progressbar1")[1].value = backlight
|
||||
w:get_children_by_id("icon1")[1].image = gears.color.recolor_image(backlight_icon, color["Pink200"])
|
||||
tooltip.text = "Backlight: " .. backlight .. "%"
|
||||
rubato_timer.target = backlight
|
||||
@@ -661,7 +661,7 @@ return function()
|
||||
awesome.connect_signal(
|
||||
"update::battery_widget",
|
||||
function(battery, battery_icon)
|
||||
w:get_children_by_id("progressbar1")[1].value = battery
|
||||
--w:get_children_by_id("progressbar1")[1].value = battery
|
||||
w:get_children_by_id("icon1")[1].image = gears.color.recolor_image(battery_icon, color["Purple200"])
|
||||
tooltip.text = "Battery: " .. battery .. "%"
|
||||
rubato_timer.target = battery
|
||||
|
||||
@@ -9,7 +9,8 @@ local dpi = require("beautiful").xresources.apply_dpi
|
||||
local gears = require("gears")
|
||||
local naughty = require("naughty")
|
||||
local wibox = require("wibox")
|
||||
require("src.core.signals")
|
||||
|
||||
local rubato = require("src.lib.rubato")
|
||||
|
||||
-- Icon directory path
|
||||
local icondir = awful.util.getdir("config") .. "src/assets/icons/audio/"
|
||||
@@ -23,145 +24,53 @@ return function(s)
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
image = "",
|
||||
id = "icon",
|
||||
resize = false,
|
||||
widget = wibox.widget.imagebox
|
||||
},
|
||||
{
|
||||
text = name,
|
||||
id = "node",
|
||||
widget = wibox.widget.textbox
|
||||
},
|
||||
id = "device_layout",
|
||||
layout = wibox.layout.align.horizontal
|
||||
id = "icon",
|
||||
resize = false,
|
||||
widget = wibox.widget.imagebox
|
||||
},
|
||||
id = "device_margin",
|
||||
margins = dpi(5),
|
||||
widget = wibox.container.margin
|
||||
spacing = dpi(10),
|
||||
{
|
||||
text = name,
|
||||
id = "node",
|
||||
widget = wibox.widget.textbox
|
||||
},
|
||||
id = "device_layout",
|
||||
layout = wibox.layout.fixed.horizontal
|
||||
},
|
||||
id = "background",
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, 4)
|
||||
end,
|
||||
widget = wibox.container.background
|
||||
id = "device_margin",
|
||||
margins = dpi(9),
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
margins = dpi(5),
|
||||
widget = wibox.container.margin
|
||||
id = "background",
|
||||
bg = color["Grey900"],
|
||||
border_color = color["Grey800"],
|
||||
border_width = dpi(2),
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, 4)
|
||||
end,
|
||||
widget = wibox.container.background
|
||||
}
|
||||
|
||||
if sink == true then
|
||||
device:connect_signal(
|
||||
"button::press",
|
||||
function()
|
||||
if node then
|
||||
awful.spawn.spawn("./.config/awesome/src/scripts/vol.sh set_sink " .. node)
|
||||
awful.spawn("./.config/awesome/src/scripts/vol.sh set_sink " .. node)
|
||||
end
|
||||
|
||||
awesome.emit_signal("update::background:vol", node)
|
||||
awesome.emit_signal("update::bg_sink", node)
|
||||
end
|
||||
)
|
||||
|
||||
--#region Signal Functions
|
||||
local old_wibox, old_cursor, old_bg, old_fg
|
||||
local bg = ""
|
||||
local fg = ""
|
||||
local mouse_enter = function()
|
||||
if bg then
|
||||
old_bg = device.background.bg
|
||||
device.background.bg = bg .. 'dd'
|
||||
end
|
||||
if fg then
|
||||
old_fg = device.background.fg
|
||||
device.background.fg = fg
|
||||
end
|
||||
local w = mouse.current_wibox
|
||||
if w then
|
||||
old_cursor, old_wibox = w.cursor, w
|
||||
w.cursor = "hand1"
|
||||
end
|
||||
end
|
||||
|
||||
local button_press = function()
|
||||
if bg then
|
||||
if bg then
|
||||
if string.len(bg) == 7 then
|
||||
device.background.bg = bg .. 'bb'
|
||||
else
|
||||
device.background.bg = bg
|
||||
end
|
||||
end
|
||||
end
|
||||
if fg then
|
||||
device.background.fg = fg
|
||||
end
|
||||
end
|
||||
|
||||
local button_release = function()
|
||||
if bg then
|
||||
if bg then
|
||||
if string.len(bg) == 7 then
|
||||
device.background.bg = bg .. 'dd'
|
||||
else
|
||||
device.background.bg = bg
|
||||
end
|
||||
end
|
||||
end
|
||||
if fg then
|
||||
device.background.fg = fg
|
||||
end
|
||||
end
|
||||
|
||||
local mouse_leave = function()
|
||||
if bg then
|
||||
device.background.bg = old_bg
|
||||
end
|
||||
if fg then
|
||||
device.background.fg = old_fg
|
||||
end
|
||||
if old_wibox then
|
||||
old_wibox.cursor = old_cursor
|
||||
old_wibox = nil
|
||||
end
|
||||
end
|
||||
|
||||
device:connect_signal(
|
||||
"mouse::enter",
|
||||
mouse_enter
|
||||
)
|
||||
|
||||
device:connect_signal(
|
||||
"button::press",
|
||||
button_press
|
||||
)
|
||||
|
||||
device:connect_signal(
|
||||
"button::release",
|
||||
button_release
|
||||
)
|
||||
|
||||
device:connect_signal(
|
||||
"mouse::leave",
|
||||
mouse_leave
|
||||
)
|
||||
--#endregion
|
||||
|
||||
awesome.connect_signal(
|
||||
"update::background:vol",
|
||||
"update::bg_sink",
|
||||
function(new_node)
|
||||
if node == new_node then
|
||||
old_bg = color["Purple200"]
|
||||
old_fg = color["Grey900"]
|
||||
bg = color["Purple200"]
|
||||
fg = color["Grey900"]
|
||||
device.background:set_bg(color["Purple200"])
|
||||
device.background:set_fg(color["Grey900"])
|
||||
device:get_children_by_id("icon")[1].image = gears.color.recolor_image(icondir .. "headphones.svg", color["Grey900"])
|
||||
device.bg = color["Purple200"]
|
||||
device.fg = color["Grey900"]
|
||||
else
|
||||
fg = color["Purple200"]
|
||||
bg = color["Grey700"]
|
||||
device.background:set_fg(color["Purple200"])
|
||||
device.background:set_bg(color["Grey700"])
|
||||
device:get_children_by_id("icon")[1].image = gears.color.recolor_image(icondir .. "headphones.svg", color["Purple200"])
|
||||
device.bg = color["Grey900"]
|
||||
device.fg = color["Purple200"]
|
||||
end
|
||||
end
|
||||
)
|
||||
@@ -170,130 +79,40 @@ return function(s)
|
||||
function(stdout)
|
||||
local node_active = stdout:gsub("\n", "")
|
||||
if node == node_active then
|
||||
bg = color["Purple200"]
|
||||
fg = color["Grey900"]
|
||||
device.background:set_bg(color["Purple200"])
|
||||
device.background:set_fg(color["Grey900"])
|
||||
device:get_children_by_id("icon")[1].image = gears.color.recolor_image(icondir .. "headphones.svg", color["Grey900"])
|
||||
device.bg = color["Purple200"]
|
||||
device.fg = color["Grey900"]
|
||||
else
|
||||
fg = color["Purple200"]
|
||||
bg = color["Grey700"]
|
||||
device.background:set_fg(color["Purple200"])
|
||||
device.background:set_bg(color["Grey700"])
|
||||
device:get_children_by_id("icon")[1].image = gears.color.recolor_image(icondir .. "headphones.svg", color["Purple200"])
|
||||
device.bg = color["Grey900"]
|
||||
device.fg = color["Purple200"]
|
||||
end
|
||||
end
|
||||
)
|
||||
awesome.emit_signal("update::bg_sink", node)
|
||||
--Hover_signal(device, "#313131", color["Purple200"])
|
||||
else
|
||||
|
||||
device:connect_signal(
|
||||
"button::press",
|
||||
function()
|
||||
if node then
|
||||
awful.spawn.spawn("./.config/awesome/src/scripts/mic.sh set_source " .. node)
|
||||
awful.spawn("./.config/awesome/src/scripts/mic.sh set_source " .. node)
|
||||
end
|
||||
|
||||
awesome.emit_signal("update::background:mic", node)
|
||||
awesome.emit_signal("update::bg_source", node)
|
||||
end
|
||||
)
|
||||
|
||||
--#region Signal Functions
|
||||
local old_wibox, old_cursor, old_bg, old_fg
|
||||
local bg = ""
|
||||
local fg = ""
|
||||
local mouse_enter = function()
|
||||
if bg then
|
||||
old_bg = device.background.bg
|
||||
device.background.bg = bg .. 'dd'
|
||||
end
|
||||
if fg then
|
||||
old_fg = device.background.fg
|
||||
device.background.fg = fg
|
||||
end
|
||||
local w = mouse.current_wibox
|
||||
if w then
|
||||
old_cursor, old_wibox = w.cursor, w
|
||||
w.cursor = "hand1"
|
||||
end
|
||||
end
|
||||
|
||||
local button_press = function()
|
||||
if bg then
|
||||
if bg then
|
||||
if string.len(bg) == 7 then
|
||||
device.background.bg = bg .. 'bb'
|
||||
else
|
||||
device.background.bg = bg
|
||||
end
|
||||
end
|
||||
end
|
||||
if fg then
|
||||
device.background.fg = fg
|
||||
end
|
||||
end
|
||||
|
||||
local button_release = function()
|
||||
if bg then
|
||||
if bg then
|
||||
if string.len(bg) == 7 then
|
||||
device.background.bg = bg .. 'dd'
|
||||
else
|
||||
device.background.bg = bg
|
||||
end
|
||||
end
|
||||
end
|
||||
if fg then
|
||||
device.background.fg = fg
|
||||
end
|
||||
end
|
||||
|
||||
local mouse_leave = function()
|
||||
if bg then
|
||||
device.background.bg = old_bg
|
||||
end
|
||||
if fg then
|
||||
device.background.fg = old_fg
|
||||
end
|
||||
if old_wibox then
|
||||
old_wibox.cursor = old_cursor
|
||||
old_wibox = nil
|
||||
end
|
||||
end
|
||||
|
||||
device:connect_signal(
|
||||
"mouse::enter",
|
||||
mouse_enter
|
||||
)
|
||||
|
||||
device:connect_signal(
|
||||
"button::press",
|
||||
button_press
|
||||
)
|
||||
|
||||
device:connect_signal(
|
||||
"button::release",
|
||||
button_release
|
||||
)
|
||||
|
||||
device:connect_signal(
|
||||
"mouse::leave",
|
||||
mouse_leave
|
||||
)
|
||||
--#endregion
|
||||
|
||||
awesome.connect_signal(
|
||||
"update::background:mic",
|
||||
"update::bg_source",
|
||||
function(new_node)
|
||||
if node == new_node then
|
||||
old_bg = color["Blue200"]
|
||||
old_fg = color["Grey900"]
|
||||
bg = color["Blue200"]
|
||||
fg = color["Grey900"]
|
||||
device.background:set_bg(color["Blue200"])
|
||||
device.background:set_fg(color["Grey900"])
|
||||
device:get_children_by_id("icon")[1].image = gears.color.recolor_image(icondir .. "microphone.svg", color["Grey900"])
|
||||
device.bg = color["Blue200"]
|
||||
device.fg = color["Grey900"]
|
||||
else
|
||||
fg = color["Blue200"]
|
||||
bg = color["Grey700"]
|
||||
device.background:set_fg(color["Blue200"])
|
||||
device.background:set_bg(color["Grey700"])
|
||||
device:get_children_by_id("icon")[1].image = gears.color.recolor_image(icondir .. "microphone.svg", color["Blue200"])
|
||||
device.bg = color["Grey900"]
|
||||
device.fg = color["Blue200"]
|
||||
end
|
||||
end
|
||||
)
|
||||
@@ -302,18 +121,19 @@ return function(s)
|
||||
function(stdout)
|
||||
local node_active = stdout:gsub("\n", "")
|
||||
if node == node_active then
|
||||
bg = color["Blue200"]
|
||||
fg = color["Grey900"]
|
||||
device.background:set_bg(color["Blue200"])
|
||||
device.background:set_fg(color["Grey900"])
|
||||
device:get_children_by_id("icon")[1].image = gears.color.recolor_image(icondir .. "microphone.svg", color["Grey900"])
|
||||
device.bg = color["Blue200"]
|
||||
device.fg = color["Grey900"]
|
||||
Hover_signal(device, "#313131", color["Blue200"])
|
||||
else
|
||||
fg = color["Blue200"]
|
||||
bg = color["Grey700"]
|
||||
device.background:set_fg(color["Blue200"])
|
||||
device.background:set_bg(color["Grey700"])
|
||||
device:get_children_by_id("icon")[1].image = gears.color.recolor_image(icondir .. "microphone.svg", color["Blue200"])
|
||||
device.bg = color["Grey900"]
|
||||
device.fg = color["Blue200"]
|
||||
Hover_signal(device, "#313131", color["Blue200"])
|
||||
end
|
||||
end
|
||||
)
|
||||
awesome.emit_signal("update::bg_source", node)
|
||||
end
|
||||
return device
|
||||
end
|
||||
@@ -322,11 +142,26 @@ return function(s)
|
||||
local dropdown_list_volume = wibox.widget {
|
||||
{
|
||||
{
|
||||
layout = wibox.layout.fixed.vertical,
|
||||
id = "volume_device_list"
|
||||
{
|
||||
{
|
||||
spacing = dpi(10),
|
||||
layout = wibox.layout.overflow.vertical,
|
||||
scrollbar_width = 0,
|
||||
step = dpi(50),
|
||||
id = "volume_device_list",
|
||||
},
|
||||
id = "margin",
|
||||
margins = dpi(10),
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
id = "place",
|
||||
height = dpi(200),
|
||||
strategy = "max",
|
||||
widget = wibox.container.constraint
|
||||
},
|
||||
border_color = color["Grey800"],
|
||||
border_width = dpi(2),
|
||||
id = "volume_device_background",
|
||||
bg = color["Grey800"],
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.partially_rounded_rect(cr, width, height, false, false, true, true, 4)
|
||||
end,
|
||||
@@ -341,11 +176,26 @@ return function(s)
|
||||
local dropdown_list_microphone = wibox.widget {
|
||||
{
|
||||
{
|
||||
layout = wibox.layout.fixed.vertical,
|
||||
id = "volume_device_list"
|
||||
{
|
||||
{
|
||||
spacing = dpi(10),
|
||||
layout = wibox.layout.overflow.vertical,
|
||||
id = "volume_device_list",
|
||||
scrollbar_width = 0,
|
||||
step = dpi(50),
|
||||
},
|
||||
id = "margin",
|
||||
margins = dpi(10),
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
id = "place",
|
||||
height = dpi(200),
|
||||
strategy = "max",
|
||||
widget = wibox.container.constraint
|
||||
},
|
||||
id = "volume_device_background",
|
||||
bg = color["Grey800"],
|
||||
border_color = color["Grey800"],
|
||||
border_width = dpi(2),
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.partially_rounded_rect(cr, width, height, false, false, true, true, 4)
|
||||
end,
|
||||
@@ -404,7 +254,7 @@ return function(s)
|
||||
{
|
||||
id = "volume_list",
|
||||
widget = dropdown_list_volume,
|
||||
visible = false
|
||||
forced_height = 0
|
||||
},
|
||||
-- Microphone selector
|
||||
{
|
||||
@@ -451,7 +301,7 @@ return function(s)
|
||||
{
|
||||
id = "mic_list",
|
||||
widget = dropdown_list_microphone,
|
||||
visible = false
|
||||
forced_height = 0
|
||||
},
|
||||
-- Audio volume slider
|
||||
{
|
||||
@@ -558,17 +408,28 @@ return function(s)
|
||||
audio_selector_margin:connect_signal(
|
||||
"button::press",
|
||||
function()
|
||||
volume_list.visible = not volume_list.visible
|
||||
if volume_list.visible then
|
||||
local rubato_timer = rubato.timed {
|
||||
duration = 0.4,
|
||||
intro = 0.1,
|
||||
outro = 0.1,
|
||||
pos = volume_list.forced_height,
|
||||
easing = rubato.linear,
|
||||
subscribed = function(v)
|
||||
volume_list.forced_height = v
|
||||
end
|
||||
}
|
||||
if volume_list.forced_height == 0 then
|
||||
rubato_timer.target = dpi(200)
|
||||
audio_bg.shape = function(cr, width, height)
|
||||
gears.shape.partially_rounded_rect(cr, width, height, true, true, false, false, 4)
|
||||
end
|
||||
audio_volume.icon:set_image(gears.color.recolor_image(icondir .. "menu-up.svg", color["Teal200"]))
|
||||
audio_volume.icon:set_image(gears.color.recolor_image(icondir .. "menu-up.svg", color["Purple200"]))
|
||||
else
|
||||
rubato_timer.target = 0
|
||||
audio_bg.shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, 4)
|
||||
end
|
||||
audio_volume.icon:set_image(gears.color.recolor_image(icondir .. "menu-down.svg", color["Teal200"]))
|
||||
audio_volume.icon:set_image(gears.color.recolor_image(icondir .. "menu-down.svg", color["Purple200"]))
|
||||
end
|
||||
end
|
||||
)
|
||||
@@ -583,17 +444,28 @@ return function(s)
|
||||
mic_selector_margin:connect_signal(
|
||||
"button::press",
|
||||
function()
|
||||
mic_list.visible = not mic_list.visible
|
||||
if mic_list.visible then
|
||||
local rubato_timer = rubato.timed {
|
||||
duration = 0.4,
|
||||
intro = 0.1,
|
||||
outro = 0.1,
|
||||
pos = mic_list.forced_height,
|
||||
easing = rubato.linear,
|
||||
subscribed = function(v)
|
||||
mic_list.forced_height = v
|
||||
end
|
||||
}
|
||||
if mic_list.forced_height == 0 then
|
||||
rubato_timer.target = dpi(200)
|
||||
mic_selector_margin.mic_bg.shape = function(cr, width, height)
|
||||
gears.shape.partially_rounded_rect(cr, width, height, true, true, false, false, 4)
|
||||
end
|
||||
mic_volume.icon:set_image(gears.color.recolor_image(icondir .. "menu-up.svg", color["Teal200"]))
|
||||
mic_volume.icon:set_image(gears.color.recolor_image(icondir .. "menu-up.svg", color["Blue200"]))
|
||||
else
|
||||
rubato_timer.target = 0
|
||||
mic_bg.shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, 4)
|
||||
end
|
||||
mic_volume.icon:set_image(gears.color.recolor_image(icondir .. "menu-down.svg", color["Teal200"]))
|
||||
mic_volume.icon:set_image(gears.color.recolor_image(icondir .. "menu-down.svg", color["Blue200"]))
|
||||
end
|
||||
end
|
||||
)
|
||||
@@ -641,7 +513,7 @@ return function(s)
|
||||
[[ pactl list sinks | grep -E 'node.name|device.description|alsa.card_name' | awk '{gsub(/"/, ""); for(i = 1;i < NF;i++) printf $i " "; print $NF}' ]],
|
||||
|
||||
function(stdout)
|
||||
local device_list = { layout = wibox.layout.fixed.vertical }
|
||||
local device_list = {}
|
||||
local was_alsa = false
|
||||
local node_names, alsa_names = {}, {}
|
||||
for val in stdout:gmatch("[^\n]+") do
|
||||
@@ -663,7 +535,7 @@ return function(s)
|
||||
for k = 1, #alsa_names, 1 do
|
||||
device_list[#device_list + 1] = create_device(alsa_names[k], node_names[k], true)
|
||||
end
|
||||
dropdown_list_volume.volume_device_background.volume_device_list.children = device_list
|
||||
dropdown_list_volume:get_children_by_id("volume_device_list")[1].children = device_list
|
||||
end
|
||||
)
|
||||
end
|
||||
@@ -676,7 +548,7 @@ return function(s)
|
||||
[[ pactl list sources | grep -E "node.name|device.description|alsa.card_name" | awk '{gsub(/"/, ""); for(i = 1;i < NF;i++) printf $i " "; print $NF}' ]],
|
||||
|
||||
function(stdout)
|
||||
local device_list = { layout = wibox.layout.fixed.vertical }
|
||||
local device_list = {}
|
||||
local was_alsa = false
|
||||
local node_names, alsa_names = {}, {}
|
||||
|
||||
@@ -699,7 +571,7 @@ return function(s)
|
||||
for k = 1, #alsa_names, 1 do
|
||||
device_list[#device_list + 1] = create_device(alsa_names[k], node_names[k], false)
|
||||
end
|
||||
dropdown_list_microphone.volume_device_background.volume_device_list.children = device_list
|
||||
dropdown_list_microphone:get_children_by_id("volume_device_list")[1].children = device_list
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user