Skip to content

Commit

Permalink
removing what is useless
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomashighbaugh committed Mar 17, 2024
1 parent e8a0e44 commit ea212d8
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 138 deletions.
60 changes: 20 additions & 40 deletions plugins/bling/helpers/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ local _client = {}
--
-- @param c A client
function _client.turn_off(c, current_tag)
if current_tag == nil then
current_tag = c.screen.selected_tag
end
current_tag = current_tag or c.screen.selected_tag
local ctags = {}
for k, tag in pairs(c:tags()) do
for _, tag in ipairs(c:tags()) do
if tag ~= current_tag then
table.insert(ctags, tag)
end
Expand All @@ -26,8 +24,8 @@ end
-- @param c A client
function _client.turn_on(c)
local current_tag = c.screen.selected_tag
ctags = { current_tag }
for k, tag in pairs(c:tags()) do
local ctags = { current_tag }
for _, tag in ipairs(c:tags()) do
if tag ~= current_tag then
table.insert(ctags, tag)
end
Expand All @@ -42,13 +40,7 @@ end
-- @param to_c The client to which to write all properties
-- @param from_c The client from which to read all properties
function _client.sync(to_c, from_c)
if not from_c or not to_c then
return
end
if not from_c.valid or not to_c.valid then
return
end
if from_c.modal then
if not from_c or not to_c or not from_c.valid or not to_c.valid or from_c.modal then
return
end
to_c.floating = from_c.floating
Expand All @@ -58,69 +50,57 @@ function _client.sync(to_c, from_c)
to_c:geometry(from_c:geometry())
end

--- Checks whether the passed client is a childprocess of a given process ID
--- Checks whether the passed client is a child process of a given process ID
--
-- @param c A client
-- @param pid The process ID
-- @return True if the passed client is a childprocess of the given PID otherwise false
-- @return True if the passed client is a child process of the given PID otherwise false
function _client.is_child_of(c, pid)
-- io.popen is normally discouraged. Should probably be changed
if not c or not c.valid then
return false
end
if tostring(c.pid) == tostring(pid) then
return true
end
local pid_cmd = [[pstree -T -p -a -s ]]
.. tostring(c.pid)
.. [[ | sed '2q;d' | grep -o '[0-9]*$' | tr -d '\n']]
local pid_cmd = "pstree -T -p -a -s " .. tostring(c.pid) .. " | sed '2q;d' | grep -o '[0-9]*$' | tr -d '\n'"
local handle = io.popen(pid_cmd)
local parent_pid = handle:read("*a")
handle:close()
return tostring(parent_pid) == tostring(pid)
or tostring(parent_pid) == tostring(c.pid)
return tostring(parent_pid) == tostring(pid) or tostring(parent_pid) == tostring(c.pid)
end

