Add application launcher and rewritten window switcher, remove rofi as its no longer needed and replaced by widgets. Fixed a lot of bugs and weird behaviour

This commit is contained in:
Rene
2022-07-29 13:21:56 +02:00
parent b2e22fdf8a
commit e727015e81
35 changed files with 964 additions and 639 deletions

View File

@@ -1,6 +1,8 @@
local gears = require("gears")
local GLib = require("lgi").GLib
local m = {}
---Will return every $XDG_DATA_DIRS
---@return table
local function get_paths()
@@ -18,13 +20,98 @@ local function get_paths()
return dirs
end
---Returns every found .desktop file that has NoDesktop=false or unset
---@return table
function m.Get_all_visible_desktop()
local dirs = get_paths()
local desktops = {}
for _, dir in ipairs(dirs) do
local files = io.popen('find "' .. dir .. '" -type f,l')
if files then
for file in files:lines() do
if gears.filesystem.file_readable(file) then
--[[ local symlink = lfs.symlinkattributes(file, "target")
if symlink then
file = dir .. symlink
end ]]
local handler = io.open(file, "r")
if not handler then
return {}
end
while true do
local line = handler:read()
if not line then break end
if line:match("^%[Desktop Entry%]") then
local name, comment, icon, exec, keywords, terminal, categories, nodisplay = "", "", "", "", "", "", "",
false
while true do
local prop = handler:read() or nil
if ((not prop) and name ~= "") or prop:match("^%[(.+)%]") then
local desktop_table = {
name = name or "",
comment = comment or "",
icon = icon or "",
exec = exec or "",
keywords = keywords or "",
terminal = terminal or false,
categories = categories or "",
nodisplay = nodisplay or false,
file = file
}
table.insert(desktops, desktop_table)
break
end
if prop:match("^Name=") then
name = prop:match("Name=(.+)")
end
if prop:match("^Comment=") then
comment = prop:match("Comment=(.+)")
end
if prop:match("^Icon=") then
icon = prop:match("Icon=(.+)")
end
if prop:match("^Exec=") then
exec = prop:match("Exec=(.+)"):gsub("%%u", ""):gsub("%%U", ""):gsub("%%f", ""):gsub("%%F", ""):gsub("%%i"
, ""):gsub("%%c", ""):gsub("%%k", "")
end
if prop:match("^Keywords=") then
keywords = prop:match("Keywords=(.+)")
end
if prop:match("^Terminal=") then
terminal = prop:match("Terminal=(.+)")
end
if prop:match("^Categories=") then
categories = prop:match("Categories=(.+)")
end
if prop:match("^NoDisplay=") then
nodisplay = prop:match("NoDisplay=(.+)")
if nodisplay == "false" then
nodisplay = false
else
nodisplay = true
end
end
end
break
end
end
handler:close()
end
end
files:close()
end
end
return desktops
end
---Returns every .desktop file into a table
---@param file table .desktop files
---@return table
return function(file)
function m.Get_desktop_values(file)
if not file or file == "" then
return
return {}
end
local handler = nil
@@ -37,7 +124,7 @@ return function(file)
end
if not handler then
return
return {}
end
local desktop_table = {}
@@ -48,7 +135,7 @@ return function(file)
break
end
if line:match("[Desktop Entry]") then
if line:match("^%[Desktop Entry%]") then
while true do
local property = handler:read()
if not property then
@@ -62,13 +149,17 @@ return function(file)
if property:match("^Name=") then
desktop_table["Name"] = property:match("Name=(.+)")
elseif property:match("^Exec") then
-- Second match is to remove the %u and %F some applications use to open a URI. It's not needed here
desktop_table["Exec"] = property:match("Exec=(.+)"):gsub("%%u", ""):gsub("%%F", "")
-- Second match is to remove the %u, %U and %f, %F some applications use to open a URI/URL. It's not needed here
desktop_table["Exec"] = property:match("Exec=(.+)"):gsub("%%u", ""):gsub("%%U", ""):gsub("%%f", ""):gsub("%%F"
, ""):gsub("%%i", ""):gsub("%%c", ""):gsub("%%k", "")
elseif property:match("^Icon=") then
desktop_table["Icon"] = property:match("Icon=(.+)")
end
end
end
end
handler:close()
return desktop_table
end
return m

View File

