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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user