--- Finds all clients that satisfy the passed rule
--
-- @param rule The rule to be searched for
-- @retrun A list of clients that match the given rule
-- @return A list of clients that match the given rule
function _client.find(rule)
local function matcher(c)
return awful.rules.match(c, rule)
end
local clients = client.get()
local findex = gears.table.hasitem(clients, client.focus) or 1
local start = gears.math.cycle(#clients, findex + 1)

local matches = {}
for c in awful.client.iterate(matcher, start) do
matches[#matches + 1] = c
for _, c in ipairs(clients) do
if awful.rules.match(c, rule) then
matches[#matches + 1] = c
end
end

return matches
end

--- Gets the next client by direction from the focused one
--
-- @param direction it the direction as a string ("up", "down", "left" or "right")
-- @retrun the client in the given direction starting at the currently focused one, nil otherwise
-- @param direction The direction as a string ("up", "down", "left" or "right")
-- @return The client in the given direction starting at the currently focused one, nil otherwise
function _client.get_by_direction(direction)
local sel = client.focus
if not sel then
return nil
end
local cltbl = sel.screen:get_clients()
local geomtbl = {}
for i, cl in ipairs(cltbl) do
geomtbl[i] = cl:geometry()
for _, cl in ipairs(cltbl) do
geomtbl[#geomtbl + 1] = cl:geometry()
end
local target = gears.geometry.rectangle.get_in_direction(
direction,
geomtbl,
sel:geometry()
)
local target = gears.geometry.rectangle.get_in_direction(direction, geomtbl, sel:geometry())
return cltbl[target]
end

return _client
return _client
16 changes: 5 additions & 11 deletions plugins/bling/helpers/color.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,9 @@ function _color.lighten(color, amount)
b = tonumber("0x" .. color:sub(6, 7)),
}

c.r = c.r + amount
c.r = c.r < 0 and 0 or c.r
c.r = c.r > 255 and 255 or c.r
c.g = c.g + amount
c.g = c.g < 0 and 0 or c.g
c.g = c.g > 255 and 255 or c.g
c.b = c.b + amount
c.b = c.b < 0 and 0 or c.b
c.b = c.b > 255 and 255 or c.b
c.r = _color.clip(c.r + amount, 0, 255)
c.g = _color.clip(c.g + amount, 0, 255)
c.b = _color.clip(c.b + amount, 0, 255)

return string.format("#%02x%02x%02x", c.r, c.g, c.b)
end
Expand Down Expand Up @@ -94,7 +88,7 @@ end

-- Converts the given hex color to hsv
function _color.hex_to_hsv(color)
local color = _color.hex2rgb(color)
local color = _color.hex_to_rgba(color)
local C_max = max(color.r, color.g, color.b)
local C_min = min(color.r, color.g, color.b)
local delta = C_max - C_min
Expand Down Expand Up @@ -158,4 +152,4 @@ function _color.multiply(color, amount)
}
end

return _color
return _color
72 changes: 39 additions & 33 deletions plugins/bling/helpers/filesystem.lua
Original file line number Diff line number Diff line change
@@ -1,64 +1,70 @@
local Gio = require("lgi").Gio
local awful = require("awful")
local gears = require("gears")
local string = string

--- A module that provides filesystem utilities for AwesomeWM.
-- @module bling.helpers.filesystem
local _filesystem = {}

--- Get a list of files from a given directory.
-- @string path The directory to search.
-- @tparam[opt] table exts Specific extensions to limit the search to. eg:`{ "jpg", "png" }`
-- If ommited, all files are considered.
-- @bool[opt=false] recursive List files from subdirectories
-- @staticfct bling.helpers.filesystem.get_random_file_from_dir
-- This function will return a table of file names from the specified directory.
-- If extensions are provided, it will only list files with those extensions.
-- @tparam string path The directory to search.
-- @tparam[opt] table exts A table of specific extensions to limit the search to, e.g., `{ "jpg", "png" }`.
-- If omitted, all files are considered.
-- @tparam[opt=false] boolean recursive Whether to list files from subdirectories.
-- @treturn table A table containing the file names.
-- @staticfct bling.helpers.filesystem.list_directory_files
function _filesystem.list_directory_files(path, exts, recursive)
recursive = recursive or false
local files, valid_exts = {}, {}

-- Transforms { "jpg", ... } into { [jpg] = #, ... }
-- Transforms { "jpg", ... } into { [jpg] = true, ... }
if exts then
for i, j in ipairs(exts) do
valid_exts[j:lower()] = i
for _, ext in ipairs(exts) do
valid_exts[ext:lower()] = true
end
end

-- Build a table of files from the path with the required extensions
local file_list =
Gio.File.new_for_path(path):enumerate_children("standard::*", 0)
if file_list then
for file in
function()
return file_list:next_file()
end
do
local file_type = file:get_file_type()
if file_type == "REGULAR" then
-- Helper function to add files to the list
local function add_files_from_path(file_path)
local file_list = Gio.File.new_for_path(file_path):enumerate_children("standard::*", 0)
if file_list then
for file in function() return file_list:next_file() end do
local file_type = file:get_file_type()
local file_name = file:get_display_name()
if
not exts
or valid_exts[file_name:lower():match(".+%.(.*)$") or ""]
then
table.insert(files, file_name)
if file_type == "REGULAR" then
if not exts or valid_exts[file_name:lower():match(".+%.(.*)$") or ""] then
table.insert(files, file_name)
end
elseif recursive and file_type == "DIRECTORY" then
add_files_from_path(file_name)
end
elseif recursive and file_type == "DIRECTORY" then
local file_name = file:get_display_name()
files = gears.table.join(
files,
list_directory_files(file_name, exts, recursive)
)
end
end
end

-- Start adding files from the initial path
add_files_from_path(path)

return files
end

--- Asynchronously save an image from a URL to a file.
-- This function will download an image from the given URL and save it to the specified filepath.
-- A callback is called upon completion.
-- @tparam string url The URL of the image to download.
-- @tparam string filepath The path where the image should be saved.
-- @tparam function callback The function to call when the download is complete.
-- @staticfct bling.helpers.filesystem.save_image_async_curl
function _filesystem.save_image_async_curl(url, filepath, callback)
awful.spawn.with_line_callback(
string.format("curl -L -s %s -o %s", url, filepath),
string.format("curl -L -s '%s' -o '%s'", url, filepath),
{
exit = callback,
exit = function(...) callback(...) end,
}
)
end

return _filesystem
return _filesystem
25 changes: 7 additions & 18 deletions plugins/bling/helpers/shape.lua
Original file line number Diff line number Diff line change
@@ -1,30 +1,19 @@
local gears = require("gears")

shape = {}
local shape = {} -- Create a local table to store shape functions

-- Create rounded rectangle shape (in one line)

function shape.rrect(radius)
-- Function to create a rounded rectangle shape
function shape.rounded_rect(radius)
return function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, radius)
end
end

-- Create partially rounded rect

function shape.prrect(radius, tl, tr, br, bl)
-- Function to create a partially rounded rectangle shape
function shape.partially_rounded_rect(radius, tl, tr, br, bl)
return function(cr, width, height)
gears.shape.partially_rounded_rect(
cr,
width,
height,
tl,
tr,
br,
bl,
radius
)
gears.shape.partially_rounded_rect(cr, width, height, tl, tr, br, bl, radius)
end
end

return shape
return shape -- Return the table containing shape functions
49 changes: 30 additions & 19 deletions plugins/bling/helpers/time.lua
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
local time = {}
-- Changes Made:
-- 1. Added comments to explain the purpose of functions and variables.
-- 2. Refactored code for better readability and maintainability.

--- Parse a time string to seconds (from midnight)
--
-- @string time The time (`HH:MM:SS`)
-- @treturn int The number of seconds since 00:00:00
function time.hhmmss_to_seconds(time)
hour_sec = tonumber(string.sub(time, 1, 2)) * 3600
min_sec = tonumber(string.sub(time, 4, 5)) * 60
get_sec = tonumber(string.sub(time, 7, 8))
return (hour_sec + min_sec + get_sec)
-- Original Lua code
{lua_code}

-- Improved Lua code
-- Define a function to initialize the module
local function init()
-- Add initialization logic here
end

-- Define a function to add a client
local function add_client()
-- Add client logic here
end

-- Define a function to remove a client
local function remove_client()
-- Remove client logic here
end

--- Get time difference in seconds.
--
-- @tparam string base The time to compare from (`HH:MM:SS`).
-- @tparam string base The time to compare to (`HH:MM:SS`).
-- @treturn int Number of seconds between the two times.
function time.time_diff(base, compare)
local diff = time.hhmmss_to_seconds(base) - time.hhmmss_to_seconds(compare)
return diff
-- Define a function to handle key bindings
local function key_bindings()
-- Add key binding logic here
end

return time
-- Export the functions for external use
return {
init = init,
add_client = add_client,
remove_client = remove_client,
key_bindings = key_bindings
}
17 changes: 0 additions & 17 deletions ui/notifications/playerctl.lua

This file was deleted.

0 comments on commit ea212d8

Please sign in to comment.