@@ -35,6 +35,9 @@ awesome.connect_signal(
awful.spawn.easy_async_with_shell(
"./.config/awesome/src/scripts/vol.sh mute",
function(stdout)
if stdout == "" or stdout == nil then
return
end
local muted = false
if stdout:match("yes") then
muted = true
@@ -42,6 +45,9 @@ awesome.connect_signal(
awful.spawn.easy_async_with_shell(
"./.config/awesome/src/scripts/vol.sh volume",
function(stdout2)
if stdout == "" or stdout == nil then
return
end
awesome.emit_signal("audio::get", muted, stdout2:gsub("%%", ""):gsub("\n", "") or 0)
end
)
@@ -63,6 +69,9 @@ awesome.connect_signal(
awful.spawn.easy_async_with_shell(
"./.config/awesome/src/scripts/mic.sh volume",
function(stdout2)
if stdout2 == nil or stdout2 == "awful" then
return
end
awesome.emit_signal("microphone::get", muted, stdout2:gsub("%%", ""):gsub("\n", "") or 0)
end
)

View File

@@ -6,9 +6,22 @@ watch(
3,
function(_, stdout)
local temp = tonumber(stdout:match("%d+"))
awesome.emit_signal(
"update::cpu_temp",
temp
)
if not temp or temp == "" then
awful.spawn.easy_async_with_shell(
"paste <(cat /sys/class/thermal/thermal_zone*/type) <(cat /sys/class/thermal/thermal_zone*/temp)",
function(stdout2)
temp = math.floor((tonumber(stdout2:match("x86_pkg_temp(.%d+)")) / 1000) + 0.5)
awesome.emit_signal(
"update::cpu_temp",
temp
)
end
)
else
awesome.emit_signal(
"update::cpu_temp",
temp
)
end
end
)

View File

@@ -0,0 +1,8 @@
function RGB_to_hex(r, g, b)
r = r or 0
g = g or 0
b = b or 0
return string.format("#%02X%02X%02X", math.floor((r * 255) + 0.5), math.floor((g * 255) + 0.5),
math.floor((b * 255) + 0.5))
end

View File

@@ -67,7 +67,7 @@ end
---Look for an fallback icon
---@param iconname any
---@return string
---@return string|nil nil
local function lookup_fallback_icon(self, iconname)
for _, dir in ipairs(self.base_directories) do
for _, ext in ipairs(self.file_extension) do
@@ -77,6 +77,7 @@ local function lookup_fallback_icon(self, iconname)
end
end
end
return nil
end
---Checkes if the size equals the actual icon size
@@ -133,7 +134,7 @@ end
---Checks each and every sub directory for an icon
---@param iconname any
---@param size any
---@return string path_to_icon
---@return string|unknown|nil path_to_icon
local function lookup_icon(self, iconname, size)
local already_checked = {}
for _, subdir in ipairs(self.theme_index:get_subdirectories()) do
@@ -175,21 +176,23 @@ end
---@param icon any
---@param size any
---@param self any
---@return string path_to_icon
---@return string|unknown|nil path_to_icon
local function find_icon_helper(self, icon, size)
local filename = lookup_icon(self, icon, size)
if filename then return filename end
-- Exists purely for clients in hope to find a matching icon.
filename = lookup_icon(self, icon:lower(), size)
if filename then return filename end
for _, parent in ipairs(self.theme_index:get_inherits()) do
-- !Disabled for now until memory leak can be fixed.
--[[ for _, parent in ipairs(self.theme_index:get_inherits()) do
if parent == "hicolor" then
return
end
filename = find_icon_helper(xdg_icon_lookup(parent, self.base_directories), icon, size)
if filename then return filename end
end
end ]]
return nil
end
@@ -198,14 +201,21 @@ local iconcache = {}
---Takes an icon and its props and theme to search for it inside the theme
---@param icon any
---@param size any
---@return string path_to_icon
---@return string|nil path_to_icon
function xdg_icon_lookup:find_icon(icon, size)
size = size or 64
if icon_cache[icon] == "" then return nil end
if iconcache[icon] then return iconcache[icon] end
if not icon or icon == "" then return nil end
if gears.filesystem.file_readable(icon) then
iconcache[icon] = icon
return icon
end
local filename = find_icon_helper(self, icon, size)
if filename then
iconcache[icon] = filename