finished application laucnher and bluetooth widget
This commit is contained in:
@@ -44,6 +44,47 @@ function application_grid:get_widget()
|
||||
return self._private.widget
|
||||
end
|
||||
|
||||
local function levenshtein_distance(str1, str2)
|
||||
local len1 = string.len(str1)
|
||||
local len2 = string.len(str2)
|
||||
local matrix = {}
|
||||
local cost = 0
|
||||
|
||||
if (len1 == 0) then
|
||||
return len2
|
||||
elseif (len2 == 0) then
|
||||
return len1
|
||||
elseif (str1 == str2) then
|
||||
return 0
|
||||
end
|
||||
|
||||
for i = 0, len1, 1 do
|
||||
matrix[i] = {}
|
||||
matrix[i][0] = i
|
||||
end
|
||||
for j = 0, len2, 1 do
|
||||
matrix[0][j] = j
|
||||
end
|
||||
|
||||
for i = 1, len1, 1 do
|
||||
for j = 1, len2, 1 do
|
||||
if str1:byte(i) == str2:byte(j) then
|
||||
cost = 0
|
||||
else
|
||||
cost = 1
|
||||
end
|
||||
|
||||
matrix[i][j] = math.min(
|
||||
matrix[i - 1][j] + 1,
|
||||
matrix[i][j - 1] + 1,
|
||||
matrix[i - 1][j - 1] + cost
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
return matrix[len1][len2]
|
||||
end
|
||||
|
||||
function application_grid:get_applications_from_file()
|
||||
local list = {}
|
||||
local app_info = Gio.AppInfo
|
||||
@@ -101,6 +142,7 @@ function application_grid:get_applications_from_file()
|
||||
border_width = Theme_config.application_launcher.application.border_width,
|
||||
bg = Theme_config.application_launcher.application.bg,
|
||||
fg = Theme_config.application_launcher.application.fg,
|
||||
desktop_file = Gio.DesktopAppInfo.get_filename(desktop_app_info) or "",
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(8))
|
||||
end,
|
||||
@@ -256,29 +298,64 @@ function application_grid:set_applications(search_filter)
|
||||
layout = wibox.layout.grid
|
||||
}
|
||||
|
||||
local dir = gfilesystem.get_configuration_dir() .. "src/config/applications.json"
|
||||
if not gfilesystem.file_readable(dir) then return end
|
||||
|
||||
local handler = io.open(dir, "r")
|
||||
if not handler then return end
|
||||
local dock_encoded = handler:read("a") or "{}"
|
||||
local dock = json:decode(dock_encoded)
|
||||
if type(dock) ~= "table" then return end
|
||||
local mylist = {}
|
||||
for _, application in ipairs(self.app_list) do
|
||||
-- Match the filter
|
||||
if string.match(string.lower(application.name or ""), string.lower(filter)) or
|
||||
string.match(string.lower(application.categories or ""), string.lower(filter)) or
|
||||
string.match(string.lower(application.keywords or ""), string.lower(filter)) then
|
||||
grid:add(application)
|
||||
|
||||
-- Get the current position in the grid of the application as a table
|
||||
local pos = grid:get_widget_position(application)
|
||||
|
||||
-- Check if the curser is currently at the same position as the application
|
||||
capi.awesome.connect_signal(
|
||||
"update::selected",
|
||||
function()
|
||||
if self._private.curser.y == pos.row and self._private.curser.x == pos.col then
|
||||
application.border_color = Theme_config.application_launcher.application.border_color_active
|
||||
else
|
||||
application.border_color = Theme_config.application_launcher.application.border_color
|
||||
end
|
||||
if #dock == 0 then
|
||||
application.counter = 0
|
||||
end
|
||||
for _, app in ipairs(dock) do
|
||||
if app.desktop_file == application.desktop_file then
|
||||
application.counter = app.counter or 0
|
||||
break;
|
||||
else
|
||||
application.counter = 0
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
table.insert(mylist, application)
|
||||
end
|
||||
end
|
||||
|
||||
table.sort(mylist, function(a, b)
|
||||
return levenshtein_distance(filter, a.name) < levenshtein_distance(filter, b.name)
|
||||
end)
|
||||
--sort mytable by counter
|
||||
table.sort(mylist, function(a, b)
|
||||
return a.counter > b.counter
|
||||
end)
|
||||
|
||||
for _, app in ipairs(mylist) do
|
||||
grid:add(app)
|
||||
|
||||
-- Get the current position in the grid of the app as a table
|
||||
local pos = grid:get_widget_position(app)
|
||||
|
||||
-- Check if the curser is currently at the same position as the app
|
||||
capi.awesome.connect_signal(
|
||||
"update::selected",
|
||||
function()
|
||||
if self._private.curser.y == pos.row and self._private.curser.x == pos.col then
|
||||
app.border_color = Theme_config.application_launcher.application.border_color_active
|
||||
else
|
||||
app.border_color = Theme_config.application_launcher.application.border_color
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
capi.awesome.emit_signal("update::selected")
|
||||
self:set_widget(grid)
|
||||
end
|
||||
@@ -292,7 +369,6 @@ function application_grid:move_up()
|
||||
end
|
||||
|
||||
function application_grid:move_down()
|
||||
print(self._private.curser.y)
|
||||
self._private.curser.y = self._private.curser.y + 1
|
||||
local grid_rows, _ = self:get_widget():get_dimension()
|
||||
if self._private.curser.y > grid_rows then
|
||||
@@ -322,6 +398,35 @@ function application_grid:execute()
|
||||
local selected_widget = self:get_widget():get_widgets_at(self._private.curser.y,
|
||||
self._private.curser.x)[1]
|
||||
Gio.AppInfo.launch_uris_async(Gio.AppInfo.create_from_commandline(selected_widget.exec, nil, 0))
|
||||
|
||||
local dir = gfilesystem.get_configuration_dir() .. "src/config/applications.json"
|
||||
if not gfilesystem.file_readable(dir) then return end
|
||||
|
||||
local handler = io.open(dir, "r")
|
||||
if not handler then return end
|
||||
local dock_encoded = handler:read("a") or "{}"
|
||||
local dock = json:decode(dock_encoded)
|
||||
if type(dock) ~= "table" then return end
|
||||
for _, prog in ipairs(dock) do
|
||||
if prog.desktop_file:match(selected_widget.desktop_file) then
|
||||
prog.counter = prog.counter + 1
|
||||
goto continue
|
||||
end
|
||||
end
|
||||
do
|
||||
local prog = {
|
||||
name = selected_widget.name,
|
||||
desktop_file = selected_widget.desktop_file,
|
||||
counter = 1
|
||||
}
|
||||
table.insert(dock, prog)
|
||||
end
|
||||
::continue::
|
||||
handler:close()
|
||||
handler = io.open(dir, "w")
|
||||
if not handler then return end
|
||||
handler:write(json:encode_pretty(dock))
|
||||
handler:close()
|
||||
end
|
||||
|
||||
function application_grid:reset()
|
||||
@@ -344,10 +449,17 @@ function application_grid.new(args)
|
||||
y = 1
|
||||
}
|
||||
|
||||
-- Create folder and file if it doesn't exist
|
||||
local dir = gfilesystem.get_configuration_dir() .. "src/config"
|
||||
gfilesystem.make_directories(dir)
|
||||
dir = dir .. "/applications.json"
|
||||
if not gfilesystem.file_readable(dir) then
|
||||
os.execute("touch " .. dir)
|
||||
end
|
||||
|
||||
w:get_applications_from_file()
|
||||
|
||||
w:set_applications()
|
||||
|
||||
return w
|
||||
end
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ local wibox = require("wibox")
|
||||
local gshape = require("gears.shape")
|
||||
local gtable = require("gears.table")
|
||||
local gobject = require("gears.object")
|
||||
local abutton = require("awful.button")
|
||||
|
||||
local capi = {
|
||||
awesome = awesome,
|
||||
@@ -18,39 +19,6 @@ local capi = {
|
||||
|
||||
local application_launcher = { mt = {} }
|
||||
|
||||
application_launcher.searchbar = awful.widget.inputbox {
|
||||
widget_template = wibox.template {
|
||||
widget = wibox.widget {
|
||||
{
|
||||
{
|
||||
{
|
||||
widget = wibox.widget.textbox,
|
||||
halign = "left",
|
||||
valign = "center",
|
||||
id = "text_role",
|
||||
},
|
||||
widget = wibox.container.margin,
|
||||
margins = 5,
|
||||
id = "marg"
|
||||
},
|
||||
widget = wibox.container.constraint,
|
||||
strategy = "exact",
|
||||
width = 400,
|
||||
height = 50,
|
||||
id = "const"
|
||||
},
|
||||
widget = wibox.container.background,
|
||||
bg = "#212121",
|
||||
fg = "#F0F0F0",
|
||||
border_color = "#414141",
|
||||
border_width = 2,
|
||||
shape = gshape.rounded_rect,
|
||||
},
|
||||
update_callback = function(template_widget, args)
|
||||
template_widget.widget.const.marg.text_role.markup = args.text
|
||||
end
|
||||
}
|
||||
}
|
||||
|
||||
application_launcher.application_grid = require("src.modules.application_launcher.application") {}
|
||||
|
||||
@@ -62,10 +30,58 @@ function application_launcher.new(args)
|
||||
|
||||
gtable.crush(ret, application_launcher, true)
|
||||
|
||||
local searchbar = awful.widget.inputbox {
|
||||
hint_text = "Search...",
|
||||
valign = "center",
|
||||
halign = "left",
|
||||
}
|
||||
|
||||
searchbar:buttons(
|
||||
gtable.join {
|
||||
abutton({}, 1, function()
|
||||
searchbar:focus()
|
||||
end)
|
||||
}
|
||||
)
|
||||
|
||||
local old_cursor, old_wibox
|
||||
searchbar:connect_signal("mouse::enter", function()
|
||||
local wid = capi.mouse.current_wibox
|
||||
if wid then
|
||||
old_cursor, old_wibox = wid.cursor, wid
|
||||
wid.cursor = "xterm"
|
||||
end
|
||||
end)
|
||||
searchbar:connect_signal("mouse::leave", function()
|
||||
old_wibox.cursor = old_cursor
|
||||
old_wibox = nil
|
||||
end)
|
||||
|
||||
local applicaton_launcher = wibox.widget {
|
||||
{
|
||||
{
|
||||
ret.searchbar,
|
||||
{
|
||||
{
|
||||
{
|
||||
searchbar,
|
||||
widget = wibox.container.margin,
|
||||
margins = 5,
|
||||
id = "marg"
|
||||
},
|
||||
widget = wibox.container.constraint,
|
||||
strategy = "exact",
|
||||
width = 400,
|
||||
height = 50,
|
||||
id = "const"
|
||||
},
|
||||
widget = wibox.container.background,
|
||||
bg = Theme_config.application_launcher.searchbar.bg,
|
||||
fg = Theme_config.application_launcher.searchbar.fg,
|
||||
border_color = Theme_config.application_launcher.searchbar.border_color,
|
||||
border_width = Theme_config.application_launcher.searchbar.border_width,
|
||||
shape = gshape.rounded_rect,
|
||||
id = "searchbar_bg"
|
||||
},
|
||||
{
|
||||
ret.application_grid,
|
||||
spacing = dpi(10),
|
||||
@@ -101,52 +117,70 @@ function application_launcher.new(args)
|
||||
border_width = Theme_config.application_launcher.border_width
|
||||
}
|
||||
|
||||
local searchbar_bg = applicaton_launcher:get_children_by_id("searchbar_bg")[1]
|
||||
|
||||
capi.awesome.connect_signal(
|
||||
"application_launcher::show",
|
||||
function()
|
||||
capi.awesome.emit_signal("update::selected")
|
||||
if capi.mouse.screen == args.screen then
|
||||
ret.application_container.visible = not ret.application_container.visible
|
||||
end
|
||||
if ret.application_container.visible then
|
||||
ret.searchbar:focus()
|
||||
searchbar_bg.border_color = Theme_config.application_launcher.searchbar.border_active
|
||||
searchbar:focus()
|
||||
else
|
||||
searchbar:set_text("")
|
||||
awful.keygrabber.stop()
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
ret.searchbar:connect_signal(
|
||||
searchbar:connect_signal(
|
||||
"submit",
|
||||
function(text)
|
||||
function(_, text)
|
||||
ret.application_grid:execute()
|
||||
capi.awesome.emit_signal("application_launcher::show")
|
||||
searchbar:set_text("")
|
||||
ret.application_grid:set_applications(searchbar:get_text())
|
||||
searchbar_bg.border_color = Theme_config.application_launcher.searchbar.border_color
|
||||
end
|
||||
)
|
||||
|
||||
ret.searchbar:connect_signal(
|
||||
searchbar:connect_signal(
|
||||
"stopped",
|
||||
function()
|
||||
ret.searchbar:get_widget().widget.border_color = Theme_config.application_launcher.searchbar.border_color
|
||||
function(_, stop_key)
|
||||
if stop_key == "Escape" then
|
||||
capi.awesome.emit_signal("application_launcher::show")
|
||||
end
|
||||
searchbar:set_text("")
|
||||
ret.application_grid:set_applications(searchbar:get_text())
|
||||
searchbar_bg.border_color = Theme_config.application_launcher.searchbar.border_color
|
||||
end
|
||||
)
|
||||
|
||||
ret.searchbar:connect_signal(
|
||||
searchbar:connect_signal(
|
||||
"started",
|
||||
function()
|
||||
ret.searchbar:get_widget().widget.border_color = Theme_config.application_launcher.searchbar.border_active
|
||||
searchbar_bg.border_color = Theme_config.application_launcher.searchbar.border_active
|
||||
end
|
||||
)
|
||||
|
||||
awesome.connect_signal(
|
||||
searchbar:connect_signal(
|
||||
"inputbox::key_pressed",
|
||||
function(modkey, key)
|
||||
function(_, modkey, key)
|
||||
if key == "Escape" then
|
||||
ret.searchbar:stop()
|
||||
searchbar:stop()
|
||||
capi.awesome.emit_signal("application_launcher::show")
|
||||
ret.application_grid:reset()
|
||||
ret.searchbar:set_text("")
|
||||
searchbar:set_text("")
|
||||
elseif key == "Down" or key == "Right" then
|
||||
ret.searchbar:stop()
|
||||
if key == "Down" then
|
||||
ret.application_grid:move_down()
|
||||
elseif key == "Right" then
|
||||
ret.application_grid:move_right()
|
||||
end
|
||||
searchbar:stop()
|
||||
awful.keygrabber.run(function(mod, key2, event)
|
||||
if event == "press" then
|
||||
if key2 == "Down" then
|
||||
@@ -155,7 +189,7 @@ function application_launcher.new(args)
|
||||
local old_y = ret.application_grid._private.curser.y
|
||||
ret.application_grid:move_up()
|
||||
if old_y - ret.application_grid._private.curser.y == 0 then
|
||||
ret.searchbar:focus()
|
||||
searchbar:focus()
|
||||
end
|
||||
elseif key2 == "Left" then
|
||||
ret.application_grid:move_left()
|
||||
@@ -166,17 +200,20 @@ function application_launcher.new(args)
|
||||
ret.application_grid:execute()
|
||||
capi.awesome.emit_signal("application_launcher::show")
|
||||
ret.application_grid:reset()
|
||||
ret.searchbar:set_text("")
|
||||
searchbar:set_text("")
|
||||
ret.application_grid:set_applications(searchbar:get_text())
|
||||
elseif key2 == "Escape" then
|
||||
capi.awesome.emit_signal("application_launcher::show")
|
||||
ret.application_grid:reset()
|
||||
ret.searchbar:set_text("")
|
||||
searchbar:set_text("")
|
||||
ret.application_grid:set_applications(searchbar:get_text())
|
||||
awful.keygrabber.stop()
|
||||
end
|
||||
end
|
||||
end)
|
||||
searchbar_bg.border_color = Theme_config.application_launcher.searchbar.border_color
|
||||
end
|
||||
ret.application_grid:set_applications(ret.searchbar:get_text())
|
||||
ret.application_grid:set_applications(searchbar:get_text())
|
||||
end
|
||||
)
|
||||
|
||||
|
||||
@@ -1,252 +0,0 @@
|
||||
-------------------------------------------------------
|
||||
-- This is the seachbar for the application launcher --
|
||||
-------------------------------------------------------
|
||||
|
||||
-- Awesome Libs
|
||||
local awful = require("awful")
|
||||
local dpi = require("beautiful").xresources.apply_dpi
|
||||
local gears = require("gears")
|
||||
local gstring = gears.string
|
||||
local keygrabber = require("awful.keygrabber")
|
||||
local wibox = require("wibox")
|
||||
|
||||
local capi = {
|
||||
awesome = awesome,
|
||||
mouse = mouse,
|
||||
}
|
||||
|
||||
local icondir = gears.filesystem.get_configuration_dir() .. "src/assets/icons/application_launcher/searchbar/"
|
||||
|
||||
local kgrabber
|
||||
|
||||
return function()
|
||||
|
||||
local searchbar = wibox.widget {
|
||||
{
|
||||
{
|
||||
{ -- Search icon
|
||||
{
|
||||
{
|
||||
resize = false,
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
image = gears.color.recolor_image(icondir .. "search.svg",
|
||||
Theme_config.application_launcher.searchbar.icon_color),
|
||||
widget = wibox.widget.imagebox
|
||||
},
|
||||
bg = Theme_config.application_launcher.searchbar.icon_background,
|
||||
widget = wibox.container.background
|
||||
},
|
||||
strategy = "exact",
|
||||
width = dpi(30),
|
||||
widget = wibox.container.constraint
|
||||
},
|
||||
{
|
||||
{
|
||||
fg = Theme_config.application_launcher.searchbar.fg_hint,
|
||||
markup = "Search",
|
||||
valign = "center",
|
||||
align = "center",
|
||||
widget = wibox.widget.textbox,
|
||||
id = "search_hint"
|
||||
},
|
||||
margins = dpi(5),
|
||||
widget = wibox.container.margin,
|
||||
id = "s_margin"
|
||||
},
|
||||
widget = wibox.layout.fixed.horizontal,
|
||||
id = "s_layout"
|
||||
},
|
||||
bg = Theme_config.application_launcher.searchbar.bg,
|
||||
fg = Theme_config.application_launcher.searchbar.fg,
|
||||
border_color = Theme_config.application_launcher.searchbar.border_color,
|
||||
border_width = Theme_config.application_launcher.searchbar.border_width,
|
||||
widget = wibox.container.background,
|
||||
shape = Theme_config.application_launcher.searchbar.shape,
|
||||
id = "s_background"
|
||||
},
|
||||
width = dpi(400),
|
||||
height = dpi(40),
|
||||
strategy = "exact",
|
||||
widget = wibox.container.constraint
|
||||
}
|
||||
|
||||
local old_wibox, old_cursor
|
||||
local mouse_enter = function()
|
||||
local w = capi.mouse.current_wibox
|
||||
if w then
|
||||
old_cursor, old_wibox = w.cursor, w
|
||||
w.cursor = "xterm"
|
||||
end
|
||||
end
|
||||
|
||||
local mouse_leave = function()
|
||||
old_wibox.cursor = old_cursor
|
||||
old_wibox = nil
|
||||
end
|
||||
|
||||
searchbar:disconnect_signal("mouse::enter", mouse_enter)
|
||||
searchbar:disconnect_signal("mouse::leave", mouse_leave)
|
||||
searchbar:connect_signal("mouse::enter", mouse_enter)
|
||||
searchbar:connect_signal("mouse::leave", mouse_leave)
|
||||
|
||||
local function have_multibyte_char_at(text, position)
|
||||
return #text:sub(position, position) == -1
|
||||
end
|
||||
|
||||
local search_text = searchbar:get_children_by_id("search_hint")[1]
|
||||
|
||||
local function promt_text_with_cursor(text, cursor_pos)
|
||||
local char, spacer, text_start, text_end
|
||||
|
||||
local cursor_color = Theme_config.application_launcher.searchbar.bg_cursor
|
||||
local text_color = Theme_config.application_launcher.searchbar.fg_cursor
|
||||
|
||||
if text == "" then
|
||||
return "<span foreground='" .. Theme_config.application_launcher.searchbar.fg_hint .. "'>Search</span>"
|
||||
end
|
||||
|
||||
if #text < cursor_pos then
|
||||
char = " "
|
||||
spacer = ""
|
||||
text_start = gstring.xml_escape(text)
|
||||
text_end = ""
|
||||
else
|
||||
local offset = 0
|
||||
if have_multibyte_char_at(text, cursor_pos) then
|
||||
offset = 1
|
||||
end
|
||||
char = gstring.xml_escape(text:sub(cursor_pos, cursor_pos + offset))
|
||||
spacer = " "
|
||||
text_start = gstring.xml_escape(text:sub(1, cursor_pos - 1))
|
||||
text_end = gstring.xml_escape(text:sub(cursor_pos + offset + 1))
|
||||
end
|
||||
|
||||
return text_start ..
|
||||
"<span background='" ..
|
||||
cursor_color .. "' foreground='" .. text_color .. "'>" .. char .. "</span>" .. text_end .. spacer
|
||||
end
|
||||
|
||||
local text_string = ""
|
||||
|
||||
---Start a new keygrabber to simulate an input textbox
|
||||
local function keygrabber_start()
|
||||
local cur_pos = #text_string + 1
|
||||
|
||||
--Draws the string on each keypress
|
||||
local function update()
|
||||
search_text:set_markup(promt_text_with_cursor(text_string, cur_pos))
|
||||
--Send the string over to the application to filter applications
|
||||
capi.awesome.emit_signal("update::application_list", text_string)
|
||||
end
|
||||
|
||||
update()
|
||||
|
||||
kgrabber = keygrabber.run(
|
||||
function(modifiers, key, event)
|
||||
capi.awesome.connect_signal("searchbar::stop", function()
|
||||
keygrabber.stop(kgrabber)
|
||||
capi.awesome.emit_signal("application_launcher::kgrabber_start")
|
||||
end)
|
||||
|
||||
local mod = {}
|
||||
for _, v in ipairs(modifiers) do
|
||||
mod[v] = true
|
||||
end
|
||||
|
||||
if event ~= "press" then
|
||||
return
|
||||
end
|
||||
|
||||
--Escape cases
|
||||
if (mod.Control and (key == "c" or key == "g"))
|
||||
or (not mod.Control and key == "Escape") then
|
||||
keygrabber.stop(kgrabber)
|
||||
search_text:set_markup(promt_text_with_cursor("", 1))
|
||||
text_string = ""
|
||||
capi.awesome.emit_signal("application_launcher::show")
|
||||
elseif (not mod.Control and key == "Return") or
|
||||
(not mod.Control and key == "KP_Enter") then
|
||||
keygrabber.stop(kgrabber)
|
||||
searchbar.s_background.border_color = Theme_config.application_launcher.searchbar.border_color
|
||||
searchbar.s_background.fg = Theme_config.application_launcher.searchbar.fg_hint
|
||||
search_text:set_markup(promt_text_with_cursor("", 1))
|
||||
text_string = ""
|
||||
capi.awesome.emit_signal("application_launcher::execute")
|
||||
capi.awesome.emit_signal("application_launcher::show")
|
||||
end
|
||||
|
||||
if mod.Control then
|
||||
elseif mod.Mod1 or mod.Mod3 then
|
||||
else
|
||||
--Delete character to the left and move cursor
|
||||
if key == "BackSpace" then
|
||||
if cur_pos > 1 then
|
||||
local offset = 0
|
||||
if have_multibyte_char_at(text_string, cur_pos - 1) then
|
||||
offset = 1
|
||||
end
|
||||
text_string = text_string:sub(1, cur_pos - 2 - offset) .. text_string:sub(cur_pos)
|
||||
cur_pos = cur_pos - 1 - offset
|
||||
end
|
||||
update()
|
||||
--Delete character to the right
|
||||
elseif key == "Delete" then
|
||||
text_string = text_string:sub(1, cur_pos - 1) .. text_string:sub(cur_pos + 1)
|
||||
update()
|
||||
-- Move cursor to the left
|
||||
elseif key == "Left" then
|
||||
--cur_pos = cur_pos - 1
|
||||
capi.awesome.emit_signal("application::left")
|
||||
-- Move cursor to the right
|
||||
elseif key == "Right" then
|
||||
--cur_pos = cur_pos + 1
|
||||
capi.awesome.emit_signal("application::right")
|
||||
elseif key == "Up" then
|
||||
capi.awesome.emit_signal("application::up")
|
||||
elseif key == "Down" then
|
||||
capi.awesome.emit_signal("application::down")
|
||||
else
|
||||
--Add key at cursor position
|
||||
if key:wlen() == 1 then
|
||||
text_string = text_string:sub(1, cur_pos - 1) .. key .. text_string:sub(cur_pos)
|
||||
cur_pos = cur_pos + #key
|
||||
end
|
||||
update()
|
||||
end
|
||||
--Make sure cursor can't leave string bounds
|
||||
if cur_pos < 1 then
|
||||
cur_pos = 1
|
||||
elseif cur_pos > #text_string + 1 then
|
||||
cur_pos = #text_string + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
--Start the keygrabber when the searchbar is left clicked
|
||||
searchbar:buttons(gears.table.join(
|
||||
awful.button({}, 1, function()
|
||||
if not awful.keygrabber.is_running then
|
||||
searchbar.s_background.border_color = Theme_config.application_launcher.searchbar.border_active
|
||||
searchbar.s_background.fg = Theme_config.application_launcher.searchbar.fg
|
||||
search_text:set_markup(promt_text_with_cursor("", 1))
|
||||
end
|
||||
end)
|
||||
))
|
||||
|
||||
capi.awesome.connect_signal(
|
||||
"searchbar::start",
|
||||
function()
|
||||
if not awful.keygrabber.is_running then
|
||||
keygrabber_start()
|
||||
searchbar.s_background.border_color = Theme_config.application_launcher.searchbar.border_active
|
||||
searchbar.s_background.fg = Theme_config.application_launcher.searchbar.fg
|
||||
search_text:set_markup(promt_text_with_cursor("", 1))
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
return searchbar
|
||||
end
|
||||
@@ -5,52 +5,106 @@
|
||||
-- Awesome Libs
|
||||
local awful = require("awful")
|
||||
local dpi = require("beautiful").xresources.apply_dpi
|
||||
local gobject = require("gears").object
|
||||
local gtable = require("gears").table
|
||||
local gcolor = require("gears").color
|
||||
local gshape = require("gears").shape
|
||||
local gfilesystem = require("gears").filesystem
|
||||
local wibox = require("wibox")
|
||||
local base = require("wibox.widget.base")
|
||||
local lgi = require("lgi")
|
||||
local dbus_proxy = require("dbus_proxy")
|
||||
|
||||
local capi = {
|
||||
awesome = awesome,
|
||||
}
|
||||
local context_menu = require("src.modules.context_menu")
|
||||
|
||||
local icondir = gfilesystem.get_configuration_dir() .. "src/assets/icons/bluetooth/"
|
||||
|
||||
local capi = {
|
||||
awesome = awesome
|
||||
}
|
||||
|
||||
local device = { mt = {} }
|
||||
|
||||
function device:connect()
|
||||
self.device:Connect()
|
||||
self.widget:get_children_by_id("con")[1].image = gcolor.recolor_image(icondir .. "link.svg",
|
||||
Theme_config.bluetooth_controller.icon_color_dark)
|
||||
capi.awesome.emit_signal("bluetooth::disconnect", device)
|
||||
function device:layout(_, width, height)
|
||||
if self._private.widget then
|
||||
return { base.place_widget_at(self._private.widget, 0, 0, width, height) }
|
||||
end
|
||||
end
|
||||
|
||||
function device:disconnect()
|
||||
self.device:Disconnect()
|
||||
self.widget:get_children_by_id("con")[1].image = gcolor.recolor_image(icondir .. "link-off.svg",
|
||||
Theme_config.bluetooth_controller.icon_color_dark)
|
||||
capi.awesome.emit_signal("bluetooth::connect", device)
|
||||
function device:fit(context, width, height)
|
||||
local w, h = 0, 0
|
||||
if self._private.widget then
|
||||
w, h = base.fit_widget(self, context, self._private.widget, width, height)
|
||||
end
|
||||
return w, h
|
||||
end
|
||||
|
||||
device.set_widget = base.set_widget_common
|
||||
|
||||
function device:get_widget()
|
||||
return self._private.widget
|
||||
end
|
||||
|
||||
function device:toggle_connect()
|
||||
if not self.device.Connected then
|
||||
|
||||
--TODO: Implement device passcode support, I have no idea how to get the
|
||||
--TODO: Methods from Agent1 implemented
|
||||
--[[ self._private.AgentManager1 = dbus_proxy.Proxy:new {
|
||||
bus = dbus_proxy.Bus.SYSTEM,
|
||||
name = "org.bluez",
|
||||
path = "/org/bluez",
|
||||
interface = "org.bluez.AgentManager1"
|
||||
}
|
||||
|
||||
self._private.Agent1 = dbus_proxy.Proxy:new {
|
||||
bus = dbus_proxy.Bus.SYSTEM,
|
||||
name = "org.bluez",
|
||||
path = "/org/bluez",
|
||||
interface = "org.bluez.Agent1",
|
||||
}
|
||||
|
||||
self._private.AgentManager1:RegisterAgent(self._private.Agent1.object_path, "")
|
||||
self._private.AgentManager1:RequestDefaultAgent(self._private.Agent1.object_path) ]]
|
||||
|
||||
self.device:ConnectAsync()
|
||||
else
|
||||
self.device:DisconnectAsync()
|
||||
end
|
||||
end
|
||||
|
||||
function device:toggle_pair()
|
||||
if self.device.Paired then
|
||||
self.device:PairAsync()
|
||||
else
|
||||
self.device:CancelPairingAsync()
|
||||
end
|
||||
end
|
||||
|
||||
function device:toggle_trusted()
|
||||
self.device:Set("org.bluez.Device1", "Trusted", lgi.GLib.Variant("b", not self.device.Trusted))
|
||||
self.device.Trusted = { signature = "b", value = not self.device.Trusted }
|
||||
|
||||
end
|
||||
|
||||
function device:rename(newname)
|
||||
self.device:Set("org.bluez.Device1", "Alias", lgi.GLib.Variant("s", newname))
|
||||
self.device.Alias = { signature = "s", value = newname }
|
||||
return self.device:Get("org.bluez.Device1", "Alias")
|
||||
end
|
||||
|
||||
function device.new(args)
|
||||
args = args or {}
|
||||
args.device = args.device or {}
|
||||
args.battery = args.battery or {}
|
||||
|
||||
local ret = gobject { enable_properties = true, enable_auto_signals = true }
|
||||
gtable.crush(ret, device, true)
|
||||
|
||||
if args.device then
|
||||
ret.device = args.device
|
||||
end
|
||||
if args.battery then
|
||||
ret.battery = args.battery
|
||||
end
|
||||
|
||||
local icon = device.Icon or "bluetooth-on"
|
||||
local device_widget = wibox.widget {
|
||||
|
||||
local inputbox = awful.widget.inputbox {
|
||||
text = args.device.Alias or args.device.Name,
|
||||
halign = "left",
|
||||
valign = "center",
|
||||
}
|
||||
|
||||
local ret = base.make_widget_from_value(wibox.widget {
|
||||
{
|
||||
{
|
||||
{
|
||||
@@ -75,9 +129,11 @@ function device.new(args)
|
||||
{
|
||||
{
|
||||
{
|
||||
text = ret.device.Alias or ret.device.Name,
|
||||
id = "alias",
|
||||
widget = wibox.widget.textbox
|
||||
inputbox,
|
||||
widget = wibox.container.constraint,
|
||||
strategy = "min",
|
||||
width = dpi(400),
|
||||
id = "const"
|
||||
},
|
||||
{
|
||||
text = "Connecting...",
|
||||
@@ -150,33 +206,133 @@ function device.new(args)
|
||||
shape = function(cr, width, height)
|
||||
gshape.rounded_rect(cr, width, height, dpi(4))
|
||||
end,
|
||||
device = ret.device,
|
||||
widget = wibox.container.background
|
||||
}
|
||||
})
|
||||
|
||||
if ret.device.Connected then
|
||||
device_widget:get_children_by_id("con")[1].image = gcolor.recolor_image(icondir .. "link.svg",
|
||||
Theme_config.bluetooth_controller.icon_color_dark)
|
||||
else
|
||||
device_widget:get_children_by_id("con")[1].image = gcolor.recolor_image(icondir .. "link-off.svg",
|
||||
Theme_config.bluetooth_controller.icon_color_dark)
|
||||
gtable.crush(ret, device, true)
|
||||
|
||||
if args.device then
|
||||
ret.device = args.device
|
||||
end
|
||||
|
||||
device_widget:buttons(
|
||||
ret:get_children_by_id("con")[1].image = gcolor.recolor_image(ret.device.Connected and icondir .. "link.svg" or
|
||||
icondir .. "link-off.svg",
|
||||
Theme_config.bluetooth_controller.icon_color_dark)
|
||||
|
||||
local cm = context_menu {
|
||||
widget_template = wibox.widget {
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
widget = wibox.widget.imagebox,
|
||||
resize = true,
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
id = "icon_role",
|
||||
},
|
||||
widget = wibox.container.constraint,
|
||||
stragety = "exact",
|
||||
width = dpi(24),
|
||||
height = dpi(24),
|
||||
id = "const"
|
||||
},
|
||||
{
|
||||
widget = wibox.widget.textbox,
|
||||
valign = "center",
|
||||
halign = "left",
|
||||
id = "text_role"
|
||||
},
|
||||
layout = wibox.layout.fixed.horizontal
|
||||
},
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
widget = wibox.container.background,
|
||||
}, spacing = dpi(10),
|
||||
entries = {
|
||||
{
|
||||
name = ret.device.Connected and "Disconnect" or "Connect",
|
||||
icon = gcolor.recolor_image(ret.device.Connected and icondir .. "bluetooth-off.svg" or
|
||||
icondir .. "bluetooth-on.svg",
|
||||
Theme_config.bluetooth_controller.icon_color),
|
||||
callback = function()
|
||||
ret:toggle_connect()
|
||||
end,
|
||||
id = "connected"
|
||||
},
|
||||
{
|
||||
name = "Pair",
|
||||
icon = gcolor.recolor_image(ret.device.Paired and icondir .. "link-off.svg" or
|
||||
icondir .. "link.svg",
|
||||
Theme_config.bluetooth_controller.icon_color),
|
||||
callback = function()
|
||||
ret:toggle_pair()
|
||||
end
|
||||
},
|
||||
{
|
||||
name = ret.device.Trusted and "Untrust" or "Trust",
|
||||
icon = gcolor.recolor_image(ret.device.Trusted and icondir .. "untrusted.svg" or icondir .. "trusted.svg",
|
||||
Theme_config.bluetooth_controller.icon_color),
|
||||
callback = function()
|
||||
ret:toggle_trusted()
|
||||
end,
|
||||
id = "trusted"
|
||||
},
|
||||
{
|
||||
name = "Rename",
|
||||
icon = gcolor.recolor_image(icondir .. "edit.svg", Theme_config.bluetooth_controller.icon_color),
|
||||
callback = function()
|
||||
inputbox:focus()
|
||||
inputbox:connect_signal("submit", function(text)
|
||||
text = text:get_text()
|
||||
inputbox.markup = ret:rename(text)
|
||||
end)
|
||||
end
|
||||
},
|
||||
{
|
||||
name = "Remove",
|
||||
icon = gcolor.recolor_image(icondir .. "delete.svg", Theme_config.bluetooth_controller.icon_color),
|
||||
callback = function()
|
||||
args.remove_callback(ret.device)
|
||||
end
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ret:buttons(
|
||||
gtable.join(
|
||||
awful.button({}, 1, function()
|
||||
if ret.device.Connected then
|
||||
ret:disconnect()
|
||||
else
|
||||
ret:connect()
|
||||
ret:toggle_connect()
|
||||
end),
|
||||
awful.button({}, 3, function()
|
||||
for _, value in ipairs(cm.widget.children) do
|
||||
value.id = value.id or ""
|
||||
if value.id:match("connected") then
|
||||
value:get_children_by_id("text_role")[1].text = ret.device.Connected and "Disconnect" or "Connect"
|
||||
value:get_children_by_id("icon_role")[1].image = gcolor.recolor_image(ret.device.Connected and
|
||||
icondir .. "bluetooth-off.svg" or icondir .. "bluetooth-on.svg",
|
||||
Theme_config.bluetooth_controller.icon_color)
|
||||
elseif value.id:match("trusted") then
|
||||
value:get_children_by_id("text_role")[1].text = ret.device.Trusted and "Untrust" or "Trust"
|
||||
value:get_children_by_id("icon_role")[1].image = gcolor.recolor_image(ret.device.Trusted and
|
||||
icondir .. "untrusted.svg" or icondir .. "trusted.svg", Theme_config.bluetooth_controller.icon_color)
|
||||
elseif value.id:match("paired") then
|
||||
value:get_children_by_id("icon_role")[1].image = gcolor.recolor_image(ret.device.Paired and
|
||||
icondir .. "link-off.svg" or icondir .. "link.svg", Theme_config.bluetooth_controller.icon_color)
|
||||
end
|
||||
end
|
||||
cm:toggle()
|
||||
end)
|
||||
)
|
||||
)
|
||||
|
||||
Hover_signal(device_widget)
|
||||
capi.awesome.connect_signal(ret.device.object_path .. "_updated", function(d)
|
||||
ret:get_children_by_id("con")[1].image = gcolor.recolor_image(d.Connected and icondir .. "link.svg" or
|
||||
icondir .. "link-off.svg",
|
||||
Theme_config.bluetooth_controller.icon_color_dark)
|
||||
end)
|
||||
|
||||
ret.widget = device_widget
|
||||
Hover_signal(ret)
|
||||
|
||||
return ret
|
||||
end
|
||||
|
||||
@@ -5,12 +5,16 @@
|
||||
-- Awesome Libs
|
||||
local awful = require("awful")
|
||||
local dpi = require("beautiful").xresources.apply_dpi
|
||||
local gobject = require("gears").object
|
||||
local gtable = require("gears").table
|
||||
local gcolor = require("gears").color
|
||||
local gshape = require("gears").shape
|
||||
local gfilesystem = require("gears").filesystem
|
||||
local wibox = require("wibox")
|
||||
local base = require("wibox.widget.base")
|
||||
local dbus_proxy = require("dbus_proxy")
|
||||
local lgi = require("lgi")
|
||||
local gtimer = require("gears.timer")
|
||||
local naughty = require("naughty")
|
||||
|
||||
local bt_device = require("src.modules.bluetooth.device")
|
||||
|
||||
@@ -18,54 +22,218 @@ local rubato = require("src.lib.rubato")
|
||||
|
||||
local icondir = gfilesystem.get_configuration_dir() .. "src/assets/icons/bluetooth/"
|
||||
|
||||
local dnd_widget = require("awful.widget.toggle_widget")
|
||||
|
||||
local capi = {
|
||||
awesome = awesome,
|
||||
mouse = mouse,
|
||||
mousegrabber = mousegrabber,
|
||||
}
|
||||
|
||||
local bluetooth = { mt = {} }
|
||||
|
||||
bluetooth.devices = {
|
||||
paired = { layout = wibox.layout.fixed.vertical },
|
||||
discovered = { layout = wibox.layout.fixed.vertical }
|
||||
}
|
||||
|
||||
function bluetooth:get_devices()
|
||||
return self.devices
|
||||
function bluetooth:layout(_, width, height)
|
||||
if self._private.widget then
|
||||
return { base.place_widget_at(self._private.widget, 0, 0, width, height) }
|
||||
end
|
||||
end
|
||||
|
||||
local function add_device(self, device, battery)
|
||||
--Check if the device is already in the list
|
||||
for _, status in pairs(self.devices) do
|
||||
for _, dev in ipairs(status) do
|
||||
if dev.device.Address == device.Address then
|
||||
return
|
||||
function bluetooth:fit(context, width, height)
|
||||
local w, h = 0, 0
|
||||
if self._private.widget then
|
||||
w, h = base.fit_widget(self, context, self._private.widget, width, height)
|
||||
end
|
||||
return w, h
|
||||
end
|
||||
|
||||
bluetooth.set_widget = base.set_widget_common
|
||||
|
||||
function bluetooth:get_widget()
|
||||
return self._private.widget
|
||||
end
|
||||
|
||||
function bluetooth:get_paired_devices()
|
||||
return self:get_children_by_id("connected_device_list")[1].children
|
||||
end
|
||||
|
||||
function bluetooth:get_discovered_devices()
|
||||
return self:get_children_by_id("discovered_device_list")[1].children
|
||||
end
|
||||
|
||||
function bluetooth:remove_device_information(device)
|
||||
-- Either disconnect async and have to remove the device "twice"
|
||||
-- or do it sync but awesome freezes for a second or two
|
||||
print("bruh?")
|
||||
device:DisconnectAsync(function(_, _, out, err)
|
||||
print(out, err)
|
||||
self._private.Adapter1:RemoveDevice(device.object_path)
|
||||
end)
|
||||
end
|
||||
|
||||
function bluetooth:add_device(device, object_path)
|
||||
|
||||
local plist = self:get_children_by_id("connected_device_list")[1]
|
||||
local dlist = self:get_children_by_id("discovered_device_list")[1]
|
||||
|
||||
for _, value in pairs(dlist.children) do
|
||||
-- I'm not sure why Connected is in both cases true when its a new connection but eh just take it, it works
|
||||
if value.device.Address:match(device.Address) and (device.Connected ~= value.device.Connected) then
|
||||
print("Bad ", value.device.Alias)
|
||||
return
|
||||
elseif value.device.Address:match(device.Address) and (device.Connected == value.device.Connected) then
|
||||
print("Good ", value.device.Alias)
|
||||
dlist:remove_widgets(value)
|
||||
plist:add(plist:add(bt_device {
|
||||
device = device,
|
||||
path = object_path,
|
||||
remove_callback = function()
|
||||
self:remove_device_information(device)
|
||||
end,
|
||||
}))
|
||||
return;
|
||||
end
|
||||
end
|
||||
for _, value in pairs(plist.children) do
|
||||
if value.device.Address:match(device.Address) then return end
|
||||
end
|
||||
|
||||
if device.Paired then
|
||||
plist:add(bt_device {
|
||||
device = device,
|
||||
path = object_path,
|
||||
remove_callback = function()
|
||||
self:remove_device_information(device)
|
||||
end,
|
||||
})
|
||||
else
|
||||
dlist:add(bt_device {
|
||||
device = device,
|
||||
path = object_path,
|
||||
remove_callback = function()
|
||||
self:remove_device_information(device)
|
||||
end,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
function bluetooth:remove_device(object_path)
|
||||
local plist = self:get_children_by_id("connected_device_list")[1]
|
||||
local dlist = self:get_children_by_id("discovered_device_list")[1]
|
||||
for _, d in ipairs(dlist.children) do
|
||||
if d.device.object_path == object_path then
|
||||
dlist:remove_widgets(d)
|
||||
end
|
||||
end
|
||||
for _, d in ipairs(plist.children) do
|
||||
if d.device.object_path == object_path then
|
||||
plist:remove_widgets(d)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function bluetooth:update_device(new_device, object_path)
|
||||
for _, device in ipairs(self.devices.paired:get_children()) do
|
||||
if device.path == object_path then
|
||||
device.device:update(new_device)
|
||||
end
|
||||
end
|
||||
for _, device in ipairs(self.devices.discovered:get_children()) do
|
||||
if device.path == object_path then
|
||||
device.device:update(new_device)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function bluetooth:scan()
|
||||
self._private.Adapter1:StartDiscovery()
|
||||
end
|
||||
|
||||
function bluetooth:stop_scan()
|
||||
self._private.Adapter1:StopDiscovery()
|
||||
end
|
||||
|
||||
function bluetooth:toggle()
|
||||
local powered = self._private.Adapter1.Powered
|
||||
|
||||
self._private.Adapter1:Set("org.bluez.Adapter1", "Powered", lgi.GLib.Variant("b", not powered))
|
||||
self._private.Adapter1.Powered = {
|
||||
signature = "b",
|
||||
value = not powered
|
||||
}
|
||||
end
|
||||
|
||||
function bluetooth:open_settings()
|
||||
awful.spawn("blueman-manager")
|
||||
end
|
||||
|
||||
function bluetooth:get_device_info(object_path)
|
||||
if (not object_path) or (not object_path:match("/org/bluez/hci0/dev")) then return end
|
||||
|
||||
local Device1 = dbus_proxy.Proxy:new {
|
||||
bus = dbus_proxy.Bus.SYSTEM,
|
||||
name = "org.bluez",
|
||||
interface = "org.bluez.Device1",
|
||||
path = object_path
|
||||
}
|
||||
|
||||
local Device1Properties = dbus_proxy.Proxy:new {
|
||||
bus = dbus_proxy.Bus.SYSTEM,
|
||||
name = "org.bluez",
|
||||
interface = "org.freedesktop.DBus.Properties",
|
||||
path = object_path
|
||||
}
|
||||
|
||||
if (not Device1.Name) or (Device1.Name == "") then return end
|
||||
|
||||
local just_notified = false
|
||||
|
||||
local notify_timer = gtimer {
|
||||
timeout = 3,
|
||||
autostart = false,
|
||||
single_shot = true,
|
||||
callback = function()
|
||||
just_notified = false
|
||||
end
|
||||
}
|
||||
|
||||
Device1Properties:connect_signal(function(_, _, changed_props)
|
||||
if changed_props["Connected"] ~= nil then
|
||||
if not just_notified then
|
||||
naughty.notification({
|
||||
app_icon = icondir .. "bluetooth-on.svg",
|
||||
app_name = "Bluetooth",
|
||||
title = Device1.Name,
|
||||
icon = gcolor.recolor_image(icondir .. Device1.Icon .. ".svg", Theme_config.bluetooth_controller.icon_color),
|
||||
timeout = 5,
|
||||
message = "Device " ..
|
||||
Device1.Name .. " is now " .. (changed_props["Connected"] and "connected" or "disconnected"),
|
||||
category = Device1.Connected and "device.added" or "device.removed",
|
||||
})
|
||||
just_notified = true
|
||||
notify_timer:start()
|
||||
end
|
||||
end
|
||||
end
|
||||
if device.Paired then
|
||||
table.insert(self.devices.paired, bt_device.new { device = device, battery = battery }.widget)
|
||||
else
|
||||
table.insert(self.devices.discovered, bt_device.new { device = device, battery = battery }.widget)
|
||||
end
|
||||
capi.awesome.emit_signal(object_path .. "_updated", Device1)
|
||||
end, "PropertiesChanged")
|
||||
|
||||
self:add_device(Device1, object_path)
|
||||
end
|
||||
|
||||
local function remove_device(self, device)
|
||||
for i, dev in pairs(self.devices) do
|
||||
if dev.Address == device.Address then
|
||||
table.remove(self.devices, i)
|
||||
end
|
||||
end
|
||||
local function send_state_notification(powered)
|
||||
naughty.notification {
|
||||
app_icon = gcolor.recolor_image(icondir .. "bluetooth-on.svg", Theme_config.bluetooth_controller.icon_color),
|
||||
app_name = "Bluetooth",
|
||||
title = "Bluetooth",
|
||||
message = powered and "Enabled" or "Disabled",
|
||||
icon = gcolor.recolor_image(powered and icondir .. "bluetooth-on.svg" or icondir .. "bluetooth-off.svg",
|
||||
Theme_config.bluetooth_controller.icon_color),
|
||||
category = powered and "device.added" or "device.removed",
|
||||
}
|
||||
end
|
||||
|
||||
function bluetooth.new(args)
|
||||
args = args or {}
|
||||
|
||||
local ret = gobject { enable_properties = true, enable_auto_signals = true }
|
||||
gtable.crush(ret, bluetooth, true)
|
||||
|
||||
local bluetooth_container = wibox.widget {
|
||||
local ret = base.make_widget_from_value(wibox.widget {
|
||||
{
|
||||
{
|
||||
{
|
||||
@@ -198,29 +366,15 @@ function bluetooth.new(args)
|
||||
},
|
||||
{
|
||||
{ -- action buttons
|
||||
{ -- turn off
|
||||
{
|
||||
{
|
||||
image = gcolor.recolor_image(icondir .. "power.svg",
|
||||
Theme_config.bluetooth_controller.power_icon_color),
|
||||
resize = false,
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
widget = wibox.widget.imagebox,
|
||||
id = "icon"
|
||||
},
|
||||
widget = wibox.container.margin,
|
||||
margins = dpi(5),
|
||||
id = "center"
|
||||
{
|
||||
dnd_widget {
|
||||
color = Theme_config.bluetooth_controller.power_bg,
|
||||
size = dpi(40)
|
||||
},
|
||||
border_width = dpi(2),
|
||||
border_color = Theme_config.bluetooth_controller.border_color,
|
||||
shape = function(cr, width, height)
|
||||
gshape.rounded_rect(cr, width, height, dpi(4))
|
||||
end,
|
||||
bg = Theme_config.bluetooth_controller.power_bg,
|
||||
widget = wibox.container.background,
|
||||
id = "power",
|
||||
id = "dnd",
|
||||
widget = wibox.container.place,
|
||||
valign = "center",
|
||||
halign = "center"
|
||||
},
|
||||
nil,
|
||||
{ -- refresh
|
||||
@@ -236,16 +390,16 @@ function bluetooth.new(args)
|
||||
widget = wibox.container.margin,
|
||||
margins = dpi(5),
|
||||
},
|
||||
border_width = dpi(2),
|
||||
border_color = Theme_config.bluetooth_controller.border_color,
|
||||
shape = function(cr, width, height)
|
||||
gshape.rounded_rect(cr, width, height, dpi(4))
|
||||
end,
|
||||
bg = Theme_config.bluetooth_controller.refresh_bg,
|
||||
id = "scan",
|
||||
widget = wibox.container.background
|
||||
},
|
||||
layout = wibox.layout.align.horizontal
|
||||
},
|
||||
id = "marg_dnd",
|
||||
widget = wibox.container.margin,
|
||||
top = dpi(10),
|
||||
},
|
||||
@@ -266,28 +420,91 @@ function bluetooth.new(args)
|
||||
widget = wibox.container.background
|
||||
},
|
||||
width = dpi(400),
|
||||
forced_width = dpi(400),
|
||||
strategy = "exact",
|
||||
widget = wibox.container.constraint
|
||||
})
|
||||
|
||||
local dnd = ret:get_children_by_id("dnd")[1]:get_widget()
|
||||
|
||||
dnd:connect_signal("dnd::toggle", function(enable)
|
||||
ret:toggle()
|
||||
end)
|
||||
|
||||
gtable.crush(ret, bluetooth, true)
|
||||
|
||||
--#region Bluetooth Proxies
|
||||
-- Create a proxy for the freedesktop ObjectManager
|
||||
ret._private.ObjectManager = dbus_proxy.Proxy:new {
|
||||
bus = dbus_proxy.Bus.SYSTEM,
|
||||
name = "org.bluez",
|
||||
interface = "org.freedesktop.DBus.ObjectManager",
|
||||
path = "/"
|
||||
}
|
||||
|
||||
capi.awesome.connect_signal(
|
||||
"bluetooth::device_changed",
|
||||
function(device, battery)
|
||||
add_device(ret, device, battery)
|
||||
remove_device(ret, device)
|
||||
bluetooth_container:get_children_by_id("connected_device_list")[1].children = ret:get_devices().paired
|
||||
bluetooth_container:get_children_by_id("discovered_device_list")[1].children = ret:get_devices().discovered
|
||||
end
|
||||
)
|
||||
-- Create a proxy for the bluez Adapter1 interface
|
||||
ret._private.Adapter1 = dbus_proxy.Proxy:new {
|
||||
bus = dbus_proxy.Bus.SYSTEM,
|
||||
name = "org.bluez",
|
||||
interface = "org.bluez.Adapter1",
|
||||
path = "/org/bluez/hci0"
|
||||
}
|
||||
|
||||
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 = bluetooth_container:get_children_by_id("connected")[1].center
|
||||
-- Create a proxy for the bluez Adapter1 Properties interface
|
||||
ret._private.Adapter1Properties = dbus_proxy.Proxy:new {
|
||||
bus = dbus_proxy.Bus.SYSTEM,
|
||||
name = "org.bluez",
|
||||
interface = "org.freedesktop.DBus.Properties",
|
||||
path = "/org/bluez/hci0"
|
||||
}
|
||||
|
||||
-- Connect to the ObjectManager's InterfacesAdded signal
|
||||
ret._private.ObjectManager:connect_signal(function(_, interface)
|
||||
ret:get_device_info(interface)
|
||||
end, "InterfacesAdded")
|
||||
|
||||
-- Connect to the ObjectManager's InterfacesRemoved signal
|
||||
ret._private.ObjectManager:connect_signal(function(_, interface)
|
||||
ret:remove_device(interface)
|
||||
end, "InterfacesRemoved")
|
||||
|
||||
-- Connect to the Adapter1's PropertiesChanged signal
|
||||
ret._private.Adapter1Properties:connect_signal(function(_, _, data)
|
||||
if data.Powered ~= nil then
|
||||
send_state_notification(data.Powered)
|
||||
if data.Powered then
|
||||
dnd:set_enabled()
|
||||
ret:scan()
|
||||
else
|
||||
dnd:set_disabled()
|
||||
end
|
||||
ret:emit_signal("bluetooth::status", data.Powered)
|
||||
end
|
||||
end, "PropertiesChanged")
|
||||
|
||||
gtimer.delayed_call(function()
|
||||
for path, _ in pairs(ret._private.ObjectManager:GetManagedObjects()) do
|
||||
ret:get_device_info(path)
|
||||
end
|
||||
if ret._private.Adapter1.Powered then
|
||||
dnd:set_enabled()
|
||||
ret:scan()
|
||||
else
|
||||
dnd:set_disabled()
|
||||
end
|
||||
ret:emit_signal("bluetooth::status", ret._private.Adapter1.Powered)
|
||||
send_state_notification(ret._private.Adapter1.Powered)
|
||||
end)
|
||||
--#endregion
|
||||
|
||||
--#region Dropdown logic
|
||||
local connected_margin = ret:get_children_by_id("connected_margin")[1]
|
||||
local connected_list = ret:get_children_by_id("connected_list")[1]
|
||||
local connected = ret:get_children_by_id("connected")[1].center
|
||||
|
||||
connected_margin:connect_signal(
|
||||
"button::press",
|
||||
function()
|
||||
capi.awesome.emit_signal("bluetooth::scan")
|
||||
local rubato_timer = rubato.timed {
|
||||
duration = 0.2,
|
||||
pos = connected_list.forced_height,
|
||||
@@ -297,7 +514,7 @@ function bluetooth.new(args)
|
||||
end
|
||||
}
|
||||
if connected_list.forced_height == 0 then
|
||||
local size = (#ret:get_devices().paired * 60) + 1
|
||||
local size = (#ret:get_paired_devices() * 60) + 1
|
||||
if size < 210 then
|
||||
rubato_timer.target = dpi(size)
|
||||
end
|
||||
@@ -317,16 +534,14 @@ function bluetooth.new(args)
|
||||
end
|
||||
)
|
||||
|
||||
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
|
||||
local discovered_margin = ret:get_children_by_id("discovered_margin")[1]
|
||||
local discovered_list = ret:get_children_by_id("discovered_list")[1]
|
||||
local discovered_bg = ret:get_children_by_id("discovered_bg")[1]
|
||||
local discovered = ret:get_children_by_id("discovered")[1].center
|
||||
|
||||
discovered_margin:connect_signal(
|
||||
"button::press",
|
||||
function()
|
||||
capi.awesome.emit_signal("bluetooth::scan")
|
||||
|
||||
local rubato_timer = rubato.timed {
|
||||
duration = 0.2,
|
||||
pos = discovered_list.forced_height,
|
||||
@@ -337,7 +552,7 @@ function bluetooth.new(args)
|
||||
}
|
||||
|
||||
if discovered_list.forced_height == 0 then
|
||||
local size = (#ret:get_devices().discovered * 60) + 1
|
||||
local size = (#ret:get_discovered_devices() * 60) + 1
|
||||
if size > 210 then
|
||||
size = 210
|
||||
end
|
||||
@@ -357,52 +572,17 @@ function bluetooth.new(args)
|
||||
end
|
||||
end
|
||||
)
|
||||
--#endregion
|
||||
|
||||
ret.widget = awful.popup {
|
||||
widget = bluetooth_container,
|
||||
ontop = true,
|
||||
bg = Theme_config.bluetooth_controller.container_bg,
|
||||
stretch = false,
|
||||
visible = false,
|
||||
screen = args.screen,
|
||||
placement = function(c) awful.placement.align(c,
|
||||
{ position = "top_right", margins = { right = dpi(360), top = dpi(60) } })
|
||||
end,
|
||||
shape = function(cr, width, height)
|
||||
gshape.rounded_rect(cr, width, height, dpi(12))
|
||||
end
|
||||
}
|
||||
ret:get_children_by_id("scan")[1]:buttons({
|
||||
awful.button({}, 1, function()
|
||||
ret:scan()
|
||||
end)
|
||||
})
|
||||
|
||||
awesome.connect_signal(
|
||||
"bluetooth_controller::toggle",
|
||||
function()
|
||||
if ret.widget.screen == capi.mouse.screen then
|
||||
ret.widget.visible = not ret.widget.visible
|
||||
end
|
||||
end
|
||||
)
|
||||
Hover_signal(ret:get_children_by_id("scan")[1])
|
||||
|
||||
|
||||
ret.widget:connect_signal(
|
||||
"mouse::leave",
|
||||
function()
|
||||
capi.mousegrabber.run(
|
||||
function()
|
||||
capi.awesome.emit_signal("bluetooth_controller::toggle", args.screen)
|
||||
capi.mousegrabber.stop()
|
||||
return true
|
||||
end,
|
||||
"arrow"
|
||||
)
|
||||
end
|
||||
)
|
||||
|
||||
ret.widget:connect_signal(
|
||||
"mouse::enter",
|
||||
function()
|
||||
capi.mousegrabber.stop()
|
||||
end
|
||||
)
|
||||
return ret
|
||||
end
|
||||
|
||||
function bluetooth.mt:__call(...)
|
||||
|
||||
@@ -1,513 +0,0 @@
|
||||
--------------------------------------
|
||||
-- This is the bluetooth controller --
|
||||
--------------------------------------
|
||||
|
||||
-- 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 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", Theme_config.bluetooth_controller.icon_color),
|
||||
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_config.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 = Theme_config.bluetooth_controller.con_button_color,
|
||||
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 = Theme_config.bluetooth_controller.device_bg,
|
||||
fg = Theme_config.bluetooth_controller.device_fg,
|
||||
border_color = Theme_config.bluetooth_controller.device_border_color,
|
||||
border_width = Theme_config.bluetooth_controller.device_border_width,
|
||||
id = "background",
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(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",
|
||||
Theme_config.bluetooth_controller.icon_color_dark)
|
||||
device_widget:connect_signal(
|
||||
"button::press",
|
||||
function(_, _, _, 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",
|
||||
Theme_config.bluetooth_controller.icon_color_dark)
|
||||
device_widget:connect_signal(
|
||||
"button::press",
|
||||
function(_, _, _, key)
|
||||
if key == 1 then
|
||||
device:Connect()
|
||||
awesome.emit_signal("bluetooth::disconnect", device)
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
Hover_signal(device_widget)
|
||||
return device_widget
|
||||
end
|
||||
|
||||
local connected_devices_list = wibox.widget {
|
||||
{
|
||||
{
|
||||
{
|
||||
step = dpi(50),
|
||||
spacing = dpi(10),
|
||||
layout = require("src.lib.overflow_widget.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 = Theme_config.bluetooth_controller.con_device_border_color,
|
||||
border_width = Theme_config.bluetooth_controller.con_device_border_width,
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.partially_rounded_rect(cr, width, height, false, false, true, true, dpi(4))
|
||||
end,
|
||||
widget = wibox.container.background
|
||||
}
|
||||
|
||||
local discovered_devices_list = wibox.widget {
|
||||
{
|
||||
{
|
||||
{
|
||||
spacing = dpi(10),
|
||||
step = dpi(50),
|
||||
layout = require("src.lib.overflow_widget.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 = Theme_config.bluetooth_controller.con_device_border_color,
|
||||
border_width = Theme_config.bluetooth_controller.con_device_border_width,
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.partially_rounded_rect(cr, width, height, false, false, true, true, dpi(4))
|
||||
end,
|
||||
widget = wibox.container.background
|
||||
}
|
||||
|
||||
local bluetooth_container = wibox.widget {
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
resize = false,
|
||||
image = gears.color.recolor_image(icondir .. "menu-down.svg",
|
||||
Theme_config.bluetooth_controller.connected_icon_color),
|
||||
widget = wibox.widget.imagebox,
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
id = "icon"
|
||||
},
|
||||
id = "center",
|
||||
halign = "center",
|
||||
valign = "center",
|
||||
widget = wibox.container.place,
|
||||
},
|
||||
{
|
||||
{
|
||||
text = "Paired 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 = Theme_config.bluetooth_controller.connected_bg,
|
||||
fg = Theme_config.bluetooth_controller.connected_fg,
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(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",
|
||||
Theme_config.bluetooth_controller.discovered_icon_color),
|
||||
widget = wibox.widget.imagebox,
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
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 = Theme_config.bluetooth_controller.discovered_bg,
|
||||
fg = Theme_config.bluetooth_controller.discovered_fg,
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(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 = Theme_config.bluetooth_controller.container_border_color,
|
||||
border_width = Theme_config.bluetooth_controller.container_border_width,
|
||||
bg = Theme_config.bluetooth_controller.container_bg,
|
||||
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 = Theme_config.bluetooth_controller.container_bg,
|
||||
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, dpi(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, dpi(4))
|
||||
end
|
||||
connected.icon:set_image(gears.color.recolor_image(icondir .. "menu-up.svg",
|
||||
Theme_config.bluetooth_controller.connected_icon_color))
|
||||
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",
|
||||
Theme_config.bluetooth_controller.connected_icon_color))
|
||||
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, dpi(4))
|
||||
end
|
||||
discovered.icon:set_image(gears.color.recolor_image(icondir .. "menu-up.svg",
|
||||
Theme_config.bluetooth_controller.discovered_icon_color))
|
||||
else
|
||||
rubato_timer.target = 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",
|
||||
Theme_config.bluetooth_controller.discovered_icon_color))
|
||||
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
|
||||
@@ -1,134 +0,0 @@
|
||||
---------------------------------------
|
||||
-- This is the brightness_osd module --
|
||||
---------------------------------------
|
||||
|
||||
-- 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/brightness/"
|
||||
|
||||
return function(s)
|
||||
|
||||
local brightness_osd_widget = wibox.widget {
|
||||
{
|
||||
{
|
||||
{ -- Brightness Icon
|
||||
image = gears.color.recolor_image(icondir .. "brightness-high.svg", Theme_config.brightness_osd.icon_color),
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
resize = false,
|
||||
id = "icon",
|
||||
widget = wibox.widget.imagebox
|
||||
},
|
||||
{ -- Brightness Bar
|
||||
{
|
||||
{
|
||||
id = "progressbar1",
|
||||
color = Theme_config.brightness_osd.bar_bg_active,
|
||||
background_color = Theme_config.brightness_osd.bar_bg,
|
||||
max_value = 100,
|
||||
value = 0,
|
||||
forced_height = dpi(6),
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.rounded_bar(cr, width, height, dpi(6))
|
||||
end,
|
||||
widget = wibox.widget.progressbar
|
||||
},
|
||||
id = "progressbar_container2",
|
||||
halign = "center",
|
||||
valign = "center",
|
||||
widget = wibox.container.place
|
||||
},
|
||||
id = "progressbar_container",
|
||||
width = dpi(240),
|
||||
heigth = dpi(20),
|
||||
stragety = "max",
|
||||
widget = wibox.container.constraint
|
||||
},
|
||||
id = "layout1",
|
||||
spacing = dpi(10),
|
||||
layout = wibox.layout.fixed.horizontal
|
||||
},
|
||||
id = "margin",
|
||||
margins = dpi(10),
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
forced_width = dpi(300),
|
||||
forced_height = dpi(80),
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(12))
|
||||
end,
|
||||
border_color = Theme_config.brightness_osd.border_color,
|
||||
border_width = Theme_config.brightness_osd.border_width,
|
||||
fg = Theme_config.brightness_osd.fg,
|
||||
bg = Theme_config.brightness_osd.bg,
|
||||
widget = wibox.container.background
|
||||
}
|
||||
|
||||
capi.awesome.connect_signal(
|
||||
"brightness::get",
|
||||
function(brightness)
|
||||
print(brightness)
|
||||
brightness_osd_widget:get_children_by_id("progressbar1")[1].value = 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
|
||||
brightness_osd_widget:get_children_by_id("icon")[1]:set_image(gears.color.recolor_image(icon .. ".svg",
|
||||
Theme_config.brightness_osd.icon_color))
|
||||
end
|
||||
)
|
||||
|
||||
local brightness_container = awful.popup {
|
||||
widget = {},
|
||||
ontop = true,
|
||||
stretch = false,
|
||||
visible = false,
|
||||
screen = s,
|
||||
placement = function(c) awful.placement.bottom_left(c, { margins = dpi(20) }) end,
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(14))
|
||||
end
|
||||
}
|
||||
|
||||
local hide_brightness_osd = gears.timer {
|
||||
timeout = 2,
|
||||
autostart = true,
|
||||
callback = function()
|
||||
brightness_container.visible = false
|
||||
end
|
||||
}
|
||||
|
||||
brightness_container:setup {
|
||||
brightness_osd_widget,
|
||||
layout = wibox.layout.fixed.horizontal
|
||||
}
|
||||
|
||||
capi.awesome.connect_signal(
|
||||
"brightness::rerun",
|
||||
function()
|
||||
if capi.mouse.screen == s then
|
||||
brightness_container.visible = true
|
||||
if hide_brightness_osd.started then
|
||||
hide_brightness_osd:again()
|
||||
else
|
||||
hide_brightness_osd:start()
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
@@ -1,117 +0,0 @@
|
||||
---------------------------------------
|
||||
-- This is the brightness_osd module --
|
||||
---------------------------------------
|
||||
|
||||
-- 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,
|
||||
}
|
||||
|
||||
return function(args)
|
||||
if not args then
|
||||
return
|
||||
end
|
||||
|
||||
local function get_entries()
|
||||
|
||||
local menu_entries = { layout = wibox.layout.fixed.vertical, spacing = dpi(10) }
|
||||
|
||||
if args.entries then
|
||||
for _, entry in ipairs(args.entries) do
|
||||
local menu_entry = wibox.widget {
|
||||
{
|
||||
{
|
||||
{
|
||||
{ -- Icon
|
||||
widget = wibox.widget.imagebox,
|
||||
image = gears.color.recolor_image(entry.icon, Theme_config.context_menu.entry.icon_color),
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
resize = true,
|
||||
icon = entry.icon,
|
||||
id = "icon"
|
||||
},
|
||||
widget = wibox.container.constraint,
|
||||
stragety = "exact",
|
||||
width = dpi(24),
|
||||
height = dpi(24),
|
||||
id = "const"
|
||||
},
|
||||
{ -- Text
|
||||
widget = wibox.widget.textbox,
|
||||
text = entry.name,
|
||||
id = "name"
|
||||
},
|
||||
id = "lay",
|
||||
spacing = dpi(5),
|
||||
layout = wibox.layout.fixed.horizontal
|
||||
},
|
||||
margins = dpi(10),
|
||||
widget = wibox.container.margin,
|
||||
id = "mar"
|
||||
},
|
||||
bg = Theme_config.context_menu.entry.bg,
|
||||
fg = Theme_config.context_menu.entry.fg,
|
||||
shape = Theme_config.context_menu.entry.shape,
|
||||
border_width = Theme_config.context_menu.entry.border_width,
|
||||
border_color = Theme_config.context_menu.entry.border_color,
|
||||
widget = wibox.container.background,
|
||||
id = "menu_entry"
|
||||
}
|
||||
|
||||
menu_entry:buttons(gears.table.join(
|
||||
awful.button({
|
||||
modifiers = {},
|
||||
button = 1,
|
||||
on_release = function()
|
||||
capi.awesome.emit_signal("context_menu::hide")
|
||||
entry.callback()
|
||||
end
|
||||
})
|
||||
))
|
||||
|
||||
Hover_signal(menu_entry, nil, Theme_config.context_menu.entry.hover_fg,
|
||||
Theme_config.context_menu.entry.hover_border, Theme_config.context_menu.entry.icon_color,
|
||||
Theme_config.context_menu.entry.icon_color_hover)
|
||||
table.insert(menu_entries, menu_entry)
|
||||
end
|
||||
end
|
||||
return menu_entries
|
||||
end
|
||||
|
||||
local menu = awful.popup {
|
||||
widget = {
|
||||
get_entries(),
|
||||
margins = dpi(10),
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
bg = Theme_config.context_menu.bg,
|
||||
fg = Theme_config.context_menu.fg,
|
||||
border_width = Theme_config.context_menu.border_width,
|
||||
border_color = Theme_config.context_menu.border_color,
|
||||
shape = Theme_config.context_menu.shape,
|
||||
x = capi.mouse.coords().x,
|
||||
y = capi.mouse.coords().y,
|
||||
visible = false,
|
||||
ontop = true,
|
||||
placement = awful.placement.no_offscreen,
|
||||
}
|
||||
|
||||
menu:connect_signal("mouse::leave", function()
|
||||
capi.awesome.emit_signal("context_menu::hide")
|
||||
end)
|
||||
|
||||
capi.awesome.connect_signal(
|
||||
"context_menu::hide",
|
||||
function()
|
||||
menu.visible = false
|
||||
end
|
||||
)
|
||||
return menu
|
||||
end
|
||||
@@ -52,7 +52,7 @@ function context_menu:make_entries(wtemplate, entries, spacing)
|
||||
return
|
||||
end
|
||||
|
||||
for _, entry in ipairs(entries) do
|
||||
for key, entry in pairs(entries) do
|
||||
-- TODO: Figure out how to make a new widget from etemplate
|
||||
local menu_entry = wibox.widget {
|
||||
{
|
||||
@@ -124,7 +124,8 @@ function context_menu:make_entries(wtemplate, entries, spacing)
|
||||
if not entry.submenu then
|
||||
entry.callback()
|
||||
end
|
||||
self.visible = false
|
||||
capi.awesome.emit_signal("submenu::close")
|
||||
capi.awesome.emit_signal("cm::hide")
|
||||
end
|
||||
})
|
||||
})
|
||||
@@ -169,10 +170,8 @@ function context_menu:make_entries(wtemplate, entries, spacing)
|
||||
menu_entry.popup.visible = false
|
||||
end)
|
||||
end
|
||||
|
||||
table.insert(menu_entries, menu_entry)
|
||||
menu_entries[key] = menu_entry
|
||||
end
|
||||
|
||||
return menu_entries
|
||||
end
|
||||
|
||||
@@ -182,6 +181,8 @@ function context_menu:toggle()
|
||||
self.visible = not self.visible
|
||||
end
|
||||
|
||||
-- This is terribly done but I don't know how to do it better since
|
||||
-- the awful.popup.widget needs to know itself which I don't think is possible
|
||||
function context_menu.new(args)
|
||||
args = args or {}
|
||||
|
||||
@@ -202,6 +203,11 @@ function context_menu.new(args)
|
||||
y = capi.mouse.coords().y - 10
|
||||
}
|
||||
|
||||
-- I literally have no clue how to do it better, it doesn't really matter anyways
|
||||
capi.awesome.connect_signal("cm::hide", function()
|
||||
ret.visible = false
|
||||
end)
|
||||
|
||||
gtable.crush(ret, context_menu, true)
|
||||
|
||||
return ret
|
||||
|
||||
@@ -62,10 +62,7 @@ return function(s, widgets)
|
||||
bg = Theme_config.center_bar.bg,
|
||||
visible = true,
|
||||
maximum_width = dpi(500),
|
||||
placement = function(c) awful.placement.top(c, { margins = dpi(10) }) end,
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(6))
|
||||
end
|
||||
placement = function(c) awful.placement.top(c, { margins = dpi(10) }) end
|
||||
}
|
||||
|
||||
top_center:struts {
|
||||
|
||||
@@ -257,10 +257,7 @@ return function(screen)
|
||||
screen = screen,
|
||||
type = "dock",
|
||||
height = dpi(User_config.dock_icon_size + 10),
|
||||
placement = function(c) awful.placement.bottom(c, { margins = dpi(10) }) end,
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(16))
|
||||
end
|
||||
placement = function(c) awful.placement.bottom(c, { margins = dpi(10) }) end
|
||||
}
|
||||
|
||||
--- A fakedock to send a signal when the mouse is over it
|
||||
|
||||
@@ -57,10 +57,7 @@ return function(s, w)
|
||||
bg = Theme_config.left_bar.bg,
|
||||
visible = true,
|
||||
maximum_width = dpi(650),
|
||||
placement = function(c) awful.placement.top_left(c, { margins = dpi(10) }) end,
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(6))
|
||||
end
|
||||
placement = function(c) awful.placement.top_left(c, { margins = dpi(10) }) end
|
||||
}
|
||||
|
||||
top_left:struts {
|
||||
|
||||
@@ -56,10 +56,7 @@ return function(s, w)
|
||||
bg = Theme_config.right_bar.bg,
|
||||
visible = true,
|
||||
screen = s,
|
||||
placement = function(c) awful.placement.top_right(c, { margins = dpi(10) }) end,
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(6))
|
||||
end
|
||||
placement = function(c) awful.placement.top_right(c, { margins = dpi(10) }) end
|
||||
}
|
||||
|
||||
top_right:struts {
|
||||
|
||||
@@ -31,8 +31,6 @@ function context_menu.new(args)
|
||||
local ret = gobject {}
|
||||
gtable.crush(ret, context_menu, true)
|
||||
|
||||
|
||||
|
||||
capi.awesome.connect_signal("context_menu:show", function()
|
||||
ret:toggle()
|
||||
mousegrabber.run(function()
|
||||
@@ -44,7 +42,7 @@ function context_menu.new(args)
|
||||
end, nil)
|
||||
end)
|
||||
|
||||
return w
|
||||
return ret
|
||||
end
|
||||
|
||||
function context_menu.mt:__call(...)
|
||||
|
||||
@@ -17,13 +17,11 @@ awful.screen.connect_for_each_screen(
|
||||
User_config.layouts[1]
|
||||
)
|
||||
|
||||
require("src.modules.desktop.context_menu") { screen = s }
|
||||
require("src.modules.desktop.desktop") { screen = s }
|
||||
require("src.modules.powermenu.powermenu")(s)
|
||||
require("src.modules.audio.volume_osd") { screen = s }
|
||||
--require("src.modules.audio.volume_controller") { screen = s }
|
||||
require("src.modules.brightness.brightness_osd")(s)
|
||||
require("src.modules.bluetooth.init") { screen = s }
|
||||
require("src.modules.titlebar.titlebar")
|
||||
require("src.modules.crylia_bar.init")(s)
|
||||
--require("src.modules.crylia_wibox.init")(s)
|
||||
|
||||
@@ -10,6 +10,8 @@ local gfilesystem = require("gears").filesystem
|
||||
local gobject = require("gears").object
|
||||
local gcolor = require("gears").color
|
||||
local wibox = require("wibox")
|
||||
local base = require("wibox.widget.base")
|
||||
local NM = require("lgi").NM
|
||||
|
||||
local ap_form = require("src.modules.network_controller.ap_form")
|
||||
|
||||
@@ -17,39 +19,28 @@ local icondir = gfilesystem.get_configuration_dir() .. "src/assets/icons/network
|
||||
|
||||
local access_point = { mt = {} }
|
||||
|
||||
access_point.connected = false
|
||||
|
||||
function access_point.new(args)
|
||||
args = args or {}
|
||||
|
||||
if not args.access_point then return end
|
||||
|
||||
local ret = gobject { enable_properties = true, enable_auto_signals = true }
|
||||
gtable.crush(ret, access_point, true)
|
||||
|
||||
local strength = args.access_point.strength or 0
|
||||
|
||||
--normalize strength between 1 and 4
|
||||
strength = math.floor(strength / 25) + 1
|
||||
|
||||
local icon = "wifi-strength-" .. strength .. ".svg"
|
||||
if not args.NetworkManagerAccessPoint then return end
|
||||
|
||||
local bg, fg, icon_color = Theme_config.network_manager.access_point.bg, Theme_config.network_manager.access_point.fg,
|
||||
Theme_config.network_manager.access_point.icon_color
|
||||
|
||||
if args.active == args.access_point.access_point_path then
|
||||
--[[ if get_active_access_point() == args.NetworkManagerAccessPoint.access_point_path then
|
||||
bg, fg, icon_color = Theme_config.network_manager.access_point.fg, Theme_config.network_manager.access_point.bg,
|
||||
Theme_config.network_manager.access_point.icon_color2
|
||||
end
|
||||
end ]]
|
||||
|
||||
local ap_widget = wibox.widget {
|
||||
local ret = base.make_widget_from_value(wibox.widget {
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
image = gcolor.recolor_image(
|
||||
icondir .. icon, icon_color),
|
||||
icondir .. "wifi-strength-" .. math.floor(args.NetworkManagerAccessPoint.Strength / 25) + 1 .. ".svg",
|
||||
icon_color),
|
||||
id = "icon",
|
||||
resize = true,
|
||||
valign = "center",
|
||||
@@ -67,7 +58,8 @@ function access_point.new(args)
|
||||
{
|
||||
{
|
||||
{
|
||||
text = args.access_point.ssid or args.access_point.hw_address or "Unknown",
|
||||
text = NM.utils_ssid_to_utf8(args.NetworkManagerAccessPoint.Ssid) or
|
||||
args.NetworkManagerAccessPoint.hw_address or "Unknown",
|
||||
id = "alias",
|
||||
widget = wibox.widget.textbox
|
||||
},
|
||||
@@ -132,31 +124,32 @@ function access_point.new(args)
|
||||
border_width = Theme_config.network_manager.access_point.border_width,
|
||||
id = "background",
|
||||
shape = Theme_config.network_manager.access_point.device_shape,
|
||||
device = ret.access_point,
|
||||
widget = wibox.container.background
|
||||
}
|
||||
})
|
||||
|
||||
ap_form { screen = args.screen, SSID = args.access_point.ssid }
|
||||
gtable.crush(ret, access_point, true)
|
||||
|
||||
ap_widget:buttons(
|
||||
ret.NetworkManagerAccessPoint = args.NetworkManagerAccessPoint
|
||||
|
||||
ret.ap_form = ap_form { screen = args.screen, ssid = NM.utils_ssid_to_utf8(ret.NetworkManagerAccessPoint.Ssid) }
|
||||
|
||||
ret:buttons(
|
||||
gtable.join(
|
||||
awful.button(
|
||||
{},
|
||||
1,
|
||||
nil,
|
||||
function()
|
||||
ap_form:popup_toggle()
|
||||
ret.ap_form:popup_toggle()
|
||||
end
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
ap_widget:get_children_by_id("con")[1].image = gcolor.recolor_image(
|
||||
ret:get_children_by_id("con")[1].image = gcolor.recolor_image(
|
||||
icondir .. "link.svg", icon_color)
|
||||
|
||||
Hover_signal(ap_widget)
|
||||
|
||||
ret.widget = ap_widget
|
||||
Hover_signal(ret)
|
||||
|
||||
return ret
|
||||
end
|
||||
|
||||
@@ -15,202 +15,171 @@ local capi = {
|
||||
}
|
||||
|
||||
local ap_form = { mt = {} }
|
||||
ap_form._private = {}
|
||||
|
||||
ap_form.settigns_form = {
|
||||
ssid = awful.widget.inputbox {
|
||||
widget_template = wibox.template {
|
||||
widget = wibox.widget {
|
||||
{
|
||||
{
|
||||
{
|
||||
widget = wibox.widget.textbox,
|
||||
halign = "left",
|
||||
valign = "center",
|
||||
id = "text_role",
|
||||
},
|
||||
widget = wibox.container.margin,
|
||||
margins = 5,
|
||||
id = "marg"
|
||||
},
|
||||
widget = wibox.container.constraint,
|
||||
strategy = "exact",
|
||||
width = 400,
|
||||
height = 50,
|
||||
id = "const"
|
||||
},
|
||||
widget = wibox.container.background,
|
||||
bg = "#212121",
|
||||
fg = "#F0F0F0",
|
||||
border_color = "#414141",
|
||||
border_width = 2,
|
||||
shape = gshape.rounded_rect,
|
||||
forced_width = 300,
|
||||
forced_height = 50,
|
||||
},
|
||||
update_callback = function(template_widget, args)
|
||||
template_widget.widget.const.marg.text_role.markup = args.text
|
||||
end
|
||||
}
|
||||
},
|
||||
password = awful.widget.inputbox {
|
||||
widget_template = wibox.template {
|
||||
widget = wibox.widget {
|
||||
{
|
||||
{
|
||||
{
|
||||
widget = wibox.widget.textbox,
|
||||
halign = "left",
|
||||
valign = "center",
|
||||
id = "text_role",
|
||||
},
|
||||
widget = wibox.container.margin,
|
||||
margins = 5,
|
||||
id = "marg"
|
||||
},
|
||||
widget = wibox.container.constraint,
|
||||
strategy = "exact",
|
||||
width = 400,
|
||||
height = 50,
|
||||
id = "const"
|
||||
},
|
||||
widget = wibox.container.background,
|
||||
bg = "#212121",
|
||||
fg = "#F0F0F0",
|
||||
border_color = "#414141",
|
||||
border_width = 2,
|
||||
shape = gshape.rounded_rect,
|
||||
forced_width = 300,
|
||||
forced_height = 50,
|
||||
},
|
||||
update_callback = function(template_widget, args)
|
||||
template_widget.widget.const.marg.text_role.markup = args.text
|
||||
end
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
function ap_form:popup_toggle()
|
||||
self._private.popup.visible = not self._private.popup.visible
|
||||
self.visible = not self.visible
|
||||
end
|
||||
|
||||
function ap_form.new(args)
|
||||
args = args or {}
|
||||
args.screen = args.screen or awful.screen.preferred()
|
||||
local ret = gobject {}
|
||||
ret._private = {}
|
||||
gtable.crush(ret, ap_form, true)
|
||||
|
||||
gtable.crush(ret, args)
|
||||
|
||||
ret._private.popup = awful.popup {
|
||||
widget = {
|
||||
{ -- Header
|
||||
{
|
||||
nil,
|
||||
local settigns_form = {
|
||||
password = awful.widget.inputbox {
|
||||
widget_template = wibox.template {
|
||||
widget = wibox.widget {
|
||||
{
|
||||
{
|
||||
widget = wibox.widget.textbox,
|
||||
text = args.SSID,
|
||||
halign = "center",
|
||||
valign = "center",
|
||||
},
|
||||
widget = wibox.container.margin,
|
||||
margins = dpi(5)
|
||||
},
|
||||
{ -- Close button
|
||||
{
|
||||
{
|
||||
widget = wibox.widget.imagebox,
|
||||
image = gcolor.recolor_image(icondir .. "close.svg", Theme_config.network_manager.form.icon_fg),
|
||||
resize = false,
|
||||
widget = wibox.widget.textbox,
|
||||
halign = "left",
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
id = "text_role",
|
||||
},
|
||||
widget = wibox.container.margin,
|
||||
margins = 5,
|
||||
id = "marg"
|
||||
},
|
||||
widget = wibox.container.background,
|
||||
id = "close_button",
|
||||
bg = Theme_config.network_manager.form.close_bg
|
||||
widget = wibox.container.constraint,
|
||||
strategy = "exact",
|
||||
width = 400,
|
||||
height = 50,
|
||||
id = "const"
|
||||
},
|
||||
layout = wibox.layout.align.horizontal
|
||||
widget = wibox.container.background,
|
||||
bg = "#212121",
|
||||
fg = "#F0F0F0",
|
||||
border_color = "#414141",
|
||||
border_width = 2,
|
||||
shape = gshape.rounded_rect,
|
||||
forced_width = 300,
|
||||
forced_height = 50,
|
||||
},
|
||||
widget = wibox.container.background,
|
||||
bg = Theme_config.network_manager.form.header_bg,
|
||||
fg = Theme_config.network_manager.form.header_fg,
|
||||
},
|
||||
{ -- Form
|
||||
{ -- SSID
|
||||
update_callback = function(template_widget, args)
|
||||
template_widget.widget.const.marg.text_role.markup = args.text
|
||||
end
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
local ret = awful.popup {
|
||||
widget = {
|
||||
{
|
||||
{ -- Header
|
||||
{
|
||||
widget = wibox.widget.textbox,
|
||||
text = "SSID",
|
||||
halign = "center",
|
||||
valign = "center"
|
||||
nil,
|
||||
{
|
||||
{
|
||||
widget = wibox.widget.textbox,
|
||||
text = args.ssid,
|
||||
font = User_config.font.specify .. ",extra bold 16",
|
||||
halign = "center",
|
||||
valign = "center",
|
||||
},
|
||||
widget = wibox.container.margin,
|
||||
margins = dpi(5)
|
||||
},
|
||||
{ -- Close button
|
||||
{
|
||||
{
|
||||
widget = wibox.widget.imagebox,
|
||||
image = gcolor.recolor_image(icondir .. "close.svg", Theme_config.network_manager.form.icon_fg),
|
||||
resize = false,
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
},
|
||||
widget = wibox.container.margin,
|
||||
margins = dpi(5),
|
||||
},
|
||||
widget = wibox.container.background,
|
||||
shape = Theme_config.network_manager.form.close_icon_shape,
|
||||
id = "close_button",
|
||||
bg = Theme_config.network_manager.form.close_bg
|
||||
},
|
||||
layout = wibox.layout.align.horizontal
|
||||
},
|
||||
nil,
|
||||
-- Change to inputtextbox container
|
||||
ret.settigns_form.ssid,
|
||||
layout = wibox.layout.align.horizontal
|
||||
widget = wibox.container.background,
|
||||
bg = Theme_config.network_manager.form.header_bg,
|
||||
fg = Theme_config.network_manager.form.header_fg,
|
||||
},
|
||||
{ -- Password
|
||||
{
|
||||
{ -- Form
|
||||
{ -- Password
|
||||
widget = wibox.widget.textbox,
|
||||
text = "Password",
|
||||
halign = "center",
|
||||
valign = "center"
|
||||
},
|
||||
nil,
|
||||
{
|
||||
widget = wibox.container.margin,
|
||||
left = dpi(20),
|
||||
right = dpi(20),
|
||||
},
|
||||
-- Change to inputtextbox container
|
||||
ret.settigns_form.password,
|
||||
settigns_form.password,
|
||||
layout = wibox.layout.align.horizontal
|
||||
},
|
||||
spacing = dpi(10),
|
||||
layout = wibox.layout.fixed.vertical
|
||||
},
|
||||
{ -- Actions
|
||||
{ -- Auto connect
|
||||
{
|
||||
{ -- Actions
|
||||
{ -- Auto connect
|
||||
{
|
||||
checked = false,
|
||||
shape = Theme_config.network_manager.form.checkbox_shape,
|
||||
color = Theme_config.network_manager.form.checkbox_bg,
|
||||
check_color = Theme_config.network_manager.form.checkbox_fg,
|
||||
check_border_color = Theme_config.network_manager.form.check_border_color,
|
||||
check_border_width = Theme_config.network_manager.form.check_border_width,
|
||||
widget = wibox.widget.checkbox
|
||||
},
|
||||
widget = wibox.container.constraint,
|
||||
strategy = "exact",
|
||||
width = dpi(30),
|
||||
height = dpi(30)
|
||||
},
|
||||
{
|
||||
widget = wibox.widget.textbox,
|
||||
text = "Auto connect",
|
||||
halign = "center",
|
||||
valign = "center"
|
||||
},
|
||||
layout = wibox.layout.fixed.horizontal
|
||||
},
|
||||
nil,
|
||||
{ -- Connect
|
||||
{
|
||||
{
|
||||
widget = wibox.widget.textbox,
|
||||
text = "Connect",
|
||||
{
|
||||
{
|
||||
checked = false,
|
||||
shape = Theme_config.network_manager.form.checkbox_shape,
|
||||
color = Theme_config.network_manager.form.checkbox_fg,
|
||||
paddings = dpi(3),
|
||||
check_color = Theme_config.network_manager.form.checkbox_bg,
|
||||
border_color = Theme_config.network_manager.form.checkbox_bg,
|
||||
border_width = 2,
|
||||
id = "checkbox",
|
||||
widget = wibox.widget.checkbox
|
||||
},
|
||||
widget = wibox.container.constraint,
|
||||
strategy = "exact",
|
||||
width = dpi(30),
|
||||
height = dpi(30)
|
||||
},
|
||||
widget = wibox.container.place,
|
||||
halign = "center",
|
||||
valign = "center"
|
||||
},
|
||||
widget = wibox.container.background,
|
||||
bg = Theme_config.network_manager.form.button_bg,
|
||||
fg = Theme_config.network_manager.form.button_fg,
|
||||
{
|
||||
widget = wibox.widget.textbox,
|
||||
text = "Auto connect",
|
||||
halign = "center",
|
||||
valign = "center"
|
||||
},
|
||||
spacing = dpi(10),
|
||||
layout = wibox.layout.fixed.horizontal
|
||||
},
|
||||
widget = wibox.container.margin,
|
||||
margins = dpi(10),
|
||||
nil,
|
||||
{ -- Connect
|
||||
{
|
||||
{
|
||||
{
|
||||
widget = wibox.widget.textbox,
|
||||
text = "Connect",
|
||||
halign = "center",
|
||||
valign = "center"
|
||||
},
|
||||
widget = wibox.container.margin,
|
||||
margins = dpi(10),
|
||||
},
|
||||
widget = wibox.container.background,
|
||||
bg = Theme_config.network_manager.form.button_bg,
|
||||
fg = Theme_config.network_manager.form.button_fg,
|
||||
shape = Theme_config.network_manager.form.button_shape,
|
||||
id = "connect_button",
|
||||
},
|
||||
widget = wibox.container.margin,
|
||||
margins = dpi(10),
|
||||
},
|
||||
layout = wibox.layout.align.horizontal
|
||||
},
|
||||
layout = wibox.layout.align.horizontal
|
||||
spacing = dpi(20),
|
||||
layout = wibox.layout.fixed.vertical
|
||||
},
|
||||
layout = wibox.layout.align.vertical
|
||||
widget = wibox.container.margin,
|
||||
margins = dpi(10)
|
||||
},
|
||||
placement = awful.placement.centered,
|
||||
ontop = true,
|
||||
@@ -220,37 +189,36 @@ function ap_form.new(args)
|
||||
bg = Theme_config.network_manager.form.bg,
|
||||
fg = Theme_config.network_manager.form.fg,
|
||||
shape = Theme_config.network_manager.form.shape,
|
||||
border_color = Theme_config.network_manager.form.border_color,
|
||||
border_width = Theme_config.network_manager.form.border_width,
|
||||
type = "dialog",
|
||||
screen = args.screen,
|
||||
}
|
||||
|
||||
ret._private.popup.widget:get_children_by_id("close_button")[1]:connect_signal("button::press", function()
|
||||
ret:popup_toggle()
|
||||
gtable.crush(ret, ap_form, true)
|
||||
|
||||
local checkbox = ret.widget:get_children_by_id("checkbox")[1]
|
||||
checkbox:connect_signal("button::press", function()
|
||||
checkbox.checked = not checkbox.checked
|
||||
end)
|
||||
|
||||
ret.settigns_form.ssid:connect_signal(
|
||||
"submit",
|
||||
function(text)
|
||||
end
|
||||
)
|
||||
local close_button = ret.widget:get_children_by_id("close_button")[1]
|
||||
close_button:connect_signal("button::press", function()
|
||||
ret:popup_toggle()
|
||||
end)
|
||||
Hover_signal(close_button)
|
||||
|
||||
ret.settigns_form.ssid:connect_signal(
|
||||
"stopped",
|
||||
function()
|
||||
end
|
||||
)
|
||||
|
||||
ret.settigns_form.password:connect_signal(
|
||||
"submit",
|
||||
function(text)
|
||||
end
|
||||
)
|
||||
|
||||
ret.settigns_form.password:connect_signal(
|
||||
"stopped",
|
||||
function()
|
||||
end
|
||||
)
|
||||
local connect_button = ret.widget:get_children_by_id("connect_button")[1]
|
||||
connect_button:connect_signal("button::press", function()
|
||||
ret:emit_signal("ap_form::connect", {
|
||||
ssid = args.ssid,
|
||||
password = settigns_form.password:get_text(),
|
||||
auto_connect = ret.widget:get_children_by_id("checkbox")[1].checked
|
||||
})
|
||||
print("Connect to " .. args.ssid:get_text(), "\nPassword: " .. settigns_form.password:get_text(),
|
||||
"\nAuto connect: " .. tostring(ret.widget:get_children_by_id("checkbox")[1].checked))
|
||||
end)
|
||||
Hover_signal(connect_button)
|
||||
|
||||
return ret
|
||||
end
|
||||
|
||||
@@ -14,23 +14,23 @@ local gcolor = require("gears").color
|
||||
local gears = require("gears")
|
||||
local lgi = require("lgi")
|
||||
local wibox = require("wibox")
|
||||
|
||||
local NM = require("lgi").NM
|
||||
local base = require("wibox.widget.base")
|
||||
|
||||
local rubato = require("src.lib.rubato")
|
||||
|
||||
local access_point = require("src.modules.network_controller.access_point")
|
||||
local dnd_widget = require("awful.widget.toggle_widget")
|
||||
|
||||
local icondir = gears.filesystem.get_configuration_dir() .. "src/assets/icons/network/"
|
||||
|
||||
|
||||
local capi = {
|
||||
awesome = awesome,
|
||||
}
|
||||
|
||||
local network = { mt = {} }
|
||||
|
||||
network.access_points = { layout = wibox.layout.fixed.vertical }
|
||||
|
||||
network.NMState = {
|
||||
UNKNOWN = 0,
|
||||
ASLEEP = 10,
|
||||
@@ -81,37 +81,45 @@ local function flags_to_security(flags, wpa_flags, rsn_flags)
|
||||
return (str:gsub("^%s", ""))
|
||||
end
|
||||
|
||||
local function get_wifi_proxy(self)
|
||||
local devices = self._private.client_proxy:GetDevices()
|
||||
for _, device in ipairs(devices) do
|
||||
local device_proxy = dbus_proxy.Proxy:new {
|
||||
local function generate_uuid()
|
||||
return string.gsub('xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx', '[xy]', function(c)
|
||||
local v = (c == 'x') and math.random(0, 0xf) or math.random(8, 0xb)
|
||||
return string.format('%x', v)
|
||||
end)
|
||||
end
|
||||
|
||||
function network:get_wifi_proxy()
|
||||
local devices = self._private.NetworkManager:GetDevices()
|
||||
for _, path in ipairs(devices) do
|
||||
local NetworkManagerDevice = dbus_proxy.Proxy:new {
|
||||
bus = dbus_proxy.Bus.SYSTEM,
|
||||
name = "org.freedesktop.NetworkManager",
|
||||
interface = "org.freedesktop.NetworkManager.Device",
|
||||
path = device
|
||||
path = path
|
||||
}
|
||||
|
||||
if device_proxy.DeviceType == network.DeviceType.WIFI then
|
||||
self._private.device_proxy = device_proxy
|
||||
self._private.wifi_proxy = dbus_proxy.Proxy:new {
|
||||
if NetworkManagerDevice.DeviceType == network.DeviceType.WIFI then
|
||||
self._private.NetworkManagerDevice = NetworkManagerDevice
|
||||
self._private.NetworkManagerDeviceWireless = dbus_proxy.Proxy:new {
|
||||
bus = dbus_proxy.Bus.SYSTEM,
|
||||
name = "org.freedesktop.NetworkManager",
|
||||
interface = "org.freedesktop.NetworkManager.Device.Wireless",
|
||||
path = device
|
||||
path = path
|
||||
}
|
||||
|
||||
self._private.device_proxy:connect_signal(function(proxy, new_state, old_state, reason)
|
||||
local active_access_point_proxy = dbus_proxy.Proxy:new {
|
||||
self._private.NetworkManagerDevice:connect_signal(function(proxy, new_state, old_state, reason)
|
||||
local NetworkManagerAccessPoint = dbus_proxy.Proxy:new {
|
||||
bus = dbus_proxy.Bus.SYSTEM,
|
||||
name = "org.freedesktop.NetworkManager",
|
||||
interface = "org.freedesktop.NetworkManager.AccessPoint",
|
||||
path = self._private.wifi_proxy.ActiveAccessPoint
|
||||
}
|
||||
|
||||
self:emit_signal(tostring(active_access_point_proxy.HwAddress) .. "::state", new_state, old_state)
|
||||
self:emit_signal(tostring(NetworkManagerAccessPoint.HwAddress) .. "::state", new_state, old_state)
|
||||
if new_state == network.DeviceState.ACTIVATED then
|
||||
local ssid = NM.utils_ssid_to_utf8(active_access_point_proxy.Ssid)
|
||||
self:emit_signal("NM::AccessPointConnected", ssid, active_access_point_proxy.Strength)
|
||||
local ssid = NM.utils_ssid_to_utf8(NetworkManagerAccessPoint.Ssid)
|
||||
self:emit_signal("NM::AccessPointConnected", ssid, NetworkManagerAccessPoint.Strength)
|
||||
print("AP Connected: ", ssid, NetworkManagerAccessPoint.Strength)
|
||||
end
|
||||
end, "StateChanged")
|
||||
end
|
||||
@@ -119,8 +127,7 @@ local function get_wifi_proxy(self)
|
||||
end
|
||||
|
||||
function network.device_state_to_string(state)
|
||||
local device_state_to_string =
|
||||
{
|
||||
local device_state_to_string = {
|
||||
[0] = "Unknown",
|
||||
[10] = "Unmanaged",
|
||||
[20] = "Unavailable",
|
||||
@@ -139,63 +146,30 @@ function network.device_state_to_string(state)
|
||||
return device_state_to_string[state]
|
||||
end
|
||||
|
||||
local function get_access_point_connections(self, ssid)
|
||||
local connection_proxies = {}
|
||||
function network:get_access_point_connections(ssid)
|
||||
local cn = {}
|
||||
|
||||
local connections = self._private.settings_proxy:ListConnections()
|
||||
local connections = self._private.NetworkManagerSettings:ListConnections()
|
||||
for _, connection_path in ipairs(connections) do
|
||||
local connection_proxy = dbus_proxy.Proxy:new {
|
||||
local NetworkManagerSettingsConnection = dbus_proxy.Proxy:new {
|
||||
bus = dbus_proxy.Bus.SYSTEM,
|
||||
name = "org.freedesktop.NetworkManager",
|
||||
interface = "org.freedesktop.NetworkManager.Settings.Connection",
|
||||
path = connection_path
|
||||
}
|
||||
|
||||
if connection_proxy.Filename:find(ssid) then
|
||||
table.insert(connection_proxies, connection_proxy)
|
||||
if NetworkManagerSettingsConnection.Filename:find(ssid) then
|
||||
table.insert(cn, NetworkManagerSettingsConnection)
|
||||
end
|
||||
end
|
||||
|
||||
return connection_proxies
|
||||
return cn
|
||||
end
|
||||
|
||||
local function generate_uuid()
|
||||
local template = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
|
||||
local uuid = string.gsub(template, '[xy]', function(c)
|
||||
local v = (c == 'x') and math.random(0, 0xf) or math.random(8, 0xb)
|
||||
return string.format('%x', v)
|
||||
end)
|
||||
return uuid
|
||||
end
|
||||
|
||||
local function create_profile(ap, password, auto_connect)
|
||||
local s_con =
|
||||
{
|
||||
-- ["interface-name"] = lgi.GLib.Variant("s", ap.device_interface),
|
||||
["uuid"] = lgi.GLib.Variant("s", generate_uuid()),
|
||||
["id"] = lgi.GLib.Variant("s", ap.ssid),
|
||||
["type"] = lgi.GLib.Variant("s", "802-11-wireless"),
|
||||
["autoconnect"] = lgi.GLib.Variant("b", auto_connect),
|
||||
}
|
||||
|
||||
local s_ip4 =
|
||||
{
|
||||
["method"] = lgi.GLib.Variant("s", "auto")
|
||||
}
|
||||
|
||||
local s_ip6 =
|
||||
{
|
||||
["method"] = lgi.GLib.Variant("s", "auto"),
|
||||
}
|
||||
|
||||
local s_wifi =
|
||||
{
|
||||
["mode"] = lgi.GLib.Variant("s", "infrastructure"),
|
||||
}
|
||||
|
||||
function network:create_profile(ap, password, auto_connect)
|
||||
local s_wsec = {}
|
||||
if ap.security ~= "" then
|
||||
if ap.security:match("WPA") ~= nil then
|
||||
if ap.security:match("WPA") then
|
||||
s_wsec["key-mgmt"] = lgi.GLib.Variant("s", "wpa-psk")
|
||||
s_wsec["auth-alg"] = lgi.GLib.Variant("s", "open")
|
||||
--s_wsec["psk"] = lgi.GLib.Variant("s", helpers.string.trim(password))
|
||||
@@ -207,108 +181,85 @@ local function create_profile(ap, password, auto_connect)
|
||||
end
|
||||
|
||||
return {
|
||||
["connection"] = s_con,
|
||||
["ipv4"] = s_ip4,
|
||||
["ipv6"] = s_ip6,
|
||||
["802-11-wireless"] = s_wifi,
|
||||
["connection"] = {
|
||||
-- ["interface-name"] = lgi.GLib.Variant("s", ap.device_interface),
|
||||
["uuid"] = lgi.GLib.Variant("s", generate_uuid()),
|
||||
["id"] = lgi.GLib.Variant("s", ap.ssid),
|
||||
["type"] = lgi.GLib.Variant("s", "802-11-wireless"),
|
||||
["autoconnect"] = lgi.GLib.Variant("b", auto_connect),
|
||||
},
|
||||
["ipv4"] = {
|
||||
["method"] = lgi.GLib.Variant("s", "auto")
|
||||
},
|
||||
["ipv6"] = {
|
||||
["method"] = lgi.GLib.Variant("s", "auto"),
|
||||
},
|
||||
["802-11-wireless"] = {
|
||||
["mode"] = lgi.GLib.Variant("s", "infrastructure"),
|
||||
},
|
||||
["802-11-wireless-security"] = s_wsec
|
||||
}
|
||||
end
|
||||
|
||||
---Scan for access points and create a widget for each one.
|
||||
function network:scan_access_points()
|
||||
self._private.access_points = {}
|
||||
local ap_list = self:get_children_by_id("wifi_ap_list")[1]
|
||||
|
||||
self._private.wifi_proxy:RequestScanAsync(function(proxy, context, success, failure)
|
||||
if failure ~= nil then
|
||||
self.access_points = { layout = wibox.layout.fixed.vertical }
|
||||
self:emit_signal("NM::AccessPointsFound", self.access_points[1].ssid)
|
||||
self:emit_signal("NM::ScanFailed", tostring(failure))
|
||||
self._private.NetworkManagerDeviceWireless:RequestScanAsync(function(proxy, context, success, failure)
|
||||
if failure then
|
||||
-- Send an error notification
|
||||
print("AP Scan failed: ", failure)
|
||||
return
|
||||
end
|
||||
|
||||
local access_points = self._private.wifi_proxy:GetAllAccessPoints()
|
||||
-- Get every access point even those who hide their ssid
|
||||
print(#self._private.NetworkManagerDeviceWireless:GetAllAccessPoints())
|
||||
for _, ap in ipairs(self._private.NetworkManagerDeviceWireless:GetAllAccessPoints()) do
|
||||
|
||||
self._private.access_points = {}
|
||||
if (not access_point) or (#access_points == 0) then
|
||||
self.access_points = { layout = wibox.layout.fixed.vertical }
|
||||
self:emit_signal("NM::AccessPointsFound", self.access_points[1].ssid)
|
||||
end
|
||||
|
||||
for _, ap in ipairs(access_points) do
|
||||
local access_point_proxy = dbus_proxy.Proxy:new {
|
||||
-- Create a new proxy for every ap
|
||||
local NetworkManagerAccessPoint = dbus_proxy.Proxy:new {
|
||||
bus = dbus_proxy.Bus.SYSTEM,
|
||||
name = "org.freedesktop.NetworkManager",
|
||||
interface = "org.freedesktop.NetworkManager.AccessPoint",
|
||||
path = ap
|
||||
}
|
||||
|
||||
if access_point_proxy.Ssid then
|
||||
local appSsid = access_point_proxy.Ssid or ""
|
||||
local ssid = NM.utils_ssid_to_utf8(appSsid) or ""
|
||||
local security = flags_to_security(access_point_proxy.Flags, access_point_proxy.WpaFlags)
|
||||
local password = ""
|
||||
local connections = get_access_point_connections(self, ssid)
|
||||
|
||||
for _, connection in ipairs(connections) do
|
||||
if connection.Filename:find(ssid) then
|
||||
local secrets = connection:GetSecrets("802-11-wireless-security")
|
||||
if secrets then
|
||||
password = secrets["802-11-wireless-security"].psk
|
||||
end
|
||||
end
|
||||
--[[ for _, ap2 in ipairs(ap_list.children) do
|
||||
if ap2.NetworkManagerAccessPoint.HwAddress:match(ap.HwAddress or "") then
|
||||
goto continue
|
||||
end
|
||||
end ]]
|
||||
|
||||
table.insert(self._private.access_points, {
|
||||
ssid = ssid,
|
||||
security = security,
|
||||
password = password,
|
||||
strength = access_point_proxy.Strength,
|
||||
hw_address = access_point_proxy.HwAddress,
|
||||
device_interface = self._private.device_proxy.Interface,
|
||||
device_path = self._private.device_proxy.object_path,
|
||||
access_point_path = ap
|
||||
})
|
||||
print("AP Found: ", NetworkManagerAccessPoint.HwAddress, NM.utils_ssid_to_utf8(NetworkManagerAccessPoint.Ssid),
|
||||
NetworkManagerAccessPoint.Strength)
|
||||
|
||||
|
||||
-- We are only interested in those with a ssid
|
||||
if NetworkManagerAccessPoint.Ssid then
|
||||
ap_list:add(access_point { NetworkManagerAccessPoint = NetworkManagerAccessPoint })
|
||||
end
|
||||
end
|
||||
|
||||
self.access_points = { layout = wibox.layout.fixed.vertical }
|
||||
|
||||
local seen = {}
|
||||
for _, ap2 in ipairs(self._private.access_points) do
|
||||
if not seen[ap2.ssid] then
|
||||
seen[ap2.ssid] = true
|
||||
table.insert(self.access_points,
|
||||
access_point.new { access_point = ap2, active = self._private.wifi_proxy.ActiveAccessPoint }.widget)
|
||||
end
|
||||
end
|
||||
|
||||
table.sort(self._private.access_points, function(a, b)
|
||||
return a.strength > b.strength
|
||||
table.sort(ap_list, function(a, b)
|
||||
return a.NetworkManagerAccessPoint.Strength > b.NetworkManagerAccessPoint.Strength
|
||||
end)
|
||||
|
||||
self:emit_signal("NM::AccessPointsFound", self.access_points[1].ssid)
|
||||
print("AP_Anzahl: ", #ap_list.children)
|
||||
end, { call_id = "my-id" }, {})
|
||||
end
|
||||
|
||||
function network:toggle()
|
||||
self.container.visible = not self.container.visible
|
||||
end
|
||||
|
||||
function network:is_ap_active(ap)
|
||||
print(self._private.wifi_proxy.ActiveAccessPoint)
|
||||
return ap.path == self._private.wifi_proxy.ActiveAccessPoint
|
||||
end
|
||||
|
||||
function network:disconnect_ap()
|
||||
self._private.client_proxy:DeactivateConnection(self._private.device_proxy.ActiveConnection)
|
||||
self._private.NetworkManager:DeactivateConnection(self._private.NetworkManagerDevice.ActiveConnection)
|
||||
end
|
||||
|
||||
function network:connect_ap(ap, pw, auto_connect)
|
||||
local connections = get_access_point_connections(self, ap.ssid)
|
||||
local profile = create_profile(ap, pw, auto_connect)
|
||||
local connections = self:get_access_point_connections(ap.ssid)
|
||||
local profile = self:create_profile(ap, pw, auto_connect)
|
||||
|
||||
if #connections == 0 then
|
||||
self._private.client_proxy:AddAndActivateConnectionAsync(function(proxy, context, success, failure)
|
||||
self._private.NetworkManager:AddAndActivateConnectionAsync(function(proxy, context, success, failure)
|
||||
if failure then
|
||||
self:emit_signal("NM::AccessPointFailed", tostring(failure))
|
||||
return
|
||||
@@ -318,7 +269,7 @@ function network:connect_ap(ap, pw, auto_connect)
|
||||
end, { call_id = "my-id", profile, ap.device_proxy_path, ap.path })
|
||||
else
|
||||
connections[1]:Update(profile)
|
||||
self._private.client_proxy:ActivateConnectionAsync(function(proxy, context, success, failure)
|
||||
self._private.NetworkManager:ActivateConnectionAsync(function(proxy, context, success, failure)
|
||||
if failure then
|
||||
self:emit_signal("NM::AccessPointFailed", tostring(failure))
|
||||
return
|
||||
@@ -337,89 +288,21 @@ function network:toggle_access_point(ap, password, auto_connect)
|
||||
end
|
||||
end
|
||||
|
||||
function network:toggle_wireless()
|
||||
local enable = not self._private.client_proxy.WirelessEnabled
|
||||
---Toggles networking on or off
|
||||
function network:toggle_wifi()
|
||||
local enable = not self._private.NetworkManager.WirelessEnabled
|
||||
if enable then
|
||||
self._private.client_proxy:Enable(true)
|
||||
self._private.NetworkManager.Enable(true)
|
||||
end
|
||||
|
||||
self._private.client_proxy:Set("org.freedesktop.NetworkManager", "WirelessEnabled", lgi.GLib.Variant("b", enable))
|
||||
|
||||
return enable
|
||||
self._private.NetworkManager:Set("org.freedesktop.NetworkManager", "WirelessEnabled", lgi.GLib.Variant("b", enable))
|
||||
self._private.NetworkManager.WirelessEnabled = { signature = "b", value = enable }
|
||||
end
|
||||
|
||||
function network.new(args)
|
||||
args = args or {}
|
||||
|
||||
local ret = gobject {}
|
||||
|
||||
gtable.crush(ret, network, true)
|
||||
|
||||
ret._private = {}
|
||||
|
||||
ret._private.client_proxy = dbus_proxy.Proxy:new {
|
||||
bus = dbus_proxy.Bus.SYSTEM,
|
||||
name = "org.freedesktop.NetworkManager",
|
||||
interface = "org.freedesktop.NetworkManager",
|
||||
path = "/org/freedesktop/NetworkManager",
|
||||
}
|
||||
|
||||
ret._private.settings_proxy = dbus_proxy.Proxy:new {
|
||||
bus = dbus_proxy.Bus.SYSTEM,
|
||||
name = "org.freedesktop.NetworkManager",
|
||||
interface = "org.freedesktop.NetworkManager.Settings",
|
||||
path = "/org/freedesktop/NetworkManager/Settings",
|
||||
}
|
||||
|
||||
local property_proxy = dbus_proxy.Proxy:new {
|
||||
bus = dbus_proxy.Bus.SYSTEM,
|
||||
name = "org.freedesktop.NetworkManager",
|
||||
interface = "org.freedesktop.DBus.Properties",
|
||||
path = "/org/freedesktop/NetworkManager",
|
||||
}
|
||||
|
||||
-- dbus proxy signals are in reversed order (function, signal)
|
||||
property_proxy:connect_signal(function(_, properties, data)
|
||||
if data.WirelessEnables ~= nil and ret._private.WirelessEnabled ~= data.WirelessEnabled then
|
||||
ret._private.WirelessEnabled = data.WirelessEnabled
|
||||
ret:emit_signal("NM::WirelessStateChanged", ret._private.WirelessEnabled)
|
||||
|
||||
if data.WirelessEnabled then
|
||||
gtimer {
|
||||
timeout = 5,
|
||||
autostart = true,
|
||||
call_now = false,
|
||||
single_shot = true,
|
||||
callback = function()
|
||||
ret:get_access_points()
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
end, "PropertiesChanged")
|
||||
|
||||
get_wifi_proxy(ret)
|
||||
|
||||
ret:scan_access_points()
|
||||
|
||||
gtimer.delayed_call(function()
|
||||
ret:emit_signal("NM::WirelessStateChanged", ret._private.client_proxy.WirelessEnabled)
|
||||
|
||||
local active_access_point = ret._private.wifi_proxy.ActiveAccessPoint
|
||||
if ret._private.device_proxy.State == network.DeviceState.ACTIVATED and active_access_point ~= "/" then
|
||||
local active_access_point_proxy = dbus_proxy.Proxy:new {
|
||||
bus = dbus_proxy.Bus.SYSTEM,
|
||||
name = "org.freedesktop.NetworkManager",
|
||||
interface = "org.freedesktop.NetworkManager.AccessPoint",
|
||||
path = active_access_point,
|
||||
}
|
||||
|
||||
local ssid = NM.utils_ssid_to_utf8(active_access_point_proxy.Ssid)
|
||||
ret:emit_signal("NM:AccessPointConnected", ssid, active_access_point_proxy.Strength)
|
||||
end
|
||||
end)
|
||||
|
||||
local network_widget = wibox.widget {
|
||||
local ret = base.make_widget_from_value(wibox.widget {
|
||||
{
|
||||
{
|
||||
{
|
||||
@@ -488,6 +371,17 @@ function network.new(args)
|
||||
},
|
||||
{
|
||||
{ -- action buttons
|
||||
{
|
||||
dnd_widget {
|
||||
color = Theme_config.network_manager.power_icon_color,
|
||||
size = dpi(40)
|
||||
},
|
||||
id = "dnd",
|
||||
widget = wibox.container.place,
|
||||
valign = "center",
|
||||
halign = "center"
|
||||
},
|
||||
nil,
|
||||
{ -- refresh
|
||||
{
|
||||
{
|
||||
@@ -512,31 +406,6 @@ function network.new(args)
|
||||
widget = wibox.container.background,
|
||||
id = "refresh"
|
||||
},
|
||||
nil,
|
||||
{ -- airplane mode
|
||||
{
|
||||
{
|
||||
image = gcolor.recolor_image(icondir .. "airplane-off.svg",
|
||||
Theme_config.network_manager.airplane_icon_color),
|
||||
resize = false,
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
widget = wibox.widget.imagebox,
|
||||
id = "icon"
|
||||
},
|
||||
widget = wibox.container.margin,
|
||||
margins = dpi(5),
|
||||
id = "center",
|
||||
},
|
||||
border_width = dpi(2),
|
||||
border_color = Theme_config.network_manager.border_color,
|
||||
shape = function(cr, width, height)
|
||||
gshape.rounded_rect(cr, width, height, dpi(4))
|
||||
end,
|
||||
bg = Theme_config.network_manager.refresh_bg,
|
||||
widget = wibox.container.background,
|
||||
id = "airplane"
|
||||
},
|
||||
layout = wibox.layout.align.horizontal
|
||||
},
|
||||
widget = wibox.container.margin,
|
||||
@@ -562,54 +431,82 @@ function network.new(args)
|
||||
width = dpi(400),
|
||||
strategy = "exact",
|
||||
widget = wibox.container.constraint
|
||||
})
|
||||
|
||||
local dnd = ret:get_children_by_id("dnd")[1]:get_widget()
|
||||
|
||||
dnd:connect_signal("dnd::toggle", function(enable)
|
||||
ret:toggle_wifi()
|
||||
end)
|
||||
|
||||
gtable.crush(ret, network, true)
|
||||
|
||||
--#region Wifi Proxies
|
||||
|
||||
ret._private.NetworkManager = dbus_proxy.Proxy:new {
|
||||
bus = dbus_proxy.Bus.SYSTEM,
|
||||
name = "org.freedesktop.NetworkManager",
|
||||
interface = "org.freedesktop.NetworkManager",
|
||||
path = "/org/freedesktop/NetworkManager",
|
||||
}
|
||||
|
||||
local refresh_button = network_widget:get_children_by_id("refresh")[1]
|
||||
ret._private.NetworkManagerSettings = dbus_proxy.Proxy:new {
|
||||
bus = dbus_proxy.Bus.SYSTEM,
|
||||
name = "org.freedesktop.NetworkManager",
|
||||
interface = "org.freedesktop.NetworkManager.Settings",
|
||||
path = "/org/freedesktop/NetworkManager/Settings",
|
||||
}
|
||||
|
||||
refresh_button:buttons(
|
||||
gtable.join(
|
||||
awful.button(
|
||||
{},
|
||||
1,
|
||||
nil,
|
||||
function()
|
||||
ret:scan_access_points()
|
||||
end
|
||||
)
|
||||
)
|
||||
)
|
||||
ret._private.NetworkManagerProperties = dbus_proxy.Proxy:new {
|
||||
bus = dbus_proxy.Bus.SYSTEM,
|
||||
name = "org.freedesktop.NetworkManager",
|
||||
interface = "org.freedesktop.DBus.Properties",
|
||||
path = "/org/freedesktop/NetworkManager",
|
||||
}
|
||||
|
||||
Hover_signal(refresh_button)
|
||||
ret._private.NetworkManagerProperties:connect_signal(function(_, properties, data)
|
||||
if data.WirelessEnables ~= nil and ret._private.WirelessEnabled ~= data.WirelessEnabled then
|
||||
ret._private.WirelessEnabled = data.WirelessEnabled
|
||||
|
||||
local airplane_button = network_widget:get_children_by_id("airplane")[1]
|
||||
ret:emit_signal("NetworkManager::status", ret._private.WirelessEnabled)
|
||||
print(ret._private.WirelessEnabled)
|
||||
|
||||
airplane_button:buttons(
|
||||
gtable.join(
|
||||
awful.button(
|
||||
{},
|
||||
1,
|
||||
nil,
|
||||
function()
|
||||
if ret:toggle_wireless() then
|
||||
airplane_button.center.icon.image = gcolor.recolor_image(icondir
|
||||
.. "airplane-off.svg",
|
||||
Theme_config.network_manager.airplane_icon_color)
|
||||
else
|
||||
airplane_button.center.icon.image = gcolor.recolor_image(icondir
|
||||
.. "airplane-on.svg",
|
||||
Theme_config.network_manager.airplane_icon_color)
|
||||
if data.WirelessEnabled then
|
||||
gtimer {
|
||||
timeout = 5,
|
||||
autostart = true,
|
||||
call_now = false,
|
||||
single_shot = true,
|
||||
callback = function()
|
||||
ret:scan_access_points()
|
||||
end
|
||||
ret:scan_access_points()
|
||||
end
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
end
|
||||
end
|
||||
end, "PropertiesChanged")
|
||||
|
||||
Hover_signal(airplane_button)
|
||||
ret:get_wifi_proxy()
|
||||
|
||||
local wifi_margin = network_widget:get_children_by_id("wifi_margin")[1]
|
||||
local wifi_list = network_widget:get_children_by_id("wifi_list")[1]
|
||||
local wifi = network_widget:get_children_by_id("wifi")[1].center
|
||||
ret:scan_access_points()
|
||||
|
||||
gtimer.delayed_call(function()
|
||||
local active_access_point = ret._private.NetworkManagerDeviceWireless.ActiveAccessPoint
|
||||
if ret._private.NetworkManager.State == network.DeviceState.ACTIVATED and active_access_point ~= "/" then
|
||||
local active_access_point_proxy = dbus_proxy.Proxy:new {
|
||||
bus = dbus_proxy.Bus.SYSTEM,
|
||||
name = "org.freedesktop.NetworkManager",
|
||||
interface = "org.freedesktop.NetworkManager.AccessPoint",
|
||||
path = active_access_point,
|
||||
}
|
||||
end
|
||||
end)
|
||||
|
||||
--#endregion
|
||||
|
||||
--#region Dropdown logic
|
||||
local wifi_margin = ret:get_children_by_id("wifi_margin")[1]
|
||||
local wifi_list = ret:get_children_by_id("wifi_list")[1]
|
||||
local wifi = ret:get_children_by_id("wifi")[1].center
|
||||
|
||||
local rubato_timer = rubato.timed {
|
||||
duration = 0.2,
|
||||
@@ -620,64 +517,47 @@ function network.new(args)
|
||||
end
|
||||
}
|
||||
|
||||
wifi_margin:buttons(
|
||||
gtable.join(
|
||||
awful.button(
|
||||
{},
|
||||
1,
|
||||
nil,
|
||||
function()
|
||||
if wifi_list.forced_height == 0 then
|
||||
local size = (#ret.access_points * 49) + 1
|
||||
|
||||
size = size > 210 and 210 or size
|
||||
|
||||
rubato_timer.target = dpi(size)
|
||||
wifi_margin.wifi_bg.shape = function(cr, width, height)
|
||||
gshape.partially_rounded_rect(cr, width, height, true, true, false, false, dpi(4))
|
||||
end
|
||||
wifi.icon:set_image(gcolor.recolor_image(icondir .. "menu-up.svg",
|
||||
Theme_config.network_manager.wifi_icon_color))
|
||||
else
|
||||
rubato_timer.target = 0
|
||||
wifi_margin.wifi_bg.shape = function(cr, width, height)
|
||||
gshape.partially_rounded_rect(cr, width, height, true, true, true, true, dpi(4))
|
||||
end
|
||||
wifi.icon:set_image(gcolor.recolor_image(icondir .. "menu-down.svg",
|
||||
Theme_config.network_manager.wifi_icon_color))
|
||||
wifi_margin:buttons(gtable.join(
|
||||
awful.button({}, 1, nil,
|
||||
function()
|
||||
if wifi_list.forced_height == 0 then
|
||||
if not ret:get_children_by_id("wifi_ap_list")[1].children then
|
||||
return
|
||||
end
|
||||
local size = (5 * 49) + 1
|
||||
|
||||
size = size > 210 and 210 or size
|
||||
|
||||
rubato_timer.target = dpi(size)
|
||||
wifi_margin.wifi_bg.shape = function(cr, width, height)
|
||||
gshape.partially_rounded_rect(cr, width, height, true, true, false, false, dpi(4))
|
||||
end
|
||||
wifi.icon:set_image(gcolor.recolor_image(icondir .. "menu-up.svg",
|
||||
Theme_config.network_manager.wifi_icon_color))
|
||||
else
|
||||
rubato_timer.target = 0
|
||||
wifi_margin.wifi_bg.shape = function(cr, width, height)
|
||||
gshape.partially_rounded_rect(cr, width, height, true, true, true, true, dpi(4))
|
||||
end
|
||||
wifi.icon:set_image(gcolor.recolor_image(icondir .. "menu-down.svg",
|
||||
Theme_config.network_manager.wifi_icon_color))
|
||||
end
|
||||
)
|
||||
end
|
||||
)
|
||||
)
|
||||
))
|
||||
--#endregion
|
||||
|
||||
ret.widget = awful.popup {
|
||||
widget = network_widget,
|
||||
bg = Theme_config.network_manager.bg,
|
||||
screen = args.screen,
|
||||
stretch = false,
|
||||
visible = false,
|
||||
ontop = true,
|
||||
placement = function(c) awful.placement.align(c,
|
||||
{ position = "top_right", margins = { right = dpi(350), top = dpi(60) } })
|
||||
end,
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(12))
|
||||
end
|
||||
}
|
||||
local refresh_button = ret:get_children_by_id("refresh")[1]
|
||||
refresh_button:buttons(gtable.join(
|
||||
awful.button({}, 1, nil,
|
||||
function()
|
||||
ret:scan_access_points()
|
||||
end
|
||||
)
|
||||
))
|
||||
Hover_signal(refresh_button)
|
||||
|
||||
capi.awesome.connect_signal("NM::toggle_container", function()
|
||||
ret.widget.visible = not ret.widget.visible
|
||||
ret:scan_access_points()
|
||||
end)
|
||||
|
||||
capi.awesome.connect_signal("NM::toggle_wifi", function()
|
||||
ret:toggle_wireless()
|
||||
end)
|
||||
|
||||
ret:connect_signal("NM::AccessPointsFound", function(tab)
|
||||
network_widget:get_children_by_id("wifi_ap_list")[1].children = ret.access_points
|
||||
end)
|
||||
return ret
|
||||
end
|
||||
|
||||
function network.mt:__call(...)
|
||||
|
||||
@@ -7,8 +7,7 @@ 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 dnd_widget = require("awful.widget.toggle_widget")
|
||||
|
||||
local capi = {
|
||||
awesome = awesome,
|
||||
@@ -19,6 +18,17 @@ local icondir = gears.filesystem.get_configuration_dir() .. "src/assets/icons/no
|
||||
|
||||
return function(s)
|
||||
|
||||
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)
|
||||
})
|
||||
|
||||
dnd:get_widget():connect_signal("dnd::toggle", function(enabled)
|
||||
User_config.dnd = enabled
|
||||
end)
|
||||
|
||||
--#region Activation area
|
||||
|
||||
local activation_area = awful.popup {
|
||||
@@ -90,121 +100,6 @@ return function(s)
|
||||
halign = "right",
|
||||
}
|
||||
|
||||
local color = Theme_config.notification_center.dnd.disabled
|
||||
|
||||
local function toggle_animation(pos)
|
||||
if pos > 43 then return end
|
||||
return function(_, _, cr, width, height)
|
||||
cr:set_source(gears.color(Theme_config.notification_center.dnd.bg));
|
||||
cr:paint();
|
||||
cr:set_source(gears.color(color))
|
||||
cr:move_to(pos, 0)
|
||||
local x = pos
|
||||
local y = 5
|
||||
local newwidth = width / 2 - 10
|
||||
local newheight = height - 10
|
||||
|
||||
local radius = height / 6.0
|
||||
local degrees = math.pi / 180.0;
|
||||
|
||||
cr:new_sub_path()
|
||||
cr:arc(x + newwidth - radius, y + radius, radius, -90 * degrees, 0 * degrees)
|
||||
cr:arc(x + newwidth - radius, y + newheight - radius, radius, 0 * degrees, 90 * degrees)
|
||||
cr:arc(x + radius, y + newheight - radius, radius, 90 * degrees, 180 * degrees)
|
||||
cr:arc(x + radius, y + radius, radius, 180 * degrees, 270 * degrees)
|
||||
cr:close_path()
|
||||
cr:fill()
|
||||
end
|
||||
end
|
||||
|
||||
local rubato_timed
|
||||
|
||||
local toggle_button = wibox.widget {
|
||||
{
|
||||
widget = wibox.widget {
|
||||
fit = function(_, width, height)
|
||||
return width, height
|
||||
end,
|
||||
draw = toggle_animation(0),
|
||||
},
|
||||
id = "background",
|
||||
},
|
||||
active = false,
|
||||
widget = wibox.container.background,
|
||||
bg = Theme_config.notification_center.dnd.bg,
|
||||
border_color = Theme_config.notification_center.dnd.border_disabled,
|
||||
border_width = dpi(2),
|
||||
forced_height = dpi(40),
|
||||
forced_width = dpi(80),
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(10))
|
||||
end,
|
||||
}
|
||||
|
||||
toggle_button:buttons(
|
||||
gears.table.join(
|
||||
awful.button({}, 1, function()
|
||||
if toggle_button.active then
|
||||
toggle_button.active = not toggle_button.active
|
||||
toggle_button.border_color = Theme_config.notification_center.dnd.border_disabled
|
||||
color = Theme_config.notification_center.dnd.disabled
|
||||
User_config.dnd = false
|
||||
rubato_timed.target = 5
|
||||
else
|
||||
toggle_button.active = not toggle_button.active
|
||||
toggle_button.border_color = Theme_config.notification_center.dnd.border_enabled
|
||||
color = Theme_config.notification_center.dnd.enabled
|
||||
User_config.dnd = true
|
||||
rubato_timed.target = 43
|
||||
end
|
||||
end
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
rubato_timed = rubato.timed {
|
||||
duration = 0.5,
|
||||
pos = 5,
|
||||
subscribed = function(pos)
|
||||
toggle_button:get_children_by_id("background")[1].draw = toggle_animation(pos)
|
||||
toggle_button:emit_signal("widget::redraw_needed")
|
||||
end
|
||||
}
|
||||
|
||||
local dnd = wibox.widget {
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
text = "Do Not Disturb",
|
||||
valign = "center",
|
||||
align = "center",
|
||||
widget = wibox.widget.textbox,
|
||||
id = "clearall"
|
||||
},
|
||||
toggle_button,
|
||||
spacing = dpi(10),
|
||||
layout = wibox.layout.fixed.horizontal,
|
||||
id = "layout12"
|
||||
},
|
||||
id = "background4",
|
||||
fg = Theme_config.notification_center.dnd.fg,
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(12))
|
||||
end,
|
||||
forced_height = dpi(40),
|
||||
widget = wibox.container.background
|
||||
},
|
||||
id = "margin3",
|
||||
margins = dpi(10),
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
id = "place",
|
||||
widget = wibox.container.place,
|
||||
valign = "bottom",
|
||||
halign = "right",
|
||||
}
|
||||
|
||||
local no_notification_widget = wibox.widget {
|
||||
{
|
||||
{
|
||||
@@ -288,7 +183,12 @@ return function(s)
|
||||
widget = wibox.container.constraint
|
||||
},
|
||||
{
|
||||
dnd,
|
||||
{
|
||||
dnd,
|
||||
widget = wibox.container.place,
|
||||
valign = "center",
|
||||
halign = "center"
|
||||
},
|
||||
nil,
|
||||
clear_all_widget,
|
||||
layout = wibox.layout.align.horizontal
|
||||
|
||||
@@ -1,249 +0,0 @@
|
||||
--------------------------------
|
||||
-- This is the network widget --
|
||||
--------------------------------
|
||||
|
||||
-- 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/powermenu/"
|
||||
|
||||
return function(s)
|
||||
|
||||
-- Profile picture imagebox
|
||||
local profile_picture = wibox.widget {
|
||||
image = icondir .. "defaultpfp.svg",
|
||||
resize = true,
|
||||
forced_height = dpi(200),
|
||||
clip_shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(30))
|
||||
end,
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
widget = wibox.widget.imagebox
|
||||
}
|
||||
|
||||
-- Username textbox
|
||||
local profile_name = wibox.widget {
|
||||
align = 'center',
|
||||
valign = 'center',
|
||||
text = " ",
|
||||
font = "JetBrains Mono Bold 30",
|
||||
widget = wibox.widget.textbox
|
||||
}
|
||||
|
||||
-- Get the profile script from /var/lib/AccountsService/icons/${USER}
|
||||
-- and copy it to the assets folder
|
||||
-- TODO: If the user doesnt have AccountsService look into $HOME/.faces
|
||||
local update_profile_picture = function()
|
||||
awful.spawn.easy_async_with_shell(
|
||||
"./.config/awesome/src/scripts/pfp.sh 'userPfp'",
|
||||
function(stdout)
|
||||
if stdout then
|
||||
profile_picture:set_image(stdout:gsub("\n", ""))
|
||||
else
|
||||
profile_picture:set_image(icondir .. "defaultpfp.svg")
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
update_profile_picture()
|
||||
|
||||
-- Get the full username(if set) and the username + hostname
|
||||
local update_user_name = function()
|
||||
awful.spawn.easy_async_with_shell(
|
||||
"./.config/awesome/src/scripts/pfp.sh 'userName' '" .. User_config.namestyle .. "'",
|
||||
function(stdout)
|
||||
if stdout:gsub("\n", "") == "Rick Astley" then
|
||||
profile_picture:set_image(gears.filesystem.get_configuration_dir() .. "src/assets/userpfp/" .. "rickastley.jpg")
|
||||
end
|
||||
profile_name:set_text(stdout)
|
||||
end
|
||||
)
|
||||
end
|
||||
update_user_name()
|
||||
|
||||
-- Universal Button widget
|
||||
local button = function(name, icon, bg_color, callback)
|
||||
local item = wibox.widget {
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
-- TODO: using gears.color to recolor a SVG will make it look super low res
|
||||
-- currently I recolor it in the .svg file directly, but later implement
|
||||
-- a better way to recolor a SVG
|
||||
image = icon,
|
||||
resize = true,
|
||||
forced_height = dpi(30),
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
widget = wibox.widget.imagebox
|
||||
},
|
||||
{
|
||||
text = name,
|
||||
font = "JetBrains Mono Bold 30",
|
||||
widget = wibox.widget.textbox
|
||||
},
|
||||
widget = wibox.layout.fixed.horizontal
|
||||
},
|
||||
margins = dpi(10),
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
fg = Theme_config.powermenu.button_fg,
|
||||
bg = bg_color,
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(10))
|
||||
end,
|
||||
widget = wibox.container.background,
|
||||
id = 'background'
|
||||
},
|
||||
layout = wibox.layout.align.vertical
|
||||
}
|
||||
|
||||
item:connect_signal(
|
||||
"button::release",
|
||||
function()
|
||||
callback()
|
||||
end
|
||||
)
|
||||
|
||||
return item
|
||||
end
|
||||
|
||||
-- Create the power menu actions
|
||||
local suspend_command = function()
|
||||
awful.spawn("systemctl suspend")
|
||||
capi.awesome.emit_signal("module::powermenu:hide")
|
||||
end
|
||||
|
||||
local logout_command = function()
|
||||
capi.awesome.quit()
|
||||
end
|
||||
|
||||
local lock_command = function()
|
||||
awful.spawn("dm-tool lock")
|
||||
capi.awesome.emit_signal("module::powermenu:hide")
|
||||
end
|
||||
|
||||
local shutdown_command = function()
|
||||
awful.spawn("shutdown now")
|
||||
capi.awesome.emit_signal("module::powermenu:hide")
|
||||
end
|
||||
|
||||
local reboot_command = function()
|
||||
awful.spawn("reboot")
|
||||
capi.awesome.emit_signal("module::powermenu:hide")
|
||||
end
|
||||
|
||||
-- Create the buttons with their command and name etc
|
||||
local shutdown_button = button("Shutdown", icondir .. "shutdown.svg", Theme_config.powermenu.shutdown_button_bg,
|
||||
shutdown_command)
|
||||
local reboot_button = button("Reboot", icondir .. "reboot.svg", Theme_config.powermenu.reboot_button_bg, reboot_command)
|
||||
local suspend_button = button("Suspend", icondir .. "suspend.svg", Theme_config.powermenu.suspend_button_bg,
|
||||
suspend_command)
|
||||
local logout_button = button("Logout", icondir .. "logout.svg", Theme_config.powermenu.logout_button_bg, logout_command)
|
||||
local lock_button = button("Lock", icondir .. "lock.svg", Theme_config.powermenu.lock_button_bg, lock_command)
|
||||
|
||||
-- Signals to change color on hover
|
||||
Hover_signal(shutdown_button.background)
|
||||
Hover_signal(reboot_button.background)
|
||||
Hover_signal(suspend_button.background)
|
||||
Hover_signal(logout_button.background)
|
||||
Hover_signal(lock_button.background)
|
||||
|
||||
-- The powermenu widget
|
||||
local powermenu = wibox.widget {
|
||||
{
|
||||
{
|
||||
profile_picture,
|
||||
profile_name,
|
||||
spacing = dpi(50),
|
||||
layout = wibox.layout.fixed.vertical
|
||||
},
|
||||
{
|
||||
{
|
||||
shutdown_button,
|
||||
reboot_button,
|
||||
logout_button,
|
||||
lock_button,
|
||||
suspend_button,
|
||||
spacing = dpi(30),
|
||||
layout = wibox.layout.fixed.horizontal
|
||||
},
|
||||
halign = "center",
|
||||
valign = "center",
|
||||
widget = wibox.container.place
|
||||
},
|
||||
layout = wibox.layout.fixed.vertical
|
||||
},
|
||||
halign = "center",
|
||||
valign = "center",
|
||||
widget = wibox.container.place
|
||||
}
|
||||
|
||||
-- Container for the widget, covers the entire screen
|
||||
local powermenu_container = wibox {
|
||||
widget = powermenu,
|
||||
screen = s,
|
||||
type = "splash",
|
||||
visible = false,
|
||||
ontop = true,
|
||||
bg = Theme_config.powermenu.container_bg,
|
||||
height = s.geometry.height,
|
||||
width = s.geometry.width,
|
||||
x = s.geometry.x,
|
||||
y = s.geometry.y
|
||||
}
|
||||
|
||||
-- Close on rightclick
|
||||
powermenu_container:buttons(
|
||||
gears.table.join(
|
||||
awful.button(
|
||||
{},
|
||||
3,
|
||||
function()
|
||||
capi.awesome.emit_signal("module::powermenu:hide")
|
||||
end
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
-- Close on Escape
|
||||
local powermenu_keygrabber = awful.keygrabber {
|
||||
autostart = false,
|
||||
stop_event = 'release',
|
||||
keypressed_callback = function(self, mod, key, command)
|
||||
if key == 'Escape' then
|
||||
capi.awesome.emit_signal("module::powermenu:hide")
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
-- Signals
|
||||
capi.awesome.connect_signal(
|
||||
"module::powermenu:show",
|
||||
function()
|
||||
if s == capi.mouse.screen then
|
||||
powermenu_container.visible = true
|
||||
powermenu_keygrabber:start()
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
capi.awesome.connect_signal(
|
||||
"module::powermenu:hide",
|
||||
function()
|
||||
powermenu_keygrabber:stop()
|
||||
powermenu_container.visible = false
|
||||
end
|
||||
)
|
||||
end
|
||||
@@ -1,447 +0,0 @@
|
||||
-----------------------------------
|
||||
-- This is the titlebar module --
|
||||
-----------------------------------
|
||||
|
||||
-- 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,
|
||||
client = client
|
||||
}
|
||||
|
||||
-- Icon directory path
|
||||
local icondir = gears.filesystem.get_configuration_dir() .. "src/assets/icons/titlebar/"
|
||||
|
||||
awful.titlebar.enable_tooltip = true
|
||||
awful.titlebar.fallback_name = 'Client'
|
||||
|
||||
-- Normal AND Focus(active/inactive) have to be set or errors will appear in stdout
|
||||
Theme.titlebar_close_button_normal = icondir .. "close.svg"
|
||||
Theme.titlebar_close_button_focus = icondir .. "close.svg"
|
||||
Theme.titlebar_minimize_button_normal = icondir .. "minimize.svg"
|
||||
Theme.titlebar_minimize_button_focus = icondir .. "minimize.svg"
|
||||
Theme.titlebar_maximized_button_normal = icondir .. "maximize.svg"
|
||||
Theme.titlebar_maximized_button_active = icondir .. "maximize.svg"
|
||||
Theme.titlebar_maximized_button_inactive = icondir .. "maximize.svg"
|
||||
|
||||
local create_buttons = function(c)
|
||||
local buttons = gears.table.join(
|
||||
awful.button(
|
||||
{},
|
||||
1,
|
||||
function()
|
||||
c:activate { context = 'titlebar', action = 'mouse_move' }
|
||||
end
|
||||
),
|
||||
awful.button(
|
||||
{},
|
||||
3,
|
||||
function()
|
||||
c:activate { context = 'titlebar', action = 'mouse_resize' }
|
||||
end
|
||||
)
|
||||
)
|
||||
return buttons
|
||||
end
|
||||
|
||||
local create_titlebar = function(c, size, position)
|
||||
local close_button = awful.titlebar.widget.closebutton(c)
|
||||
local minimize_button = awful.titlebar.widget.minimizebutton(c)
|
||||
local maximize_button = awful.titlebar.widget.maximizedbutton(c)
|
||||
|
||||
local tb
|
||||
|
||||
if position == "left" then
|
||||
local titlebar = awful.titlebar(c, {
|
||||
position = "left",
|
||||
bg = Theme_config.titlebar.bg,
|
||||
size = size
|
||||
})
|
||||
|
||||
tb = wibox.widget {
|
||||
{
|
||||
{
|
||||
{
|
||||
close_button,
|
||||
widget = wibox.container.background,
|
||||
border_color = Theme_config.titlebar.close_button.border_color,
|
||||
border_width = dpi(2),
|
||||
shape = function(cr, height, width)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(6))
|
||||
end,
|
||||
id = "closebutton"
|
||||
},
|
||||
{
|
||||
maximize_button,
|
||||
widget = wibox.container.background,
|
||||
border_color = Theme_config.titlebar.maximize_button.border_color,
|
||||
border_width = dpi(2),
|
||||
shape = function(cr, height, width)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(6))
|
||||
end,
|
||||
id = "maximizebutton"
|
||||
},
|
||||
{
|
||||
minimize_button,
|
||||
widget = wibox.container.background,
|
||||
border_color = Theme_config.titlebar.minimize_button.border_color,
|
||||
border_width = dpi(2),
|
||||
shape = function(cr, height, width)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(6))
|
||||
end,
|
||||
id = "minimizebutton"
|
||||
},
|
||||
spacing = dpi(10),
|
||||
layout = wibox.layout.fixed.vertical,
|
||||
id = "spacing"
|
||||
},
|
||||
margins = dpi(5),
|
||||
widget = wibox.container.margin,
|
||||
id = "margin"
|
||||
},
|
||||
{
|
||||
buttons = create_buttons(c),
|
||||
layout = wibox.layout.flex.vertical
|
||||
},
|
||||
{
|
||||
awful.titlebar.widget.iconwidget(c),
|
||||
margins = dpi(5),
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
layout = wibox.layout.align.vertical,
|
||||
id = "main"
|
||||
}
|
||||
|
||||
titlebar:setup { tb, layout = wibox.layout.fixed.horizontal }
|
||||
|
||||
elseif position == "top" then
|
||||
local titlebar = awful.titlebar(c, {
|
||||
position = "top",
|
||||
bg = Theme_config.titlebar.bg,
|
||||
size = size
|
||||
})
|
||||
|
||||
tb = wibox.widget {
|
||||
{
|
||||
awful.titlebar.widget.iconwidget(c),
|
||||
margins = dpi(5),
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
{
|
||||
{
|
||||
awful.titlebar.widget.titlewidget(c),
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
layout = wibox.container.place,
|
||||
},
|
||||
buttons = create_buttons(c),
|
||||
fill_space = true,
|
||||
layout = wibox.layout.stack
|
||||
},
|
||||
{
|
||||
{
|
||||
{
|
||||
minimize_button,
|
||||
widget = wibox.container.background,
|
||||
border_color = Theme_config.titlebar.minimize_button.border_color,
|
||||
border_width = dpi(2),
|
||||
shape = function(cr, height, width)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(6))
|
||||
end,
|
||||
id = "minimizebutton"
|
||||
},
|
||||
{
|
||||
maximize_button,
|
||||
widget = wibox.container.background,
|
||||
border_color = Theme_config.titlebar.maximize_button.border_color,
|
||||
border_width = dpi(2),
|
||||
shape = function(cr, height, width)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(6))
|
||||
end,
|
||||
id = "maximizebutton"
|
||||
},
|
||||
{
|
||||
close_button,
|
||||
widget = wibox.container.background,
|
||||
border_color = Theme_config.titlebar.close_button.border_color,
|
||||
border_width = dpi(2),
|
||||
shape = function(cr, height, width)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(6))
|
||||
end,
|
||||
id = "closebutton"
|
||||
},
|
||||
spacing = dpi(10),
|
||||
layout = wibox.layout.fixed.horizontal,
|
||||
id = "spacing"
|
||||
},
|
||||
margins = dpi(5),
|
||||
widget = wibox.container.margin,
|
||||
id = "margin"
|
||||
},
|
||||
layout = wibox.layout.align.horizontal,
|
||||
id = "main"
|
||||
}
|
||||
|
||||
titlebar:setup { tb, layout = wibox.layout.fixed.vertical }
|
||||
end
|
||||
|
||||
if not tb then return end
|
||||
|
||||
close_button:connect_signal(
|
||||
"mouse::enter",
|
||||
function()
|
||||
c.border_color = Theme_config.titlebar.close_button.hover_border
|
||||
local cb = tb:get_children_by_id("closebutton")[1]
|
||||
cb.border_color = Theme_config.titlebar.close_button.hover_border
|
||||
cb.bg = Theme_config.titlebar.close_button.hover_bg
|
||||
end
|
||||
)
|
||||
|
||||
close_button:connect_signal(
|
||||
"mouse::leave",
|
||||
function()
|
||||
c.border_color = Theme_config.window.border_normal
|
||||
local cb = tb:get_children_by_id("closebutton")[1]
|
||||
cb.border_color = Theme_config.titlebar.close_button.border_color
|
||||
cb.bg = Theme_config.titlebar.close_button.bg
|
||||
end
|
||||
)
|
||||
|
||||
minimize_button:connect_signal(
|
||||
"mouse::enter",
|
||||
function()
|
||||
c.border_color = Theme_config.titlebar.minimize_button.hover_border
|
||||
local mb = tb:get_children_by_id("minimizebutton")[1]
|
||||
mb.border_color = Theme_config.titlebar.minimize_button.hover_border
|
||||
mb.bg = Theme_config.titlebar.minimize_button.hover_bg
|
||||
end
|
||||
)
|
||||
|
||||
minimize_button:connect_signal(
|
||||
"mouse::leave",
|
||||
function()
|
||||
c.border_color = Theme_config.window.border_normal
|
||||
local mb = tb:get_children_by_id("minimizebutton")[1]
|
||||
mb.border_color = Theme_config.titlebar.minimize_button.border_color
|
||||
mb.bg = Theme_config.titlebar.minimize_button.bg
|
||||
end
|
||||
)
|
||||
|
||||
maximize_button:connect_signal(
|
||||
"mouse::enter",
|
||||
function()
|
||||
c.border_color = Theme_config.titlebar.maximize_button.hover_border
|
||||
local mb = tb:get_children_by_id("maximizebutton")[1]
|
||||
mb.border_color = Theme_config.titlebar.maximize_button.hover_border
|
||||
mb.bg = Theme_config.titlebar.maximize_button.hover_bg
|
||||
end
|
||||
)
|
||||
|
||||
maximize_button:connect_signal(
|
||||
"mouse::leave",
|
||||
function()
|
||||
c.border_color = Theme_config.window.border_normal
|
||||
local mb = tb:get_children_by_id("maximizebutton")[1]
|
||||
mb.border_color = Theme_config.titlebar.maximize_button.border_color
|
||||
mb.bg = Theme_config.titlebar.maximize_button.bg
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
local create_titlebar_dialog_modal = function(c, size, position)
|
||||
local close_button = awful.titlebar.widget.closebutton(c)
|
||||
local minimize_button = awful.titlebar.widget.minimizebutton(c)
|
||||
local maximize_button = awful.titlebar.widget.maximizedbutton(c)
|
||||
|
||||
local tb
|
||||
|
||||
if position == "left" then
|
||||
local titlebar = awful.titlebar(c, {
|
||||
position = "left",
|
||||
bg = Theme_config.titlebar.bg,
|
||||
size = size
|
||||
})
|
||||
|
||||
tb = wibox.widget {
|
||||
{
|
||||
{
|
||||
close_button,
|
||||
widget = wibox.container.background,
|
||||
border_color = Theme_config.titlebar.close_button.border_color,
|
||||
border_width = dpi(2),
|
||||
shape = function(cr, height, width)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(6))
|
||||
end,
|
||||
id = "closebutton"
|
||||
},
|
||||
margins = dpi(5),
|
||||
widget = wibox.container.margin,
|
||||
id = "margin"
|
||||
},
|
||||
{
|
||||
buttons = create_buttons(c),
|
||||
layout = wibox.layout.flex.vertical
|
||||
},
|
||||
{
|
||||
awful.titlebar.widget.iconwidget(c),
|
||||
margins = dpi(5),
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
layout = wibox.layout.align.vertical,
|
||||
id = "main"
|
||||
}
|
||||
|
||||
titlebar:setup { tb, layout = wibox.layout.fixed.horizontal }
|
||||
|
||||
elseif position == "top" then
|
||||
local titlebar = awful.titlebar(c, {
|
||||
position = "top",
|
||||
bg = Theme_config.titlebar.bg,
|
||||
size = size
|
||||
})
|
||||
|
||||
tb = wibox.widget {
|
||||
{
|
||||
awful.titlebar.widget.iconwidget(c),
|
||||
margins = dpi(5),
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
{
|
||||
{
|
||||
awful.titlebar.widget.titlewidget(c),
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
layout = wibox.container.place,
|
||||
},
|
||||
buttons = create_buttons(c),
|
||||
fill_space = true,
|
||||
layout = wibox.layout.stack
|
||||
},
|
||||
{
|
||||
{
|
||||
close_button,
|
||||
widget = wibox.container.background,
|
||||
border_color = Theme_config.titlebar.close_button.border_color,
|
||||
border_width = dpi(2),
|
||||
shape = function(cr, height, width)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(6))
|
||||
end,
|
||||
id = "closebutton"
|
||||
},
|
||||
margins = dpi(5),
|
||||
widget = wibox.container.margin,
|
||||
id = "margin"
|
||||
},
|
||||
layout = wibox.layout.align.horizontal,
|
||||
id = "main"
|
||||
}
|
||||
|
||||
titlebar:setup { tb, layout = wibox.layout.fixed.vertical }
|
||||
end
|
||||
|
||||
if not tb then return end
|
||||
|
||||
close_button:connect_signal(
|
||||
"mouse::enter",
|
||||
function()
|
||||
c.border_color = Theme_config.titlebar.close_button.hover_border
|
||||
local cb = tb:get_children_by_id("closebutton")[1]
|
||||
cb.border_color = Theme_config.titlebar.close_button.hover_border
|
||||
cb.bg = Theme_config.titlebar.close_button.hover_bg
|
||||
end
|
||||
)
|
||||
|
||||
close_button:connect_signal(
|
||||
"mouse::leave",
|
||||
function()
|
||||
c.border_color = Theme_config.window.border_normal
|
||||
local cb = tb:get_children_by_id("closebutton")[1]
|
||||
cb.border_color = Theme_config.titlebar.close_button.border_color
|
||||
cb.bg = Theme_config.titlebar.close_button.bg
|
||||
end
|
||||
)
|
||||
|
||||
minimize_button:connect_signal(
|
||||
"mouse::enter",
|
||||
function()
|
||||
c.border_color = Theme_config.titlebar.minimize_button.hover_border
|
||||
local mb = tb:get_children_by_id("minimizebutton")[1]
|
||||
mb.border_color = Theme_config.titlebar.minimize_button.hover_border
|
||||
mb.bg = Theme_config.titlebar.minimize_button.hover_bg
|
||||
end
|
||||
)
|
||||
|
||||
minimize_button:connect_signal(
|
||||
"mouse::leave",
|
||||
function()
|
||||
c.border_color = Theme_config.window.border_normal
|
||||
local mb = tb:get_children_by_id("minimizebutton")[1]
|
||||
mb.border_color = Theme_config.titlebar.minimize_button.border_color
|
||||
mb.bg = Theme_config.titlebar.minimize_button.bg
|
||||
end
|
||||
)
|
||||
|
||||
maximize_button:connect_signal(
|
||||
"mouse::enter",
|
||||
function()
|
||||
c.border_color = Theme_config.titlebar.maximize_button.hover_border
|
||||
local mb = tb:get_children_by_id("maximizebutton")[1]
|
||||
mb.border_color = Theme_config.titlebar.maximize_button.hover_border
|
||||
mb.bg = Theme_config.titlebar.maximize_button.hover_bg
|
||||
end
|
||||
)
|
||||
|
||||
maximize_button:connect_signal(
|
||||
"mouse::leave",
|
||||
function()
|
||||
c.border_color = Theme_config.window.border_normal
|
||||
local mb = tb:get_children_by_id("maximizebutton")[1]
|
||||
mb.border_color = Theme_config.titlebar.maximize_button.border_color
|
||||
mb.bg = Theme_config.titlebar.maximize_button.bg
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
capi.client.connect_signal(
|
||||
"request::titlebars",
|
||||
function(c)
|
||||
if c.type == "dialog" then
|
||||
create_titlebar_dialog_modal(c, dpi(35), User_config.titlebar_position)
|
||||
elseif c.type == "modal" then
|
||||
create_titlebar_dialog_modal(c, dpi(35), User_config.titlebar_position)
|
||||
else
|
||||
create_titlebar(c, dpi(35), User_config.titlebar_position)
|
||||
end
|
||||
|
||||
if not c.floating or c.maximized or c.fullscreen then
|
||||
if User_config.titlebar_position == "left" then
|
||||
awful.titlebar.hide(c, "left")
|
||||
elseif User_config.titlebar_position == "top" then
|
||||
awful.titlebar.hide(c, "top")
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
capi.client.connect_signal(
|
||||
"property::floating",
|
||||
function(c)
|
||||
if c.floating and not (c.maximized or c.fullscreen) then
|
||||
if User_config.titlebar_position == "left" then
|
||||
awful.titlebar.show(c, "left")
|
||||
elseif User_config.titlebar_position == "top" then
|
||||
awful.titlebar.show(c, "top")
|
||||
end
|
||||
else
|
||||
if User_config.titlebar_position == "left" then
|
||||
awful.titlebar.hide(c, "left")
|
||||
elseif User_config.titlebar_position == "top" then
|
||||
awful.titlebar.hide(c, "top")
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
@@ -1,725 +0,0 @@
|
||||
-----------------------------------
|
||||
-- This is the volume controller --
|
||||
-----------------------------------
|
||||
|
||||
-- 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,
|
||||
mousegrabber = mousegrabber,
|
||||
}
|
||||
|
||||
local rubato = require("src.lib.rubato")
|
||||
|
||||
-- Icon directory path
|
||||
local icondir = gears.filesystem.get_configuration_dir() .. "src/assets/icons/audio/"
|
||||
|
||||
-- Returns the volume controller
|
||||
return function(s)
|
||||
|
||||
-- Function to create source/sink devices
|
||||
local function create_device(name, node, sink)
|
||||
local device = wibox.widget {
|
||||
{
|
||||
{
|
||||
{
|
||||
id = "icon",
|
||||
resize = false,
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
widget = wibox.widget.imagebox
|
||||
},
|
||||
spacing = dpi(10),
|
||||
{
|
||||
text = name,
|
||||
id = "node",
|
||||
widget = wibox.widget.textbox
|
||||
},
|
||||
id = "device_layout",
|
||||
layout = wibox.layout.fixed.horizontal
|
||||
},
|
||||
id = "device_margin",
|
||||
margins = dpi(9),
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
id = "background",
|
||||
bg = Theme_config.volume_controller.device_bg,
|
||||
border_color = Theme_config.volume_controller.device_border_color,
|
||||
border_width = Theme_config.volume_controller.device_border_width,
|
||||
shape = Theme_config.volume_controller.device_shape,
|
||||
widget = wibox.container.background
|
||||
}
|
||||
if sink == true then
|
||||
device:connect_signal(
|
||||
"button::press",
|
||||
function(_, _, _, key)
|
||||
if key == 1 then
|
||||
if node then
|
||||
awful.spawn("./.config/awesome/src/scripts/vol.sh set_sink " .. node)
|
||||
capi.awesome.emit_signal("update::bg_sink", node)
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
capi.awesome.connect_signal(
|
||||
"update::bg_sink",
|
||||
function(new_node)
|
||||
if node == new_node then
|
||||
device:get_children_by_id("icon")[1].image = gears.color.recolor_image(icondir .. "headphones.svg",
|
||||
Theme_config.volume_controller.device_icon_color)
|
||||
device.bg = Theme_config.volume_controller.device_headphones_selected_bg
|
||||
device.fg = Theme_config.volume_controller.device_headphones_selected_fg
|
||||
Hover_signal(device)
|
||||
else
|
||||
device:get_children_by_id("icon")[1].image = gears.color.recolor_image(icondir .. "headphones.svg",
|
||||
Theme_config.volume_controller.device_headphones_selected_icon_color)
|
||||
device.bg = Theme_config.volume_controller.device_bg
|
||||
device.fg = Theme_config.volume_controller.device_headphones_fg
|
||||
Hover_signal(device)
|
||||
end
|
||||
end
|
||||
)
|
||||
awful.spawn.easy_async_with_shell(
|
||||
[[ pactl get-default-sink ]],
|
||||
function(stdout)
|
||||
local node_active = stdout:gsub("\n", "")
|
||||
if node == node_active then
|
||||
device:get_children_by_id("icon")[1].image = gears.color.recolor_image(icondir .. "headphones.svg",
|
||||
Theme_config.volume_controller.device_icon_color)
|
||||
device.bg = Theme_config.volume_controller.device_headphones_selected_bg
|
||||
device.fg = Theme_config.volume_controller.device_headphones_selected_fg
|
||||
Hover_signal(device)
|
||||
else
|
||||
device:get_children_by_id("icon")[1].image = gears.color.recolor_image(icondir .. "headphones.svg",
|
||||
Theme_config.volume_controller.device_headphones_selected_icon_color)
|
||||
device.bg = Theme_config.volume_controller.device_bg
|
||||
device.fg = Theme_config.volume_controller.device_headphones_fg
|
||||
Hover_signal(device)
|
||||
end
|
||||
end
|
||||
)
|
||||
capi.awesome.emit_signal("update::bg_sink", node)
|
||||
else
|
||||
device:connect_signal(
|
||||
"button::press",
|
||||
function(_, _, _, key)
|
||||
if key == 1 then
|
||||
if node then
|
||||
awful.spawn("./.config/awesome/src/scripts/mic.sh set_source " .. node)
|
||||
capi.awesome.emit_signal("update::bg_source", node)
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
capi.awesome.connect_signal(
|
||||
"update::bg_source",
|
||||
function(new_node)
|
||||
if node == new_node then
|
||||
device:get_children_by_id("icon")[1].image = gears.color.recolor_image(icondir .. "microphone.svg",
|
||||
Theme_config.volume_controller.device_icon_color)
|
||||
device.bg = Theme_config.volume_controller.device_microphone_selected_bg
|
||||
device.fg = Theme_config.volume_controller.device_microphone_selected_fg
|
||||
Hover_signal(device)
|
||||
else
|
||||
device:get_children_by_id("icon")[1].image = gears.color.recolor_image(icondir .. "microphone.svg",
|
||||
Theme_config.volume_controller.device_microphone_selected_icon_color)
|
||||
device.bg = Theme_config.volume_controller.device_bg
|
||||
device.fg = Theme_config.volume_controller.device_microphone_fg
|
||||
Hover_signal(device)
|
||||
end
|
||||
end
|
||||
)
|
||||
awful.spawn.easy_async_with_shell(
|
||||
[[ pactl get-default-source ]],
|
||||
function(stdout)
|
||||
local node_active = stdout:gsub("\n", "")
|
||||
if node == node_active then
|
||||
device:get_children_by_id("icon")[1].image = gears.color.recolor_image(icondir .. "microphone.svg",
|
||||
Theme_config.volume_controller.device_icon_color)
|
||||
device.bg = Theme_config.volume_controller.device_microphone_selected_bg
|
||||
device.fg = Theme_config.volume_controller.device_microphone_selected_fg
|
||||
Hover_signal(device)
|
||||
else
|
||||
device:get_children_by_id("icon")[1].image = gears.color.recolor_image(icondir .. "microphone.svg",
|
||||
Theme_config.volume_controller.device_microphone_selected_icon_color)
|
||||
device.bg = Theme_config.volume_controller.device_bg
|
||||
device.fg = Theme_config.volume_controller.device_microphone_fg
|
||||
Hover_signal(device)
|
||||
end
|
||||
end
|
||||
)
|
||||
capi.awesome.emit_signal("update::bg_source", node)
|
||||
end
|
||||
return device
|
||||
end
|
||||
|
||||
-- Container for the source devices
|
||||
local dropdown_list_volume = wibox.widget {
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
spacing = dpi(10),
|
||||
layout = require("src.lib.overflow_widget.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 = Theme_config.volume_controller.list_border_color,
|
||||
border_width = Theme_config.volume_controller.list_border_width,
|
||||
id = "volume_device_background",
|
||||
shape = Theme_config.volume_controller.list_shape,
|
||||
widget = wibox.container.background
|
||||
},
|
||||
left = dpi(10),
|
||||
right = dpi(10),
|
||||
widget = wibox.container.margin
|
||||
}
|
||||
|
||||
-- Container for the sink devices
|
||||
local dropdown_list_microphone = wibox.widget {
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
spacing = dpi(10),
|
||||
layout = require("src.lib.overflow_widget.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",
|
||||
border_color = Theme_config.volume_controller.list_border_color,
|
||||
border_width = Theme_config.volume_controller.list_border_width,
|
||||
shape = Theme_config.volume_controller.list_shape,
|
||||
widget = wibox.container.background
|
||||
},
|
||||
left = dpi(10),
|
||||
right = dpi(10),
|
||||
widget = wibox.container.margin
|
||||
}
|
||||
|
||||
local volume_controller = wibox.widget {
|
||||
{
|
||||
{
|
||||
-- Audio Device selector
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
resize = false,
|
||||
image = gears.color.recolor_image(icondir .. "menu-down.svg",
|
||||
Theme_config.volume_controller.device_headphones_selected_icon_color),
|
||||
widget = wibox.widget.imagebox,
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
id = "icon"
|
||||
},
|
||||
id = "center",
|
||||
halign = "center",
|
||||
valign = "center",
|
||||
widget = wibox.container.place,
|
||||
},
|
||||
{
|
||||
{
|
||||
text = "Output Device",
|
||||
widget = wibox.widget.textbox,
|
||||
id = "device_name"
|
||||
},
|
||||
margins = dpi(5),
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
id = "audio_volume",
|
||||
layout = wibox.layout.fixed.horizontal
|
||||
},
|
||||
id = "audio_bg",
|
||||
bg = Theme_config.volume_controller.list_bg,
|
||||
fg = Theme_config.volume_controller.list_headphones_fg,
|
||||
shape = Theme_config.volume_controller.list_shape,
|
||||
widget = wibox.container.background
|
||||
},
|
||||
id = "audio_selector_margin",
|
||||
left = dpi(10),
|
||||
right = dpi(10),
|
||||
top = dpi(10),
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
{
|
||||
id = "volume_list",
|
||||
widget = dropdown_list_volume,
|
||||
forced_height = 0
|
||||
},
|
||||
-- Microphone selector
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
resize = false,
|
||||
image = gears.color.recolor_image(icondir .. "menu-down.svg",
|
||||
Theme_config.volume_controller.device_microphone_selected_icon_color),
|
||||
widget = wibox.widget.imagebox,
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
id = "icon",
|
||||
},
|
||||
id = "center",
|
||||
halign = "center",
|
||||
valign = "center",
|
||||
widget = wibox.container.place,
|
||||
},
|
||||
{
|
||||
{
|
||||
text = "Input Device",
|
||||
widget = wibox.widget.textbox,
|
||||
id = "device_name"
|
||||
},
|
||||
margins = dpi(5),
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
id = "mic_volume",
|
||||
layout = wibox.layout.fixed.horizontal
|
||||
},
|
||||
id = "mic_bg",
|
||||
bg = Theme_config.volume_controller.list_bg,
|
||||
fg = Theme_config.volume_controller.list_microphone_fg,
|
||||
shape = Theme_config.volume_controller.selector_shape,
|
||||
widget = wibox.container.background
|
||||
},
|
||||
id = "mic_selector_margin",
|
||||
left = dpi(10),
|
||||
right = dpi(10),
|
||||
top = dpi(10),
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
{
|
||||
id = "mic_list",
|
||||
widget = dropdown_list_microphone,
|
||||
forced_height = 0
|
||||
},
|
||||
-- Audio volume slider
|
||||
{
|
||||
{
|
||||
{
|
||||
resize = false,
|
||||
widget = wibox.widget.imagebox,
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
image = gears.color.recolor_image(icondir .. "volume-high.svg", Theme_config.volume_controller.volume_fg),
|
||||
id = "icon",
|
||||
},
|
||||
{
|
||||
{
|
||||
bar_shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(5))
|
||||
end,
|
||||
bar_height = dpi(5),
|
||||
bar_color = Theme_config.volume_controller.border_color,
|
||||
bar_active_color = Theme_config.volume_controller.volume_fg,
|
||||
handle_color = Theme_config.volume_controller.volume_fg,
|
||||
handle_shape = gears.shape.circle,
|
||||
handle_border_color = Theme_config.volume_controller.volume_fg,
|
||||
handle_width = dpi(12),
|
||||
maximum = 100,
|
||||
forced_height = dpi(26),
|
||||
widget = wibox.widget.slider,
|
||||
id = "slider"
|
||||
},
|
||||
left = dpi(5),
|
||||
id = "slider_margin",
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
id = "audio_volume",
|
||||
layout = wibox.layout.align.horizontal
|
||||
},
|
||||
id = "audio_volume_margin",
|
||||
top = dpi(10),
|
||||
left = dpi(10),
|
||||
right = dpi(10),
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
-- Microphone volume slider
|
||||
{
|
||||
{
|
||||
{
|
||||
resize = false,
|
||||
widget = wibox.widget.imagebox,
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
image = gears.color.recolor_image(icondir .. "microphone.svg", Theme_config.volume_controller.microphone_fg),
|
||||
id = "icon"
|
||||
},
|
||||
{
|
||||
{
|
||||
bar_shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(5))
|
||||
end,
|
||||
bar_height = dpi(5),
|
||||
bar_color = Theme_config.volume_controller.device_border_color,
|
||||
bar_active_color = Theme_config.volume_controller.microphone_fg,
|
||||
handle_color = Theme_config.volume_controller.microphone_fg,
|
||||
handle_shape = gears.shape.circle,
|
||||
handle_border_color = Theme_config.volume_controller.microphone_fg,
|
||||
handle_width = dpi(12),
|
||||
maximum = 100,
|
||||
forced_height = dpi(26),
|
||||
widget = wibox.widget.slider,
|
||||
id = "slider"
|
||||
},
|
||||
left = dpi(5),
|
||||
id = "slider_margin",
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
id = "mic_volume",
|
||||
layout = wibox.layout.align.horizontal
|
||||
},
|
||||
id = "mic_volume_margin",
|
||||
left = dpi(10),
|
||||
right = dpi(10),
|
||||
top = dpi(10),
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
id = "controller_layout",
|
||||
layout = wibox.layout.fixed.vertical
|
||||
},
|
||||
id = "controller_margin",
|
||||
margins = dpi(10),
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
bg = Theme_config.volume_controller.bg,
|
||||
border_color = Theme_config.volume_controller.border_color,
|
||||
border_width = Theme_config.volume_controller.border_width,
|
||||
shape = Theme_config.volume_controller.shape,
|
||||
forced_width = dpi(400),
|
||||
widget = wibox.container.background
|
||||
}
|
||||
|
||||
-- Variables for easier access and better readability
|
||||
local audio_selector_margin = volume_controller:get_children_by_id("audio_selector_margin")[1]
|
||||
local volume_list = volume_controller:get_children_by_id("volume_list")[1]
|
||||
local audio_bg = volume_controller:get_children_by_id("audio_bg")[1]
|
||||
local audio_volume = volume_controller:get_children_by_id("audio_volume")[1].center
|
||||
|
||||
-- Click event for the audio dropdown
|
||||
audio_selector_margin:connect_signal(
|
||||
"button::press",
|
||||
function(_, _, _, key)
|
||||
if key == 1 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, dpi(4))
|
||||
end
|
||||
audio_volume.icon:set_image(gears.color.recolor_image(icondir .. "menu-up.svg",
|
||||
Theme_config.volume_controller.device_headphones_selected_icon_color))
|
||||
else
|
||||
rubato_timer.target = 0
|
||||
audio_bg.shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(4))
|
||||
end
|
||||
audio_volume.icon:set_image(gears.color.recolor_image(icondir .. "menu-down.svg",
|
||||
Theme_config.volume_controller.device_headphones_selected_icon_color))
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
-- Variables for easier access and better readability
|
||||
local mic_selector_margin = volume_controller:get_children_by_id("mic_selector_margin")[1]
|
||||
local mic_list = volume_controller:get_children_by_id("mic_list")[1]
|
||||
local mic_bg = volume_controller:get_children_by_id("mic_bg")[1]
|
||||
local mic_volume = volume_controller:get_children_by_id("mic_volume")[1].center
|
||||
|
||||
-- Click event for the microphone dropdown
|
||||
mic_selector_margin:connect_signal(
|
||||
"button::press",
|
||||
function(_, _, _, key)
|
||||
if key == 1 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, dpi(4))
|
||||
end
|
||||
mic_volume.icon:set_image(gears.color.recolor_image(icondir .. "menu-up.svg",
|
||||
Theme_config.volume_controller.device_microphone_selected_icon_color))
|
||||
else
|
||||
rubato_timer.target = 0
|
||||
mic_bg.shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(4))
|
||||
end
|
||||
mic_volume.icon:set_image(gears.color.recolor_image(icondir .. "menu-down.svg",
|
||||
Theme_config.volume_controller.device_microphone_selected_icon_color))
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
local audio_slider_margin = volume_controller:get_children_by_id("audio_volume_margin")[1].audio_volume.slider_margin.slider
|
||||
|
||||
-- Volume slider change event
|
||||
audio_slider_margin:connect_signal(
|
||||
"property::value",
|
||||
function()
|
||||
awful.spawn.with_shell("pactl set-sink-volume @DEFAULT_SINK@ " .. tonumber(audio_slider_margin.value) .. "%")
|
||||
end
|
||||
)
|
||||
|
||||
local mic_slider_margin = volume_controller:get_children_by_id("mic_volume_margin")[1].mic_volume.slider_margin.slider
|
||||
|
||||
-- Microphone slider change event
|
||||
mic_slider_margin:connect_signal(
|
||||
"property::value",
|
||||
function()
|
||||
awful.spawn("pactl set-source-volume @DEFAULT_SOURCE@ " .. tonumber(mic_slider_margin.value) .. "%")
|
||||
end
|
||||
)
|
||||
|
||||
-- Main container
|
||||
local volume_controller_container = awful.popup {
|
||||
widget = wibox.container.background,
|
||||
ontop = true,
|
||||
bg = Theme_config.volume_controller.bg,
|
||||
stretch = false,
|
||||
visible = false,
|
||||
screen = s,
|
||||
placement = function(c) awful.placement.align(c,
|
||||
{ position = "top_right", margins = { right = dpi(305), top = dpi(60) } })
|
||||
end,
|
||||
shape = Theme_config.volume_controller.shape,
|
||||
}
|
||||
|
||||
-- Get all source devices
|
||||
local function get_source_devices()
|
||||
awful.spawn.easy_async_with_shell(
|
||||
[[
|
||||
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 = {}
|
||||
local was_alsa = false
|
||||
local node_names, alsa_names = {}, {}
|
||||
for val in stdout:gmatch("[^\n]+") do
|
||||
if val:match("alsa%.card_name") then
|
||||
table.insert(alsa_names, val:match("alsa%.card_name%s=%s(.*)"))
|
||||
was_alsa = true
|
||||
elseif val:match("device%.description") and not was_alsa then
|
||||
table.insert(alsa_names, val:match("device%.description%s=%s(.*)"))
|
||||
was_alsa = false
|
||||
else
|
||||
was_alsa = false
|
||||
end
|
||||
|
||||
if val:match("node%.name") then
|
||||
table.insert(node_names, val:match("node%.name%s=%s(.*)"))
|
||||
end
|
||||
end
|
||||
|
||||
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:get_children_by_id("volume_device_list")[1].children = device_list
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
-- Get all input devices
|
||||
local function get_input_devices()
|
||||
awful.spawn.easy_async_with_shell(
|
||||
[[
|
||||
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 = {}
|
||||
local was_alsa = false
|
||||
local node_names, alsa_names = {}, {}
|
||||
|
||||
for val in stdout:gmatch("[^\n]+") do
|
||||
if val:match("alsa%.card_name") then
|
||||
table.insert(alsa_names, val:match("alsa%.card_name%s=%s(.*)"))
|
||||
was_alsa = true
|
||||
elseif val:match("device%.description") and not was_alsa then
|
||||
table.insert(alsa_names, val:match("device%.description%s=%s(.*)"))
|
||||
was_alsa = false
|
||||
else
|
||||
was_alsa = false
|
||||
end
|
||||
|
||||
if val:match("node%.name") then
|
||||
table.insert(node_names, val:match("node%.name%s=%s(.*)"))
|
||||
end
|
||||
end
|
||||
|
||||
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:get_children_by_id("volume_device_list")[1].children = device_list
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
capi.awesome.connect_signal(
|
||||
"audio::device_changed",
|
||||
function()
|
||||
get_input_devices()
|
||||
end
|
||||
)
|
||||
|
||||
capi.awesome.connect_signal(
|
||||
|
||||
"microphone::device_changed",
|
||||
function()
|
||||
get_source_devices()
|
||||
end
|
||||
)
|
||||
|
||||
-- Set the volume and icon
|
||||
capi.awesome.connect_signal(
|
||||
|
||||
"audio::get",
|
||||
function(muted, volume)
|
||||
if muted then
|
||||
volume_controller.controller_margin.controller_layout.audio_volume_margin.audio_volume.icon:set_image(gears.color
|
||||
.recolor_image(icondir .. "volume-mute.svg", Theme_config.volume_controller.volume_fg))
|
||||
else
|
||||
volume = tonumber(volume)
|
||||
if not volume then
|
||||
return
|
||||
end
|
||||
local icon = icondir .. "volume"
|
||||
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
|
||||
|
||||
volume_controller.controller_margin.controller_layout.audio_volume_margin.audio_volume.slider_margin.slider:
|
||||
set_value(volume)
|
||||
volume_controller.controller_margin.controller_layout.audio_volume_margin.audio_volume.icon:set_image(gears.color
|
||||
.recolor_image(icon
|
||||
.. ".svg", Theme_config.volume_controller.volume_fg))
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
-- Get microphone volume
|
||||
capi.awesome.connect_signal(
|
||||
"microphone::get",
|
||||
function(muted, volume)
|
||||
if muted then
|
||||
--volume_controller:get_children_by_id("mic_volume_margin")[1].mic_volume.slider_margin.slider:set_value(tonumber(0))
|
||||
volume_controller:get_children_by_id("mic_volume_margin")[1].mic_volume.icon:set_image(gears.color.recolor_image(icondir
|
||||
.. "microphone-off.svg", Theme_config.volume_controller.microphone_fg))
|
||||
else
|
||||
volume = tonumber(volume)
|
||||
if not volume then
|
||||
return
|
||||
end
|
||||
volume_controller:get_children_by_id("mic_volume_margin")[1].mic_volume.slider_margin.slider:set_value(tonumber(volume))
|
||||
if volume > 0 then
|
||||
volume_controller:get_children_by_id("mic_volume_margin")[1].mic_volume.icon:set_image(gears.color.recolor_image(icondir
|
||||
.. "microphone.svg", Theme_config.volume_controller.microphone_fg))
|
||||
else
|
||||
volume_controller:get_children_by_id("mic_volume_margin")[1].mic_volume.icon:set_image(gears.color.recolor_image(icondir
|
||||
.. "microphone-off.svg", Theme_config.volume_controller.microphone_fg))
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
-- When the mouse leaves the popup it stops the mousegrabber and hides the popup.
|
||||
volume_controller_container:connect_signal(
|
||||
"mouse::leave",
|
||||
function()
|
||||
capi.mousegrabber.run(
|
||||
function()
|
||||
capi.awesome.emit_signal("volume_controller::toggle", s)
|
||||
capi.mousegrabber.stop()
|
||||
return true
|
||||
end,
|
||||
"arrow"
|
||||
)
|
||||
end
|
||||
)
|
||||
|
||||
volume_controller_container:connect_signal(
|
||||
"mouse::enter",
|
||||
function()
|
||||
capi.mousegrabber.stop()
|
||||
end
|
||||
)
|
||||
|
||||
-- Grabs all keys and hides popup when anything is pressed
|
||||
-- TODO: Make it possible to navigate and select using the kb
|
||||
awful.keygrabber {
|
||||
autostart = false,
|
||||
stop_event = 'release',
|
||||
keypressed_callback = function()
|
||||
capi.awesome.emit_signal("volume_controller::toggle", s)
|
||||
capi.mousegrabber.stop()
|
||||
end
|
||||
}
|
||||
|
||||
-- Draw the popup
|
||||
volume_controller_container:setup {
|
||||
volume_controller,
|
||||
layout = wibox.layout.fixed.horizontal
|
||||
}
|
||||
|
||||
-- Toggle container visibility
|
||||
capi.awesome.connect_signal(
|
||||
"volume_controller::toggle",
|
||||
function(scr)
|
||||
if scr == s then
|
||||
volume_controller_container.visible = not volume_controller_container.visible
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
end
|
||||
@@ -1,147 +0,0 @@
|
||||
-----------------------------------
|
||||
-- This is the volume_old module --
|
||||
-----------------------------------
|
||||
|
||||
-- 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/audio/"
|
||||
|
||||
-- Returns the volume_osd
|
||||
return function(s)
|
||||
|
||||
local volume_osd_widget = wibox.widget {
|
||||
{
|
||||
{
|
||||
{ -- Volume Icon
|
||||
image = gears.color.recolor_image(icondir .. "volume-high.svg", Theme_config.volume_osd.icon_color),
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
resize = false,
|
||||
id = "icon",
|
||||
widget = wibox.widget.imagebox
|
||||
},
|
||||
{ -- Volume Bar
|
||||
{
|
||||
{
|
||||
id = "progressbar1",
|
||||
color = Theme_config.volume_osd.bar_bg_active,
|
||||
background_color = Theme_config.volume_osd.bar_bg,
|
||||
max_value = 100,
|
||||
value = 50,
|
||||
forced_height = dpi(6),
|
||||
shape = function(cr, width, heigth)
|
||||
gears.shape.rounded_bar(cr, width, heigth, dpi(6))
|
||||
end,
|
||||
widget = wibox.widget.progressbar
|
||||
},
|
||||
id = "progressbar_container2",
|
||||
halign = "center",
|
||||
valign = "center",
|
||||
widget = wibox.container.place
|
||||
},
|
||||
id = "progressbar_container",
|
||||
width = dpi(240),
|
||||
heigth = dpi(20),
|
||||
stragety = "max",
|
||||
widget = wibox.container.constraint
|
||||
},
|
||||
id = "layout1",
|
||||
spacing = dpi(10),
|
||||
layout = wibox.layout.fixed.horizontal
|
||||
},
|
||||
id = "margin",
|
||||
margins = dpi(10),
|
||||
widget = wibox.container.margin
|
||||
},
|
||||
forced_width = dpi(300),
|
||||
forced_height = dpi(80),
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(12))
|
||||
end,
|
||||
border_color = Theme_config.volume_osd.border_color,
|
||||
border_width = Theme_config.volume_osd.border_width,
|
||||
fg = Theme_config.volume_osd.fg,
|
||||
bg = Theme_config.volume_osd.bg,
|
||||
widget = wibox.container.background
|
||||
}
|
||||
|
||||
capi.awesome.connect_signal(
|
||||
"audio::get",
|
||||
function(muted, volume)
|
||||
if muted then
|
||||
volume_osd_widget:get_children_by_id("icon")[1]
|
||||
:set_image(gears.color.recolor_image(
|
||||
icondir .. "volume-mute" .. ".svg", Theme_config.volume_osd.icon_color))
|
||||
volume_osd_widget:get_children_by_id("progressbar1")[1].value = tonumber(0)
|
||||
else
|
||||
volume = tonumber(volume)
|
||||
if not volume then
|
||||
return
|
||||
end
|
||||
volume_osd_widget:get_children_by_id("progressbar1")[1].value = tonumber(volume)
|
||||
local icon = icondir .. "volume"
|
||||
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
|
||||
volume_osd_widget:get_children_by_id("icon")[1]:set_image(gears.color.recolor_image(icon .. ".svg",
|
||||
Theme_config.volume_osd.icon_color))
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
|
||||
local volume_container = awful.popup {
|
||||
widget = {},
|
||||
ontop = true,
|
||||
stretch = false,
|
||||
visible = false,
|
||||
screen = s,
|
||||
placement = function(c) awful.placement.bottom_left(c, { margins = dpi(20) }) end,
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(14))
|
||||
end
|
||||
}
|
||||
|
||||
local hide_volume_osd = gears.timer {
|
||||
timeout = 2,
|
||||
autostart = true,
|
||||
callback = function()
|
||||
volume_container.visible = false
|
||||
end
|
||||
}
|
||||
|
||||
volume_container:setup {
|
||||
volume_osd_widget,
|
||||
layout = wibox.layout.fixed.horizontal
|
||||
}
|
||||
|
||||
capi.awesome.connect_signal(
|
||||
"widget::volume_osd:rerun",
|
||||
function()
|
||||
if capi.mouse.screen == s then
|
||||
volume_container.visible = true
|
||||
if hide_volume_osd.started then
|
||||
hide_volume_osd:again()
|
||||
else
|
||||
hide_volume_osd:start()
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
Reference in New Issue
Block a user